本文整理汇总了Python中shapely.geometry.LineString.difference方法的典型用法代码示例。如果您正苦于以下问题:Python LineString.difference方法的具体用法?Python LineString.difference怎么用?Python LineString.difference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shapely.geometry.LineString
的用法示例。
在下文中一共展示了LineString.difference方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: closest_polygon
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import difference [as 别名]
def closest_polygon(x, y, angle, polygons, dist = 10000):
angle = angle * pi / 180.0
line = LineString([(x, y), (x + dist * sin(angle), y + dist * cos(angle))])
dist_min = None
closest_polygon = None
for i in range(len(polygons)):
difference = line.difference(polygons[i])
if difference.geom_type == 'MultiLineString':
dist = list(difference.geoms)[0].length
if dist_min is None or dist_min > dist:
dist_min = dist
closest_polygon = i
return {'closest_polygon': closest_polygon, 'distance': dist_min}
示例2: closest_polygon
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import difference [as 别名]
def closest_polygon(x, y, angle, polygons, dist = 100):
angle = angle * pi / 180.0
line = LineString([(x, y), (x + dist * sin(angle), y + dist * cos(angle))])
i = 0
dist_min = None
for polygon in polygons:
difference = line.difference(polygon)
print i, difference
if difference.geom_type == 'MultiLineString':
dist = list(difference.geoms)[0].length
print dist
if dist_min is None or dist_min > dist:
dist_min = dist
i += 1
print "Dist min: " , dist_min
return i
示例3: closest_polygon
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import difference [as 别名]
def closest_polygon(x, y, angle, polygons, dist=100):
angle = angle * pi / 180.0
line = LineString([(x, y), (x + dist * sin(angle), y + dist * cos(angle))])
i = 0
dist_min = None
closest = None
for polygon in polygons:
difference = line.difference(polygon)
if difference.geom_type == "MultiLineString":
dist = list(difference.geoms)[0].length
if dist_min is None or dist_min > dist:
dist_min = dist
closest = i
i += 1
return closest
示例4: closest_polygon
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import difference [as 别名]
def closest_polygon(self, angle, dist=280000000):
angle = angle * pi / 180.0
line = LineString([(self.xpt, self.ypt), (self.xpt + dist * sin(angle), self.ypt + dist * cos(angle))])
i = 0
dist_min = None
index_min = None
for polygon in self.polygons:
try:
difference = line.difference(polygon)
if difference.geom_type == "MultiLineString":
dist = list(difference.geoms)[0].length
# print i, dist
if dist_min is None or dist_min > dist:
dist_min = dist
index_min = i
except Exception, ex:
pass
# print "%d doesn't work"%i
i += 1
示例5: closest_polygon
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import difference [as 别名]
def closest_polygon(x, y, angle, polygons, dist = 900000):
angle = angle * pi / 180.0
line = LineString([(x, y), (x + dist * sin(angle), y + dist * cos(angle))])
i = 0
dist_min = None
index_min = None
for polygon in polygons:
try:
difference = line.difference(polygon)
#print i, difference
if difference.geom_type == 'MultiLineString':
dist = list(difference.geoms)[0].length
#print i, dist
if dist_min is None or dist_min > dist:
dist_min = dist
index_min = i
except Exception, ex:
pass
#print "%d doesn't work"%i
i += 1
示例6: draw_text_on_line
# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import difference [as 别名]
def draw_text_on_line(
self,
coords,
text,
color=(0, 0, 0),
font_size=10,
font_family='Tahoma',
font_style=cairo.FONT_SLANT_NORMAL,
font_weight=cairo.FONT_WEIGHT_NORMAL,
text_halo_width=1,
text_halo_color=(1, 1, 1),
text_halo_line_cap=cairo.LINE_CAP_ROUND,
text_halo_line_join=cairo.LINE_JOIN_ROUND,
text_halo_line_dash=None,
text_transform=None,
):
'''
Draws text on a line. Tries to find a position with the least change
in gradient and which is closest to the middle of the line.
:param coords: iterable containing all coordinates as ``(lon, lat)``
:param text: text to be drawn
:param color: ``(r, g, b[, a])``
:param font_size: font-size in unit (pixel/point)
:param font_family: font name
:param font_style: ``cairo.FONT_SLANT_NORMAL``,
``cairo.FONT_SLANT_ITALIC`` or ``cairo.FONT_SLANT_OBLIQUE``
:param font_weight: ``cairo.FONT_WEIGHT_NORMAL`` or
``cairo.FONT_WEIGHT_BOLD``
:param text_halo_width: border-width in unit (pixel/point)
:param text_halo_color: ``(r, g, b[, a])``
:param text_halo_line_cap: one of :const:`cairo.LINE_CAP_*`
:param text_halo_line_join: one of :const:`cairo.LINE_JOIN_*`
:param text_halo_line_dash: list/tuple used by
:meth:`cairo.Context.set_dash`
:param text_transform: one of ``'lowercase'``, ``'uppercase'`` or
``'capitalize'``
'''
text = text.strip()
if not text:
return
coords = map(lambda c: self.transform_coords(*c), coords)
self.context.select_font_face(font_family, font_style, font_weight)
self.context.set_font_size(font_size)
text = utils.text_transform(text, text_transform)
width, height = self.context.text_extents(text)[2:4]
font_ascent, font_descent = self.context.font_extents()[0:2]
self.context.new_path()
#: make sure line does not intersect other conflict objects
line = LineString(coords)
line = self.map_area.intersection(line)
line = line.difference(self.map_area.exterior.buffer(height))
line = line.difference(self.conflict_area)
#: check whether line is empty or is split into several different parts
if line.geom_type == 'GeometryCollection':
return
elif line.geom_type == 'MultiLineString':
longest = None
min_len = width * 1.2
for seg in line.geoms:
seg_len = seg.length
if seg_len > min_len:
longest = seg
min_len = seg_len
if longest is None:
return
line = longest
coords = tuple(line.coords)
seg = utils.linestring_text_optimal_segment(coords, width)
# line has either to much change in gradients or is too short
if seg is None:
return
#: crop optimal segment of linestring
start, end = seg
coords = coords[start:end+1]
#: make sure text is rendered from left to right
if coords[-1][0] < coords[0][0]:
coords = tuple(reversed(coords))
# translate linestring so text is rendered vertically in the middle
line = LineString(tuple(coords))
offset = font_ascent / 2. - font_descent
line = line.parallel_offset(offset, 'left', resolution=3)
# make sure text is rendered centered on line
start_len = (line.length - width) / 2.
char_coords = None
chars = utils.generate_char_geoms(self.context, text)
#: draw all character paths
for char in utils.iter_chars_on_line(chars, line, start_len):
for geom in char.geoms:
char_coords = iter(geom.exterior.coords)
self.context.move_to(*char_coords.next())
for lon, lat in char_coords:
self.context.line_to(lon, lat)
self.context.close_path()
#: only add line to reserved area if text was drawn
if char_coords is not None:
covered = line.buffer(height)
self.conflict_union(covered)
#.........这里部分代码省略.........