Wednesday 29 August 2018

gdal - Lossless conversion from shapefiles to XML/JSON/Text


I'm a software developer and I need to create a custom tool that imports ESRI shapefiles (shp + shx + dbf), manipulates the content and then exports new shapefiles. To avoid a complex binary reading of the 3 formats, I'd like to convert the input files into a "well known" textual format (JSON, XML, plain text, ...) and I want to be able to revert the conversion.


I tried to use gdal/ogr2ogr to convert the shapefiles into CSV but the output seems to only include the content of the database (dbf file). This means that, if I try to convert the CSV back into shapefiles, I lose all the polygon coordinates.


I then tried to convert to GeoJSON, which was much better but a few data appear to be missing again (like shape boundaries and polygon indexes).


Is there an option in gdal for a "lossless" conversion between shapefiles and any humanly readable format?



Answer



All of the vector formats supported by GDAL/OGR are listed here. With each driver, check out the creation options to control the output. These are passed to ogr2ogr using -dco and -lco flags.


Good text-based output drivers include:




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...