本文整理汇总了Python中shapely.geometry.Point.intersects方法的典型用法代码示例。如果您正苦于以下问题:Python Point.intersects方法的具体用法?Python Point.intersects怎么用?Python Point.intersects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shapely.geometry.Point
的用法示例。
在下文中一共展示了Point.intersects方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_on_edge
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import intersects [as 别名]
def is_on_edge(self, moveable_obj, edge_index):
edge = self.vertices_of_edges[edge_index]
radius = moveable_obj.fixtures[0].shape.radius
center = moveable_obj.position
circle = Point(center).buffer(radius)
edge_line = Line(edge).buffer(1)
return circle.intersects(edge_line)
示例2: game_loop
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import intersects [as 别名]
def game_loop(self):
while 1:
for event in pygame.event.get():
if event.type == QUIT:
return
elif event.type == KEYDOWN and event.key == K_ESCAPE:
return
elif event.type == MOUSEBUTTONDOWN:
pt = Point(pygame.mouse.get_pos())
#this list comprehension gets the clicked region
pt_match = ([[key for key,val in regns.iteritems()
if pt.intersects(Polygon(val))] for regns in self.all_regions])
if pt_match:
#clear out the empty lists so that pt_match
#only contains the region string
pt_match = [match for match in pt_match if match]
try:
#send click info to the world object
self.world.process_action(pt_match[0][0])
except IndexError:
pass
self.screen.blit(self.background, (0, 0))
pygame.display.flip()
示例3: bnw
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import intersects [as 别名]
def bnw(self, inside=False):
poly = Polygon(self.lines)
for y in xrange(self.size):
for x in xrange(self.size):
p = Point(x,y)
if p.intersects(poly):
self.array[x,y] = 1
else:
self.array[x,y] = -1
示例4: intersect_point
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import intersects [as 别名]
def intersect_point(objshape, lat, lon, t_srs=config.TARGET_PROJECTION, s_srs=config.SOURCE_PROJECTION, transform=True):
'''Transform point checks if Point intersects objshape '''
if transform == True:
x, y = transform_point(lat, lon, t_srs, s_srs)
else:
x, y = lat, lon
point = Point(x, y)
if point.intersects(shape(objshape)):
return True
return False
示例5: perform_geo_class_nyc
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import intersects [as 别名]
def perform_geo_class_nyc():
"""
since the slowest part of this is figuring out which borough things are in,
we are going to classify them and store the result in SQL where a JOIN
will hopefully be quicker.
:return:
"""
connect()
boroughs = fiona.open('./shp/nybb_wgs84.shp', 'r')
geoms = list()
for item in boroughs:
shply_shape = shape(item['geometry'])
adder = [shply_shape, item['properties']['BoroName']]
geoms.append(adder)
curs = CONNECTION.cursor(cursor_factory=psycopg2.extras.DictCursor)
notes = "nyc_class"
sql = "SELECT fd.latitude, fd.longitude, fd.internal_id, gc.geo_notes " \
"FROM flickr_data fd " \
"LEFT JOIN geo_class gc ON (fd.internal_id=gc.internal_id) " \
"WHERE gc.internal_id IS NULL"
# Warning: doens't take into account non-NYC classifications
curs.execute(sql)
res = curs.fetchall()
print("Results to categorize: ", len(res))
for numcoord, line in enumerate(res):
if (numcoord % 10000) == 0:
print(time.asctime(), "Geo categorized: ", numcoord)
tgt_point = Point(line['longitude'], line['latitude'])
# if not tgt_point.intersects(not_nyc_shp):
tval = -1
for index, geo in enumerate(geoms):
if tgt_point.intersects(geo[0]):
tval = index
break
geo_code = tval
if tval > -1:
geo_text = geoms[tval][1]
else:
geo_text = "none"
sql = "INSERT INTO geo_class" \
" (geo_code, geo_text, internal_id, geo_notes) " \
"VALUES (%s, %s, %s, %s)"
data = (geo_code, geo_text, line['internal_id'], notes)
curs.execute(sql, data)
CONNECTION.commit()
示例6: inside_limits
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import intersects [as 别名]
def inside_limits(self, point):
"""Checks if point is inside coords limits or possible region."""
if not self.regions:
# Use rectangle check
lat, lon = point.latitude, point.longitude
if (lon > self.limits[0] and lat > self.limits[1] and
lon < self.limits[2] and lat < self.limits[3]):
return True
else:
return False
else:
# Check inside all possible regions
p = Point((point.longitude, point.latitude))
for name, poly in self.regions.items():
# if poly.contains(p):
if p.intersects(poly):
return name
return False
示例7: game_loop
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import intersects [as 别名]
def game_loop():
while 1:
for event in pygame.event.get():
if event.type == QUIT:
return
elif event.type == KEYDOWN and event.key == K_ESCAPE:
return
elif event.type == MOUSEBUTTONDOWN:
pt = Point(pygame.mouse.get_pos())
#this list comprehension gets the clicked region
pt_match = ([[key for key,val in regns.iteritems()
if pt.intersects(Polygon(val))] for regns in all_regions])
if pt_match:
#player clicked a region, coords are in nested list
#clear out the empty lists so that pt_match
#only contains the region int
pt_match = [match for match in pt_match if match]
try:
pt_int = pt_match[0][0]
print "state is "
print pt_int
except IndexError:
pt_int = 14
else:
#player clicked outside of a region
pt_int = 15
#send click info to the world object
global world
world = _world.process_action(world, pt_int)
world = _world.refresh(world)
color_regions(world)
'''
if world['end'] == 1:
print "Game over."
return
'''
background.blit(foreground, (0, 0))
screen.blit(background, (0, 0))
pygame.display.flip()
pygame.display.update()
示例8: blocks
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import intersects [as 别名]
def blocks(self, location):
""" If the location is blocked by some other location
in the index, return the blocker's name or False.
"""
coord = self.locationCoordinate(location).zoomTo(self.zpixel)
point = Point(coord.column, coord.row)
# figure out which quad the point is in
key = quadkey(coord.zoomTo(self.zgroup))
# first try the easy hash check
if key not in self.quads:
return False
# then do the expensive shape check
for (name, area) in self.quads[key]:
if point.intersects(area):
# ensure name evals to true
return name or True
return False
示例9: get_borough_item
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import intersects [as 别名]
def get_borough_item(json_line, borough_geoms, stopwords, findwords):
"""
given a line of JSON data, return the borough and JSON line, if applicable.
If no borough, return a -1 code .
:param json_line: JSON flickr object
:param borough_geoms: Geometry objects for boroughs
:return: (borough_key, JSON flickr object)
"""
geoms = borough_geoms
lat = json_line['latitude']
lon = json_line['longitude']
# It pains me to do the below two lines, but sometimes flickr
# sends back geos that match NYC but the original data is bad
# I think it has to do with their indexing being diffrent from
# actual values? But anyways, we need the data and the tags
# make sense for NYC.
if lon > 0:
lon *= -1
tgt_point = Point(lon, lat) # silly shapely - Point(x,y,z)
ret_val = list()
# if not tgt_point.intersects(not_nyc_shp):
for index, geo in enumerate(geoms):
if tgt_point.intersects(geo[0]):
ret_val.append(index)
break
if len(ret_val) > 0:
tags = json_line['tags'] + " " + json_line['title']
tags = clean_tags(tags, stopwords, findwords)
if len(tags) > 20: # more than 20 chars
ret_val.append(tags)
return ret_val
else:
return False
示例10: test_intersects
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import intersects [as 别名]
def test_intersects():
circle = Point([1,2]).buffer(2)
line = LineString([[0,0],[2,0]])
c = line.buffer(1)
circle.intersects(c)
示例11: fix_duplicated_lines
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import intersects [as 别名]
def fix_duplicated_lines(lines, MINIMALDIST):
new_lines=[]
while len(lines)>0:
print len(lines),len(new_lines)
l1=lines[0]
if l1.length<MINIMALDIST:
print 'Null-length'
lines.pop(0)
continue
if len(lines)==0:
break
elif len(lines)==1:
new_lines.append(l1)
lines.pop(0)
break
else:
for i in range(1, len(lines)+1):
if i==len(lines):
new_lines.append(l1)
lines.pop(0)
break
l2=lines[i]
if l2.length<MINIMALDIST:
print 'Null-length'
lines.pop(i)
break
a1=angle_of_line(l1)
a2=angle_of_line(l2)
if math.fabs(a1-a2)<=2:
bff=l1.buffer(MINIMALDIST, resolution=16, cap_style=2)
if bff.intersects(l2)==True:
if bff.exterior.intersection(l2).geom_type=='GeometryCollection':
# contains
lines.pop(i)
print 'Contains'
break
elif bff.exterior.intersection(l2).geom_type=='Point':
# overlapped or consecutive
pt11=Point(list(l1.coords)[0])
pt12=Point(list(l1.coords)[1])
pt21=Point(list(l2.coords)[0])
pt22=Point(list(l2.coords)[1])
if pt21.intersects(bff)==True:
if pt22.distance(pt11)>=pt22.distance(pt12):
nl=LineString([(pt11.x, pt11.y), (pt22.x, pt22.y)])
else:
nl=LineString([(pt12.x, pt12.y), (pt22.x, pt22.y)])
else:
if pt21.distance(pt11)>=pt21.distance(pt12):
nl=LineString([(pt11.x, pt11.y), (pt21.x, pt21.y)])
else:
nl=LineString([(pt12.x, pt12.y), (pt21.x, pt21.y)])
lines.pop(i)
lines.pop(0)
lines.append(nl)
print 'Overlapped or Consecutive'
break
elif bff.exterior.intersection(l2).geom_type=='MultiPoint':
# contained
lines.pop(0)
print 'Contained'
break
return new_lines
示例12: ISR_figures_demo
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import intersects [as 别名]
def ISR_figures_demo():
import mywfc3.orient
#### Pixel scale
ps = {'x':0.1355, 'y':0.1211}
#### dispersion offsets
disp_box = {'G102': [53, 210], 'G141': [36, 168]}
#### Apertures
refpix_aper = {'GRISM1024':[497, 562], 'IR':[562, 562], 'IR-FIX': [512,512]}
grism = 'G102'
aper = 'GRISM1024'
#### Demo
fig = unicorn.plotting.plot_init(xs=11, aspect=1./4, square=True, left=0.01, bottom=0.01, right=0.01, top=0.01, use_tex=True, NO_GUI=True)
theta_pairs = [[-20], [50], [160], [-20,50,160]]
dx = 0.99/len(theta_pairs)
for i in range(len(theta_pairs)):
ax = fig.add_axes((0.005+i*(dx+0*0.005),0.01, dx, 0.97))
if i < 3:
ax.text(0.5, 0.05, r'PA($y$) = %d' %(-theta_pairs[i][0]), transform=ax.transAxes, ha='center', va='bottom')
else:
ax.text(0.5, 0.05, r'PA($y$) = %d $\times$ %d $\times$ %d' %(-theta_pairs[i][0], -theta_pairs[i][1], -theta_pairs[i][2]), transform=ax.transAxes, ha='center', va='bottom')
ax.scatter(refpix_aper[aper][0]*ps['x'],refpix_aper[aper][1]*ps['y'], color='purple', marker='x', s=60, label=aper)
plt_range = np.array([-72, 180])*0.95
ax.set_xlim(plt_range+10); ax.set_ylim(plt_range+10)
ax.set_xticklabels([]); ax.set_yticklabels([])
ax.set_xticks(ax.get_xlim()); ax.set_yticks(ax.get_ylim())
ax.plot([-1000,-1100],[-1110,-1100], color='green', alpha=0.4, linewidth=2, label=grism)
if i == 0:
ax.legend(scatterpoints=1, loc='upper left', fontsize=10)
#theta = 70
pair = theta_pairs[i]
results = []
for theta in pair:
result = mywfc3.orient.overlap(theta=theta, grism=grism, have_mosaic=True, plot=False, aper='GRISM1024', f_spec=0.5, recenter_target=False)
results.append(result)
overlap_region = results[0][1].intersection(results[0][1])
for result in results:
overlap_region = overlap_region.intersection(result[1])
for j in range(len(pair)):
full_poly, sub_poly = results[j][0], results[j][1]
full_patch = PolygonPatch(full_poly, fc='None', ec='black', alpha=0.9, zorder=-2)
sub_patch = PolygonPatch(sub_poly, fc='black', ec='black', alpha=0.2, zorder=-2)
ax.add_patch(full_patch)
ax.add_patch(sub_patch)
### Death star
xds, yds = threedhst.utils.xyrot(np.array([357,357])*ps['x'], np.array([55,55])*ps['y'], pair[j], x0=refpix_aper[aper][0]*ps['x'], y0=refpix_aper[aper][1]*ps['y'])
ds = Point(xds[0], yds[0]).buffer(20*ps['x'])
ds_patch = PolygonPatch(ds, fc='None', ec='black', alpha=0.9, zorder=-2)
ax.add_patch(ds_patch)
if i == 3:
isect_patch = PolygonPatch(overlap_region, fc='green', ec='green', alpha=0.2, zorder=1)
ax.add_patch(isect_patch)
else:
for xi in np.arange(-15, 180, 33):
for yi in np.arange(15, 180, 30):
pi = Point((xi, yi))
if pi.intersects(overlap_region):
ax.scatter(xi, yi, color='green', alpha=0.8, zorder=1)
trace_x = xi+np.array(disp_box[grism])*ps['x']
trace_y = np.array([yi,yi])
trace_x, trace_y = threedhst.utils.xyrot(trace_x, trace_y, pair[j], x0=xi, y0=yi)
#ax.plot(trace_x, trace_y, color='green', alpha=0.4, linewidth=2, zorder=1)
trace_line = LineString([(trace_x[0], trace_y[0]), (trace_x[1], trace_y[1])])
trace_in_full = trace_line.buffer(1, resolution=8)
ax.add_patch(PolygonPatch(trace_in_full, fc='black', ec='None', alpha=0.15, zorder=1))
trace_in_full = trace_line.buffer(1, resolution=8).intersection(full_poly)
ax.add_patch(PolygonPatch(trace_in_full, fc='green', ec='None', alpha=0.5, zorder=1))
unicorn.plotting.savefig(fig, 'orient_demo.pdf')
#### Testing
if False:
line = LineString([(-2,0.5), (0.5, 0.5)])
full_box_x = np.array([0, 1, 1, 0, 0])
full_box_y = np.array([0, 0, 1, 1, 0])
box = Polygon(np.array([full_box_x, full_box_y]).T)
line_within = line.buffer(0.02, resolution=8).intersection(box)
plt.figure()
ax = plt.gca()
ax.add_patch(PolygonPatch(box, fc='black', ec='black', alpha=0.2, zorder=-2))
ax.add_patch(PolygonPatch(line_within, fc='green', ec='None', alpha=0.2, zorder=-1))
plt.xlim(-2,2)
#.........这里部分代码省略.........
示例13: Point
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import intersects [as 别名]
grid_polygons.append(Polygon(s.points))
xpts = np.linspace(xmin+pt_deltax,xmax-pt_deltax,5)
ypts = np.linspace(ymin+pt_deltay,ymax-pt_deltay,10)
#--find valid points - those that intersect a model cell with an appropriate ibound
valid_points = []
valid_Points = []
for x in xpts:
for y in ypts:
pt = [x,y]
point = Point(pt)
#--make sure this point is in an active model cell
for poly,rec in zip(grid_polygons,grid_records):
ibnd = rec[ibnd_idx]
if ibnd != 0 and ibnd != 2 and point.intersects(poly):
valid_points.append([x,y])
valid_Points.append(point)
pass
#--write a valid points shapefile
wr = shapefile.Writer()
wr.field('x',fieldType='N',size=20,decimal=3)
wr.field('y',fieldType='N',size=20,decimal=3)
for [x,y] in valid_points:
wr.poly([[[x,y]]],shapeType=shapefile.POINT)
wr.record([x,y])
wr.save('shapes\\nexrad_points')
示例14: intersection
# 需要导入模块: from shapely.geometry import Point [as 别名]
# 或者: from shapely.geometry.Point import intersects [as 别名]
def intersection(self, lon, lat):
if self.index_zupc is None:
self.__init_zupc()
p = Point(lon, lat)
return [i.id for i in self.index_zupc.intersection((lon, lat, lon, lat),
objects=True) if p.intersects(i.object)]