vector_tools

pymmaster.vector_tools provides tools to manipulate tilings (naming, extents) and vectors (rasterize, buffer, transform, …)

pyddem.vector_tools.SRTMGL1_naming_to_latlon(tile_name)[source]

Convert widely used 1x1° tile naming convention to lat, lon (originally SRTMGL1)

Parameters:tile_name – naming convention of southwestern 1x1° corner
Returns:lat, lon of southwestern corner
pyddem.vector_tools.coord_trans(is_src_wkt, proj_src, is_tgt_wkt, proj_tgt)[source]

Create a OGR Transform object to reproject between different coordinate systems

Parameters:
  • is_src_wkt – Boolean, is the provided projection source in WKT, if not it needs to be EPSG code (int)
  • proj_src – WKT or EPSG code for projection source
  • is_tgt_wkt – Boolean, is the provided projection target in WKT, if not it needs to be EPSG code (int)
  • proj_tgt – WKT or EPSG code for projection target
Returns:

OGR Transform object

pyddem.vector_tools.create_mem_raster_on_geoimg(geoimg)[source]

Create raster in memory with the same extent that a GeoImg

Parameters:geoimg – GeoImg
Returns:GDAL DataSet
pyddem.vector_tools.create_mem_shp(geom, srs, layer_name='NA', layer_type=<MagicMock id='140317250373616'>, field_id='ID', field_val='1', field_type=<MagicMock id='140317250386128'>)[source]

Create shapefile object in memory

Parameters:
  • geom – Geometry object
  • srs – Projection
  • layer_name – Shapefile layer name
  • layer_type – Shapefile layer type (polygon by default)
  • field_id – Basic field id (field necessary by default)
  • field_val – Basic field value
  • field_type – Basic field type
Returns:

OGR DataSet

pyddem.vector_tools.epsg_from_utm(utm_zone)[source]

Get EPSG code from UTM zone naming

Parameters:utm_zone – UTM zone naming
Returns:epsg
pyddem.vector_tools.extent_from_poly(poly)[source]

Get extent of polygon

Parameters:poly – OGR polygon
Returns:extent
pyddem.vector_tools.extent_rast(raster_in)[source]

Get raster extent

Parameters:raster_in – Filename of raster
Returns:extent
pyddem.vector_tools.extract_odl_astL1A(fn)[source]

Extract data from ASTER L1A metadata (old ODL format)

Parameters:fn – Filename of L1A .met file
Returns:Arrays and DataFrames with metadata
pyddem.vector_tools.geoimg_mask_on_feat_shp_ds(shp_ds, geoimg, layer_name='NA', feat_id='ID', feat_val='1', **kwargs)[source]

Create mask of a shapefile feature on a GeoImg

Parameters:
  • shp_ds – GDAL DataSet of input shapefile
  • geoimg – GeoImg
  • layer_name – Layer name for shapefile
  • feat_id – Feature of interest
  • feat_val – Value of the feature to be masked
Returns:

GDAL DataSet

pyddem.vector_tools.get_buffered_area_ratio(geom, proj_in, buff)[source]

Get buffered area ratio (for error estimation): reproject in a meter system centered on polygon, buffer of a certain distance, and look

Parameters:
  • geom – OGR polygon
  • proj_in – Projection source
  • buff – Buffer distance
Returns:

Area buffered to area ratio in percent, Area of polygon

pyddem.vector_tools.inters_list_poly_with_poly(list_poly, poly)[source]

Find intersection between a list of polygon and another polygon

Parameters:
  • list_poly – List of OGR polygons
  • poly – OGR polygon
Returns:

List of intersecting OGR polygons

pyddem.vector_tools.l1astrip_polygon(l1a_subdir)[source]

Compute the merged polygon of stitched ASTER L1A granules from the metadata of the original granules

Parameters:l1a_subdir – Directory containing several L1A .met files
Returns:OGR polygon
pyddem.vector_tools.latlon_to_SRTMGL1_naming(lat, lon)[source]

Convert lat, lon to widely used 1x1° tile naming (originally SRTMGL1)

Parameters:
  • lat – latitude of southwestern corner
  • lon – longitude of southwestern corner
Returns:

tile naming

pyddem.vector_tools.latlon_to_UTM(lat, lon)[source]

Get UTM zone, and corresponding EPSG given lat,lon coordinates

Parameters:
  • lat – latitude
  • lon – longitude
Returns:

epsg, UTM zone naming

pyddem.vector_tools.latlontile_nodatamask(geoimg, tile_name)[source]

Create mask on the extent of a 1x1° tile (used to avoid sampling twice neighbouring tiles in final calculations, although those need to have overlapping pixels to avoid resampling issues)

Parameters:
  • geoimg – GeoImg
  • tile_name – Tile naming
Returns:

Mask

pyddem.vector_tools.list_shp_field_inters_extent(fn_shp, field_name, extent, proj_ext)[source]

List features intersecting an extent in a shapefile

Parameters:
  • fn_shp – Filename of shapefile
  • field_name – Field name to list for the features
  • extent – extent
  • proj_ext – projection of extent
Returns:

List of field feature values (e.g., RGIIds)

pyddem.vector_tools.niceextent_utm_latlontile(tile_name, utm_zone, gsd)[source]

Create overlapping tile extents to avoid resampling effects at the edges

Parameters:
  • tile_name – tile naming
  • utm_zone – UTM zone naming
  • gsd – ground sampling distance (pixel size)
Returns:

extent

pyddem.vector_tools.poly_from_coords(list_coord)[source]

Create polygon from list of coordinates

Parameters:list_coord – List of tuples, need to repeat the first/last in order to close polygon
Returns:OGR polygon
pyddem.vector_tools.poly_from_extent(extent)[source]

Create polygon based on extent

Parameters:extent – extent (xmin, ymin, xmax, ymax)
Returns:OGR polygon
pyddem.vector_tools.poly_utm_latlontile(tile_name, utm_zone)[source]

Create polygon of a 1x1° lat, lon tile projected in a specific UTM zone

Parameters:
  • tile_name – tile naming
  • utm_zone – UTM zone naming
Returns:

OGR polygon

pyddem.vector_tools.utm_from_epsg(epsg)[source]

Get UTM zone naming from EPSG code

Parameters:epsg – EPSG code
Returns:UTM zone naming