[GIS] How to validate longitude and latitude coordinates in Python

geopandaspythonshapely

I am working on a bunch of shapefile data, and I need to process it and after some kind of processing, I need to feed the data to an indexer (in this case ElasticSearch). The problem is I just discovered that there are some anomalies in the data. I found this in one of my polygons.

[(593.0587471450001, -1.8046608309999783),
 (593.0587471160001, -1.8046608379999611),
 (593.0587470810001, -1.804660872999932),
....]

Now correct me if I am wrong, but aren't longitudes suposed to be in the range of -180 to 180 and latitudes in the range of -90 to 90? So the numbers above just don't make sense. Is there any function in shapely, GeoPandas or any other library that can validate/check whether a coordinate is valid or not? Or should I do that manually?

UPDATE:

<Geographic 2D CRS: EPSG:4326>
Name: WGS 84
Axis Info [ellipsoidal]:
- Lat[north]: Geodetic latitude (degree)
- Lon[east]: Geodetic longitude (degree)
Area of Use:
- name: World
- bounds: (-180.0, -90.0, 180.0, 90.0)
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich

Also I don't know if this is relevant, but I only found this one polygon with very big numbers in it. The other polygons in the same file are fine (in the right range).

Best Answer

use crs attribute, for example

x = gpd.read_file("your_shapefile.shp")
coord = x.crs
print(coord)

there should be an EPSG value, and that is your coordinate system.
according to this right here what you need to do about your over 180 degrees coordinate value is to subtract/add it by 360 until it is in the range of -180 and 180 degrees.

to verify if your data is correct, you might want another shapefile, that you know that the shapefile is in good projection quality, as your orientation and overlay/subplot them.

#read trusted good quality shapefile for orientation
verif = gpd.read_file("orientation_shapefile.shp")

#plot the layers
base = x.plot()
verif.plot(ax=base)
plot.show()