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


Python Polygon.boundingBox方法代码示例

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


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

示例1: Polygon

# 需要导入模块: import Polygon [as 别名]
# 或者: from Polygon import boundingBox [as 别名]
class Solid:
    name = "solid"
    id = 0
    
    polygon = Polygon()
    material = Material()
    
    def __init__(self, points):
        self.polygon = Polygon(points)
        
    def fill(self, particles):
        xmin, xmax, ymin, ymax = self.polygon.boundingBox()
        
        d2 = 2 * self.material.d
        x = xmin
        while x < xmax:
            x += d2
            y = ymin
            while y < ymax:
                y += d2
                if self.polygon.isInside(x, y):
                    id = len(particles)
                    particles.append(self.material.createParticle(x, y, id))
                    
        pass
        
    def setInfo(self, name, id):
        self.name = name
        self.id = id
        
    def setMaterial(self, material):
        self.material = material
        
    def scaleIn(self, scale):
        self.polygon.scale(scale, scale, 0.0, 0.0)
        
    def scaleOut(self, scale):
        self.polygon.scale(1.0 / scale, 1.0 / scale, 0.0, 0.0)
        
    def points(self):
        return self.polygon[0]
    
    def len(self):
        return self.polygon.nPoints(0)
开发者ID:BackupTheBerlios,项目名称:veda-svn,代码行数:46,代码来源:Project.py

示例2: reduceExample

# 需要导入模块: import Polygon [as 别名]
# 或者: from Polygon import boundingBox [as 别名]
def reduceExample():
    # read Polygon from file
    p = Polygon('testpoly.gpf')
    # use ireland only, I know it's contour 0
    pnew = Polygon(p[0])
    # number of points
    l = len(pnew[0])
    # get shift value to show many polygons in drawing
    bb = pnew.boundingBox()
    xs = 1.1 * (bb[1]-bb[0])
    # list with polygons to plot
    plist = [pnew]
    while l > 30:
        # reduce points to the half
        l /= 2
        print "Reducing contour to %d points" % l
        pnew = Polygon(reducePoints(pnew[0], l))
        pnew.shift(xs, 0)
        plist.append(pnew)
    # draw the results
    print "Plotting ReduceExample.svg"
    drawSVG(plist, height=400, ofile="ReduceTest.svg")
开发者ID:Germanc,项目名称:supreme,代码行数:24,代码来源:PolygonExamples.py

示例3: reduceExample

# 需要导入模块: import Polygon [as 别名]
# 或者: from Polygon import boundingBox [as 别名]
def reduceExample():
    # read Polygon from file
    p = Polygon('testpoly.gpf')
    # use ireland only, I know it's contour 0
    pnew = Polygon(p[0])
    # number of points
    l = len(pnew[0])
    # get shift value to show many polygons in drawing
    bb = pnew.boundingBox()
    xs = 1.1 * (bb[1]-bb[0])
    # list with polygons to plot
    plist = [pnew]
    while l > 30:
        # reduce points to the half
        l /= 2
        print 'Reducing contour to %d points' % l
        pnew = Polygon(reducePoints(pnew[0], l))
        pnew.shift(xs, 0)
        plist.append(pnew)
    # draw the results
    writeSVG('ReducePoints.svg', plist, height=400)
    if hasPDFExport:
        writePDF('ReducePoints.pdf', plist)
开发者ID:EUPSForge,项目名称:polygon,代码行数:25,代码来源:Examples.py

示例4: postDividePolygons

# 需要导入模块: import Polygon [as 别名]
# 或者: from Polygon import boundingBox [as 别名]
    def postDividePolygons(self,areas,nAreas):
        def getPointInFace(face,bbox):
            if face == 0:
                x = bbox[0]
                y = numpy.random.uniform(bbox[2],bbox[3])
            elif face == 1:
                y = bbox[3]
                x = numpy.random.uniform(bbox[0],bbox[1])
            elif face == 2:
                x = bbox[1]
                y = numpy.random.uniform(bbox[2],bbox[3])
            elif face == 3:
                y = bbox[2]
                x = numpy.random.uniform(bbox[0],bbox[1])
            return x,y

        def getCornersOfFace(face,bbox):
            if face == 0:
                c1 = (bbox[0],bbox[2])
                c2 = (bbox[0],bbox[3])
            elif face == 1:
                c1 = (bbox[0],bbox[3])
                c2 = (bbox[1],bbox[3])
            elif face == 2:
                c1 = (bbox[1],bbox[3])
                c2 = (bbox[1],bbox[2])
            elif face == 3:
                c1 = (bbox[1],bbox[2])
                c2 = (bbox[0],bbox[2])
            return c1,c2

        while len(areas) < nAreas:
            end = False
            while not end:
                areaOrder = range(0,len(areas))
                areaOrder.sort(key=lambda x: areas[x].area(),reverse=True)
                na = areaOrder[0]
                #na = numpy.random.randint(0,len(areas))
                if areas[na][0][0] != areas[na][0][-1]:
                    areas[na] = Polygon([x for x in areas[na][0]] + [areas[na][0][0]])
                area = areas[na]
                bbox = area.boundingBox()
                bboxp = Polygon([(bbox[0]-1,bbox[2]-1),(bbox[0]-1,bbox[3]+1),
                               (bbox[1]+1,bbox[3]+1),(bbox[1]+1,bbox[2]-1),
                               (bbox[0]-1,bbox[2]-1)])
                bbox = bboxp.boundingBox()
                inside = False
                errors = 0
                warnings = 0
                i = 0
                while not inside:
                    if errors == 20 and na +1 < len(areas):
                        i += 1
                        na = areaOrder[i]
                        if areas[na][0][0] != areas[na][0][-1]:
                            areas[na] = Polygon([x for x in areas[na][0]] + [areas[na][0][0]])
                        area = areas[na]
                        bbox = area.boundingBox()
                        bboxp = Polygon([(bbox[0]-1,bbox[2]-1),(bbox[0]-1,bbox[3]+1),
                                       (bbox[1]+1,bbox[3]+1),(bbox[1]+1,bbox[2]-1),
                                       (bbox[0]-1,bbox[2]-1)])
                        bbox = bboxp.boundingBox()
                        errors = 0

                    f1 = numpy.random.randint(0,4)
                    f2 = (f1 + numpy.random.randint(1,4))%4
                    faces = [f1,f2]
                    faces.sort()
                    p1 = getPointInFace(faces[0],bbox)
                    if f1%2 == 0:
                        p2 = (p1[0],p1[1]+1)
                    else:    
                        p2 = (p1[0]+1,p1[1])
                    p3 = getPointInFace(faces[1],bbox)
                    if f2%2 == 0:
                        p4 = (p3[0],p3[1]+1)
                    else:    
                        p4 = (p3[0]+1,p3[1])
                    line = Polygon([p1,p2,p3,p4,p1])
                    inters = area & line
                    parts = line - area
                    if len(parts) == 2 and inters.area() >= line.area()*0.2 :
                        inside = True
                    else:
                        errors += 1

                divPolygon = [p1]
                for i in range(*faces):
                    c1,c2 = getCornersOfFace(i,bbox)
                    divPolygon.append(c2)
                divPolygon.append(p3)
                divPolygon.append(p1)
                divPolygon = Polygon(divPolygon)
                polygon1 = divPolygon & area
                divPolygon = bboxp - divPolygon
                polygon2 = area - polygon1
                if len(polygon1) == 1 and \
                   len(polygon2) == 1 and \
                   polygon1.area() > 0 and \
                   polygon2.area() > 0 and \
#.........这里部分代码省略.........
开发者ID:1990q828j,项目名称:clusterpy,代码行数:103,代码来源:rimaps.py

示例5: updateBbox

# 需要导入模块: import Polygon [as 别名]
# 或者: from Polygon import boundingBox [as 别名]
            # remove last redundant coordinate from each contour
            # (Tangram doesn't like this - it needs the last coordinate
            # to draw the last face properly)
            # del c[-1]

            # for each vertex
            # for v in c:
            # offset all verts in tile to arrange in scenespace
            # this isn't necessary when the data is coming straight from the json,
            # only when the data is coming from a tangram vbo
            # v = [v[0]+(4096*(tilemax[0]-tile.x)), v[1]+(4096*(tilemax[1]-tile.y))]

            poly.addContour(c)

            # update tile's bbox with contour's bbox
            t.bbox = updateBbox(t.bbox, list(poly.boundingBox()))

        poly.tile = t
        t.polys.append(poly)

printStatus("100%")


# make a list of all polys
# this list comprehension is the same as the nested for loops below
# neat, eh? ...but harder to read :/
# polys = [p for t in tiles for p in t.polys]

polys = []
for t in tiles:
    for p in t.polys:
开发者ID:klwiley,项目名称:landgrab,代码行数:33,代码来源:dedupe.py


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