To do some geospatial analysis I am using the USA counties map from topojson/us-atlas repository
After loading the link https://cdn.jsdelivr.net/npm/us-atlas@3/counties-10m.json in geopandas I get the geodataframe correctly.
import geopandas as gpd
counties = gpd.read_file('https://cdn.jsdelivr.net/npm/us-atlas@3/counties-10m.json')
Then I just do the following to get the longitude and latitude -
counties['lon'] = counties['geometry'].centroid.x
counties['lat'] = counties['geometry'].centroid.y
But I get the error -
IndexError: list index out of range
Only the centroid
attribute seems to give the output :
counties['geometry'].centroid
gives -
0 POINT (-113.75823 35.70499)
1 POINT (-90.40498 30.62627)
2 POINT (-114.13825 43.00235)
3 POINT (-96.40159 47.77421)
4 POINT (-97.24835 46.93312)
Any idea how to get the longitude and latitude of the counties / states from the us-atlas file?
centroid
too would have given error right? I plotted the raw data and it worked, so I figured that atleast the geometries are alright. But I not so sure. Maybe you can check since the file is there in topojson's repository.None
in that case. You can check withcounties.geometry.isna().any()
,counties.geometry.is_empty().any()
andcounties.geometry.is_valid().any()
.counties.geometry.isna().any()
I get False. But the rest give the same errorTypeError: 'Series' object is not callable
()
. Ascounties.geometry.is_empty.any()