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); }
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); } }
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 }); }
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); }