mapbox / mapboxgl-jupyter

Use Mapbox GL JS to visualize data in a Python Jupyter notebook
MIT License
661 stars 136 forks source link

How to load Polygon data into Mapbox? #154

Closed vgoklani closed 5 years ago

vgoklani commented 5 years ago

I converted my ArcGIS data into geojson and rendered it via geopandas, which worked correctly. But I'm unable to render this same data in Mapbox.

Here's a sample of the dataset:

    values  geometry
0   74.6906 POLYGON ((-9236522 4858133, -9235453 4858064, -9235477 4857695, -9235931 4857721, -9235939 4857597, -9237082 4857688, -9237054 4858165, -9236522 4858133))
1   96.4081 POLYGON ((-9235477 4857695, -9235558 4856443, -9236173 4856480, -9236107 4857608, -9235939 4857597, -9235931 4857721, -9235477 4857695))
2   92.6004 POLYGON ((-9236173 4856480, -9235558 4856443, -9235620 4855435, -9236368 4855486, -9236377 4855334, -9237457 4855402, -9237439 4855928, -9237186 4855921, -9237150 4856542, -9236173 4856480))
3   93.4172 POLYGON ((-9235783 4860191, -9235863 4858871, -9236488 4858911, -9236470 4859179, -9236314 4859158, -9236297 4859445, -9236404 4859449, -9236387 4860205, -9235783 4860191))
4   36.5780 POLYGON ((-9235863 4858871, -9235878 4858615, -9235420 4858586, -9235453 4858064, -9236522 4858133, -9236488 4858911, -9235863 4858871))

In general, what's the procedure to render this type data in Mapbox? Could someone please point me to an example. Thanks!

akacarlyann commented 5 years ago

I recommend starting with this example to get a feel for the Mapboxgl-jupyter library: https://github.com/mapbox/mapboxgl-jupyter/blob/master/examples/notebooks/point-viz-types-example.ipynb

Polygon maps are currently handled under the ChoroplethViz type, which you can find at: https://github.com/mapbox/mapboxgl-jupyter/blob/master/examples/notebooks/choropleth-viz-example.ipynb

akacarlyann commented 5 years ago

@vgoklani will you let us know when you've succeeded in loading your dataset?

vgoklani commented 5 years ago

I'm trying to understand what's in these arrays because they clearly don't look like lat/longs:

((-9236522 4858133, -9235453 4858064, -9235477 4857695, -9235931 4857721, -9235939 4857597, -9237082 4857688, -9237054 4858165, -9236522 4858133))

Any idea on how to convert these, thanks!

akacarlyann commented 5 years ago

@vgoklani these are map units and depend on the projection you are using in your GIS software. This is a little outside the scope of this library, which is focused on providing Python bindings for rendering maps in a Jypyter interactive Python notebook using MapboxGL JavaScript library. I recommend further reading on https://docs.mapbox.com/studio-manual/overview/ which might have some tools for converting map units to lat/lon and will help you generate custom vector layers.

I don't use ArcGIS on a daily basis, but there should also be options to re-export your data with the locations encoded as latitude/longitude too, in which case you'll be able to use this library after all :). I found this article which might be relevant? http://solutions.arcgis.com/defense/help/coordinate-conversion/arcmap/export-coordinates.htm

vgoklani commented 5 years ago

Hello - thanks again for all your help; I eventually figured out how to properly convert the geojson data from the ARCGIS server to get the lat/lon data!