Last active
March 26, 2020 15:20
-
-
Save capooti/7aa7cd4f5a2f4a034b2933dc105027cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fiona | |
from shapely.geometry import shape, Point | |
def is_point_in_poly_with_iteration(shape_path, coords): | |
print(coords) | |
point = Point(coords) | |
with fiona.open(shape_path) as source: | |
for i, feat in enumerate(source): | |
if point.within(shape(feat['geometry'])): | |
print(f'Found it after checking {i} features!') | |
return True | |
print('Could not find it') | |
return False | |
shp_path = 'data/Ultra_Rural_V8/Ultra_Rural_V8.shp' | |
coords_list = [ | |
[18.9579665978941, -31.0257535106293], | |
[23.0105144945916, -32.5487989838937], | |
[25.4153231365879, -31.123727196044], | |
[26.1812992225571, -31.1771673880884], | |
[21.897177160334, -31.6848492125098], | |
[26.0922322358165, -32.3884784077606], | |
[21.7992034749193, -33.7957367982621], | |
[22.3692321900592, -34.3212320200317], | |
[19.385488134249, -31.9698635700797], | |
[18.5838852535835, -30.1439903418974], | |
] | |
for coords in coords_list: | |
is_point_in_poly_with_iteration(shp_path, coords) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment