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

pydeck and @deck.gl/json error: No registered class of type Feature #3836

Closed
pancho111203 opened this issue Nov 1, 2019 · 6 comments
Closed
Labels

Comments

@pancho111203
Copy link

Description

In PyDeck, when initializing a GeoJsonLayer with a features object, we get a warning and no polygons are displayed in the map.

Repro Steps

import pydeck
import requests as req
DATA_URL = "https://raw.githubusercontent.com/uber-common/deck.gl-data/master/examples/geojson/vancouver-blocks.json"
data_geojson = req.get(DATA_URL).json()

INITIAL_VIEW_STATE = pydeck.ViewState(
  latitude=49.254,
  longitude=-123.13,
  zoom=11,
  max_zoom=16,
)

gg = pydeck.Layer(
    'GeoJsonLayer',
    data_geojson,
    stroked=False,
    filled=True,
    extruded=True,
    wireframe=True,
    pickable=True,
    get_line_color=[255, 255, 255]

)

r = pydeck.Deck(
    layers=[gg],
    initial_view_state=INITIAL_VIEW_STATE)

r.to_html()
@ibgreen
Copy link
Collaborator

ibgreen commented Nov 1, 2019

Thanks for reporting. Fixing this bug that will require changes to how we generate intermediate JSON as described in #3767.

In the meantime, if you don't need to process the GeoJSON in Python, can you just pass the URL to the layer?

gg = pydeck.Layer(
    'GeoJsonLayer',
    DATA_URL,
    ...

This way the GeoJSON won't be part of the JSON sent between Python and the browser but instead loaded directly into the browser without any intermediate processing.

Passing URL would work in the JavaScript API so I assume it should work in pydeck as well... @ajduberstein ?

@pancho111203
Copy link
Author

@ibgreen The problem is that I load the GeoJson from a file, it's not hosted anywhere. Is there another workaround to use files instead of urls?

@ibgreen
Copy link
Collaborator

ibgreen commented Nov 1, 2019

@pancho111203 In that case I can't think of an easy workaround. The problem that we do special processing on JSON "type": "..." fields and these are also used by GeoJSON, and when your GeoJSON data is "inline" with the JSON we use to describe the layers, everything gets processed the same way.

My current sense is that we should be able to fix this in one of our weekly deck.gl v7.3 patch releases, i.e. you should not have to wait for a new major release to get this fixed.

@ajduberstein
Copy link
Collaborator

Thank you for reporting this, @pancho111203. I've written a demo notebook here named after this issue–click deck.gl #3836 Example.ipynb to see the workaround. You can use pandas clean the data and pass the result to a deck.gl PolygonLayer. The code in that notebook:

import pandas as pd
import pydeck

# Load in the JSON data
DATA_URL = 'https://raw.githubusercontent.com/uber-common/deck.gl-data/master/examples/geojson/vancouver-blocks.json'
json = pd.read_json(DATA_URL)
polygon_df = pd.DataFrame()

# Parse the geometry out in Pandas and pass it to deck.gl's PolygonLayer
# I'll make the next release such that you don't have to do this
# manual extraction.
polygon_df['coordinates'] = json['features'].apply(lambda row: row['geometry']['coordinates'])
polygon_df['valuePerSqm'] = json['features'].apply(lambda row: row['properties']['valuePerSqm'])
polygon_df['growth'] = json['features'].apply(lambda row: row['properties']['growth'])
polygon_df.head()

INITIAL_VIEW_STATE = pydeck.ViewState(
    latitude=49.254,
    longitude=-123.13,
    zoom=11,
    max_zoom=16,
    pitch=45,
    bearing=0
)

geojson = pydeck.Layer(
    'PolygonLayer',
    polygon_df,
    opacity=0.8,
    get_polygon='coordinates',
    stroked=False,
    filled=True,
    extruded=True,
    wireframe=True,
    get_elevation='valuePerSqm / 20',
    get_fill_color='[255, 255, growth * 255]',
    get_line_color=[255, 255, 255],
    pickable=True
)

r = pydeck.Deck(
    layers=[geojson],
    initial_view_state=INITIAL_VIEW_STATE)
r.to_html(iframe_width=1000)

image

Unambiguously we should have support for parsing GeoJSON built into pydeck–expect this in the next release.

@pancho111203
Copy link
Author

Great, I'll use that workaround in the meantime. Thank you both for your help!

@ajduberstein ajduberstein changed the title JSON converter: No registered class of type Feature pydeck and @deck.gl/json error: No registered class of type Feature Dec 2, 2019
@ajduberstein
Copy link
Collaborator

This is fixed in pydeck 0.2.0–please update your installation. Feel free to re-open this issue if something doesn't work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants