Thursday, 26 November 2015

python - How to easily shift all features in a vector dataset?


Let's say that I put together a Shapefile and all the features have their vertices shifted by a constant amount. What's the easiest way of shifting all the features (hence the (x,y) position of their vertices) by an arbitrary shift? I have lots of files that I would apply this correction to, so a Bash/OGR answer would be preferred :)


Finally, I ended up using Spatialite for this, as it has the nice function ShiftCoords. However, the thread was very informative! Thanks all!




Answer



Using JEQL This can be done with three lines:


ShapefileReader t file: "shapefile.shp";
out = select * except (GEOMETRY), Geom.translate(GEOMETRY,100,100) from t;
ShapefileWriter out file: "ahapefile_shift.shp";

No comments:

Post a Comment