How can I get of the extent of all features within a GeoJSON FeatureCollection with Python 3? One extent for all features, not one per feature.

The Feature collection includes multiple points features and multiple LineStrings features.


If your FeatureCollection doesn't have a bbox member as described in RFC 7946, you will need to loop over all Features and update a global variable as you go.

The code found in this answer can serve as a starting point for your script.

  • Now getting this error: c1 = [x[0] for x in c] TypeError: 'float' object is not subscriptable – Dean Sep 8 '18 at 20:58
  • Not sure about your location, but here it is getting late - maybe for you too... ;-) A point doesn't have an array of coordinates of course. :) For points it is simply: c1 = f["geometry"]["coordinates"][0] and c2 = f["geometry"]["coordinates"][1]. – Stefan Sep 8 '18 at 21:12
  • what about LineString. It's only 4:15pm here – Dean Sep 8 '18 at 21:15
  • See tools.ietf.org/html/rfc7946#appendix-A.2 You will have to find the outermost coordinates. I'm wondering if you aren't better off using node.js to compute bbox for your FeatureCollection: npmjs.com/package/@mapbox/geojson-extent – Stefan Sep 8 '18 at 21:26

I found the answer here with @Stefan_Fairphone's help...

The answer is here

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.