0

My goal is to plot two shapefiles as layers on an interactive map. The files I'm using live at https://github.com/AnnaMag/maps.

I transformed shapefiles to .geojson using

ogr2ogr -f ...

e.g. ogr2ogr -f geoJSON Wards2011.geojson Wards2011.shp

Neither of the files is being plotted using folium or Leaflet alone.

Code example for 1 shapefile:

#center in SA:
lllon = 15
lllat = -35
urlon = 33
urlat = -22

state_geo = r'data/Wards2011.geojson'
map = folium.Map(location=[(lllat+urlat)/2, (lllon+urlon)/2], zoom_start=6, 
tiles='cartodbpositron')
map.geo_json(geo_path=state_geo)


map.create_map(path='test.html')

Replacing the geo_path with:

state_geo = r'data/sal_population.json'

is not working either.

Is there anything wrong with the json files or the approach?

UPDATE

As suggested I reduced the complexity:

  1. in Wards shapefile I left only 4 necessary features (incl. geometry, of course)

  2. Simplified the shapefiles

    ogr2ogr out.shp in.shp -simplify 0.000001

  3. transformed to geojson

    ogr2ogr -t_srs EPSG:4326 -f GeoJSON Wards2011.geojson out.shp

  4. transformed to topojson

    topojson --spherical --properties -s 0.001 -q 1E6 -o Wards2011.topojson Wards2011.geojson

Neither of the files is working. What should be fixed to make it work?

  • is "Wards2011.json" the geojson output from ogr2ogr? – Riccardo Mar 3 '16 at 10:18
  • And is it working without the map.geo_json line? – Riccardo Mar 3 '16 at 10:20
  • yes, all *json are outputs from ogr2ogr. It does work without it. – Anna Magdalena Mar 3 '16 at 10:22
2

The geo_path you mentioned a path that is not valid! Your shapes are stored in the file Wards2011.geojson and not Wards2011.json

Furthermore your geojson has 143mb which is very much to handle. simplify the geometry of the shapefile! I have done something similar in QGIS and reduced 120mb to 4mb which works in a browser.

  • Apologies, it is a typo- I actually had 2 files: .json, and .geojson to try if it was extension problem (I did try everything I could think of). I changed it and tried again- the map is not even showing the background – Anna Magdalena Mar 3 '16 at 10:28
  • Your files are definitely too big for a webmap! – Riccardo Mar 3 '16 at 11:01
  • thanks @Riccardo, makes sense. Can I plot it in QGIS or it's also too big? – Anna Magdalena Mar 3 '16 at 11:32
  • it will plot in QGIS but I would prefer to work with the shapefile and simplify this. also remove columns that aren't needed. – Riccardo Mar 3 '16 at 11:53
  • I tried simplification with topojson and input the topojson file. Not working... – Anna Magdalena Mar 3 '16 at 12:40

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.