Access GeoPandas points' lat/long in encode() ?
See original GitHub issueHi,
Is there an elegant way to adress the lat and long component of points in the geometry column of a Geopandas Dataframe in Altair’s encode method to link it to latitude and longitude? I could not find anything on this in the documentation.
I understand that it transparently does it for mark_geoshape(), but for the case of graduated symbol maps, e.g., via mark_circle(), it would be nice to have a bit more control and not have to generate separate columns in the DataFrame just to point at it.
Here is a relatively minimal example:
import altair as alt
import pandas as pd
import geopandas as gpd
districts = gpd.read_file("https://opendata.potsdam.de/explore/dataset/statistische-bezirke-in-potsdam/download/?format=geojson")
schools = gpd.read_file("https://opendata.potsdam.de/explore/dataset/schulen/download/?format=geojson")
# i would like to skip this step:
schools['lon'] = schools['geometry'].x
schools['lat'] = schools['geometry'].y
basemap = alt.Chart(districts).mark_geoshape(fill="lightgray", stroke="darkgray"
).encode(tooltip="bezeichnun")
pois = alt.Chart(schools).mark_circle().encode(
latitude='lat:Q',
longitude='lon:Q',
tooltip="schulname",
size="planungsra:Q"
)
basemap + pois
Thanks a lot, Marian
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
geopandas.points_from_xy
Generate GeometryArray of shapely Point geometries from x, y(, z) coordinates. In case of geographic coordinates, it is assumed that longitude is captured...
Read more >Reverse Geocoding in Python - Towards Data Science
Reverse geocoding is the process of back (reverse) coding of a point location (latitude, longitude) to a readable address or place name.
Read more >2. More Advanced Python - Using Shapefiles with GeoPandas
We include points_from_xy() when we specify the geometry. This takes the latitude and longitude columns and uses them to create point objects that...
Read more >Introduction to Geospatial Raster and Vector Data with Python
Raster datasets can usually only encode one data type, for example you can't have a multiband ... Load point, line, and polygon vector...
Read more >Perform a Spatial Join in Python - Coiled
For example, you can join a point-based dataset with a polygon-based ... A neat trick to know about GeoPandas is that calling .plot()...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Actually, I take that back. There is a shortcut here, using vega-lite’s syntax for nested data encodings:
Yeah also just realized that it should be possible like this. It’s a bit better then assigning new
lat
,lon
columns👍.Side note: You could not have known this from the Python side, since there is no
schools.geometry.coordinates
in the GeoDataFrame. The GeoDataFrame is serialised as (slightly custom) GeoJSON for Vega-Lite insertion and referred to in the Altair spec.