コード例 #1
0
        private void DrawDynamicResult(byte[] bytes, int width, int height)
        {
            var currentFolder = _dataFolders.Last();

            //ДО того, что было
            var             oldImageFolder     = _dataFolders.First();
            var             oldDescription     = new LandsatDataDescription(oldImageFolder);
            CuttedImageInfo oldCuttedImageInfo = ClipImageHelper.GetCuttedImageInfoByPolygon(oldDescription.Channel4.Raw, _polygon);

            DrawLib.DrawNaturalColor(oldDescription.Channel4.Normalized
                                     , oldDescription.Channel3.Normalized
                                     , oldDescription.Channel2.Normalized,
                                     oldCuttedImageInfo, _pathToVisibleImage + "-old.png");



            var landsatDescription = new LandsatDataDescription(currentFolder);

            CuttedImageInfo cuttedImageInfo = ClipImageHelper.GetCuttedImageInfoByPolygon(landsatDescription.Channel4.Raw, _polygon);

            DrawLib.DrawMask(bytes, width, height, _pathToDynamicFile);

            DrawLib.DrawEdges(_pathToDynamicFile, _pathToEdgedDynamicFile);

            DrawChannelsAccordingToPhenomenonType(_phenomenon, landsatDescription, cuttedImageInfo);

            DrawLib.DrawMask(_pathToEdgedDynamicFile, _pathToVisibleImage + "4-3-2.png", _pathToVisibleDynamicFile);
        }
コード例 #2
0
        public static bool CloudValidation(string[] folders, GeographicPolygon polygon, string resultCloudMaskTifFilename, string resultCloudMaskPngFilename)
        {
            byte[]           cloudMask     = null;
            int              width         = 0;
            SpatialReference tifProjection = null;
            int              height        = 0;
            var              utmPolygon    = new UtmPolygon();

            foreach (var folder in folders)
            {
                var landsatData = new LandsatDataDescription(folder);
                var qaFile      = landsatData.ChannelBqa;

                using (var ds = Gdal.Open(qaFile, Access.GA_ReadOnly))
                {
                    double[] geotransform = new double[6];
                    ds.GetGeoTransform(geotransform);

                    utmPolygon = Helper.ConvertGeographicPolygonToUtm(polygon, ds);

                    using (var band = ds.GetRasterBand(1))
                    {
                        var projectionRef = ds.GetProjectionRef();
                        tifProjection = new SpatialReference(projectionRef);

                        var cuttedImageInfo = ClipImageHelper.GetCuttedImageInfoByPolygonData(utmPolygon, geotransform);

                        cloudMask = cloudMask ?? new byte[cuttedImageInfo.Width * cuttedImageInfo.Height];
                        cloudMask = GetCloudMaskByBandAndCoordinates(band, cuttedImageInfo, cloudMask);

                        width  = cuttedImageInfo.Width;
                        height = cuttedImageInfo.Height;
                    }
                }
            }

            if (cloudMask == null)
            {
                return(false);
            }

            double cloudedPointCount = cloudMask.Count(x => x != 0);

            var percentOfCloudedPoints = cloudedPointCount / cloudMask.Count();

            bool isValidCloudy = percentOfCloudedPoints < 0.14;

            tifProjection.ExportToWkt(out var inputShapeSrs);
            double[] argin = { polygon.UpperLeft.Latitude, 30, 0, polygon.UpperLeft.Longitude, 0, -30 };

            Helper.SaveDataInFile(resultCloudMaskTifFilename, cloudMask, width, height, DataType.GDT_Byte, argin, inputShapeSrs);
            DrawLib.DrawMask(cloudMask, width, height, resultCloudMaskPngFilename);

            return(isValidCloudy);
        }