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); }
public override string[] Process(IGeographicPoint leftUpper, IGeographicPoint rigthLower, string dataFolder, string resultFolder) { LandsatDataDescription landsatDescription = new LandsatDataDescription(dataFolder); CuttedImageInfo cuttedImageInfo = ClipImageHelper.GetCuttedImageInfoByPolygon(landsatDescription.Channel4.Raw, new GeographicPolygon { UpperLeft = leftUpper, LowerRight = rigthLower }); string resultFileName; string redChannelFileName; string blueChannelFileName; string greenChannelFileName; switch (_characteristicType) { case CharacteristicType.Channels543: { redChannelFileName = landsatDescription.Channel5.Normalized; greenChannelFileName = landsatDescription.Channel4.Normalized; blueChannelFileName = landsatDescription.Channel3.Normalized; resultFileName = resultFolder + "5-4-3.jpg"; break; } case CharacteristicType.Channels753: { redChannelFileName = landsatDescription.Channel7.Normalized; greenChannelFileName = landsatDescription.Channel5.Normalized; blueChannelFileName = landsatDescription.Channel3.Normalized; resultFileName = resultFolder + "7-5-3.jpg"; break; } case CharacteristicType.Channels432: case CharacteristicType.Unknown: default: { redChannelFileName = landsatDescription.Channel4.Normalized; greenChannelFileName = landsatDescription.Channel3.Normalized; blueChannelFileName = landsatDescription.Channel2.Normalized; resultFileName = resultFolder + "4-3-2.jpg"; break; } } DrawLib.DrawNaturalColor(redChannelFileName , greenChannelFileName , blueChannelFileName, cuttedImageInfo, resultFileName); return(new string[] { resultFileName }); }
private void SaveDynamicGeoPoints() { var dynamicPoints = DrawLib.GetMaskIndexes(_pathToEdgedDynamicFile); var landsatDescription = new LandsatDataDescription(_dataFolders.Last()); var currentTemporaryImage = landsatDescription.Channel4.Raw; var geographicPoints = ClipImageHelper.GetGeographicPointsByPointsIndexes(dynamicPoints, currentTemporaryImage, _polygon); JsonHelper.Serialize(_pathToDynamicPointsJson, geographicPoints); }
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); }
public override string[] Process(IGeographicPoint leftUpper, IGeographicPoint rigthLower, string dataFolder, string resultFolder) { var pathToEdgedDynamic = $@"{dataFolder}{FilenamesConstants.PathToEdgedDynamicFile}"; var pathToAreOfDamageResult = $@"{resultFolder}{FilenamesConstants.PathToDamagedAreaResult}"; var amountOfDynamicPoints = DrawLib.GetAmountOfDynamicPoints(pathToEdgedDynamic); double areaOfDamage = amountOfDynamicPoints * LandsatPixelSize; var resultPath = JsonHelper.Serialize(pathToAreOfDamageResult, new AreaOfDamageResult { AreaOfDamage = areaOfDamage, DamagedPointsCount = amountOfDynamicPoints }); return(new[] { resultPath }); }
private void DrawChannelsAccordingToPhenomenonType(PhenomenonType phenomenonType , LandsatDataDescription landsatDescription , CuttedImageInfo cuttedImageInfo) { switch (phenomenonType) { case PhenomenonType.ForestPlantationsDeseases: { DrawLib.DrawNaturalColor(landsatDescription.Channel4.Normalized , landsatDescription.Channel3.Normalized , landsatDescription.Channel2.Normalized, cuttedImageInfo, _pathToVisibleImage + "4-3-2.png"); DrawLib.DrawNaturalColor(landsatDescription.Channel5.Normalized , landsatDescription.Channel4.Normalized , landsatDescription.Channel3.Normalized, cuttedImageInfo, _pathToVisibleImage + "5-4-3.png"); DrawLib.DrawNaturalColor(landsatDescription.Channel7.Normalized , landsatDescription.Channel5.Normalized , landsatDescription.Channel3.Normalized, cuttedImageInfo, _pathToVisibleImage + "7-5-3.png"); } break; case PhenomenonType.SoilErosion: { DrawLib.DrawNaturalColor(landsatDescription.Channel7.Normalized , landsatDescription.Channel5.Normalized , landsatDescription.Channel3.Normalized, cuttedImageInfo, _pathToVisibleImage + "7-5-3.png"); DrawLib.DrawNaturalColor(landsatDescription.Channel4.Normalized , landsatDescription.Channel3.Normalized , landsatDescription.Channel2.Normalized, cuttedImageInfo, _pathToVisibleImage + "4-3-2.png"); } break; case PhenomenonType.SoilPollutionByOilProducts: { DrawLib.DrawNaturalColor(landsatDescription.Channel4.Normalized , landsatDescription.Channel3.Normalized , landsatDescription.Channel2.Normalized, cuttedImageInfo, _pathToVisibleImage + "4-3-2.png"); } break; case PhenomenonType.SurfaceDumps: { DrawLib.DrawNaturalColor(landsatDescription.Channel4.Normalized , landsatDescription.Channel3.Normalized , landsatDescription.Channel2.Normalized, cuttedImageInfo, _pathToVisibleImage + "4-3-2.png"); } break; case PhenomenonType.Unknown: { DrawLib.DrawNaturalColor(landsatDescription.Channel4.Normalized , landsatDescription.Channel3.Normalized , landsatDescription.Channel2.Normalized, cuttedImageInfo, _pathToVisibleImage + "4-3-2.png"); } break; } }