Questions RE: PyDeck GeoJson Layer Data Format (URL, JSON, Dataframe) #7303
Replies: 4 comments 3 replies
-
Chrome doesn't allow sites to perform requests to If you want to load local data, you need to host the local data on a server on |
Beta Was this translation helpful? Give feedback.
-
Yeah, could be, because in the first case the data never goes through Python, but rather Python sends JS just a short string. Whereas in the second case all of the data goes through Python, and Python needs to send the entire JSON-encoded data from the Python side to the JS side |
Beta Was this translation helpful? Give feedback.
-
I assume you can pass in a geopandas |
Beta Was this translation helpful? Give feedback.
-
Okay! I figured out the dataframe part. It's straightforward - Basically you just need a column Every other column in the dataframe is treated also loaded akin to the The trick was making sure the dataframe geometry column was loaded as dict. import pandas as pd
import ast
# on load
df = pd.read_csv('path/to/file.csv', converters = {'geometry': ast.literal_eval})
# or convert column of already load dataframe
try:
df_existing['geometry'] = df_existing['geometry'].apply(ast.literal_eval) # is there a better way?
except ValueError: # maybe already converted object to dict previously
pass Under the hood pydeck takes this dataframe and calls Generally, I'm still find that just pointing to a URL (when it's geojson) seems to out perform the other methods. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
TL;DR Questions
GeoJsonLayer
? Assuming a record perfeature
and each feature could haveproperties
?Observations
I have been looking at documentation / code from PyDeck
0.8.3b
, specifically the examples using theGeoJsonLayer
Additionally, based on my read of some of the underlying code of the python API bindings to deck.gl it states
deck.gl/bindings/pydeck/pydeck/bindings/layer.py
Line 34 in 1a42362
deck.gl/bindings/pydeck/pydeck/data_utils/type_checking.py
Line 16 in 1a42362
The examples that point to a URL of the (geo)json work fine. In fact even in my tests of pointing them to much larger files they also render peformantly (as in the map renders and can pan smoothly). What is a bit strange to me is how the performance drops a lot when taking the same file and loading it as json.
Example:
Both the example of using the DATA_URL and this method to load a local file work. The former being more performant in my testing. For kicks I tried turning the local file into a URI (i.e.
file:///path/to/fexample.json
) and that would not render.Loading the (geo)json also will work if you filter the
data
json object todata['features']
.One thing I don't currently understand is how to pass in a dataframe to the geojson layer. In the GeoJson you have an array of features which will have at minimum a
geometry
key as well as an optionalproperties
key.Beta Was this translation helpful? Give feedback.
All reactions