TransWikia.com

Get geopandas geo or affine transform

Geographic Information Systems Asked by a crazy Minion on September 17, 2020

Does anyone know how to get the affine transformation from a geopandas dataframe?

I need this for rasterising geospatial vector data with rasterio.

shapes = ((geom,value) for geom, value in zip(geodataframe.geometry, len(geodataframe)*[255]))

numpy_array = features.rasterize(
    shapes,
    out_shape=self.tile_size,
    transform=geodataframe.transform???,
    all_touched=True)

I am however still missing the transform part.

One Answer

The solution I found to work for anybody else searching is to create the transform yourself.

import affine
transform = affine.Affine(res, 0, minx, 0, -res, maxy)

shapes = ((geom,value) for geom, value in zip(dataset.geometry, len(dataset)*[val]))

raster = rasterio.features.rasterize(shapes,
                                     out_shape=tile_size,
                                     transform=transform)

whereby res is the spatial resolution (ie 1pixel = 2m). minx and maxy correspond to the geographic position and the y axis is chosen negative to match the different coordinate system of the another raster I am using.

Answered by a crazy Minion on September 17, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP