2

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.

1

3 Answers 3

6

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 :

1

The "canonical" way (and the only feasible way to handle medium to big size data) would be to load the shapefile in a WMS/WFS server (geoserver), and use WMS for the visualization of the data, and WFS (as GeoJSON, but could by gml or whatever) when you need to select a feature or to see the attributes as table. You can give a look at OpenGeo Suite

Maybe you could try to minimize the coordinates of the shapes using the Google Maps algorithm, it seems that the encoded form is supported by OL EncodedPolylineFormat.

0

TopoJson has smaller file size than corresponding GeoJson. You can send the data as topojson, then convert it to geojson in client or read topojson directly in openlayers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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