-
-
Notifications
You must be signed in to change notification settings - Fork 108
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
checks geodataframe for crs before conversion #1459
base: main
Are you sure you want to change the base?
Conversation
Azaya89
commented
Nov 25, 2024
- fixes "AttributeError: 'DataFrame' object has no attribute 'crs'" for spatialpandas polygons #1457
- tests added
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1459 +/- ##
==========================================
+ Coverage 88.94% 88.96% +0.01%
==========================================
Files 52 52
Lines 7781 7799 +18
==========================================
+ Hits 6921 6938 +17
- Misses 860 861 +1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we don't automatically project with tiles=True
when the data is:
- a lazy dataset
- a spatialpandas object
If think we need to update the docs to mention the second item, the first one is already documented.
Side note but I think I just realized that GeoDataFrame
means:
- Geometry DataFrame for spatialpandas
- GeoSpatial DataFrame for geopandas
Could that be true? :)
We do project when bk_plot = bk_renderer.get_plot(plot)
assert bk_plot.projection == 'mercator' # projection enabled due to `tiles=True`
I think so. See https://github.com/holoviz/hvplot/blob/main/hvplot/util.py#L496 |
@Azaya89, no :) The data is presented on a map with Mercator coordinates but hvPlot doesn't convert the coordinates to Mercator, so they all go on vacation to the null island! I guess that, when the data is a spatialpandas object, we should apply the same logic as for a standard Pandas DataFrame object. This is where Full Code
import geopandas as gpd
import spatialpandas as spd
import hvplot.pandas
# hack to get spatialpandas to work (already fixed, not in a final release yet)
import numpy as np
np.VisibleDeprecationWarning = np.exceptions.VisibleDeprecationWarning
data = {
'City': ['London', 'Paris', 'Berlin', 'Madrid', 'Rome', 'Vienna', 'Warsaw', 'Amsterdam'],
'Country': ['United Kingdom', 'France', 'Germany', 'Spain', 'Italy', 'Austria', 'Poland', 'Netherlands'],
'Latitude': [51.5074, 48.8566, 52.5200, 40.4168, 41.9028, 48.2082, 52.2297, 52.3676],
'Longitude': [-0.1278, 2.3522, 13.4050, -3.7038, 12.4964, 16.3738, 21.0122, 4.9041]
}
gdf = gpd.GeoDataFrame(
data,
geometry=gpd.points_from_xy(data['Longitude'], data['Latitude']),
crs="EPSG:4326",
)
gdf.hvplot.points(tiles=True, color='red')
sdf = spd.GeoDataFrame(gdf)
sdf.hvplot.points(tiles=True, color='red') |
Is having a |
That certainly means it has something geo-related but not necessarily geographic, which is what we need here to perform the conversion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks right to me!