I have a WKT object and want to move its center to the origin (0,0). Here is an example and what I tried:
from shapely import wkt
poly_str = 'POLYGON ((14.217343909259455 -2.9030822376560224, 16.003619392313993 -2.639545672126154, 16.363681477720576 -5.080080154489572, 14.577405994666037 -5.34361672001944, 14.217343909259455 -2.9030822376560224))'
geom = wkt.loads(poly_str)
normalized = geom.normalize() # this does nothing
normalized == geom # TRUE
centroid = geom.centroid
moved_geom = geom - centroid # this seems logical, but does not achieve what I want
print(moved)
>>>> 'POLYGON ((16.003619392313993 -2.639545672126154, 16.363681477720576 -5.080080154489572, 14.577405994666037 -5.34361672001944, 14.217343909259455 -2.9030822376560224, 16.003619392313993 -2.639545672126154))'
Why is that last polygon not moved by the amount of the centroid and how would I obtain a shifted polygon from my original whose centroid would be at (0,0)?
You are actually on the right track, but there's a mistake in how you're calculating the moved geometry. The subtraction operation
geom - centroidis not directly supported in Shapely for moving geometries. Instead, you should manually translate the coordinates of each point. This should be your solution:Output:
Moving both interior and exterior points to the center
If you have a polygon with both interior and exterior points, here's how you move it to the center
Output: