TransWikia.com

Get min/max lat and long values from geodataframe

Geographic Information Systems Asked by jtam on July 3, 2021

I am new to Geopandas and I want the min and max values of both latitude and longitude for a single record. The Geodataframe is structured as so (not sure it matters):

STATEFP   STATENS     GEOID   STUSPS   NAME   geometry
49         48           48      TX     Texas  (POLYGON ((-94.718296 29.728855, -94.717207 29... 

2 Answers

Individual POLYGONs in geometry column are shapely objects, so you can use .bounds method on this object to get a tuple of (minx, miny, maxx, maxy).

from shapely.geometry import Polygon
poly = Polygon([[1,2], [2,5], [4,6], [5,3], [1,2]])
poly.bounds
# out: (1.0, 2.0, 5.0, 6.0)

Correct answer by Alz on July 3, 2021

If you're using ESRI shapefile as vectorfile, then

import geopandas as gpd
from shapely.geometry import Polygon

vector_file_path=r"C or D:pathshapefilename.shp"
vector_data=gpd.read_file(vector_file_path)
vector_bound_coordinates= vector_data['geometry']
vector_bound_coordinates.bounds
out[]: 
      minx        miny         maxx        maxy
0   78.158751   19.172422   78.977808   19.916980
1   77.423083   26.741696   78.854721   27.409776
2   71.839711   21.984888   72.843705   23.508623
3   73.908371   25.647207   75.353247   26.978540
4   76.692215   20.274559   77.620988   21.247055
... ... ... ... ...
712 86.796486   23.409566   87.539374   23.880466
713 87.054093   21.763803   87.892579   22.951303
714 87.438626   22.932676   88.419780   23.843992
715 85.832496   22.703573   86.899489   23.697929
716 87.809878   25.241873   88.533093   26.496043

Answered by Abhilash Singh Chauhan on July 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP