def getBoundingBoxScene(product): logger = logging.getLogger('root') gc = product.getSceneGeoCoding() rsize = product.getSceneRasterSize() h = rsize.getHeight() w = rsize.getWidth() p1 = gc.getGeoPos(PixelPos(0, 0), None) p2 = gc.getGeoPos(PixelPos(0, h), None) p3 = gc.getGeoPos(PixelPos(w, h), None) p4 = gc.getGeoPos(PixelPos(w, 0), None) rect = Polygon([(p1.getLon(), p1.getLat()), (p2.getLon(), p2.getLat()), (p3.getLon(), p3.getLat()), (p4.getLon(), p4.getLat())]) rect_utm = utils.wgs2utm(rect) return (rect_utm)
def findProductCornerInAuxData(product): width = product.getSceneRasterWidth() height = product.getSceneRasterHeight() cornerX = [0 + 0.5, 0 + 0.5, width - 0.5, width - 0.5] cornerY = [0 + 0.5, height - 0.5, 0 + 0.5, height - 0.5] cornerLat = [] cornerLon = [] for x, y in zip(cornerX, cornerY): pixelPos = PixelPos(x + 0.5, y + 0.5) geoPos = product.getSceneGeoCoding().getGeoPos(pixelPos, None) cornerLat.append(geoPos.getLat() + 90.) # only positive indeces! cornerLon.append(geoPos.getLon() + 180.) # only positive indeces! # if geoPos.getLon() < 0: # cornerLon.append(360 - geoPos.getLon()) # else: # cornerLon.append(geoPos.getLon()) minLat = np.min(cornerLat) maxLat = np.max(cornerLat) minLon = np.min(cornerLon) maxLon = np.max(cornerLon) coordXmin = np.floor(minLon) coordXmax = np.round(maxLon) if coordXmax < maxLon: coordXmax += 1 coordYmin = np.floor(minLat) coordYmax = np.round(maxLat) if coordYmax < maxLat: coordYmax += 1 return coordXmin.astype(np.int32), coordXmax.astype(np.int32), coordYmin.astype(np.int32), coordYmax.astype(np.int32)
def getGeoPositionsForS2Product(product, reshape=True, subset=None): if subset is None: height = product.getSceneRasterHeight() width = product.getSceneRasterWidth() sline, eline, scol, ecol = 0, height-1, 0, width -1 else: sline,eline,scol,ecol = subset height = eline - sline + 1 width = ecol - scol + 1 latitude = np.zeros((height, width)) longitude = np.zeros((height, width)) for ix, x in enumerate(range(scol, ecol+1)): for iy, y in enumerate(range(sline, eline+1)): pixelPos = PixelPos(x + 0.5, y + 0.5) geoPos = product.getSceneGeoCoding().getGeoPos(pixelPos, None) latitude[iy,ix] = geoPos.getLat() longitude[iy, ix] = geoPos.getLon() if not reshape: latitude.shape = (height*width) longitude.shape = (height*width) return latitude, longitude
def get_subset(files1, files2): files1_geocoding = files1.getSceneRasterGeoCoding() files2_geocoding = files2.getSceneRasterGeoCoding() height = files1.getSceneRasterHeight() width =files1.getSceneRasterWidth() for h in range(1, height): for w in range(1, width): g = files1_geocoding.getGeoPos(PixelPos(w, h), None) p = files2_geocoding.getPixelPos(g, None) if files2.containsPixel(p):
def pixel_position(inprod, inlat, inlon): """Get pixel position in a product. Extract the pixel position from a product, based on lat / lon coordinates. Args: inprod (java.lang.Object): SNAP image product inlat (float): latitude of the coordinate in degrees EPSG:4326 inlon (float): longitude of the coordinate in degrees EPSG:4326 Returns: (tuple): pixel coordinates xx: (int), yy: (int). Returns "None" if\ pixel is out of bounds. """ # Read lat/lon position into a GeoPos item gpos = GeoPos(inlat, inlon) # Retrieve pixel position of lat/lon values pixpos = inprod.getSceneGeoCoding().getPixelPos(gpos, PixelPos()) # If the pixpos coordinates are NaN, the queried position is outside of the # image bands if math.isnan(pixpos.getX()) or math.isnan(pixpos.getY()): xx = None yy = None # Set coordinates to None if pixpos X/Y is larger than scene width/height # (or smaller than zero) elif pixpos.getX() <= 0 or pixpos.getY() <= 0 \ or pixpos.getX() >= inprod.getSceneRasterWidth() \ or pixpos.getY() >= inprod.getSceneRasterHeight(): xx = None yy = None else: # Get pixel position in the product and retrieve pixel position of # lat/lon values. xx = int(pixpos.getX()) yy = int(pixpos.getY()) return (xx, yy)
def xyToLatLonDim(dataset, x, y): pos = dataset.getSceneGeoCoding().getGeoPos(PixelPos(x, y), None) return pos.getLon(), pos.getLat()
print("Wind vector created and added to image!") # ------------------------------------------------------------------------------------------- ################### MAKING KMZ AND KML FILES #################### print ("Making KML/KMZ files...") band_lat = target_2.getBand('latitude') band_long = target_2.getBand('longitude') group = PixelGeoCoding(band_lat, band_long, None, 5) # TODO: Check last parameter (is 5 optimal?) imHeight = band_lat.getRasterHeight() imWidth = band_lat.getRasterWidth() boundNorth = group.getGeoPos(PixelPos(imWidth, 0), GeoPos()).getLat() boundWest = group.getGeoPos(PixelPos(0, imHeight), GeoPos()).getLon() boundEast = group.getGeoPos(PixelPos(imWidth, imHeight), GeoPos()).getLon() boundSouth = group.getGeoPos(PixelPos(imWidth, imHeight), GeoPos()).getLat() print boundNorth, boundWest, boundEast, boundSouth # TODO: KMZ generating on hold since I dont know how to show them directly dirName = fileName """ os.makedirs('kmzfiles/' + dirName) kmz_saveName = 'kmzfiles/' + dirName + '/' + fileName + '.png' cv2.imwrite(kmz_saveName, img) print "Writing KML file..." # TODO: Make legend (bar that shows backscatter color scale) txt_file = open('kmzfiles/' + dirName + "/doc.kml", "w")