Coordinate transformations for vector data

Adapted from https://solaris.readthedocs.io/en/latest/_modules/solaris/vector/polygon.html

source

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)

source

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


source

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


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


source

get_geo_transform

 get_geo_transform (src)

Extract geotransform for a raster image source


source

list_to_affine

 list_to_affine (xform_mat:list)

Adapted from Solaris.geo. Creates an affine object from array-formatted list

gdf = gpd.read_file('example_data/R70C21.shp')
im_path = 'example_data/R70C21.tif'

with rio.open(im_path) as im: 
    im_data = im.read()
plt.imshow(im_data.swapaxes(0,2).swapaxes(0,1))
plt.show()

gdf.plot(column='label', #facecolor='none', 
         edgecolor='black', lw=0.7, cmap='viridis')
<AxesSubplot:>

tfmd_gdf = gdf_to_px(gdf, im_path)
tfmd_gdf.plot(column='label', #facecolor='none', 
              edgecolor='black', lw=0.7, cmap='viridis')
<AxesSubplot:>

Origin in lower left for this data.

fig, ax = plt.subplots()
ax.imshow(im_data.swapaxes(0,2).swapaxes(0,1))
tfmd_gdf.plot(ax=ax, column='label', facecolor='none', edgecolor='black', lw=0.7, cmap='viridis')
plt.show()
<AxesSubplot:>

Overlaid on image coordinates are correct

tfmd_gdf = georegister_px_df(tfmd_gdf, im_path)
tfmd_gdf.plot(column='label', facecolor='none', edgecolor='black', lw=0.7, cmap='viridis')
<AxesSubplot:>

Backwards transformation works