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


Python LineString.touches方法代码示例

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


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

示例1: SpatialToplogy

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import touches [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

示例2: intersect

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import touches [as 别名]
    def intersect(self, **kwargs):
        """
            Intersect a Line or Point Collection and the Shoreline

            Returns the point of intersection along the coastline
            Should also return a linestring buffer around the interseciton point
            so we can calculate the direction to bounce a particle.
        """
        ls = None
        if "linestring" in kwargs:
            ls = kwargs.pop('linestring')
            spoint = Point(ls.coords[0])
            epoint = Point(ls.coords[-1])
        elif "start_point" and "end_point" in kwargs:
            spoint = kwargs.pop('start_point')
            epoint = kwargs.pop('end_point')
            ls = LineString(list(spoint.coords) + list(epoint.coords))
        else:
            raise TypeError( "must provide a LineString geometry object or (2) Point geometry objects" )

        inter = False

        # If the current point lies outside of our current shapefile index,
        # re-query the shapefile in a buffer around this point
        if self._spatial_query_object and not ls.within(self._spatial_query_object):
            self.index(point=spoint)

        for element in self._geoms:
            prepped_element = prep(element)

            # Test if starting on land
            if prepped_element.contains(spoint):
                raise Exception('Starting point on land')

            inter = ls.intersection(element)
            if inter:
                # Return the first point in the linestring, and the linestring that it hit
                if isinstance(inter, MultiLineString):
                    inter = inter.geoms[0]

                inter = Point(inter.coords[0])
                smaller_int = inter.buffer(self._spatialbuffer)
                shorelines = element.exterior.intersection(smaller_int)
                if isinstance(shorelines, LineString):
                    shorelines = [shorelines]
                else:
                    shorelines = list(shorelines)

                for shore_segment in shorelines:
                    # Once we find the linestring in the Polygon that was
                    # intersected, break out and return
                    if ls.touches(shore_segment):
                        break

                return {'point': Point(inter.x, inter.y, 0), 'feature': shore_segment or None}
        return None
开发者ID:hetland,项目名称:paegan,代码行数:58,代码来源:shoreline.py

示例3: test_split_line_with_line

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import touches [as 别名]
	def test_split_line_with_line(self):
		# crosses at one point --> return 2 segments
		splitter = LineString([(0, 1), (1, 0)])
		self.helper(self.ls, splitter, 2)

		# crosses at two points --> return 3 segments
		splitter = LineString([(0, 1), (1, 0), (1, 2)])
		self.helper(self.ls, splitter, 3)

		# overlaps --> raise
		splitter = LineString([(0, 0), (15, 15)])
		with self.assertRaises(ValueError):
			self.helper(self.ls, splitter, 1)

		# does not cross --> return equal
		splitter = LineString([(0, 1), (0, 2)])
		self.helper(self.ls, splitter, 1)

		# is touching the boundary --> return equal
		splitter = LineString([(-1, 1), (1, -1)])
		self.assertTrue(splitter.touches(self.ls))
		self.helper(self.ls, splitter, 1)
开发者ID:Toblerity,项目名称:Shapely,代码行数:24,代码来源:test_split.py

示例4: LineString

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import touches [as 别名]
[p.wkt for p in contained]

LineString(coords).crosses(LineString([(0,1),(1,0)]))

LineString(coords).crosses(Point(0.5,0.5))
Point(0,0).disjoint(Point(1,1))

a = LineString([(0,0),(1,1)])
b = LineString([(0,0),(0.5,0.5),(1,1)])
c = LineString([(0,0),(0,0),(1,1),])
a.equals(b)
b.equals(c)

a = LineString([(0,0),(1,1)])
b = LineString([(1,1),(2,2)])
a.touches(b)

a = Point(2,2)
b = Polygon([[1,1],[1,3],[3,3],[3,1]])
c = Polygon([[0,0],[0,4],[4,4],[4,0]])
d = Point(-1,-1)

feature = [c,a,d,c]

from shapely.geometry import asShape
class Width(object):
    def __init__(self,o):
        self.o = o

    def __init__(self,other):
        return self.o.width(other.o)
开发者ID:bukun,项目名称:book_python_gis,代码行数:33,代码来源:g7_3_2_eryaunweici.py

示例5: sqrt

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import touches [as 别名]
print 'line2', line2
print 'line2 type', line2.geom_type
print 'line2 coordinates:', line2.coords[:]
print 'line2 length:', line2.length, '== sqrt(2)/2', line2.length==sqrt(2)/2


print ''
line3 = LineString([(0,0),(-1,1)])
print 'line3', line3
print 'line3 type', line3.geom_type
print 'line3 coordinates:', line3.coords[:]
print 'line3 length:', line3.length, '== sqrt(2)', line3.length==sqrt(2)



print ''
print 'line1-line2'
ipt = line1.intersection(line2)
print 'ipt', ipt
print 'touches:', line1.touches(line2)
print 'crosses:', line1.crosses(line2)



print ''
print 'line1-line3'
ipt = line1.intersection(line3)
print 'ipt', ipt
print 'touches:', line1.touches(line3)
print 'crosses:', line1.crosses(line3)
开发者ID:wbkifun,项目名称:my_stuff,代码行数:32,代码来源:line_line.py

示例6: intersect

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import touches [as 别名]
    def intersect(self, **kwargs):
        """
            Intersect a Line or Point Collection and the Shoreline

            Returns the point of intersection along the coastline
            Should also return a linestring buffer around the interseciton point
            so we can calculate the direction to bounce a particle.
        """
        ls = None

        if "linestring" in kwargs:
            ls = kwargs.pop('linestring')
            spoint = Point(ls.coords[0])
            epoint = Point(ls.coords[-1])
        elif "start_point" and "end_point" in kwargs:
            spoint = kwargs.get('start_point')
            epoint = kwargs.get('end_point')
            ls = LineString(list(spoint.coords) + list(epoint.coords))
        elif "single_point" in kwargs:
            spoint = kwargs.get('single_point')
            epoint = None
            ls = LineString(list(spoint.coords) + list(spoint.coords))
        else:
            raise TypeError( "must provide a LineString geometry object, (2) Point geometry objects, or (1) Point geometry object" )

        inter = False

        # If the current point lies outside of our current shapefile index,
        # re-query the shapefile in a buffer around this point
        #logger.info("Spatial query object: %s" % unicode(self._spatial_query_object))

        if self._spatial_query_object is None:
            # Index if we have not
            self.index(point=spoint)
        elif self._spatial_query_object.contains(ls):
            # If we contain the entire linestring, we have nothing more to index
            pass
        elif epoint and not self._spatial_query_object.contains(epoint):
            # If we don't contain the end point, index on that
            self.index(point=epoint)
        elif not self._spatial_query_object.contains(spoint):
            # Index on the start point
            self.index(point=spoint)

        for element in self._geoms:

            # Test if starting on land
            if element.contains(spoint):
                if epoint is None:
                    # If we only passed in one point, return the intersection is true.
                    return {'point': spoint, 'feature': None}
                else:
                    # If we are testing a linestring, raise an exception that we started on land.
                    raise Exception('Intersection starting point on land: %s %s %s' % (spoint.envelope, epoint.envelope, element.envelope))
            else:
                # If we are just checking a single point, continue looping.
                if epoint is None:
                    continue

            inter = ls.intersection(element)
            if not inter.is_empty:
                # Return the first point in the linestring, and the linestring that it hit
                if isinstance(inter, MultiLineString):
                    inter = inter.geoms[0]

                inter = Point(inter.coords[0])
                smaller_int = inter.buffer(self._spatialbuffer)
                shorelines = element.exterior.intersection(smaller_int)
                if isinstance(shorelines, LineString):
                    shorelines = [shorelines]
                else:
                    shorelines = list(shorelines)

                for shore_segment in shorelines:
                    # Once we find the linestring in the Polygon that was
                    # intersected, break out and return
                    if ls.touches(shore_segment):
                        break

                return {'point': Point(inter.x, inter.y, 0), 'feature': shore_segment or None}

        return None
开发者ID:axiom-data-science,项目名称:paegan-transport,代码行数:84,代码来源:shoreline.py


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