本文整理汇总了Python中shapefile.Reader.shapeRecords方法的典型用法代码示例。如果您正苦于以下问题:Python Reader.shapeRecords方法的具体用法?Python Reader.shapeRecords怎么用?Python Reader.shapeRecords使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shapefile.Reader
的用法示例。
在下文中一共展示了Reader.shapeRecords方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_coast_polygons
# 需要导入模块: from shapefile import Reader [as 别名]
# 或者: from shapefile.Reader import shapeRecords [as 别名]
def get_coast_polygons(resolution):
polymeta = []; polybounds = []
for level in [1,2,3,5]:
filename = os.path.join(GSHHS_DIR, 'GSHHS_shp/', resolution,
'GSHHS_{}_L{}'.format(resolution, level))
print filename
shf = Reader(filename)
fields = shf.fields
try:
shf.shapeRecords()
except:
continue
for shprec in shf.shapeRecords():
shp = shprec.shape; rec = shprec.record
parts = shp.parts.tolist()
if parts != [0]:
print 'multipart polygon'
raise SystemExit
verts = shp.points
lons, lats = list(zip(*verts))
north = max(lats); south = min(lats)
attdict={}
for r,key in zip(rec,fields[1:]):
attdict[key[0]]=r
area = attdict['area']
id = attdict['id']
polymeta.append([level,area,south,north,len(lons),id])
b = np.empty((len(lons),2),np.float32)
b[:,0] = lons; b[:,1] = lats
if lsd is not None:
b = quantize(b,lsd)
polybounds.append(b)
# Manual fix for incorrect Antarctica polygons at full resolution
# This issue is only present in the shapefile version and may be fixed
# in future versions of GSHHS!
if resolution == 'f' and level == 5:
i = [item[-1] for item in polymeta].index('4-E')
coords = polybounds[i][2:-1, :]
coords = np.vstack([coords,
[180.0, -90.0],
[0.0, -90.0]]).astype(np.float32)
polybounds[i] = coords
polymeta[i][-2] = len(coords)
j = [item[-1] for item in polymeta].index('4-W')
coords = polybounds[j][3:, :]
np.savetxt('coordinates.txt', coords)
coords = np.vstack([coords,
[0.0, coords[-1][1]],
[0.0, -90.0],
[-180.0, -90.0],
coords[0]]).astype(np.float32)
polybounds[j] = coords
polymeta[j][-2] = len(coords)
return polybounds, polymeta
示例2: get_wdb_boundaries
# 需要导入模块: from shapefile import Reader [as 别名]
# 或者: from shapefile.Reader import shapeRecords [as 别名]
def get_wdb_boundaries(resolution, level, rivers=False):
polymeta = []
polybounds = []
if rivers:
filename = "WDBII_shp/%s/WDBII_river_%s_L%02i" % (resolution, resolution, level)
else:
filename = "WDBII_shp/%s/WDBII_border_%s_L%s" % (resolution, resolution, level)
print filename
shf = Reader(filename)
fields = shf.fields
for shprec in shf.shapeRecords():
shp = shprec.shape
rec = shprec.record
parts = shp.parts.tolist()
if parts != [0]:
print "multipart polygon"
raise SystemExit
verts = shp.points
lons, lats = list(zip(*verts))
north = max(lats)
south = min(lats)
attdict = {}
for r, key in zip(rec, fields[1:]):
attdict[key[0]] = r
area = -1
id = attdict["id"]
polymeta.append([-1, -1, south, north, len(lons), id])
b = np.empty((len(lons), 2), np.float32)
b[:, 0] = lons
b[:, 1] = lats
if lsd is not None:
b = quantize(b, lsd)
polybounds.append(b)
return polybounds, polymeta
示例3: get_coast_polygons
# 需要导入模块: from shapefile import Reader [as 别名]
# 或者: from shapefile.Reader import shapeRecords [as 别名]
def get_coast_polygons(resolution):
polymeta = []
polybounds = []
for level in [1, 2, 3, 4]:
filename = "GSHHS_shp/%s/GSHHS_%s_L%s" % (resolution, resolution, level)
# filename = 'WDBII_shp/%s/WDBII_border_%s_L%s' % (resolution, resolution, level)
print filename
shf = Reader(filename)
fields = shf.fields
try:
shf.shapeRecords()
except:
continue
for shprec in shf.shapeRecords():
shp = shprec.shape
rec = shprec.record
parts = shp.parts.tolist()
if parts != [0]:
print "multipart polygon"
raise SystemExit
verts = shp.points
lons, lats = list(zip(*verts))
north = max(lats)
south = min(lats)
attdict = {}
for r, key in zip(rec, fields[1:]):
attdict[key[0]] = r
area = attdict["area"]
id = attdict["id"]
polymeta.append([level, area, south, north, len(lons), id])
b = np.empty((len(lons), 2), np.float32)
b[:, 0] = lons
b[:, 1] = lats
if lsd is not None:
b = quantize(b, lsd)
polybounds.append(b)
return polybounds, polymeta
示例4: get_wdb_boundaries
# 需要导入模块: from shapefile import Reader [as 别名]
# 或者: from shapefile.Reader import shapeRecords [as 别名]
def get_wdb_boundaries(resolution,level,rivers=False):
polymeta = []; polybounds = []
if rivers:
filename = os.path.join(GSHHS_DIR, 'WDBII_shp', resolution,
'WDBII_river_{}_L{:02}'.format(resolution, level))
else:
filename = os.path.join(GSHHS_DIR, 'WDBII_shp', resolution,
'WDBII_border_{}_L{}'.format(resolution, level))
print filename
shf = Reader(filename)
fields = shf.fields
for shprec in shf.shapeRecords():
shp = shprec.shape; rec = shprec.record
parts = shp.parts.tolist()
if parts != [0]:
print 'multipart polygon'
raise SystemExit
verts = shp.points
# Detect degenerate lines that are actually points...
if len(verts) == 2 and np.allclose(verts[0], verts[1]):
print 'Skipping degenerate line...'
continue
lons, lats = list(zip(*verts))
north = max(lats); south = min(lats)
attdict={}
for r,key in zip(rec,fields[1:]):
attdict[key[0]]=r
area = -1
poly_id = attdict['id']
b = np.empty((len(lons),2),np.float32)
b[:,0] = lons; b[:,1] = lats
if not rivers:
b = interpolate_long_segments(b, resolution)
if lsd is not None:
b = quantize(b,lsd)
polymeta.append([-1,-1,south,north,len(b),poly_id])
polybounds.append(b)
return polybounds, polymeta