Ejemplo n.º 1
0
        public static CuttedImageInfo GetCuttedImageInfoByPolygonData(UtmPolygon utmPolygon, double[] geoTransform)
        {
            //utm-easting upperleft point
            var xinit = geoTransform[0];

            //utm-northing upperleft point
            var yinit = geoTransform[3];

            //размер пикселя
            var xsize = geoTransform[1];
            var ysize = geoTransform[5];

            var row1    = Convert.ToInt32((utmPolygon.UpperLeft.Northing - yinit) / ysize);
            var col1    = Convert.ToInt32((utmPolygon.UpperLeft.Easting - xinit) / xsize);
            var row2    = Convert.ToInt32((utmPolygon.LowerRight.Northing - yinit) / ysize);
            var col2    = Convert.ToInt32((utmPolygon.LowerRight.Easting - xinit) / xsize);
            var colSize = col2 - col1 + 1;
            var rowSize = row2 - row1 + 1;

            var cuttedImageInfo = new CuttedImageInfo
            {
                Col    = col1,
                Row    = row1,
                Width  = colSize,
                Height = rowSize
            };

            return(cuttedImageInfo);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        public static GeographicPolygon ConvertUtmPolygonToGeographic(UtmPolygon utmPolygon, Dataset ds)
        {
            SpatialReference monUtm = new SpatialReference(ds.GetProjectionRef());

            var geoPolygon = new GeographicPolygon();

            SpatialReference monGeo = new SpatialReference(ds.GetProjectionRef());

            monGeo.ImportFromEPSG(4326);
            double[] res = new double[3];

            CoordinateTransformation coordTrans = new CoordinateTransformation(monUtm, monGeo);

            coordTrans.TransformPoint(res, utmPolygon.UpperLeft.Easting, utmPolygon.UpperLeft.Northing, 0);
            geoPolygon.UpperLeft.Longitude = res[0];
            geoPolygon.UpperLeft.Latitude  = res[1];

            coordTrans.TransformPoint(res, utmPolygon.LowerRight.Easting, utmPolygon.LowerRight.Northing, 0);
            geoPolygon.LowerRight.Longitude = res[0];
            geoPolygon.LowerRight.Latitude  = res[1];

            return(geoPolygon);
        }