本文整理匯總了Python中Polygon.numParts方法的典型用法代碼示例。如果您正苦於以下問題:Python Polygon.numParts方法的具體用法?Python Polygon.numParts怎麽用?Python Polygon.numParts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Polygon
的用法示例。
在下文中一共展示了Polygon.numParts方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: readShpPolygon
# 需要導入模塊: import Polygon [as 別名]
# 或者: from Polygon import numParts [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)