コード例 #1
0
ファイル: AOITemplateStat.cs プロジェクト: configare/hispeed
        public StatResultItem[] CountByVector(IRasterDataProvider raster, Dictionary <string, int[]> aoi, Func <T, bool> filter)
        {
            if (filter == null)
            {
                return(null);
            }
            if (aoi == null || aoi.Count == 0)
            {
                return(null);
            }
            double lon   = raster.CoordEnvelope.Center.X;
            double lat   = raster.CoordEnvelope.Center.Y;
            int    count = 0;
            List <StatResultItem> items = new List <StatResultItem>();
            IRasterOperator <T>   oper  = new RasterOperator <T>();

            foreach (string fea in aoi.Keys)
            {
                if (aoi[fea] == null)
                {
                    count = 0;
                }
                else
                {
                    count = oper.Count(raster, aoi[fea], filter);
                }
                StatResultItem it = new StatResultItem();
                it.Name = fea;
                double d = AreaCountHelper.CalcArea(lon, lat, raster.ResolutionX, raster.ResolutionY) * count * Math.Pow(10, -6);
                it.Value = Math.Round(d, 3);
                items.Add(it);
            }
            return(items != null?items.ToArray() : null);
        }
コード例 #2
0
        private StatResultItem[] DoStatByAdminAndLanduseType(IRasterDataProvider raster, Func <T, bool> filter)
        {
            SataAdminAndLandUse <T> stat = new SataAdminAndLandUse <T>();
            Dictionary <string, Dictionary <string, double> > result = stat.StatArea(raster, filter);

            if (result == null)
            {
                return(null);
            }
            List <StatResultItem> items = new List <StatResultItem>();

            foreach (string admin in result.Keys)
            {
                if (result[admin] == null)
                {
                    continue;
                }
                foreach (string landuse in result[admin].Keys)
                {
                    if (result[admin][landuse] == 0)
                    {
                        continue;
                    }
                    StatResultItem it = new StatResultItem();
                    it.Name  = admin + "_" + landuse;
                    it.Value = result[admin][landuse];
                    items.Add(it);
                }
            }
            return(items.Count > 0 ? items.ToArray() : null);
        }
コード例 #3
0
        public StatResultItem[] StatAreaCustom(IRasterDataProvider raster, Dictionary <string, int[]> aoi, Func <T, int, int> weight)
        {
            if (weight == null)
            {
                return(null);
            }
            StatResultItem[] results = null;
            results = ApplyStatByVectorProvider(raster, aoi, weight);
            if (results == null || results.Length == 0)
            {
                return(null);
            }
            List <StatResultItem> primaryItems = new List <StatResultItem>();
            StatResultItem        item         = null;

            foreach (string name in aoi.Keys)
            {
                item = MatchItemInResults(name, results);
                if (item != null)
                {
                    primaryItems.Add(item);
                }
            }
            if (primaryItems.Count == 0)
            {
                return(null);
            }
            return(primaryItems.ToArray());
        }
コード例 #4
0
ファイル: AOITemplateStat.cs プロジェクト: configare/hispeed
        public StatResultItem[] CountByVector(IRasterDataProvider raster, string shpFullname, string shpPrimaryField, Func <T, int, int> weight)
        {
            if (weight == null)
            {
                return(null);
            }
            if (String.IsNullOrEmpty(shpFullname))
            {
                return(null);
            }
            //step2:读取矢量
            CodeCell.AgileMap.Core.Feature[] features = GetFeatures(shpFullname);
            if (features == null || features.Length == 0)
            {
                return(null);
            }
            double lon = raster.CoordEnvelope.Center.X;
            double lat = raster.CoordEnvelope.Center.Y;

            //step3:矢量栅格化
            Dictionary <string, Color> nameColors = new Dictionary <string, Color>();

            using (Bitmap bitmap = VectorsToBitmap(raster, features, shpPrimaryField, out nameColors))
            {
                int[]  aoi;
                Color  color;
                int    count;
                string name;
                List <StatResultItem> items = new List <StatResultItem>();
                IRasterOperator <T>   oper  = new RasterOperator <T>();
                foreach (Feature fea in features)
                {
                    name = fea.GetFieldValue(shpPrimaryField);
                    if (String.IsNullOrEmpty(name))
                    {
                        continue;
                    }
                    color = nameColors[name];
                    aoi   = GetAOIByFeature(bitmap, color);
                    if (aoi == null)
                    {
                        count = 0;
                    }
                    else
                    {
                        count = oper.Count(raster, aoi, weight);
                    }
                    StatResultItem it = new StatResultItem();
                    it.Name = name;
                    it.Code = fea.OID.ToString();
                    double d = AreaCountHelper.CalcArea(lon, lat, raster.ResolutionX, raster.ResolutionY) * count * Math.Pow(10, -6);
                    it.Value = Math.Round(d, 3);
                    items.Add(it);
                }
                return(items != null?items.ToArray() : null);
            }
        }
コード例 #5
0
        private static StatResultItem[] AreaStatCurrentRegion <T>(IRasterDataProvider prd, string title, Func <T, bool> filter)
        {
            RasterOperator <T> oper = new RasterOperator <T>();
            int            count    = oper.Count(prd, null, filter);
            StatResultItem sri      = new StatResultItem();

            sri.Name = "当前区域";
            //精细面积计算
            //sri.Value = oper.Area(prd, null, filter);
            double lon = prd.CoordEnvelope.Center.X;
            double lat = prd.CoordEnvelope.Center.Y;

            sri.Value = Math.Round(count * AreaCountHelper.CalcArea(lon, lat, prd.ResolutionX, prd.ResolutionX) / Math.Pow(10, 6), 3);
            return(new StatResultItem[] { sri });
        }
コード例 #6
0
        private StatResultItem MatchItemInResults(string name, StatResultItem[] results)
        {
            StatResultItem result = null;

            foreach (StatResultItem item in results)
            {
                if (name == item.Name)
                {
                    return(item);
                }
            }
            result       = new StatResultItem();
            result.Name  = name;
            result.Value = 0;
            return(result);
        }
コード例 #7
0
        public StatResultItem[] StatAreaCustom(IRasterDataProvider raster, string templateName, string[] FiledNames, string primaryFieldName, Func <T, bool> filter)
        {
            if (filter == null)
            {
                return(null);
            }
            StatResultItem[] results = null;
            switch (templateName)
            {
            case "分级行政区划":
                results = ApplyStatByRasterTemplate(raster, templateName, filter);
                break;

            case "省级行政区划":
                results = ApplyStatByVectorTemplate(raster, "省级行政区域_面.shp", primaryFieldName, filter);
                break;

            case "土地利用类型":
                results = ApplyStatByVectorTemplate(raster, "土地利用类型_合并.shp", primaryFieldName, filter);
                break;

            default:
                results = ApplyStatByVectorProvider(raster, templateName, primaryFieldName, filter);
                break;
            }
            if (results == null || results.Length == 0)
            {
                return(null);
            }
            List <StatResultItem> primaryItems = new List <StatResultItem>();
            StatResultItem        item         = null;

            foreach (string name in FiledNames)
            {
                item = MatchItemInResults(name, results);
                if (item != null)
                {
                    primaryItems.Add(item);
                }
            }
            if (primaryItems.Count == 0)
            {
                return(null);
            }
            return(primaryItems.ToArray());
        }
コード例 #8
0
ファイル: AOITemplateStat.cs プロジェクト: configare/hispeed
        private StatResultItem[] CountByLandRaster(IRasterDataProvider raster, Func <T, int, int> weight)
        {
            IRasterDictionaryTemplate <byte> temp  = RasterDictionaryTemplateFactory.CreateLandRasterTemplate();
            Dictionary <byte, string>        paris = temp.CodeNameParis;

            if (paris == null)
            {
                return(null);
            }
            double lon = raster.CoordEnvelope.Center.X;
            double lat = raster.CoordEnvelope.Center.Y;
            IRasterOperator <T>   oper  = new RasterOperator <T>();
            List <StatResultItem> items = new List <StatResultItem>();

            int[] aoi;
            int   count;

            foreach (string value in paris.Values)
            {
                aoi = temp.GetAOI(value, raster.CoordEnvelope.MinX, raster.CoordEnvelope.MaxX, raster.CoordEnvelope.MinY, raster.CoordEnvelope.MaxY, new Size(raster.Width, raster.Height));
                if (aoi == null)
                {
                    continue;
                }
                count = oper.Count(raster, aoi, weight);
                if (count == 0)
                {
                    continue;
                }
                StatResultItem it = new StatResultItem();
                it.Name  = value;
                it.Value = count;
                double d = AreaCountHelper.CalcArea(lon, lat, raster.ResolutionX, raster.ResolutionY) * count * Math.Pow(10, -6);
                it.Value = Math.Round(d, 3);
                items.Add(it);
            }
            return(items != null?items.ToArray() : null);
        }
コード例 #9
0
 public void WriteResultToTxt(StatResultItem item)
 {
     _strList.Add(item.Name.PadRight(15, ' ') + "\t" + (item.Value / Zoom).ToString("0.##") + "\n");
 }