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


Python LineString.distance方法代码示例

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


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

示例1: _splitLineString

# 需要导入模块: from django.contrib.gis.geos import LineString [as 别名]
# 或者: from django.contrib.gis.geos.LineString import distance [as 别名]
 def _splitLineString(self, lineString, *args):
     """
     args type could be Point or list
     """
     minDist = sys.maxint
     tolerance = 0.1
     
     #split line string with a single point    
     if type(args[0]) == Point:
         splitPoint = args[0]
         startPt = lineString.coords[0]
         for i in range(1,len(lineString.coords)):
             endPt = lineString.coords[i]
             lineSeg = LineString(startPt, endPt)
             dist = lineSeg.distance(splitPoint) 
             if dist < minDist:
                 minDist = dist
                 splitIndex = i
         coords = list(lineString.coords[0:splitIndex])
         coords.append((splitPoint.coords))
         firstLineString = LineString(coords)
         coords = []        
         coords.append((splitPoint.coords))
         coords.extend(lineString.coords[splitIndex:])        
         secondLineString = LineString(coords)
         return [firstLineString, secondLineString]
     elif type(args[0]) == tuple  or type(args[0]) == list or type(args[0]) == ControlPointList:
         splitPointList = args[0]
         assert(len(splitPointList) != 0)
                     
         splitLines = self._splitLineString(lineString, splitPointList[-1])
         splitPointList.pop()
         
         spPtList1 = []
         spPtList2 = []
         for point in splitPointList:
             if splitLines[0].distance(point) < tolerance:
                 spPtList1.append(point)
             else:
                 spPtList2.append(point)
         resList = []
         if len(spPtList1) != 0:
             resList.extend(self._splitLineString(splitLines[0], spPtList1))
         else:
             resList.append(splitLines[0])
         if len(spPtList2) != 0:
             resList.extend(self._splitLineString(splitLines[1], spPtList2))
         else:
             resList.append(splitLines[1])
         return resList  
     else:
         raise 'Error, unsupported type'
开发者ID:dynaturtle,项目名称:xiao-personal-code,代码行数:54,代码来源:models.py

示例2: test_distance

# 需要导入模块: from django.contrib.gis.geos import LineString [as 别名]
# 或者: from django.contrib.gis.geos.LineString import distance [as 别名]
    def test_distance(self):
        "Testing the distance() function."
        # Distance to self should be 0.
        pnt = Point(0, 0)
        self.assertEqual(0.0, pnt.distance(Point(0, 0)))

        # Distance should be 1
        self.assertEqual(1.0, pnt.distance(Point(0, 1)))

        # Distance should be ~ sqrt(2)
        self.assertAlmostEqual(1.41421356237, pnt.distance(Point(1, 1)), 11)

        # Distances are from the closest vertex in each geometry --
        #  should be 3 (distance from (2, 2) to (5, 2)).
        ls1 = LineString((0, 0), (1, 1), (2, 2))
        ls2 = LineString((5, 2), (6, 1), (7, 0))
        self.assertEqual(3, ls1.distance(ls2))
开发者ID:ricardoffv,项目名称:django-pizza,代码行数:19,代码来源:test_geos.py


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