本文整理汇总了Python中shapely.geometry.LineString.intersects方法的典型用法代码示例。如果您正苦于以下问题:Python LineString.intersects方法的具体用法?Python LineString.intersects怎么用?Python LineString.intersects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shapely.geometry.LineString
的用法示例。
在下文中一共展示了LineString.intersects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: my_view
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import intersects [as 别名]
def my_view(request):
start_lat, start_long = [request.matchdict['lat1'], request.matchdict['long1']]
end_lat, end_long = [request.matchdict['lat2'], request.matchdict['long2']]
start_lat = float(start_lat)
start_long = float(start_long)
end_lat = float(end_lat)
end_long = float(end_long)
zip_codes = []
required_polygon = []
with fiona.open('myproject/tl_2014_us_zcta510.shp', 'r') as f:
for line in f:
zip_code = int(line['properties']['ZCTA5CE10'])
if zip_code > 90000 and zip_code < 96163: # check for California
if line['geometry']['type'] == 'Polygon':
polygon = line['geometry']['coordinates']
s = Polygon(polygon[0])
linestr = LineString([(start_long, start_lat), (end_long, end_lat)])
if linestr.intersects(s):
zip_codes.append(zip_code)
required_polygon.append(polygon[0])
else:
multi_polygon = line['geometry']['coordinates']
for polygon in multi_polygon:
s = Polygon(polygon[0])
linestr = LineString([(start_long, start_lat), (end_long, end_lat)])
if linestr.intersects(s):
zip_codes.append(zip_code)
required_polygon.append(polygon[0])
return dict(zip_codes=zip_codes, required_polygon=required_polygon)
示例2: move_ball
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import intersects [as 别名]
def move_ball(self):
"""
Move the ball in game state
it calculates boundaries and it clips
the ball positioning when it is overlapping
with walls or paddles
return rewards when right player makes contact with the ball
and when ball leaves the game screen on the left side
"""
reward = 0.0
# get ball trajectory
prev_x, prev_y = self.ballx, self.bally
next_x, next_y = self.ballx + self.ball_speed_x, self.bally + self.ball_speed_y
ball_trajectory = LineString([(prev_x, prev_y), (next_x, next_y)])
# get possible collision lines
upper_wall = LineString([(0, 0),
(SCREEN_WIDTH, 0)])
bottom_wall = LineString([(0, SCREEN_HEIGHT - BALL_SIZE),
(SCREEN_WIDTH, SCREEN_HEIGHT - BALL_SIZE)])
left_paddle = LineString([(self.cpux + PADDLE_WIDTH, self.cpuy - BALL_SIZE),
(self.cpux + PADDLE_WIDTH, self.cpuy + PADDLE_HEIGHT)])
right_paddle = LineString([(self.playerx - BALL_SIZE, self.playery - BALL_SIZE),
(self.playerx - BALL_SIZE, self.playery + PADDLE_HEIGHT)])
# chop ball trajectory when colliding
if ball_trajectory.intersects(upper_wall):
self.ball_speed_y *= -1
upper = ball_trajectory.intersection(upper_wall)
self.ballx, self.bally = upper.x, upper.y + 1
elif ball_trajectory.intersects(bottom_wall):
self.ball_speed_y *= -1
bottom = ball_trajectory.intersection(bottom_wall)
self.ballx, self.bally = bottom.x, bottom.y - 1
elif ball_trajectory.intersects(left_paddle):
left = ball_trajectory.intersection(left_paddle)
contact_point = left.y - left_paddle.xy[1][0]
if contact_point < PADDLE_UPPER_SECTION or \
contact_point > PADDLE_BOTTOM_SECTION:
self.flip_and_spin_ball()
else:
self.flip_and_speed_ball()
self.ballx, self.bally = left.x + 1, left.y
elif ball_trajectory.intersects(right_paddle):
reward += 0.1
right = ball_trajectory.intersection(right_paddle)
contact_point = right.y - right_paddle.xy[1][0]
if contact_point < PADDLE_UPPER_SECTION or \
contact_point > PADDLE_BOTTOM_SECTION:
self.flip_and_spin_ball()
else:
self.flip_and_speed_ball()
self.ballx, self.bally = right.x - 1, right.y
else:
self.ballx += self.ball_speed_x
self.bally += self.ball_speed_y
return reward
示例3: append_to_included_groups
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import intersects [as 别名]
def append_to_included_groups(locs, d):
for group_key in d.keys():
ref_gene_poly = LineString([(0.0, float(group_key[0])),(0.0, float(group_key[1]))])
locs_poly = LineString([(0, locs[2]), (0, locs[3])])
if ref_gene_poly.intersects(locs_poly):
d[group_key].append(tuple(locs))
return d
示例4: fix_polygon
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import intersects [as 别名]
def fix_polygon(poly):
"""
Fix the polygon if it is bad formed.
:param poly:
:return:
"""
# print poly
if len(poly) <= 3:
return poly
pol = Polygon(poly)
if pol.is_valid:
return poly
final_line = LineString([poly[0], poly[-1]])
for i in range(len(poly) - 2, 0, -1):
l = LineString(poly[i:i + 2])
if l.intersects(final_line):
poly1 = poly[:i] + [poly[-1]]
return fix_polygon(poly1)
return poly
示例5: getSpecDist
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import intersects [as 别名]
def getSpecDist(pt1, pt2):
line = LineString([pt1, pt2])
for zone in no_fly_zones:
if line.intersects(zone):
return float('inf')
else:
pass
return greatcircle.get_dist(pt1,pt2)
示例6: intersection
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import intersects [as 别名]
def intersection(lineA, lineB):
line1 = LineString(lineA)
line2 = LineString(lineB)
if line1.intersects(line2):
i = line1.intersection(line2)
return i
return -1
示例7: no_fly_avoidance_waypoints
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import intersects [as 别名]
def no_fly_avoidance_waypoints(no_fly_zones, flight, airport, cruise=38000, descend_distance=150, speed=500):
print flight["FlightHistoryId"]
waypoints = direct_route_waypoints(flight, airport, cruise, descend_distance, speed)
flight_loc = (flight["CurrentLatitude"], flight["CurrentLongitude"])
first_waypoint_loc = (waypoints[0][2], waypoints[0][3])
path1 = LineString([flight_loc, first_waypoint_loc])
has_second = len(waypoints) > 1
for no_fly_zone in no_fly_zones:
if path1.intersects(no_fly_zone):
astarpath = astar.to_coord(flight_loc, first_waypoint_loc)[1:]
alt = waypoints[0][4]
spd = waypoints[0][5]
lastwp = []
if has_second:
lastwp = [waypoints[1]]
waypoints[:] = []
for i in range(len(astarpath)):
(x,y) = astarpath[i]
waypoints.append([flight["FlightHistoryId"], i+1, x, y, alt, spd])
if has_second:
lastwp[0][1] = i + 2
waypoints += lastwp
break
if not has_second:
return waypoints
second_waypoint_loc = (waypoints[-1][2], waypoints[-1][3])
path2 = LineString([first_waypoint_loc, second_waypoint_loc])
for no_fly_zone in no_fly_zones:
if path2.intersects(no_fly_zone):
astarpath = astar.to_coord(first_waypoint_loc, second_waypoint_loc)[1:]
alt = waypoints[-1][4]
spd = waypoints[-1][5]
off = waypoints[-1][1]
waypoints[:] = waypoints[:-1]
for i in range(len(astarpath)):
(x,y) = astarpath[i]
waypoints.append([flight["FlightHistoryId"], i+off, x, y, alt, spd])
break
return waypoints
示例8: tanget_dir
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import intersects [as 别名]
def tanget_dir(point_in, points):
p = Point(point_in).buffer(.0001)
for p1, p2 in zip(points[:-1], points[1:]):
l = LineString([p1, p2])
if l.intersects(p):
vec = np.array(p2) - np.array(p1)
return vec / LA.norm(vec)
return None
示例9: __init__
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import intersects [as 别名]
def __init__(self, line, fromNode, min_distance, inCircle):
self.fromNode = fromNode
if type(line) is LineString:
self.lineObj = line
else:
self.lineObj = LineString(line)
self.qurt = 0
self.a = 0
self.b = 0
self.interPts = ""
self.interLine = ""
coords = list(self.lineObj.coords)
coords = [x for x in coords if Point(x) != Point(self.fromNode)]
self.toNode = coords[0]
xx = self.toNode[0] - self.fromNode[0]
yy = self.toNode[1] - self.fromNode[1]
self.a = yy / xx
self.b = self.fromNode[1] - self.a * self.fromNode[0]
if xx > 0:
self.new_toNode = (self.toNode[0] + min_distance, self.a * (self.toNode[0] + min_distance) + self.b)
elif xx < 0:
self.new_toNode = (self.toNode[0] - min_distance, self.a * (self.toNode[0] - min_distance) + self.b)
ext_line = LineString([self.fromNode, self.new_toNode])
minX, minY, maxX, maxY = inCircle.bounds
maxXLine = LineString([[maxX, maxY], [maxX, minY]])
maxYLine = LineString([[minX, maxY], [maxX, maxY]])
minXLine = LineString([[minX, maxY], [minX, minY]])
minYLine = LineString([[minX, minY], [maxX, minY]])
if ext_line.intersects(maxXLine):
self.interPts = self.intersectPoint(maxXLine)
self.interLine = "maxXLine"
elif ext_line.intersects(maxYLine):
self.interPts = self.intersectPoint(maxYLine)
self.interLine = "maxYLine"
elif ext_line.intersects(minXLine):
self.interPts = self.intersectPoint(minXLine)
self.interLine = "minXLine"
elif ext_line.intersects(minYLine):
self.interPts = self.intersectPoint(minYLine)
self.interLine = "minYLine"
示例10: no_fly_avoidance_waypoints
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import intersects [as 别名]
def no_fly_avoidance_waypoints(no_fly_zones, flight, airport, cruise=38000, descend_distance=150, speed=500):
waypoints = direct_route_waypoints(flight, airport, cruise, descend_distance, speed)
flight_loc = (flight["CurrentLatitude"], flight["CurrentLongitude"])
first_waypoint_loc = (waypoints[0][2], waypoints[0][3])
path = LineString([flight_loc, first_waypoint_loc])
for no_fly_zone in no_fly_zones:
if path.intersects(no_fly_zone):
waypoints = avoid_no_fly_zone(no_fly_zone, waypoints, flight_loc, first_waypoint_loc, path)
break
return waypoints
示例11: remove_intersecting_hits
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import intersects [as 别名]
def remove_intersecting_hits(hit_list):
"""takes hits and remove if intersect keeping the best bit score"""
for hit in hit_list:
hit_list_missing = list(hit_list)
hit_list_missing.remove(hit)
qref_hit = LineString([(0.0,hit[0]),(0.0,hit[1]-30)])
sref_hit = LineString([(0,hit[2]),(0,hit[3]-30)])
for addt_hit in hit_list_missing:
qaddt_hit = LineString([(0,addt_hit[0]),(0,addt_hit[1])])
saddt_hit = LineString([(0,addt_hit[2]),(0,addt_hit[3])])
if qaddt_hit.intersects(qaddt_hit) or sref_hit.intersects(saddt_hit):
try:
if qref_hit >= qaddt_hit:
remove_hit = qaddt_hit
else:
remove_hit = qref_hit
hit_list.remove(remove_hit)
hit_list_missing.remove(remove_hit)
except ValueError: continue
return hit_list
示例12: is_on_surface
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import intersects [as 别名]
def is_on_surface(self, moveable_obj, edge_index):
edge = self.vertices_of_edges[edge_index]
center_x, center_y = moveable_obj.position
gravity_vec = Line([moveable_obj.position, (center_x, 0)])
edge_line = Line(edge).buffer(1)
radius = moveable_obj.fixtures[0].shape.radius
center = Point(center_x, center_y)
circle = center.buffer(radius)
if circle.intersects(edge_line):
if self.is_edge_surface[edge_index] == 1 and gravity_vec.intersects(edge_line):
return True, 0
return False, center.distance(edge_line)
示例13: shoot
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import intersects [as 别名]
def shoot(self, pid, angle):
_logger.info("Starting shoot method")
shooter = self.__players[pid]
# Shoot "angle"
a = radians(angle)
# Weapon error angle application:
a += shooter.weapon.draw_random_error()
# Direction of the bullet (normalized vector)
normalized_direction_vector = self.__get_normalized_direction_vector_from_angle(a) # x, y, but in the "kivy convention"
# This vector/line represents the trajectory of the bullet
origin = array((shooter.posx, shooter.posy))
vector = (tuple(origin), tuple(origin + (normalized_direction_vector * shooter.weapon.range)))
line = LineString(vector)
_logger.info("origin=" + str(origin))
_logger.info("vector=" + str(vector))
# First, check if we could even potentially shoot any player
victims = []
for p in self.__players:
if p == shooter:
continue # you cannot shoot yourself
# Yes, we do compute the player's hitbox on shoot. It is in fact lighter that storing it in the player, because storing it in the player's object would mean
# updating it on every player's move. Here we do computation only on shoots, we are going to be many times less frequent that movements!
hitbox = p.hitbox
if line.intersects(hitbox): # hit!
victims.append(p)
# Then, if yes, check that there is not any obstacle to that shoot
# Only check on obstacles that are close to that shot's trajectory (that is to say, not < (x,y) (depending on the angle, could be not > (x,y) or event more complex cases, but that's the idea)))
if 0 != len(victims):
distance, first_victim = self.__find_closest_victim(victims, shooter)
# We re-compute the vector, stopping it at the victim's position. Indeed, if we used the "vector" variable
# to look for collisions, as it uses the maximum weapon's range, we would look for collision BEHIND the
# victim as well !
to_first_victim_vector = (tuple(origin), tuple(origin + (normalized_direction_vector * distance)))
if not self.__shoot_collide_with_obstacle(to_first_victim_vector, line): # no collision with any obstacle, thus we can harm the victim
return self.__harm_victim(first_victim, shooter)
else: # Else, there's just nothing to do, you did not aim at anyone, n00b
return None
示例14: IsIntersect
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import intersects [as 别名]
def IsIntersect(edge1,edge2,o_graph):
lng11 = o_graph.node[edge1[0]]['lng']
lng12 = o_graph.node[edge1[1]]['lng']
lng21 = o_graph.node[edge2[0]]['lng']
lng22 = o_graph.node[edge2[1]]['lng']
lat11 = o_graph.node[edge1[0]]['lat']
lat12 = o_graph.node[edge1[1]]['lat']
lat21 = o_graph.node[edge2[0]]['lat']
lat22 = o_graph.node[edge2[1]]['lat']
l1 = LS([(lng11,lat11),(lng12,lat12)])
l2 = LS([(lng21,lat21),(lng22,lat22)])
if l1.intersects(l2):
itsctpt = copy(list(l1.intersection(l2).coords)[0])
if IsInline(itsctpt,[lng11,lat11],[lng12,lat12]) and IsInline(itsctpt,[lng21,lat21],[lng22,lat22]):
return True
else:
return False
else:
return False
return False
示例15: parse_blast
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import intersects [as 别名]
def parse_blast(blast_str, orient, qfeat, sfeat, qbed, sbed, qpad, spad, unmasked_fasta):
blast = []
slope = orient
qgene = [qfeat['start'], qfeat['end']]
sgene = [sfeat['start'], sfeat['end']]
qcds = qfeat['locs']
scds = sfeat['locs']
sgene = sgene[::slope]
center = sum(qgene)/2., sum(sgene)/2.
EXP = EXPON
if abs(abs(qgene[1] - qgene[0]) - abs(sgene[1] - sgene[0])) > 3000:
EXP = 0.94
#intercept = (sgene[0] + sgene[1])/2. - slope * (qgene[0] + qgene[1])/2.
intercept = center[1] - slope * center[0]
rngx = qgene[1] - qgene[0]
rngy = abs(sgene[1] - sgene[0])
x = np.linspace(qgene[0] - qpad, qgene[1] + qpad, 50)
y = slope * x + intercept
xb = x + -slope * rngx/3. + -slope * np.abs(x - center[0])**EXP
yb = y + rngy/3. + np.abs(y - center[1])**EXP
xy = x + slope * rngx/3. + slope * np.abs(x - center[0])**EXP
yy = y - rngy/3. - np.abs(y - center[1])**EXP
if slope == 1:
xall = np.hstack((xy[::-1], xb[::slope], xy[-1]))
yall = np.hstack((yy[::-1],yb, yy[-1]))
if slope == -1:
xall = np.hstack((xy, xb[::-1], xy[0]))
yall = np.hstack((yy,yb[::-1], yy[0]))
feats_nearby = {}
feats_nearby['q'] = get_feats_in_space(qgene, qfeat['seqid'], int(x.min()), int(x.max()), qbed)
feats_nearby['s'] = get_feats_in_space(sgene, sfeat['seqid'], int(y.min()), int(y.max()), sbed)
genespace_poly = Polygon(zip(xall, yall))
for sub in ('q', 's'):
if len(feats_nearby[sub]) !=0:
feats_nearby[sub] = MultiLineString([[(0, c0),(0, c1)] for c0, c1, fname in feats_nearby[sub]])
else:
feats_nearby[sub] = None
cnss = set([])
qgene_poly = LineString([(0.0, qgene[0]), (0.0, qgene[1])])
sgene_poly = LineString([(0.0, sgene[0]), (0.0, sgene[1])])
intronic_removed = 0
for line in blast_str.split("\n"):
if "WARNING:" in line: continue
if "ERROR" in line: continue
line = line.split("\t")
locs = map(int, line[6:10])
locs.extend(map(float, line[10:]))
xx = locs[:2]
yy = locs[2:4]
# to be saved. a hit must either be in an intron in both
# genes, or in neither.
##########################################################
# DEAL WITH INTRONIC cnss in the gene of interest.
##########################################################
xls = LineString([(0, locs[0]), (0, locs[1])])
yls = LineString([(0, locs[2]), (0, locs[3])])
locs = tuple(locs) # make it hashable.
if qgene_poly.intersects(xls) and sgene_poly.intersects(yls):
cnss.update((locs,))
continue
# has to be both or neither.
if qgene_poly.intersects(xls) or sgene_poly.intersects(yls):
intronic_removed += 1
continue
##########################################################
###############################################################
# for all other genes, if it's in an intron, we dont keep it.
###############################################################
intronic = False
# get rid of stuff that overlaps another gene:
for sub, (start, stop) in (('q', locs[:2]), ('s', locs[2:4])):
feats = feats_nearby[sub]
if feats is None: continue
# the current hsp is overlapping another gene. we dont want that...
if feats.contains(Point(0, start)) or feats.contains(Point(0, stop)):
intronic = True
#.........这里部分代码省略.........