本文整理汇总了Python中shapely.geometry.Point.contains方法的典型用法代码示例。如果您正苦于以下问题:Python Point.contains方法的具体用法?Python Point.contains怎么用?Python Point.contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shapely.geometry.Point
的用法示例。
在下文中一共展示了Point.contains方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_busses_in_circle
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import contains [as 别名]
def get_busses_in_circle(self,key,lat,lng,dist):
cherrypy.response.headers["Access-Control-Allow-Origin"] = "*"
circle = Point(float(lat),float(lng)).buffer(float(dist))
ourRoutes = []
city_data = []
with open(os.path.join(PATH, 'stops.pickle'), 'rb') as f:
stops = pickle.load(f)
for stopid, stop in stops.items():
point = Point(float(stop.lat), float(stop.lng))
if circle.contains(point):
ourRoutes.extend(stop.routes)
ten = []
while (len(ourRoutes) > 10):
ten.append(ourRoutes.pop())
print ten
if (len(ten) == 10):
url = "http://www.ctabustracker.com/bustime/api/v1/getvehicles?key="+keys[0]+"&rt="+",".join(ten)+"&format=json&diagnostics=true&callback="
r = requests.get(url)
i=0
while (r.text.find("exceeded") != -1):
url = "http://www.ctabustracker.com/bustime/api/v1/getvehicles?key="+keys[i]+"&rt="+",".join(ten)+"&format=json&diagnostics=true&callback="
r = requests.get(url)
i=i+1
ten = []
j = r.json()
for bus in j['bustime-response'][0]['vehicle']:
city_data.append(bus)
url = "http://www.ctabustracker.com/bustime/api/v1/getvehicles?key="+keys[0]+"&rt="+",".join(ourRoutes)+"&format=json&diagnostics=true&callback="
r = requests.get(url)
i=0
while (r.text.find("exceeded") != -1):
url = "http://www.ctabustracker.com/bustime/api/v1/getvehicles?key="+keys[i]+"&rt="+",".join(ourRoutes)+"&format=json&diagnostics=true&callback="
r = requests.get(url)
i=i+1
j = r.json()
for bus in j['bustime-response'][0]['vehicle']:
city_data.append(bus)
ret_busses = []
for bus in city_data:
point = Point(float(bus['lat']), float(bus['lon']))
if circle.contains(point):
ret_busses.append(bus)
return json.dumps(ret_busses)
示例2: get_nearby_stations
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import contains [as 别名]
def get_nearby_stations(self, lat, lng, dist):
cherrypy.response.headers["Access-Control-Allow-Origin"] = "*"
r = requests.get('http://www.divvybikes.com/stations/json/')
jsonData = r.json()
stations = jsonData['stationBeanList']
ret_stations = []
circle = Point(float(lat),float(lng)).buffer(float(dist))
for station in stations:
point = Point(station['latitude'], station['longitude'])
if circle.contains(point):
ret_stations.append(station)
return json.dumps(ret_stations)
示例3: test_binary_predicates
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import contains [as 别名]
def test_binary_predicates(self):
point = Point(0.0, 0.0)
self.assertTrue(point.disjoint(Point(-1.0, -1.0)))
self.assertFalse(point.touches(Point(-1.0, -1.0)))
self.assertFalse(point.crosses(Point(-1.0, -1.0)))
self.assertFalse(point.within(Point(-1.0, -1.0)))
self.assertFalse(point.contains(Point(-1.0, -1.0)))
self.assertFalse(point.equals(Point(-1.0, -1.0)))
self.assertFalse(point.touches(Point(-1.0, -1.0)))
self.assertTrue(point.equals(Point(0.0, 0.0)))
示例4: Point
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import contains [as 别名]
sCircle = Point(circleX, circleY)
sCircle = sCircle.buffer(circleRadius, 16)
pointList = []
for i in range(numberOfPoints):
x = random.randint(0, gridWidth)
y = random.randint(0, gridHeight)
pointList.append((x, y))
iPoint = Point(x, y)
iPoint.idx = i # set our custom attribute. (if this doesnt work I have other ways)
shapePoints.append(iPoint)
matchingPoints = []
searchBench = time.time()
for idx, point in enumerate(shapePoints):
if sCircle.contains(point):
matchingPoints.append(idx)
searchBench = time.time() - searchBench
print "There were %d points within the circle [%d, %d] - r[%d]\n" % (len(matchingPoints), circleX, circleY, circleRadius)
print "Calculation Took %s seconds for %s points" % (searchBench, numberOfPoints)
print "Saving Graph to %s" % (filename)
#_-------------------------------------------------------------------------------
# DRAW A REPRESENTATION OF THE LOGIC ABOVE:
import matplotlib
matplotlib.use('Agg') # Do NOT attempt to open X11 instance
from pylab import *
from matplotlib.patches import Circle
示例5: getLogger
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import contains [as 别名]
class Landmark:
''' Contains information about user-defined landmarks.'''
log = getLogger('landmarks')
def __init__(self, name, shortname=None, points=None, query=None,
hashtags=None, phrase=None, is_area=False, query_suffix=None):
self.name = name
self.shortname = shortname
self.is_area = is_area
if not points and not query:
query = name.lstrip('the ')
if ((query_suffix and query) and
query_suffix.lower() not in query.lower()):
query = '{} {}'.format(query, query_suffix)
self.location = None
if query:
self.query_location(query)
elif points:
try:
length = len(points)
if length > 2:
self.location = Polygon(points)
elif length == 2:
self.location = box(points[0][0], points[0][1],
points[1][0], points[1][1])
elif length == 1:
self.location = Point(*points[0])
except TypeError:
raise ValueError('points must be a list/tuple of lists/tuples'
' containing 2 coordinates each')
if not self.location:
raise ValueError('No location provided for {}. Must provide'
' either points, or query.'.format(self.name))
elif not isinstance(self.location, (Point, Polygon, LineString)):
raise NotImplementedError('{} is a {} which is not supported'
.format(self.name, self.location.type))
self.south, self.west, self.north, self.east = self.location.bounds
# very imprecise conversion to square meters
self.size = self.location.area * 12100000000
if phrase:
self.phrase = phrase
elif is_area:
self.phrase = 'in'
else:
self.phrase = 'at'
self.hashtags = hashtags
def __contains__(self, coordinates):
"""determine if a point is within this object range"""
lat, lon = coordinates
if (self.south <= lat <= self.north and
self.west <= lon <= self.east):
return self.location.contains(Point(lat, lon))
return False
def query_location(self, query):
def swap_coords(geojson):
out = []
for x in geojson:
if isinstance(x, list):
out.append(swap_coords(x))
else:
return geojson[1], geojson[0]
return out
nom = Nominatim()
try:
geo = nom.geocode(query=query, geometry='geojson', timeout=3).raw
geojson = geo['geojson']
except (AttributeError, KeyError):
raise FailedQuery('Query for {} did not return results.'.format(query))
self.log.info('Nominatim returned {} for {}'.format(geo['display_name'], query))
geojson['coordinates'] = swap_coords(geojson['coordinates'])
self.location = shape(geojson)
def get_coordinates(self):
if isinstance(self.location, Polygon):
return tuple(self.location.exterior.coordinates)
else:
return self.location.coords[0]
def generate_string(self, coordinates):
if coordinates in self:
return '{} {}'.format(self.phrase, self.name)
distance = self.distance_from_point(coordinates)
if distance < 50 or (self.is_area and distance < 100):
return '{} {}'.format(self.phrase, self.name)
else:
return '{:.0f} meters from {}'.format(distance, self.name)
def distance_from_point(self, coordinates):
point = Point(*coordinates)
if isinstance(self.location, Point):
#.........这里部分代码省略.........