[GIS] Shapefile to GeoJSON conversion

geojsonopenlayers-2shapefile

I am working with OpenLayers. I want to convert Shapefile into GeoJSON format and send it to browser to show with OpenLayers. But the problem is that when the size of my Shapefile is bigger than 60Mb, then it is not convenient to send whole GeoJSON data to browser.

Anyone can help me, how can i minimize the GeoJSON file size while my Shapefile size is still very large.

Are there any tools or techniques by which I can encode GeoJSON data to minimize the size and send it to client side as well as decode this data to show in map.

Best Answer

As said by neogeomat, topojson format is probably a good alternative, but I think you should first apply the following steps :

  1. First of all, you should wander if geometries stored in shapefile could not be generalized -regarding to your online needs? You could, for sure, reduce dramatically the size of your file. To apply the cartographic generalization you can use the online tool mapshaper. You can also try in QGIS or other GIS softwares.

  2. Then, delete unused attributes from the database.

  3. Then, you can also gain some weight by reducing the coordinate precision. Using ogr2ogr, the command will be similar to

    ogr2ogr -f "GeoJSON" -lco COORDINATE_PRECISION=2 output.json my_input.shp

  4. And finally convert the file to topojson, with this online tool, for example : http://jeffpaine.github.io/geojson-topojson/

As references, you can read :

Related Question