I want to filter shapefiles by their latitude behaviour: If the latitudes of edges A and B are constantly decreasing or increasing then this class marked as correct, otherwise are incorrect. For example, the red polygon should be marked as incorrect! (Because it starts increasing at the point C.)
This code works but selects also some correct shapefiles (because I set an absolute value for checking the latitude. This behaviour appears in north and south).
Does someone know how can I detect this kind of shapefile?
Code
import shapefile
import numpy as np
sf = shapefile.Reader(r"shapefiles/shapefiles.shp")
of = r"_temp/error.txt"
shapes = sf.shapeRecords()
ids = np.zeros(len(shapes))
output = open(of, 'w')
output.close()
output = open(of, 'a')
for shp in shapes:
lats = np.zeros(len(shp.shape.points))
lons = np.zeros(len(shp.shape.points))
for i in range(0, len(shp.shape.points)):
point = shp.shape.points[i]
lats[i] = (point[1])
lons[i] = (point[0])
if max(lats)>86.5:
#print shp.record[0]
continue
if min(lats)<-79.2:
#print shp.record[0]
continue
# identification of shapefiles crossing dateline - not needed here
#if max(lons)>179.9: continue
#if min(lons)<-179.9: continue
output.write(shp.record[0]+'\n')
output.close()
No comments:
Post a Comment