1

I am looking to get the lat and lon coordinates for a number of different polygons in a geodataframe. The following code was suggested on another answer but this returns non lat and lon numbers (lon = '-888206.6310457245' lat = '4311591.57901232').

nc_counties['lat'] = (nc_counties.centroid.x)
nc_counties['lon'] = (nc_counties.centroid.y)

I have attempted to use the points_object.x as listed here. I have also tried that method on the shapely object in my geometry column.

nc_counties['lat'] = (nc_counties['geometry'].points_apply.x)

I get error "AttributeError: 'GeoSeries' object has no attribute 'points_apply'" How can I get usable lat and lon coordinates -xx.xxxxx and yy.yyyy that can be used with other programs rather than the longer odd answers of (lon = '-888206.6310457245' lat = '4311591.57901232')?

3

Your data is in a projected coordinated system, and your coordinates are perfectly normal not "odd" at all.

Just reproject your geodataframe to a geographic CRS, e.g EPSG:4326

nc_counties = nc_counties.to_crs(4326)
nc_counties['lon'] = nc_counties.centroid.x  
nc_counties['lat'] = nc_counties.centroid.y

Note lat = y and lon = x, not the other way around like you had in your code snippet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.