本文整理汇总了Python中matplotlib.patches.Polygon.basin_id方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.basin_id方法的具体用法?Python Polygon.basin_id怎么用?Python Polygon.basin_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Polygon
的用法示例。
在下文中一共展示了Polygon.basin_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_features_from_shape
# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import basin_id [as 别名]
def get_features_from_shape(basemap, path = 'data/shape/contour_bv_MRCC/Bassins_MRCC_utm18.shp', linewidth = 2,
edgecolor = 'k', face_color = "none", id_list = None, zorder = 0, alpha = 1):
driver = ogr.GetDriverByName("ESRI Shapefile")
dataStore = driver.Open(path, 0)
layer = dataStore.GetLayer(0)
latlong = osr.SpatialReference()
latlong.ImportFromProj4("+proj=latlong")
result = []
id_list_lower = []
if id_list is not None:
id_list_lower = map(lambda x: x.lower(), id_list)
feature = layer.GetNextFeature()
while feature:
geom = feature.GetGeometryRef()
geom.TransformTo(latlong)
#get fields of the feature
# for i in xrange(feature.GetFieldCount()):
# print feature.GetField(i)
# print geom.ExportToWkt()
polygon = loads(geom.ExportToWkt())
boundary = polygon.exterior
coords = np.zeros(( len(boundary.coords), 2))
currentId = None
for i, the_coord in enumerate(boundary.coords):
# if feature.GetFieldAsString('abr').lower() == 'rdo':
# print the_coord[0], the_coord[1]
if basemap is not None:
coords[i, 0], coords[i, 1] = basemap( the_coord[0], the_coord[1] )
currentId = feature.GetFieldAsString("abr").lower()
to_add = True
if id_list is not None:
to_add = currentId in id_list_lower
if to_add:
p = Polygon(coords,linewidth = linewidth, edgecolor = edgecolor,
facecolor=face_color, zorder = zorder, alpha = alpha)
p.basin_id = currentId
result.append(p)
feature = layer.GetNextFeature()
dataStore.Destroy()
return result