How to set shapefile (.shp, .zip) to lon and lat and hover on the region (geo object)?

How to set shapefile (.shp, .zip) to lon. and lat. and hover on the region (geo object) …?

for the example from plotly … .https://plot.ly/python/county-level-choropleth
I need an hover text effect on the region.

@jimmybow The choropleth at the link above is created via mapbox with source a geojson file. If you have a shapefile you can convert it to
a geojson file following the steps described here: https://www.statsilk.com/maps/convert-esri-shapefile-map-geojson-format
or just use another free tool…
In order to display an information on hover over each region (polygon in geojson) define a list of locations in each region and their lon and lat.
Then plot the points representing those locations via scattermapbox, with a color identical to the color assigned to the corresponding region when you create the choropleth.
See also this thread: https://community.plotly.com/t/choropleth-map-in-dash/4807/

Do you mean I need have both (type : Point) and (type : Polygon) information together in the geojson file (or dict) for a region, and add points, which are in the (type : Point) in the geojson, to the scattermapbox …? :laughing: :hushed:

 "features":[
   
 { "type": "Feature",
            "geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
            "properties": {"prop0": "value0"}
            },

    { "type": "Feature",
             "geometry": {
               "type": "Polygon",
               "coordinates": [
                 [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
                   [100.0, 1.0], [100.0, 0.0] ]
                 ]
             },
             "properties": {
               "prop0": "value0",
               "prop1": {"this": "that"}
               }
             }

]

@jimmybow It would be nice to find a file that contains as Point(s) the locations in each Polygon, but if is not the case you should collect this information from the WEB.

For my plot I picked up the lon and lat for the points of interest:

regions=[feature['properties']['NAME_1'] for feature in geoJSON['features']]# Centre Val de Loire
lon=[2.352222, 4.472525, 2.528073, 0.882833, 1.916502, -0.515749, 4.383721, 2.324468, 6.208093,
 7.441624, 6.022302, -0.329969,  -2.932644,  -0.309184,  -0.299579, 1.444209,  1.569602, 5.450282, 
 3.344854, 3.258363, 6.067919, 9.012893 ]
lat=[48.856614, 48.793409, 49.663613, 49.524641, 47.903791, 48.878847, 47.052505, 50.573277, 
 48.874423, 48.318179, 47.134321,47.763284, 48.202047,  45.903552, 44.700222, 43.604652, 
 45.893223,45.169580,45.703269,43.591236, 43.935169,42.039604 ]

regions=[u'R\xe9gion: '+r+'<br>lon: '+'{:.2f}'.format(lon[k])+'<br>lat: '+'{:.2f}'.format(lat[k])  for k,r in enumerate(regions)] 

and plotted the points as a scattermapbox trace:

trace = dict(type='scattermapbox',
            lat= lat,
            lon=lon,
            mode='markers',
            text=regions,
            marker=dict(size=5, color='red'),
            showlegend=False,
            hoverinfo='text'
            )

But…in your map, the effect is hover on the point , not hover on the region…exactly :disappointed_relieved:
https://plot.ly/~empet/14398/shapes-and-lines-in-mapbox-via-geojson-data/#plot

I need the effect on the region and show the text whenever the mouse on it

Yes, you are right, but at the moment this is the unique possibility to display some information on hover within a region.

I think I can use dash to interaction with mouse … it can obtain the location of the mouse and check if the mouse is in the polygon :laughing:

1 Like

Are there any plans to add hovering over a region instead of having to hover over the point? This seems like a big limitation