GeoPandas: return lat and long of a centroid point

المشرف العام

Administrator
طاقم الإدارة
I would like to return the lat and lon or x and y from the point object in the following series as I plan to link them with an API I built that links OSM and NetworkX. The centroids will be added as new nodes for network analysis.

gp.GeoSeries(zones.centroid).x, and gp.GeoSeries(zones.centroid).y as outlined in docs raise AttributeError: 'GeoSeries' object has no attribute 'x' error.

Modifying things a bit and printing list(gp.GeoSeries(zones.centroid)) return thousands of shapely points of the following format:

[... ,, , , , , , ]The code I'm using is the following:

import geopandas as gpzones = gp.GeoDataFrame.from_file(shp_file)for index, row in zones.iterrows(): print index, gp.GeoSeries(zones.centroid)# result:# 9700022.00 POINT (-122.8196050489696 54.00617624128658)# 9700023.00 POINT (-122.7474362519174 53.99998921974029)# 9700100.00 POINT (-121.4904983300892 53.98447191612864)# 9700101.00 POINT (-122.5513619751679 53.73999791511078)# 9700102.00 POINT (-123.0624037191615 53.62317549646422)# 9700103.00 POINT (-123.0848175548173 54.05921695782788)How can I return the x and y from the GeoPandas POINT object?



أكثر...
 
أعلى