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


Python Polygon.touches方法代码示例

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


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

示例1: __create_grid

# 需要导入模块: from shapely.geometry import Polygon [as 别名]
# 或者: from shapely.geometry.Polygon import touches [as 别名]
	def __create_grid(self):
		"""
		Create uniform grid over region.
		"""
		polygon_coords = self.__resample_polygon()
		
		# define polygon from polygon coords
		polygon = Polygon(polygon_coords)
		
		# get bounding box coordinates
		bounding_box = polygon.bounds
		min_lon = bounding_box[0]
		max_lon = bounding_box[2]
		min_lat = bounding_box[1]
		max_lat = bounding_box[3]
		
		# compute number of nodes along lat and lon
		n_lat = int(round((max_lat - min_lat) / self.grid_spacing)) + 1
		n_lon = int(round((max_lon - min_lon) / self.grid_spacing)) + 1
		
		# create grid of points inside polygon
		grid = []
		for i in range(n_lat):
			for j in range(n_lon):
				lat = min_lat + i * self.grid_spacing
				lon = min_lon + j * self.grid_spacing
				p = shapelyPoint(lon,lat)
				if polygon.contains(p) or polygon.touches(p):
					grid.append((lon,lat))
		return grid
开发者ID:monellid,项目名称:HazardEngine,代码行数:32,代码来源:area.py

示例2: goal

# 需要导入模块: from shapely.geometry import Polygon [as 别名]
# 或者: from shapely.geometry.Polygon import touches [as 别名]
 def goal(p):
     near_area = Polygon([
         (p.ha - HA_STEP/2, p.de - DE_STEP/2),
         (p.ha - HA_STEP/2, p.de + DE_STEP/2),
         (p.ha + HA_STEP/2, p.de + DE_STEP/2),
         (p.ha + HA_STEP/2, p.de - DE_STEP/2),
     ])
     return near_area.contains(p_1.point()) or near_area.touches(p_1.point())  # touches if point exactly on the grid
开发者ID:astrohr,项目名称:dagor_tca,代码行数:10,代码来源:path.py

示例3: test_inside

# 需要导入模块: from shapely.geometry import Polygon [as 别名]
# 或者: from shapely.geometry.Polygon import touches [as 别名]
    def test_inside(self):

        ext = [(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)]
        int = [(1, 1), (1, 1.5), (1.5, 1.5), (1.5, 1)]
        poly_with_hole = Polygon(ext,[int])

        polygon = Polygon([(0, 0), (0, 10), (10, 10),(0, 10)])

        point_on_edge = Point(5, 10)
        point_on_vertex = Point(10, 10)
        point_inside = Point(5, 5)
        point_outside = Point(20,20)
        point_in_hole = Point(1.25, 1.25)

        self.assertTrue(polygon.touches(point_on_vertex))
        self.assertTrue(polygon.touches(point_on_edge))
        self.assertTrue(polygon.contains(point_inside))
        self.assertFalse(polygon.contains(point_outside))
        self.assertTrue(point_in_hole.within(poly_with_hole))
开发者ID:Algotricx,项目名称:python-geospatial-analysis-cookbook,代码行数:21,代码来源:ch09-01_single_pt_test_in_poly.py

示例4: SpatialToplogy

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

示例5: test_prepared_predicates

# 需要导入模块: from shapely.geometry import Polygon [as 别名]
# 或者: from shapely.geometry.Polygon import touches [as 别名]
def test_prepared_predicates():
    # check prepared predicates give the same result as regular predicates
    polygon1 = Polygon([
        (0, 0), (0, 1), (1, 1), (1, 0), (0, 0)
    ])
    polygon2 = Polygon([
        (0.5, 0.5), (1.5, 0.5), (1.0, 1.0), (0.5, 0.5)
    ])
    point2 = Point(0.5, 0.5)
    polygon_empty = Polygon()
    prepared_polygon1 = PreparedGeometry(polygon1)
    for geom2 in (polygon2, point2, polygon_empty):
        assert polygon1.disjoint(geom2) == prepared_polygon1.disjoint(geom2)
        assert polygon1.touches(geom2) == prepared_polygon1.touches(geom2)
        assert polygon1.intersects(geom2) == prepared_polygon1.intersects(geom2)
        assert polygon1.crosses(geom2) == prepared_polygon1.crosses(geom2)
        assert polygon1.within(geom2) == prepared_polygon1.within(geom2)
        assert polygon1.contains(geom2) == prepared_polygon1.contains(geom2)
        assert polygon1.overlaps(geom2) == prepared_polygon1.overlaps(geom2)
开发者ID:Toblerity,项目名称:Shapely,代码行数:21,代码来源:test_prepared.py

示例6: checkExtent

# 需要导入模块: from shapely.geometry import Polygon [as 别名]
# 或者: from shapely.geometry.Polygon import touches [as 别名]
 def checkExtent(self, metaExtent, checkExtent, operation):
     """
     @summary: checks polygons against operation
     @param metaExtent: list in the format [minx,miny,maxx,maxy]
     @param checkExtent: list in the format [minx,miny,maxx,maxy]
     """        
     metaExtent = [float(x) for x in metaExtent]
     checkExtent = [float(x) for x in checkExtent]
     
     metaPoly = Polygon(((metaExtent[0],metaExtent[1]), (metaExtent[0],metaExtent[3]), (metaExtent[2],metaExtent[3]), (metaExtent[2],metaExtent[1])))
     checkPoly = Polygon(((checkExtent[0],checkExtent[1]), (checkExtent[0],checkExtent[3]), (checkExtent[2],checkExtent[3]), (checkExtent[2],checkExtent[1])))
     
     if operation == "Contains":
         return checkPoly.contains(metaPoly)   
     if operation == "Intersects":
         return checkPoly.intersects(metaPoly)
     if operation == "Equals":
         return checkPoly.equals(metaPoly)
     if operation == "Touches":
         return checkPoly.touches(metaPoly)
     if operation == "Within":            
         return checkPoly.within(metaPoly)
     if operation == "Outside":
         return checkPoly.disjoint(metaPoly)                    
开发者ID:BGCX261,项目名称:zmetadata-svn-to-git,代码行数:26,代码来源:MetadataManager.py


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