lonboard icon indicating copy to clipboard operation
lonboard copied to clipboard

Integrate `mapclassify`

Open kylebarron opened this issue 2 years ago • 9 comments

From the geopandas.plot docstring

Name of a choropleth classification scheme (requires mapclassify). A mapclassify.MapClassifier object will be used under the hood. Supported are all schemes provided by mapclassify (e.g. ‘BoxPlot’, ‘EqualInterval’, ‘FisherJenks’, ‘FisherJenksSampled’, ‘HeadTailBreaks’, ‘JenksCaspall’, ‘JenksCaspallForced’, ‘JenksCaspallSampled’, ‘MaxP’, ‘MaximumBreaks’, ‘NaturalBreaks’, ‘Quantiles’, ‘Percentiles’, ‘StdMean’, ‘UserDefined’). Arguments can be passed in classification_kwds.

kylebarron avatar Oct 18 '23 01:10 kylebarron

The following worked for me:


import numpy

from lonboard import Map, SolidPolygonLayer
from mapclassify import JenksCaspall

layer = SolidPolygonLayer.from_geopandas(zones_interpolated, opacity=0.2)
jc = JenksCaspall(
    zones_interpolated["ProductionAttractionSum Density"].fillna(0),
    k=20
)
colors = []
for color in jc.yb:
    colors.append(Viridis_20.colors[color])
layer.get_fill_color = numpy.uint8(colors)

Map(layers=[layer])

davidbailey avatar Jan 04 '24 19:01 davidbailey

Thanks! By the way, I'm not sure where Viridis_20 comes from, but doing an array lookup would be much faster than a loop. You should probably be able to do something like

Viridis_20.colors[jc.yb]

kylebarron avatar Feb 06 '24 22:02 kylebarron