Questions re choropleth

I’ve been playing with choropleths in Bokeh, and have several questions.

  1. Consider the Texas choropleth in the Gallery 1. When switching to a different state (in my case, Indiana), the projection is badly skewed because Bokeh “helpfully” tries to auto-calculate axis ranges. (I’ve seen older posts to this list indicate there may also be (was?) a bug with non-contiguous patches, but that’s likely not the case here.) What should the proper projection/aspect ratio be, and is it built in to Bokeh?

I added match_aspect=True to the figure constructor, but things still look off; Indiana still looks squished compared to formal maps. I’ve gone a bit down the rabbit hole and barely scratched the surface of how complicated mapping actually is. This leads to my next question:

  1. Are multiple projections built in to Bokeh? If not, are there plans to add them, or is this best left to other libraries. As someone new to both GIS and Python, which ones? (Pyproj?) I’ve seen several in various stages of seemingly abandoned alpha. In an ideal world, multiple projections, such as described at d3-geo would be available. Of particular use to me as someone in the U.S. would be the Albers
  1. Would adding (arbitrary) projections in any way be similar to #657, “Plotting polar coordinates”? I can envision a solution with a projection function that maps values to (x,y) space.
  1. Not a question, but another link of interest shows what ggplot, etc., are capable of projection-wise:

http://homepage.divms.uiowa.edu/~luke/classes/STAT4580/maps.html#choropleth-maps-of-county-population

Thanks,

—TAG

Hi,

GIS support in Bokeh is currently fairly rudimentary. The situation is basically:

* Web Mercator when using GMaps or TileRenderers

* No projections anywhere else (e.g. choropleths)

In the case of unprojected choropleths, there may be combinations of of current capabilities and features that yield acceptable results. But I'd say it depends entirely on the specifics of a particular use case. (Is interactivity needed? What kind? Over What spatial region?)

One option for something better would be to create a custom Bokeh extension:

  http://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html

Bokeh is completely extensible, so if you want to connect a fancy JS library for projected visuals to python backend tools like NumPy, Pandas, Scikit-learn, etc. then the Bokeh protocol can be a bridge to make that simpler. There is certainly an up-front development cost to create a Bokeh extension, but once written it behaves transparently like any built-in Bokeh model (automatic synchronization in Bokeh apps, etc.)

Another option is to look at GeoViews (http://geo.holoviews.org/Geometries.html\) which is a high-level library (companion to HoloViews) that can use both Bokeh and Matplotlib in various ways. It's my hope that over time having focused, narrow requirements from higher level libraries like GeoViews can drive targeted GIS feature adoption in core Bokeh. There are probably a few new features that would go a long way for both Bokeh users and higher level library users.

Wider, larger-scale GIS work in core Bokeh would probably require a committed new contributor with the right kind of experience.

Thanks,

Bryan

···

On Nov 7, 2017, at 16:05, [email protected] wrote:

I've been playing with choropleths in Bokeh, and have several questions.

1. Consider the Texas choropleth in the Gallery [1]. When switching to a different state (in my case, Indiana), the projection is badly skewed because Bokeh "helpfully" tries to auto-calculate axis ranges. (I've seen older posts to this list indicate there may also be (was?) a bug with non-contiguous patches, but that's likely not the case here.) What should the proper projection/aspect ratio be, and is it built in to Bokeh?
[1]:http://bokeh.pydata.org/en/latest/docs/gallery/texas.html

I added `match_aspect=True` to the figure constructor, but things still look off; Indiana still looks squished compared to formal maps. I've gone a bit down the rabbit hole and barely scratched the surface of how complicated mapping actually is. This leads to my next question:

2. Are multiple projections built in to Bokeh? If not, are there plans to add them, or is this best left to other libraries. As someone new to both GIS and Python, which ones? (Pyproj?) I've seen several in various stages of seemingly abandoned alpha. In an ideal world, multiple projections, such as described at d3-geo would be available. Of particular use to me as someone in the U.S. would be the Albers
[pyproj]:https://jswhit.github.io/pyproj/
[d3-geo]:https://github.com/d3/d3-geo/blob/master/README.md#projections
[d3-geoAlbers]:https://github.com/d3/d3-geo/blob/master/README.md#geoAlbers

3. Would adding (arbitrary) projections in any way be similar to #657, "Plotting polar coordinates"? I can envision a solution with a projection function that maps values to (x,y) space.
[#657]:Add support for plots in polar coordinates · Issue #657 · bokeh/bokeh · GitHub

4. Not a question, but another link of interest shows what ggplot, etc., are capable of projection-wise:
Maps and Geographical Data

Thanks,

—TAG

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0101d7f8-94b1-4604-bca8-27fea8956804%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hey,

To start off with a few general comments. Being someone who almost only plots GIS/Remote sensing data, i don’t like mixing GIS and plotting at all, or any data processing and plotting for that manner. Both subjects are difficult enough as it is, i rather see good specialized libraries instead of these monolithic packages which try to solve it all.

You mention D3, which has amazing support for ‘on-the-fly’ reprojections, but i see it mostly (mis)used for static plots, meaning every client reprojects the data on its machine, instead of the designer doing it only once. Think of the waste of resources if you have a million views on your graphic. Almost all valid examples are used for ‘educating’ about the differences between projections, which is cool but a bit of a niche. In my opinion it would (currently) be a waste of effort to integrate all this fancy GIS functionality.

So in your case my advice would be, if the data you want to plot is in the “wrong” projection, reproject it before plotting. There are many ways on how to do this in Python, i prefer pyproj and/or OGR. Both of those libraries have a bit of a learning curve, so maybe you can start by looking at something else like GeoPandas. GeoPandas can easily read shapefiles or other geographic formats. It allows some Panda-style manipulation, and also reprojection for example, see:
http://geopandas.org/projections.html#re-projecting

Furthermore, it integrates nicely with Bokeh by using the “GeoJSONDataSource” as an interface. I recently posted an example of this on Stackoverflow:

The biggest question is what projection to use, i cant answer that without guessing. Maybe there are some Indiana specific ones if you want to be very precise, or otherwise some ‘default’ CONUS projection might already be sufficient.

Let me know if you can get it working. I wouldn’t mind modifying the GeoPandas example to include a reprojection and centering on Indiana if you cant get it right. It would literally be adding one line specifying the EPSG (see the GeoPandas docs linked above).

Regards,
Rutger

···

On Tuesday, November 7, 2017 at 11:05:33 PM UTC+1, Tom Gregory wrote:

I’ve been playing with choropleths in Bokeh, and have several questions.

  1. Consider the Texas choropleth in the Gallery 1. When switching to a different state (in my case, Indiana), the projection is badly skewed because Bokeh “helpfully” tries to auto-calculate axis ranges. (I’ve seen older posts to this list indicate there may also be (was?) a bug with non-contiguous patches, but that’s likely not the case here.) What should the proper projection/aspect ratio be, and is it built in to Bokeh?

I added match_aspect=True to the figure constructor, but things still look off; Indiana still looks squished compared to formal maps. I’ve gone a bit down the rabbit hole and barely scratched the surface of how complicated mapping actually is. This leads to my next question:

  1. Are multiple projections built in to Bokeh? If not, are there plans to add them, or is this best left to other libraries. As someone new to both GIS and Python, which ones? (Pyproj?) I’ve seen several in various stages of seemingly abandoned alpha. In an ideal world, multiple projections, such as described at d3-geo would be available. Of particular use to me as someone in the U.S. would be the Albers
  1. Would adding (arbitrary) projections in any way be similar to #657, “Plotting polar coordinates”? I can envision a solution with a projection function that maps values to (x,y) space.
  1. Not a question, but another link of interest shows what ggplot, etc., are capable of projection-wise:

http://homepage.divms.uiowa.edu/~luke/classes/STAT4580/maps.html#choropleth-maps-of-county-population

Thanks,

—TAG

Just want to echo what Rutger says. Reproject your data before, ideally to a state plane system since you’re working the with US data. Geopandas is great at that.

-Paul

···

On Wed, Nov 8, 2017 at 3:48 AM, Rutger Kassies [email protected] wrote:

Hey,

To start off with a few general comments. Being someone who almost only plots GIS/Remote sensing data, i don’t like mixing GIS and plotting at all, or any data processing and plotting for that manner. Both subjects are difficult enough as it is, i rather see good specialized libraries instead of these monolithic packages which try to solve it all.

You mention D3, which has amazing support for ‘on-the-fly’ reprojections, but i see it mostly (mis)used for static plots, meaning every client reprojects the data on its machine, instead of the designer doing it only once. Think of the waste of resources if you have a million views on your graphic. Almost all valid examples are used for ‘educating’ about the differences between projections, which is cool but a bit of a niche. In my opinion it would (currently) be a waste of effort to integrate all this fancy GIS functionality.

So in your case my advice would be, if the data you want to plot is in the “wrong” projection, reproject it before plotting. There are many ways on how to do this in Python, i prefer pyproj and/or OGR. Both of those libraries have a bit of a learning curve, so maybe you can start by looking at something else like GeoPandas. GeoPandas can easily read shapefiles or other geographic formats. It allows some Panda-style manipulation, and also reprojection for example, see:
http://geopandas.org/projections.html#re-projecting

Furthermore, it integrates nicely with Bokeh by using the “GeoJSONDataSource” as an interface. I recently posted an example of this on Stackoverflow:
https://stackoverflow.com/a/47135604/1755432

The biggest question is what projection to use, i cant answer that without guessing. Maybe there are some Indiana specific ones if you want to be very precise, or otherwise some ‘default’ CONUS projection might already be sufficient.

Let me know if you can get it working. I wouldn’t mind modifying the GeoPandas example to include a reprojection and centering on Indiana if you cant get it right. It would literally be adding one line specifying the EPSG (see the GeoPandas docs linked above).

Regards,
Rutger

On Tuesday, November 7, 2017 at 11:05:33 PM UTC+1, Tom Gregory wrote:

I’ve been playing with choropleths in Bokeh, and have several questions.

  1. Consider the Texas choropleth in the Gallery 1. When switching to a different state (in my case, Indiana), the projection is badly skewed because Bokeh “helpfully” tries to auto-calculate axis ranges. (I’ve seen older posts to this list indicate there may also be (was?) a bug with non-contiguous patches, but that’s likely not the case here.) What should the proper projection/aspect ratio be, and is it built in to Bokeh?

I added match_aspect=True to the figure constructor, but things still look off; Indiana still looks squished compared to formal maps. I’ve gone a bit down the rabbit hole and barely scratched the surface of how complicated mapping actually is. This leads to my next question:

  1. Are multiple projections built in to Bokeh? If not, are there plans to add them, or is this best left to other libraries. As someone new to both GIS and Python, which ones? (Pyproj?) I’ve seen several in various stages of seemingly abandoned alpha. In an ideal world, multiple projections, such as described at d3-geo would be available. Of particular use to me as someone in the U.S. would be the Albers
  1. Would adding (arbitrary) projections in any way be similar to #657, “Plotting polar coordinates”? I can envision a solution with a projection function that maps values to (x,y) space.
  1. Not a question, but another link of interest shows what ggplot, etc., are capable of projection-wise:

http://homepage.divms.uiowa.edu/~luke/classes/STAT4580/maps.html#choropleth-maps-of-county-population

Thanks,

—TAG

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/733bbc52-b201-4ab2-80da-0e212e64d1b5%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.