July 2017
Beginner to intermediate
378 pages
10h 26m
English
You can also test if one spatial object contains another, such as a point in a polygon or a city in a state using the contains function. This can be used to determine if a location is in a postal code, province, or congressional district. The within function is the inverse and determines if the object is within another object:
#import polygon classfrom shapely.geometry import Polygon#create a square polygonpolysquare = Polygon([(0,0),(0,2),(2,2),(2,0),(0,0)])#test if polygon contains the pointprint(polysquare.contains(Point(1,1)))#test if point is within the polygonprint(Point(1,1).within(polysquare))#test if other point is within the polygonprint(Point(5,7).within(polysquare))