當前位置: 首頁>>代碼示例>>Python>>正文


Python Polygon.partsIndex方法代碼示例

本文整理匯總了Python中Polygon.partsIndex方法的典型用法代碼示例。如果您正苦於以下問題:Python Polygon.partsIndex方法的具體用法?Python Polygon.partsIndex怎麽用?Python Polygon.partsIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Polygon的用法示例。


在下文中一共展示了Polygon.partsIndex方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: readShpPolygon

# 需要導入模塊: import Polygon [as 別名]
# 或者: from Polygon import partsIndex [as 別名]
def readShpPolygon(layer,fileName):# parameter fileName is the pathfile name without extension
    indexName = fileName + '.shx'
    shpFile = open(indexName,"rb")
    fileLength = os.path.getsize(indexName)
    polygonNum = (fileLength-100)/8
    recordsOffset = []
    print fileName
    starttime = time.clock()
    shpFile.seek(0)
    s = shpFile.read(fileLength)
    shpFile.close()
    layer.minx, layer.miny, layer.maxx, layer.maxy = struct.unpack("<dddd",s[36:68])
    pointer = 100
    for i in range(0,polygonNum):
        offset = struct.unpack('>i',s[pointer:pointer+4])
        recordsOffset.append(offset[0]*2)
        pointer += 8
    shpFile.close()
    shpFile = open(fileName+'.shp',"rb")
    shpFile.seek(24)
    s = shpFile.read(4)
    header = struct.unpack(">i",s)
    fileLength = header[0]*2
    shpFile.seek(0)
    s = shpFile.read(fileLength)
    shpFile.close()
    for offset in recordsOffset:
        x, y = [], []
        polygon = Polygon()
        pointer = offset + 8 + 4
        polygon.minx,polygon.miny,polygon.maxx,polygon.maxy = struct.unpack('dddd',s[pointer:pointer+32])
        pointer = offset + 8 + 36
        polygon.numParts, polygon.numPoints = struct.unpack('ii',s[pointer:pointer+8])
        pointer += 8
        str = ''
        for i in range(polygon.numParts):
            str = str+'i'
        polygon.partsIndex = struct.unpack(str,s[pointer:pointer+polygon.numParts*4])
        pointer += polygon.numParts*4
        for i in range(polygon.numPoints):
            pointx, pointy = struct.unpack('dd',s[pointer:pointer+16])
            x.append(pointx)
            y.append(pointy)
            pointer+=16
        polygon.x, polygon.y = x, y
        layer.features.append(polygon)
    ts = time.clock()-starttime
    print ' %f seconds' % (ts)
開發者ID:majiaoGMU,項目名稱:Python-Programming-Project,代碼行數:50,代碼來源:ReadShapeFile.py


注:本文中的Polygon.partsIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。