= gpd.read_file('example_data/R70C21.shp')
gdf = 'example_data/R70C21.tif'
im_path
with rio.open(im_path) as im:
= im.read()
im_data 0,2).swapaxes(0,1))
plt.imshow(im_data.swapaxes( plt.show()
Coordinate transformations
Converting geocoordinates to pixel coordinates
list_to_affine
list_to_affine (xform_mat:list)
Adapted from Solaris.geo. Creates an affine object from array-formatted list
get_geo_transform
get_geo_transform (src)
Extract geotransform for a raster image source
convert_poly_coords
convert_poly_coords (geom:<function shape>, raster_src:str=None, affine_obj:affine.Affine=None, inverse:bool=False, precision=None)
Adapted from solaris. Converts georeferenced coordinates to pixel coordinates and vice versa
affine_transform_gdf
affine_transform_gdf (gdf:geopandas.geodataframe.GeoDataFrame, affine_obj:affine.Affine, inverse:bool=False, geom_col:str='geometry', precision:int=None)
Adapted from solaris, transforms all geometries in GeoDataFrame to pixel coordinates from Georeferced coordinates and vice versa
gdf_to_px
gdf_to_px (gdf:geopandas.geodataframe.GeoDataFrame, im_path, geom_col:str='geometry', precision:int=None, outpath=None, override_crs=False)
*Adapted from https://solaris.readthedocs.io/en/latest/_modules/solaris/vector/polygon.html#geojson_to_px_gdf Converts gdf
to pixel coordinates based on image in im_path
*
georegister_px_df
georegister_px_df (df:pandas.core.frame.DataFrame, im_path=None, affine_obj:affine.Affine=None, crs=None, geom_col:str='geometry', precision:int=None, output_path=None)
Convert geodataframe from pixel coordinates to crs
, using affine_obj
as the reference
='label', #facecolor='none',
gdf.plot(column='black', lw=0.7, cmap='viridis') edgecolor
= gdf_to_px(gdf, im_path)
tfmd_gdf ='label', #facecolor='none',
tfmd_gdf.plot(column='black', lw=0.7, cmap='viridis') edgecolor
Origin in lower left for this data.
= plt.subplots()
fig, ax 0,2).swapaxes(0,1))
ax.imshow(im_data.swapaxes(=ax, column='label', facecolor='none', edgecolor='black', lw=0.7, cmap='viridis')
tfmd_gdf.plot(ax plt.show()
Overlaid on image coordinates are correct
= georegister_px_df(tfmd_gdf, im_path)
tfmd_gdf ='label', facecolor='none', edgecolor='black', lw=0.7, cmap='viridis') tfmd_gdf.plot(column
Backwards transformation works