Re: Scaling Geometry to Match Image File


katsonandrew3.5@...
 

I did not finish my question. I have typed the rest.

Here is how I read in the population file:

world_pop_image = rasterio.open(path_to_image, nodata=0)

Here is how I read the boundaries file:

world_boundaries = gpd.read_file(path_to_boundaries)

Here is how I do my reprojection (the raster is in World Mollweide which is not explicitly supported so I found the below workaround):

world_boundaries.to_crs('+proj=eck4 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs')

Here is how I do my scaling:

from shapely.affinity import affine_transformation

population_image_affine = world_pop_image.transform

shapely_affine_repr = [population_image_affine.a, population_image_affine.b, population_image_affine.d, population_image_affine.e, population_image_affine.xoff, population_image_affine.yoff]

world_boundaries['geometry'] = world_boundaries['geometry].apply(lambda geometry: affine_transformation(geometry, shapely_affine_repr)

Join main@fiona.groups.io to automatically receive all group messages.