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


Python LineString.union方法代码示例

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


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

示例1: SkeletonLineSampler

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import union [as 别名]
class SkeletonLineSampler(PolygonToPointSampler):

    SIMPLIFY_TOLERANCE = 20

    def __init__(self, polygon = '', simplify = True, simplify_tolerance = SIMPLIFY_TOLERANCE):
        super(self.__class__, self).__init__(polygon)
        self.simplify = simplify
        self.simplify_tolerance = simplify_tolerance

    def perform_sampling(self):
        from triangle_wrapper import TriangleWrapper
        self.tw = TriangleWrapper()
        self.skel = LineString()
        
        for src in self.src:
            self.tw.set_polygon(src)
            self.tw.create_poly_data()
            tmp_name = self.tw.write_poly_file()
            self.tw.build_triangle_cmd(tmp_name)
            self.tw.execute_triangle()
            self.tw.read_node_file()
            self.tw.read_ele_file()
            single_skel = self.tw.create_skeleton_line()
            self.skel = self.skel.union(single_skel)
        
        #print self.skel
        self.tw.cleanup()
        self.convert_skeleton_to_sample_points()

    def convert_skeleton_to_sample_points(self):
        # converting straight skeleton line to its vertices

        lines = list()

        if hasattr(self.skel, 'geoms'):
            for line in self.skel:
                lines.append(line)
        else:
            lines.append(self.skel)
        
        for line in lines:
            for x, y in line.coords:
                sp = Point((x, y))
                self.samples.append(sp)
                print sp

    def distance(self, from_pt, to_pt):
        
        return sqrt((from_pt[0] - to_pt[0]) ** 2 + (from_pt[1] - to_pt[1]) ** 2)
开发者ID:leaffan,项目名称:geo,代码行数:51,代码来源:sampler.py

示例2: write_border

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import union [as 别名]
def write_border(points, out):
    # square cap and bevel join
    line_buffer = LineString(tuple(points)).buffer(BASE_OFFSET, cap_style=3, join_style=3)

    base_buffer = Point(*points[0]).buffer(LINE_OFFSET, cap_style=3)
    end_buffer = Point(*points[-1]).buffer(LINE_OFFSET, cap_style=3)

    geofence = line_buffer.union(base_buffer).union(end_buffer)

    out.writerow(geofence.centroid.coords[0])
    for p in geofence.exterior.coords:
        out.writerow(p)

    if geofence.interiors:
        print("WARNING: The geofence contains interior rings ({0} total).".format(len(geofence.interiors)))
        for n, i in enumerate(geofence.interiors, 1):
            print("          Interior {0}".format(n))
            for c in i.coords:
                print("           {0}".format(str(c)))
开发者ID:SchulichUAV,项目名称:Tools,代码行数:21,代码来源:border.py

示例3: __init__

# 需要导入模块: from shapely.geometry import LineString [as 别名]
# 或者: from shapely.geometry.LineString import union [as 别名]

#.........这里部分代码省略.........
                mag = self.image.mag
                xvals = [pt[0]*mag for pt in self.points]
                yvals = [pt[1]*mag for pt in self.points]
                pts = zip(xvals,yvals)
            else:
                if len(self.points) < 3:
                    return None
                pts = self.points
            self.shape = Polygon( self.transform.worldpts(pts) ) #===
        # Open trace
        elif self.closed == False and len(self.points)>1:
            self.shape = LineString( self.transform.worldpts(self.points) ) #===
        else:
            print('\nInvalid shape characteristics: '+self.name)
            print('Quit for debug')
            quit() # for dbugging
    def box(self):
        '''Returns bounding box of shape (shapely) library'''
        if self.shape != None:
            minx, miny, maxx, maxy = self.shape.bounds
            return box(minx, miny, maxx, maxy)
        #else:
        #    print('NoneType for shape: '+self.name)
# mergeTool functions
    def overlaps(self, other, threshold=(1+2**(-17))):
        '''Return 0 if no overlap.
        For closed traces: return 1 if AoU/AoI < threshold, return AoU/AoI if not < threshold
        For open traces: return 0 if # pts differs or distance between parallel pts > threshold
                         return 1 otherwise'''
        if self.shape == None:self.popShape()
        if other.shape == None:other.popShape()
        # Check bounding box (reduces comp. time for non-overlapping contours)

        if (self.box() is None or other.box() is None):
            return 0

        if (not self.box().intersects(other.box()) and
            not self.box().touches(other.box()) ):
            return 0
        # Check if both same type of contour
        if self.closed != other.closed:
            return 0
        # Closed contours
        if self.closed:
            AoU = self.shape.union( other.shape ).area
            AoI = self.shape.intersection( other.shape ).area
            if AoI == 0:
                return 0
            elif AoU/AoI >= threshold: #===
                return AoU/AoI # Returns actual value, not 0 or 1
            elif AoU/AoI < threshold:
                return 1
        # Open contours
        if not self.closed:
            if len( self.points ) != len( other.points ):
                return 0
            def distance(pt0, pt1):
                return math.sqrt( (pt0[0] - pt1[0])**2 + (pt0[1] - pt1[1])**2 )
            # Lists of world coords to compare
            a = self.transform.worldpts(self.points)
            b = other.transform.worldpts(other.points)
            distlist = [distance(a[i],b[i]) for i in range(len(self.points))] 
            for elem in distlist:
                if elem > threshold:
                    return 0
        return 1
# curationTool functions
    def getLength(self):
        '''Returns the sum of all line segments in the contour object'''
        length = 0
        for index in range( len(self.points) ):
            if index+1 >= len(self.points): # stop when outside index range
                break
            pt = self.points[index]
            nextPt = self.points[index+1]
            length += (((nextPt[0]-pt[0])**2)+((nextPt[1]-pt[1])**2))**(0.5)
        if self.closed: # If closed object, add distance between 1st and last pt too
            length += (((self.points[0][0]-self.points[-1][0])**2)+((self.points[0][1]-self.points[-1][1])**2))**(0.5)
        return length #=== sqrt is taxing computation; reimplement with 1 sqrt at end?
    def getStartEndCount(self, series):
        '''Returns the start, end, and count values for this contour in given series. Determined by self.name only'''
        return series.getStartEndCount(self.name)
    def getVolume(self, series):
        return series.getVolume(self.name)
    def getSurfaceArea(self, series):
        return series.getSurfaceArea(self.name)
    def getFlatArea(self, series):
        return series.getFlatArea(self.name)
    def isReverse(self):
        '''Returns true if contour is a reverse trace (negative area)'''
        self.popShape()
        if self.closed:
            ring = LinearRing(self.shape.exterior.coords) # convert polygon to ring
            return not ring.is_ccw # For some reason, the opposite is true (image vs biological coordinate system?)
        else:
            return False
    def isInvalid(self):
        '''Returns true if this is an invalid contour.'''
        if self.closed and len(self.points) < 3:
            return True
开发者ID:larrylindsey,项目名称:pyrecon,代码行数:104,代码来源:Contour.py


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