I'm trying to implement a transformation of x and y coordinates for line features of a Shapefile. geopandas.set_geometry()
isn't setting the x and y coordinates and isn't giving me any errors.
Here is my code:
import shapely
import geopandas as gpd
def calcNewXY(geom):
return geom.geometry.map(
lambda line: shapely.ops.transform(lambda x, y: (x - 100000, y - 10000), line)
)
data = gpd.read_file(inFile)
data.set_geometry(calcNewXY(data))
The actual coordinate transformation works, I debugged this part. Maybe somebody can shed some light on what I'm missing here.
SOLUTION:
inplace=True
has to be set as suggested by @mikewatt
data.set_geometry(calcNewXY(data), inplace=True)
shapely.ops.transform
takes two args,func
andgeom
. You're only feeding infunc
as written, it should be throwing a syntax error. If I were you I'd re-write this using named functions to make it easier to debug, nested lambdas is a lil messydata.set_geometry(calcNewXY(data), inplace=True)
to avoid creating a new object: geopandas.org/en/stable/docs/reference/api/…