Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import leafmap.foliumap as leafmap is unable to add_gdf if style column is present #919

Closed
patel-zeel opened this issue Oct 15, 2024 · 2 comments · Fixed by #922
Closed
Labels
bug Something isn't working

Comments

@patel-zeel
Copy link

patel-zeel commented Oct 15, 2024

Environment Information

  • leafmap version: 0.38.5
  • Python version: 3.10.12
  • Operating System: Ubuntu 20.04.6 LTS

Description

Trying to use add_gdf function fails with foliumap version of leafmap if the gdf has style column. The same functionality works with import leafmap.leafmap as leafmap.

show_what_works = False

if show_what_works:
    import leafmap.leafmap as leafmap
else:
    import leafmap.foliumap as leafmap
import geopandas as gpd
from shapely.geometry import Polygon

dict_with_style = {"name": ["A", "B", "C"], "geometry": [Polygon([(77.0, 28.0), (77.0, 29.0), (78.0, 29.0)]), Polygon([(77.0, 29.0), (77.0, 30.0), (78.0, 30.0)]), Polygon([(77.0, 30.0), (77.0, 31.0), (78.0, 31.0)])], "style": [{"color": "red"}, {"color": "green"}, {"color": "blue"}]}

gdf_with_style = gpd.GeoDataFrame.from_dict(dict_with_style, crs="EPSG:4326")
print(gdf_with_style)

m = leafmap.Map()
m.add_gdf(gdf_with_style, zoom_to_layer=True)
m
@patel-zeel patel-zeel added the bug Something isn't working label Oct 15, 2024
@mergify mergify bot closed this as completed in #922 Oct 16, 2024
@patel-zeel
Copy link
Author

Prof. @giswqs, I found a small problem with this. Not sure if it's worth opening a new issue so raising it here. When GeoPandas loads a GeoJSON with "style", by default, all "style" elements are in str format. This works fine with import leafmap.foliumap as leafmap but fails with import leafmap.leafmap as leafmap. Here is the MWE:

show_what_fails = True

if show_what_fails:
    import leafmap.leafmap as leafmap
else:
    import leafmap.foliumap as leafmap

collection = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [80.778174, 26.654166],
            [80.778882, 26.65477],
            [80.778657, 26.654981],
            [80.777949, 26.654377],
            [80.778174, 26.654166]
          ]
        ]
      },
      "properties": {
        "name": "Example",
        "style": {
          "color": "red",
        },
      }
    }]
}
gdf = gpd.GeoDataFrame.from_features(collection)
print(type(gdf.iloc[0].style))  # This is a dict
gdf.to_file("/tmp/tmp.geojson", driver="GeoJSON")
gdf = gpd.read_file("/tmp/tmp.geojson")
print(type(gdf.iloc[0].style))  # This is a str

m = leafmap.Map()
m.add_gdf(gdf)
m

@giswqs
Copy link
Member

giswqs commented Oct 17, 2024

You can open a new issue. I will look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants