def open_subset(self, geo_extent, copymetadata="true"): """ Create a subset of a given SNAP product. From a given set of coordinates defining a region of interest create a subset product containing all the bands from the original product. Args: inprod: ESA SNAP product object geo_extent (wkt): BoundingBox in WKT format copymetadata (bool): Copy all bands to subset product Returns: (self.product): ESA SNAP product object """ # Empty HashMap parameters = HashMap() # Subset parameters geo = WKTReader().read(geo_extent) parameters.put("geoRegion", geo) parameters.put("subSamplingX", "1") parameters.put("subSamplingY", "1") parameters.put("copyMetadata", copymetadata) # Create subset using operator prod_subset = GPF.createProduct("Subset", parameters, self.product) # Update product self.product = prod_subset # Close dataset prod_subset = None
def subset(product, shpPath): parameters = HashMap() wkt = shpToWKT(shpPath) SubsetOp = jpy.get_type('org.esa.snap.core.gpf.common.SubsetOp') geometry = WKTReader().read(wkt) parameters.put('copyMetadata', True) parameters.put('geoRegion', geometry) return GPF.createProduct('Subset', parameters, product)
def make_subset(product, wkt): print("Making subset") SubsetOp = snappy.jpy.get_type('org.esa.snap.core.gpf.common.SubsetOp') geom = WKTReader().read(wkt) op = SubsetOp() op.setSourceProduct(product) op.setGeoRegion(geom) sub_product = op.getTargetProduct() return sub_product
def get_subset_config(wkt, bands=None): parameters = HashMap() if bands is not None: parameters.put("sourceBands", bands) if wkt is not None: geom = WKTReader().read(wkt) parameters.put("geoRegion", geom) parameters.put("copyMetadata", True) parameters.put("outputImageScaleInDb", False) return parameters
def preprocesado(): ##Aplicar correccion orbital global product global product_calibrated global HashMap print(product) parameters = HashMap() GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() parameters.put('orbitType', 'Sentinel Precise (Auto Download)') parameters.put('polyDegree', '3') parameters.put('continueOnFail', 'false') apply_orbit_file = GPF.createProduct('Apply-Orbit-File', parameters, product) ##Recortar la imagen r = shapefile.Reader(archivo_shape) g = [] for s in r.shapes(): g.append(pygeoif.geometry.as_shape(s)) m = pygeoif.MultiPoint(g) wkt = str(m.wkt).replace("MULTIPOINT", "POLYGON(") + ")" #Usar el shapefile para cortar la imagen SubsetOp = snappy.jpy.get_type('org.esa.snap.core.gpf.common.SubsetOp') bounding_wkt = wkt geometry = WKTReader().read(bounding_wkt) HashMap = snappy.jpy.get_type('java.util.HashMap') GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() parameters = HashMap() parameters.put('copyMetadata', True) parameters.put('geoRegion', geometry) product_subset = snappy.GPF.createProduct('Subset', parameters, apply_orbit_file) #Mostrar las dimensiones de la imagen width = product_subset.getSceneRasterWidth() print("Width: {} px".format(width)) height = product_subset.getSceneRasterHeight() print("Height: {} px".format(height)) band_names = product_subset.getBandNames() print("Band names: {}".format(", ".join(band_names))) band = product_subset.getBand(band_names[0]) print(band.getRasterSize()) #plotBand(product_subset, "Intensity_VV", 0, 100000) ##Aplicar la calibracion de la imagen parameters = HashMap() parameters.put('outputSigmaBand', True) parameters.put('sourceBands', 'Intensity_VV') parameters.put('selectedPolarisations', "VV") parameters.put('outputImageScaleInDb', False) product_calibrated = GPF.createProduct("Calibration", parameters, product_subset) #plotBand(product_calibrated, "Sigma0_VV", 0, 1) print("PREPROCESAMIENTO HECHO EXITOSAMENTE")
def subsetProduct(product, pol): # if pol.area<1000: buff = pol.buffer((pol.area)**0.5) # else: # buff=pol.buffer((pol.area)**0.5) bb = getBoundingBoxWM(buff) bb_ll = utils.utm2wgs(bb) geom = WKTReader().read(bb_ll.wkt) parameters = HashMap() parameters.put('copyMetadata', True) parameters.put('geoRegion', geom) product_subset = GPF.createProduct('Subset', parameters, product) return (product_subset)
import snappy from snappy import ProductIO, WKTReader SubsetOp = snappy.jpy.get_type('org.esa.snap.core.gpf.common.SubsetOp') if len(sys.argv) != 3: print("usage: %s <file> <geometry-wkt>" % sys.argv[0]) print( " %s ./TEST.N1 \"POLYGON((15.786082 45.30223, 11.798364 46.118263, 10.878688 43.61961, 14.722727" "42.85818, 15.786082 45.30223))\"" % sys.argv[0]) sys.exit(1) file = sys.argv[1] wkt = sys.argv[2] geom = WKTReader().read(wkt) print("Reading...") product = ProductIO.readProduct(file) op = SubsetOp() op.setSourceProduct(product) op.setGeoRegion(geom) op.setCopyMetadata(True) sub_product = op.getTargetProduct() print("Writing...") ProductIO.writeProduct(sub_product, "snappy_subset_output.dim", "BEAM-DIMAP") print("Done.")
WKTReader, ProductIO, PlainFeatureFactory, SimpleFeatureBuilder, DefaultGeographicCRS, ListFeatureCollection, FeatureUtils) if len(sys.argv) != 3: print("usage: %s <inputProduct> <wkt>" % sys.argv[0]) sys.exit(1) input = sys.argv[1] inputFileName = input[input.rfind('/')+1:] wellKnownText = sys.argv[2] try: geometry = WKTReader().read(wellKnownText) except: geometry = None print('Failed to convert WKT into geometry') sys.exit(2) product = ProductIO.readProduct(input) wktFeatureType = PlainFeatureFactory.createDefaultFeatureType(DefaultGeographicCRS.WGS84) featureBuilder = SimpleFeatureBuilder(wktFeatureType) wktFeature = featureBuilder.buildFeature('shape') wktFeature.setDefaultGeometry(geometry) newCollection = ListFeatureCollection(wktFeatureType) newCollection.add(wktFeature)
import shapefile import pygeoif shp_file_path = "E:\Sentinel 1 SAR Processing\Sentinel_Mosaic\Data\Spatial Data\NPL_adm0.shp" shp_file = shapefile.Reader(shp_file_path) g = [] for s in shp_file.shapes(): g.append(pygeoif.geometry.as_shape(s)) m = pygeoif.MultiPoint(g) wkt = str(m.wkt).replace("MULTIPOINT", "POLYGON(") + ")" geometry = WKTReader().read(wkt) SRTM1SEC = "SRTM 1Sec HGT" UTM_WGS84 = "GEOGCS[\"WGS84(DD)\",DATUM[\"WGS84\",SPHEROID[\"WGS84\", 6378137.0, 298.257223563]]," \ "PRIMEM[\"Greenwich\", 0.0],UNIT[\"degree\", 0.017453292519943295],AXIS[\"Geodetic longitude\", EAST]," \ "AXIS[\"Geodetic latitude\", NORTH]] " def TOPSAR_Split_config(subswath, firstBurstIndex, lastBurstIndex, polarizations): """ This function .... """ parameters = HashMap() parameters.put('subswath', subswath)
def preproceso(product, wkt): global HashMap parameters = HashMap() GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() parameters.put('orbitType', 'Sentinel Precise (Auto Download)') parameters.put('polyDegree', '3') parameters.put('continueOnFail', 'false') global apply_orbit_file apply_orbit_file = GPF.createProduct('Apply-Orbit-File', parameters, product) #Usar el shapefile para cortar la imagen #def CorteUsandoShapefile(product, apply_orbit_file, wkt): # global HashMap SubsetOp = snappy.jpy.get_type('org.esa.snap.core.gpf.common.SubsetOp') bounding_wkt = wkt geometry = WKTReader().read(bounding_wkt) HashMap = snappy.jpy.get_type('java.util.HashMap') GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis() parameters = HashMap() parameters.put('copyMetadata', True) parameters.put('geoRegion', geometry) product_subset = snappy.GPF.createProduct('Subset', parameters, apply_orbit_file) #Mostrar las dimensiones de la imagen width = product_subset.getSceneRasterWidth() print("Width: {} px".format(width)) height = product_subset.getSceneRasterHeight() print("Height: {} px".format(height)) band_names = product_subset.getBandNames() print("Band names: {}".format(", ".join(band_names))) band = product_subset.getBand(band_names[0]) print(band.getRasterSize()) plotBand(product_subset, "Intensity_VV", 0, 100000) #return product_subset #def CalibracionImagen(product_subset): ##Aplicar la calibracion de la imagen parameters = HashMap() parameters.put('outputSigmaBand', True) parameters.put('sourceBands', 'Intensity_VV') parameters.put('selectedPolarisations', "VV") parameters.put('outputImageScaleInDb', False) product_calibrated = GPF.createProduct("Calibration", parameters, product_subset) plotBand(product_calibrated, "Sigma0_VV", 0, 1) #def filtroSpeckle(product_calibrated): ##Aplicar el filtro Speckle filterSizeY = '5' filterSizeX = '5' parameters = HashMap() parameters.put('sourceBands', 'Sigma0_VV') parameters.put('filter', 'Lee') parameters.put('filterSizeX', filterSizeX) parameters.put('filterSizeY', filterSizeY) parameters.put('dampingFactor', '2') parameters.put('estimateENL', 'true') parameters.put('enl', '1.0') parameters.put('numLooksStr', '1') parameters.put('targetWindowSizeStr', '3x3') parameters.put('sigmaStr', '0.9') parameters.put('anSize', '50') speckle_filter = snappy.GPF.createProduct('Speckle-Filter', parameters, product_calibrated) plotBand(speckle_filter, 'Sigma0_VV', 0, 1) #def CorreccionTerreno(speckle_filter): ##Aplicar la correccion del terremo parameters = HashMap() parameters.put('demName', 'SRTM 3Sec') parameters.put('pixelSpacingInMeter', 10.0) parameters.put('sourceBands', 'Sigma0_VV') global speckle_filter_tc speckle_filter_tc = GPF.createProduct("Terrain-Correction", parameters, speckle_filter) plotBand(speckle_filter_tc, 'Sigma0_VV', 0, 0.1)