简体   繁体   中英

Producing Buffer Radius Polygons - Possible Projection Issue

I created a GeoDataFrame with a Points geometry column:

1. Create df

df = pd.DataFrame([[51.502687, -3.538329, 2242, 1, 47],
                   [52.699185, -0.050122, 870, 2, 35],
                   [51.574387, 0.397882, 651, 3, 47],
                   [51.43874, 0.395791, 625, 4, 35],
                   [51.23965, 0.561919, 614, 5, 36]],
                   columns = ["lat","long","num_of_trucks","performance","num_of_routes"]
                 )

df 

2. Create gdf from df

gdf = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df["lat"],df["long"]),
                                                                 crs={"init": "epsg:4326"})
gdf

3. Reproject to CRS that uses metres and calculate 10KM buffer_radius around each Point

gdf.to_crs(epsg=3395,inplace=True)
#gdf.to_crs(epsg=3857,inplace=True)
#gdf.to_crs(epsg=27700,inplace=True)

gdf["buffer_radius"] = gdf.geometry.buffer(10000)

4. Change Geometry column to new buffer_radius column

gdf = gdf.set_geometry('buffer_radius')
gdf.geometry.name
Out: 'buffer_radius'

The above process appeared to produce my desired GeoDataFrame gdf with a new "geometry" column called buffer_radius that contains Polygons.

I then wanted to plot these newly created Polygons, so first I converted the CRS of the buffer_radius column:

5. Reproject to CRS that allows me to produce plot:

gdf.to_crs(epsg=4326,inplace=True)

6. Produce final plot:

I then tried to plot the polygons however it returned an empty plot:

gv.Polygons(gdf)

在此处输入图片说明

The fact that my plot returns empty made me wonder if it was a possible projection issue?

Does anyone have any idea what I am doing wrong here? Any thoughts or pointers would be massively appreciated.

Thanks

This is apparently an issue with geoviews , which instead of using the active geometry column uses the default column called geometry . If you just override geometry column with your buffer ( gdf["geometry"] = gdf.geometry.buffer(10000) ) or make sure that the dataframe you want to plot has the geometry you want in geometry column, it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM