本文整理汇总了Python中django.contrib.gis.geos.LineString.interpolate方法的典型用法代码示例。如果您正苦于以下问题:Python LineString.interpolate方法的具体用法?Python LineString.interpolate怎么用?Python LineString.interpolate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.gis.geos.LineString
的用法示例。
在下文中一共展示了LineString.interpolate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from django.contrib.gis.geos import LineString [as 别名]
# 或者: from django.contrib.gis.geos.LineString import interpolate [as 别名]
class Link:
def __init__(self, geom, speed):
self.line = LineString(geom['coordinates'], srid=4326)
self.line.transform(32611)
self.speed = speed
self.cur_dist = 0
self.total_dist = self.line.length
def move(self, dt):
distance = self.speed * dt
overshot = distance + self.cur_dist - self.total_dist
if overshot > 0:
self.cur_dist = self.total_dist
return float(overshot) / self.speed
else:
self.cur_dist += distance
return 0
def get_position(self):
pt = self.line.interpolate(self.cur_dist)
pt.transform(3857)
return list(pt)
示例2: crossovers
# 需要导入模块: from django.contrib.gis.geos import LineString [as 别名]
# 或者: from django.contrib.gis.geos.LineString import interpolate [as 别名]
#.........这里部分代码省略.........
else:
idx1 = idx1 - 1
#If current linestring is not made exclusively of crossovers, check
# if next one is.
elif len(lines[idx+1].coords) == 2 and idx+1 != len(lines)-1:
idx2 = idx+2
while idx2 < len(lines):
if idx2 == len(lines)-1 or len(lines[idx2].coords) > 2:
point1 = Point(lines[idx].coords[-2])
point2 = Point(lines[idx2].coords[1])
#break loop
break
else:
idx2 += 1
else:
point1 = Point(lines[idx].coords[-2])
point2 = Point(lines[idx+1].coords[1])
#Find the change in x/y in order to determine slope
change_x = point1[0] - point2[0]
change_y = point1[1] - point2[1]
#Check if the change in x is zero
if change_x == 0:
slope = None
else:
slope = change_y/change_x
#Create a new line object from the two points adjacent to the
# crossover.
newline = LineString(point1,point2)
#Find the crossover point/interpolate the gps time.
crossover = Point(lines[idx].coords[-1])
cross_pt = newline.interpolate(newline.project(crossover))
#Use crossover coordinates as keys for a dictionary storing gps
# times
if (crossover[0],crossover[1]) not in crossover_gps.keys():
crossover_gps[crossover[0],crossover[1]] = [cross_pt[2]]
else:
crossover_gps[crossover[0],crossover[1]].append(cross_pt[2])
#Use crossover coordinates as keys for a dictionary storing slopes
if (crossover[0],crossover[1]) not in crossover_slopes.keys():
crossover_slopes[crossover[0], crossover[1]] = [slope]
else:
crossover_slopes[crossover[0], crossover[1]].append(slope)
#Create a dictionary holding both gps times and slopes.
crossovers = crossover_gps
for key in crossover_slopes:
crossovers[key].append(crossover_slopes[key][0])
crossovers[key].append(crossover_slopes[key][1])
del crossover_gps, crossover_slopes
#Extract self-intersecting crossovers information from above.
self_cross_pts = []
self_gps1 = []
self_gps2 = []
self_angles = []
for x,y in crossovers:
self_cross_pts.append(Point(x,y))
self_gps1.append(crossovers[x,y][0])
self_gps2.append(crossovers[x,y][1])
#Determine angle of intersection
slope1 = crossovers[x,y][2]