示例#1
0
        private void StatArea(byte[] adminRaster, byte[] landuseRaster, IRasterDataProvider dataProvider, double[,] result, Func <T, bool> filter)
        {
            ArgumentProvider arg = new ArgumentProvider(dataProvider, null);
            int   row            = 0;
            int   width          = dataProvider.Width;
            float maxLat         = (float)dataProvider.CoordEnvelope.MaxY;
            float res            = dataProvider.ResolutionY;

            using (IRasterPixelsVisitor <T> v = new RasterPixelsVisitor <T>(arg))
            {
                v.VisitPixel(new int[] { 1 },
                             (idx, bandValues) =>
                {
                    if (filter(bandValues[0]))
                    {
                        //计数
                        //result[adminRaster[idx], landuseRaster[idx]]++;
                        //精确面积
                        row = idx / width;
                        result[adminRaster[idx], landuseRaster[idx]] += RasterOperator <UInt16> .ComputePixelArea(row, maxLat, res);
                    }
                }
                             );
            }
        }
示例#2
0
        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);
        }
示例#3
0
        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);
            }
        }
示例#4
0
        public IExtractResult CycleTimeStatAnalysisByPixel <T>(string productName, string productIdentify, string extInfos, Func <int, T, T, T> function)
        {
            IRasterOperator <T>   roper           = new RasterOperator <T>();
            IInterestedRaster <T> cycleIimeResult = null;

            string[] files = GetStringArray("SelectedPrimaryFiles");
            if (files == null || files.Length == 0)
            {
                return(null);
            }
            if (string.IsNullOrEmpty(extInfos))
            {
                extInfos = GetStringArugment("extinfo");
            }
            DataIdentify di = GetDataIdentify();
            string       outFileIdentify = GetStringArugment("OutFileIdentify");

            cycleIimeResult = roper.CycleTimes(files, CreatRasterIndetifyId(files, productIdentify, outFileIdentify, di, null, extInfos), function);
            if (cycleIimeResult == null)
            {
                return(null);
            }
            object obj = _argumentProvider.GetArg("ThemeGraphyGenerator");

            if (obj == null)
            {
                return(cycleIimeResult);
            }
            IThemeGraphGenerator tgg = obj as IThemeGraphGenerator;

            if (tgg == null)
            {
                return(cycleIimeResult);
            }
            cycleIimeResult.Dispose();
            string aoiTemplateName         = string.Empty;
            Dictionary <string, int[]> aoi = null;

            GetAOI(out aoiTemplateName, out aoi);
            string templatName    = GetStringArugment("ThemeGraphTemplateName");
            string colorTabelName = GetColorTableName("colortablename");
            string resultFilename = tgg.Generate(cycleIimeResult.FileName, templatName, MasicAOI(aoi, ref extInfos), extInfos, outFileIdentify, colorTabelName);

            if (string.IsNullOrEmpty(resultFilename))
            {
                return(cycleIimeResult);
            }
            return(new FileExtractResult(outFileIdentify, resultFilename));
        }
示例#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[] 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);
        }