3

I am looking for preferably a Linux command line tool that would spit long polylines in my shapefile to shorter segments. Length limit can be defined by the length in meters or in max number of polyline points and doesn't need to be precise.

My problem is that I have a shapefile with contours spanning the whole country and it makes rendering map with Mapnik very slow.

  • 1
    Use ogr2ogr gdal.org/ogr2ogr.html with -segmentize -segmentize max_dist: (starting with GDAL 1.6.0) maximum distance between 2 nodes. Used to create intermediate points. – user30184 Mar 14 at 10:04
  • @user30184 thanks, but it doesn't seem to help. ogr2ogr -f 'ESRI Shapefile' -F 'ESRI Shapefile' -segmentize 2 contours2.shp contours.shp produces exactly the same file (with same MD5 sum) – Martin Ždila Mar 14 at 10:19
  • 1
    Perhaps your data are in EPSG:4326 and then segment length of 2 degrees is rather long. – user30184 Mar 14 at 10:54
  • @user30184 Good point. With 0.0002 it produces bigger file, but QGis shows the same feature count in both files. So it probably only adds some nodes to polylines but does not split it. – Martin Ždila Mar 14 at 11:04
  • Right, it does not cut geometries, must be thinking something else. – user30184 Mar 14 at 11:08
2

I've created a program in nodejs which does what I need. It splits linestrings longer than default 1000 points. Output is GeoJSON which can be converted back to shapefile with ogr2ogr -F 'ESRI Shapefile' result.shp split.geojson.

You can find it at https://github.com/FreemapSlovakia/shp-polyline-splitter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.