当前位置: 首页>>代码示例>>Python>>正文


Python LineString.buffer方法代码示例

本文整理汇总了Python中shapely.geometry.LineString.buffer方法的典型用法代码示例。如果您正苦于以下问题:Python LineString.buffer方法的具体用法?Python LineString.buffer怎么用?Python LineString.buffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shapely.geometry.LineString的用法示例。


在下文中一共展示了LineString.buffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: appendNewWay

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import buffer [as 别名]
 def appendNewWay(coords, intersects, osmXml):
     way = etree.Element('way', visible='true', id=str(newOsmId('way')))
     firstNid = 0
     for i, coord in enumerate(coords):
         if i == 0: continue # the first and last coordinate are the same
         node = appendNewNode(coord, osmXml)
         if i == 1: firstNid = node.get('id')
         way.append(etree.Element('nd', ref=node.get('id')))
         
         # Check each way segment for intersecting nodes
         int_nodes = {}
         try:
             line = LineString([coord, coords[i+1]])
         except IndexError:
             line = LineString([coord, coords[1]])
         for idx, c in enumerate(intersects):
             if line.buffer(0.0000015).contains(Point(c[0], c[1])) and c not in coords:
                 t_node = appendNewNode(c, osmXml)
                 for n in way.iter('nd'):
                     if n.get('ref') == t_node.get('id'):
                         break
                 else:
                     int_nodes[t_node.get('id')] = Point(c).distance(Point(coord))
         for n in sorted(int_nodes, key=lambda key: int_nodes[key]): # add intersecting nodes in order
             way.append(etree.Element('nd', ref=n))
         
     way.append(etree.Element('nd', ref=firstNid)) # close way
     osmXml.append(way)
     return way
开发者ID:mtoupsUNO,项目名称:nola-buildings,代码行数:31,代码来源:convert.py

示例2: divide_polygon_for_intersection

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import buffer [as 别名]
    def divide_polygon_for_intersection(self, segments):
        """ Generates multiple polygons based on cutting the 
        fracture faces by line segments. 
        """
        R = self.build_rotation_matrix()
        fracture_poly_list = []
        # face_poly_list = []

        for point in self.points:
            rot_point = np.linalg.solve(R, point - self.center)
            fracture_poly_list.append(rot_point[:2])

        seg_rot = []
        for seg in segments:
            p1 = seg[0]
            p2 = seg[1]

            vec = p2 - p1
            p1 = p1 - 100.0 * vec
            p2 = p2 + 100.0 * vec

            p1_rot = np.linalg.solve(R, p1 - self.center)
            p2_rot = np.linalg.solve(R, p2 - self.center)

            line = LineString((p1_rot[:2], p2_rot[:2]))
            dilated = line.buffer(1.0e-10)
            seg_rot.append(dilated)

        fracture_poly = Polygon(fracture_poly_list)

        divided_polygons = fracture_poly.difference(seg_rot[0])

        return (divided_polygons, fracture_poly)
开发者ID:xyuan,项目名称:mimpy,代码行数:35,代码来源:hexmeshwmsfracs.py

示例3: cut_line

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import buffer [as 别名]
def cut_line(cut_point, line, eps_mult=1e2):
    dist = line.project(cut_point)
    point = line.interpolate(dist)
    eps = line.distance(point) * eps_mult

    coords = list(line.coords)

    if point.coords[0] in coords:
        i = coords.index(point.coords[0])

        if i == 0:
            return LineString(), line
        if i == len(coords) - 1:
            return line, LineString()

        start_segment = LineString(coords[:i + 1])
        end_segment = LineString(coords[i:])

        return start_segment, end_segment


    for i, p in enumerate(coords[:-1]):
        line_segment = LineString([coords[i], coords[i + 1]])
        line_segment_buffer = line_segment.buffer(eps, resolution=1)

        if line_segment_buffer.contains(point):
            start_segment = LineString(coords[:i + 1] + [point])
            end_segment = LineString([point] + coords[i + 1:])

            return start_segment, end_segment

    raise Exception('point not found in line, consider raising eps_mult')
开发者ID:hyperknot,项目名称:pgairspace,代码行数:34,代码来源:geom.py

示例4: SpatialToplogy

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import buffer [as 别名]
 def SpatialToplogy (Spatial_A,Spatial_B):
            if Spatial_A[4] == 'Point' and Spatial_B[4]== 'Point':
              Point_0=Point(Spatial_A[0],Spatial_A[1])
              Point_1=Point(Spatial_B[0],Spatial_B[1])
              #Point to point relationships
              if Point_0.equals(Point_1): return 'Point1 equals Point2'
              if Point_0.within(Point_1.buffer(2)): return 'Point1 lies within a buffer of 2 m from Point2'
              if Point_0.overlaps(Point_1): return 'Point1 overlaps Point2'
              #if Point_0.disjoint(Point_1): return 'Point1 disjoint Point2'
              
              #Point to line relationships
            if Spatial_A[4] == 'Point' and Spatial_B[4]== 'Line':
                 Point_0=Point(Spatial_A[0],Spatial_A[1])
                 Line_0=LineString([(Spatial_B[0],Spatial_B[1]),(Spatial_B[2],Spatial_B[3])])
                 if Point_0.touches(Line_0):return 'Point1 touches Line1'
                 if Point_0.within(Line_0.buffer(2)):return 'Point1 lies within a buffer of 2 m from L1'
              #Point to polygon relationships
            if Spatial_A[4] == 'Point' and Spatial_B[4]== 'Polygon':
                 Point_0=Point(Spatial_A[0],Spatial_A[1])
                 Polygon_0=Polygon([(Spatial_B[0],Spatial_B[1]),(Spatial_B[2],Spatial_B[1]),(Spatial_B[2],Spatial_B[3]),(Spatial_B[0],Spatial_B[3])])
                 if Point_0.touches(Polygon_0):return 'Point1 touches Polygon1'
                 if Point_0.within(Polygon_0):return'Point1 lies within Polygon1'
                 if Point_0.overlaps(Polygon_0):return 'Point1 lies overlaps Polygon1'
             #Line to line relationships
            if Spatial_A[4]=='Line' and Spatial_B[4]=='Line':
                 Line_0=LineString([(Spatial_A[0],Spatial_A[1]),(Spatial_A[2],Spatial_A[3])])
                 Line_1=LineString([(Spatial_B[0],Spatial_B[1]),(Spatial_B[2],Spatial_B[3])])
                 if Line_0.equals(Line_1):return 'Line0 equals Line1'
                 if Line_0.touches(Line_1):return 'Line0 touches Line1'
                 if Line_0.crosses(Line_1):return 'Line0 crosses Line1'
                 if Line_0.within(Line_1.buffer(2)):return 'Line0 lies within a buffer of 2 m Line1'
                 if Line_0.overlaps(Line_1):return 'Line0 overlaps Line1'
              #Line to polygon relationships  
            if Spatial_A[4]=='Line' and Spatial_B[4]=='Polygon':
                 Line_0=LineString([(Spatial_A[0],Spatial_A[1]),(Spatial_A[2],Spatial_A[3])])
                 Polygon_0=Polygon([(Spatial_B[0],Spatial_B[1]),(Spatial_B[2],Spatial_B[1]),(Spatial_B[2],Spatial_B[3]),(Spatial_B[0],Spatial_B[3])])
                 if Line_0.touches(Polygon_0):return 'Line0 touches Polygon1'
                 if Line_0.crosses(Polygon_0):return 'Line0 crosses Polygon1'
                 if Line_0.within(Polygon_0):return 'Line0 lies within Polygon1'
              #Polygon to Polygon relationships
            if Spatial_A[4]=='Polygon' and Spatial_B[4]=='Polygon':
                 Polygon_0=Polygon([(Spatial_A[0],Spatial_A[1]),(Spatial_A[2],Spatial_A[1]),(Spatial_A[2],Spatial_A[3]),(Spatial_A[0],Spatial_A[3])])
                 Polygon_1=Polygon([(Spatial_B[0],Spatial_B[1]),(Spatial_B[2],Spatial_B[1]),(Spatial_B[2],Spatial_B[3]),(Spatial_B[0],Spatial_B[3])])
                 if Polygon_0.touches(Polygon_1):return 'Polygon touches Polygon1'
                 if Polygon_0.equals(Polygon_1):return 'Polygon0 equals Polygon1'
                 if Polygon_0.within(Polygon_1):return 'Polygon lies within Polygon1'
                 if Polygon_0.within(Polygon_1.buffer(2)):return 'Polygon lies within a buffer of 2m  Polygon1'
开发者ID:HydroComplexity,项目名称:Data-Network,代码行数:49,代码来源:Datanetwork.py

示例5: line_to_poly

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import buffer [as 别名]
def line_to_poly(raw_line, distance=0.05):
    """
    Line in format [(), ..., ()] to Polygon with 2*distance width
    Args:
        raw_line (list): Connected dots
        distance (Optional[float]): width of polygon = 2*distance
    """
    line = LineString(raw_line)
    return Polygon(line.buffer(distance, cap_style=2, join_style=2))
开发者ID:elejke,项目名称:shortest_path,代码行数:11,代码来源:geometry.py

示例6: create_s

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import buffer [as 别名]
def create_s():
    c1 = create_circle(0, 1.03, 1, 20, 270-15)
    c2 = create_circle(0, -1.03, 1, 200, 450-15)
    s = LineString(c1 + list(reversed(c2)))
    s = s.buffer(0.4)
    g = GCode.from_geometry(s, 0, 0)
    g = g.scale_to_fit(6, 8)
    g = g.move(3, 4, 0.5, 0.5)
    g1 = g.depth(0.2, -0.3)
    g2 = g.depth(0.2, -0.6)
    g = HEADER + g1 + g2 + FOOTER
    g.save('sophia.nc')
    im = g.render(0, 0, 6, 8, 96)
    im.write_to_png('sophia.png')
开发者ID:fogleman,项目名称:Carolina,代码行数:16,代码来源:sophia.py

示例7: WayToPoly

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import buffer [as 别名]
def WayToPoly(wayId, ways, nodes):
	wayData = ways[wayId]
	wayNodes = wayData[0]
	if wayNodes[0] == wayNodes[-1]:
		#Close polygon
		tags = wayData[1]
		pts = []
		for nid in wayNodes:
			if int(nid) not in nodes:
				print "Warning: missing node", nid
				continue
			pts.append(nodes[int(nid)][0])

		#Require at least 3 points
		if len(pts) < 3:
			return None

		poly = Polygon(pts)
		if not poly.is_valid:
			print "Warning: polygon is not valid"
			print explain_validity(poly)
			poly = poly.buffer(0)
		return poly
	else:
		#Unclosed way
		tags = wayData[1]
		pts = []
		for nid in wayNodes:
			if int(nid) not in nodes:
				print "Warning: missing node", nid
				continue
			pts.append(nodes[int(nid)][0])		

		line = LineString(pts)
		if not line.is_valid:
			print "Warning: polygon is not valid"
			print explain_validity(line)
			line = line.buffer(0)
		return line

	return None	
开发者ID:TimSC,项目名称:map-utils,代码行数:43,代码来源:osmtoshapely.py

示例8: create_frames

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import buffer [as 别名]
def create_frames(mapfile):

    # increment in steps of 3 units from 1 to 35
    min_buffer = 1
    max_buffer = 35
    step = 3 

    # create a line
    line = LineString([(0, 0), (100, 100), (0, 200), (200, 200), (300, 100), (100, 0)])
    # set the map extent to this line
    mapfile["extent"] = " ".join(map(str, line.buffer(max_buffer*2).bounds))

    all_images = []

    # create expanding buffers
    for dist in range(min_buffer, max_buffer, step):
        all_images.append(create_frame(mapfile, line, dist))

    # create shrinking buffers
    for dist in range(max_buffer, min_buffer, -step):
        all_images.append(create_frame(mapfile, line, dist))

    return all_images
开发者ID:tomkralidis,项目名称:mappyfile,代码行数:25,代码来源:animated_buffer.py

示例9: lines_multiplot

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import buffer [as 别名]
def lines_multiplot(list_in, list_out, out_name):
    line_in = LineString(list_in)
    line_out = LineString(list_out)

    fig = pyplot.figure(1, figsize=(10, 4), dpi=140)
    fig.suptitle('Results of the Douglas-Peucker algorithm', fontsize=14, fontweight='bold')
    ax = fig.add_subplot(111)

    x1, y1 = line_in.xy
    x2, y2 = line_out.xy
    ax.plot(x1, y1, 'r^--',x2,y2, 'bs-' ,solid_capstyle='round', zorder=1, linewidth=1.5)
    ax.legend(['original route','simplified route'], loc='upper center', bbox_to_anchor=(0.5, -0.1),
          fancybox=True, shadow=True, ncol=2)

    dilated = line_in.buffer(0.005)
    patch1 = PolygonPatch(dilated, fc=BLUE, ec=BLUE, alpha=0.5, zorder=2)
    ax.add_patch(patch1)

    ax.tick_params(direction='out', length=2, width=0.8, pad = 0.05)
    box = ax.get_position()
    ax.set_position([box.x0, box.y0 + box.height * 0.1,
                 box.width, box.height * 0.9])

    #make some space around the plots
    start, end = ax.get_xlim()
    xrange = [start-0.005, end+0.005]
    ax.set_xlim(*xrange)
    ax.xaxis.set_tick_params(labelsize=8)

    start, end = ax.get_ylim()
    yrange = [start-0.005, end+0.005]
    ax.set_ylim(*yrange)
    ax.set_aspect(1)
    ax.yaxis.set_tick_params(labelsize=8)

    #pyplot.show()
    fig.savefig(str(out_name)+'.png')   # save the figure to file
开发者ID:AnnaMag,项目名称:Line-simplification,代码行数:39,代码来源:make_plots.py

示例10: LineString

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import buffer [as 别名]
from matplotlib import pyplot
from shapely.geometry import LineString
from descartes import PolygonPatch

from figures import SIZE, BLUE, GRAY, set_limits, plot_line

line = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)])

fig = pyplot.figure(1, figsize=SIZE, dpi=90)

# 1
ax = fig.add_subplot(121)

plot_line(ax, line)

dilated = line.buffer(0.5, cap_style=3)
patch1 = PolygonPatch(dilated, fc=BLUE, ec=BLUE, alpha=0.5, zorder=2)
ax.add_patch(patch1)

ax.set_title('a) dilation, cap_style=3')

set_limits(ax, -1, 4, -1, 3)

#2
ax = fig.add_subplot(122)

patch2a = PolygonPatch(dilated, fc=GRAY, ec=GRAY, alpha=0.5, zorder=1)
ax.add_patch(patch2a)

eroded = dilated.buffer(-0.3)
开发者ID:Toblerity,项目名称:Shapely,代码行数:32,代码来源:buffer.py

示例11: test_intersects

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import buffer [as 别名]
def test_intersects():
	circle = Point([1,2]).buffer(2)
	line = LineString([[0,0],[2,0]])
	c = line.buffer(1)
	circle.intersects(c)
开发者ID:fantastdd,项目名称:physical-reasoning-2d,代码行数:7,代码来源:test.py

示例12: _check

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import buffer [as 别名]
    def _check(self, aerodrome_type, runway_kind_detail):
        import dsl
        from tilequeue.tile import coord_to_bounds
        from shapely.geometry import LineString
        from shapely.geometry import CAP_STYLE
        from ModestMaps.Core import Coordinate

        z, x, y = (16, 0, 0)

        bounds = coord_to_bounds(Coordinate(zoom=z, column=x, row=y))

        # runway line that runs from a quarter to three quarters of the
        # tile diagonal. this is so that we can buffer it without it
        # going outside the tile boundary.
        runway_line = LineString([
            [bounds[0] + 0.25 * (bounds[2] - bounds[0]),
             bounds[1] + 0.25 * (bounds[3] - bounds[1])],
            [bounds[0] + 0.75 * (bounds[2] - bounds[0]),
             bounds[1] + 0.75 * (bounds[3] - bounds[1])],
        ])

        # runway polygon which has the runway line as a centreline.
        runway_poly = runway_line.buffer(
            0.1 * (bounds[2] - bounds[0]),  # width 1/10th of a tile
            cap_style=CAP_STYLE.flat,
        )

        self.generate_fixtures(
            dsl.way(1, dsl.tile_box(z, x, y), {
                'aeroway': 'aerodrome',
                'aerodrome:type': aerodrome_type,
                'name': 'Fake Aerodrome',
                'source': 'openstreetmap.org',
            }),
            # runway line
            dsl.way(2, runway_line, {
                'aeroway': 'runway',
                'source': 'openstreetmap.org',
            }),
            # runway polygon
            dsl.way(3, runway_poly, {
                'area:aeroway': 'runway',
                'source': 'openstreetmap.org',
            })
        )

        # runway line ends up in roads layer
        self.assert_has_feature(
            z, x, y, 'roads', {
                'id': 2,
                'kind': 'aeroway',
                'kind_detail': 'runway',
                'aerodrome_kind_detail': runway_kind_detail,
            })

        # runway polygon is in landuse
        self.assert_has_feature(
            z, x, y, 'landuse', {
                'id': 3,
                'kind': 'runway',
                'kind_detail': runway_kind_detail,
            })
开发者ID:tilezen,项目名称:vector-datasource,代码行数:64,代码来源:1852-runway-kind-detail.py

示例13: Point

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import buffer [as 别名]
expCircle = np.array(expCircle.exterior.coords)

# horseshoe tumor
rad=.007
loc=[0.0229845803642/2.0-.002,.02]
circle = Point(loc[0],loc[1]).buffer(rad)
circle = np.array(circle.exterior.coords)
semicircle=circle[circle[:,0]>=loc[0]]
semi=semicircle[semicircle[:,1].argsort()]
line = LineString(semi)#LineString([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)])
horseshoe = LineString(semi).buffer(.0025)
horseshoe = np.array(horseshoe.exterior.coords)

# additional tumor
othertumor = LineString(.008*np.array([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)]))
othertumor = othertumor.buffer(.005)
othertumor = np.array(othertumor.exterior.coords)


#######################################
# Functions for simulating deflection measurements
#######################################

def sigmoid(dist, alpha=1400, a=0.0, b=1.0):
    """  
    a, b: base and max readings of the probe with and without tumor
    dist = xProbe-xEdge
    xProbe: 
    xEdge: the center of sigmoid
    alpha: slope  
    Output:
开发者ID:yjen,项目名称:palpation_strategy,代码行数:33,代码来源:simUtils.py

示例14: plot_line

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import buffer [as 别名]
from figures import SIZE, BLUE, GRAY

def plot_line(ax, ob):
    x, y = ob.xy
    ax.plot(x, y, color=GRAY, linewidth=3, solid_capstyle='round', zorder=1)

line = LineString([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)])

fig = pyplot.figure(1, figsize=SIZE, dpi=90)

# 1
ax = fig.add_subplot(121)

plot_line(ax, line)

dilated = line.buffer(0.5)
patch1 = PolygonPatch(dilated, fc=BLUE, ec=BLUE, alpha=0.5, zorder=2)
ax.add_patch(patch1)

ax.set_title('a) dilation')

xrange = [-1, 4]
yrange = [-1, 3]
ax.set_xlim(*xrange)
ax.set_xticks(range(*xrange) + [xrange[-1]])
ax.set_ylim(*yrange)
ax.set_yticks(range(*yrange) + [yrange[-1]])
ax.set_aspect(1)

#2
ax = fig.add_subplot(122)
开发者ID:BertrandGervais,项目名称:shapely,代码行数:33,代码来源:buffer.py

示例15: computePrimitives

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import buffer [as 别名]
from computePrimitives import *
import matplotlib.pyplot as plt
from shapely.geometry import LineString, Point
from descartes import PolygonPatch
import pdb

motion_primitives = computePrimitives()

fig = plt.figure(2)
fig.clear()
plt.ion()
ax = fig.add_subplot(111, aspect = 'equal')
for mp in motion_primitives[0.0]:
    color = '#9999FF'
    if mp.isbackward:
        color = '#99FF99'
    a = LineString(mp.path)
    p = PolygonPatch(a.buffer(0.1), fc=color, ec=color, alpha=1, zorder=2)
    ax.add_patch(p)
    p2 = PolygonPatch(Point(mp.delta_state[0:2]).buffer(0.1), fc='000000', ec='000000', alpha=1, zorder=3)
    ax.add_patch(p2)
ax.set_xlim(-3.5,3.5)
ax.set_ylim(-3.5,3.5)
ax.grid()
fig.show()
plt.pause(0.1)
pdb.set_trace()
开发者ID:nthatte,项目名称:ACRLHW5,代码行数:29,代码来源:testComputePrimitives.py


注:本文中的shapely.geometry.LineString.buffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。