本文整理汇总了Python中osgeo.ogr.wkbPolygon方法的典型用法代码示例。如果您正苦于以下问题:Python ogr.wkbPolygon方法的具体用法?Python ogr.wkbPolygon怎么用?Python ogr.wkbPolygon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osgeo.ogr
的用法示例。
在下文中一共展示了ogr.wkbPolygon方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_layer
# 需要导入模块: from osgeo import ogr [as 别名]
# 或者: from osgeo.ogr import wkbPolygon [as 别名]
def plot_layer(filename, symbol, layer_index=0, **kwargs):
"""Plots an OGR polygon layer using the given symbol."""
ds = ogr.Open(filename)
# Loop through all of the features in the layer.
for row in ds.GetLayer(layer_index):
geom = row.geometry()
geom_type = geom.GetGeometryType()
# If the geometry is a single polygon.
if geom_type == ogr.wkbPolygon:
plot_polygon(geom, symbol, **kwargs)
# Else if the geometry is a multipolygon, send each
# part to plot_polygon individually.
elif geom_type == ogr.wkbMultiPolygon:
for i in range(geom.GetGeometryCount()):
subgeom = geom.GetGeometryRef(i)
plot_polygon(subgeom, symbol, **kwargs)
# Plot countries.
示例2: plot_layer
# 需要导入模块: from osgeo import ogr [as 别名]
# 或者: from osgeo.ogr import wkbPolygon [as 别名]
def plot_layer(filename, symbol, layer_index=0, **kwargs):
"""Plots an OGR layer using the given symbol."""
ds = ogr.Open(filename)
for row in ds.GetLayer(layer_index):
geom = row.geometry()
geom_type = geom.GetGeometryType()
# Polygons
if geom_type == ogr.wkbPolygon:
plot_polygon(geom, symbol, **kwargs)
# Multipolygons
elif geom_type == ogr.wkbMultiPolygon:
for i in range(geom.GetGeometryCount()):
subgeom = geom.GetGeometryRef(i)
plot_polygon(subgeom, symbol, **kwargs)
# Lines
elif geom_type == ogr.wkbLineString:
plot_line(geom, symbol, **kwargs)
# Multilines
elif geom_type == ogr.wkbMultiLineString:
for i in range(geom.GetGeometryCount()):
subgeom = geom.GetGeometryRef(i)
plot_line(subgeom, symbol, **kwargs)
# Points
elif geom_type == ogr.wkbPoint:
plot_point(geom, symbol, **kwargs)
# Multipoints
elif geom_type == ogr.wkbMultiPoint:
for i in range(geom.GetGeometryCount()):
subgeom = geom.GetGeometryRef(i)
plot_point(subgeom, symbol, **kwargs)
# Now plot countries, rivers, and cities.
示例3: _check_src
# 需要导入模块: from osgeo import ogr [as 别名]
# 或者: from osgeo.ogr import wkbPolygon [as 别名]
def _check_src(self, src):
"""Basic check of source elements (sequence of points or polygons).
- array cast of source elements
- create ogr_src datasource/layer holding src points/polygons
- transforming source grid points/polygons to ogr.geometries
on ogr.layer
"""
tmpfile = tempfile.NamedTemporaryFile(mode="w+b").name
ogr_src = io.gdal.gdal_create_dataset(
"ESRI Shapefile", os.path.join("/vsimem", tmpfile), gdal_type=gdal.OF_VECTOR
)
src = np.array(src)
# create memory datasource, layer and create features
if src.ndim == 2:
geom_type = ogr.wkbPoint
# no Polygons, just Points
else:
geom_type = ogr.wkbPolygon
fields = [("index", ogr.OFTInteger)]
georef.vector.ogr_create_layer(
ogr_src, self._name, srs=self._srs, geom_type=geom_type, fields=fields
)
georef.vector.ogr_add_feature(ogr_src, src, name=self._name)
return ogr_src
示例4: ogr_create_layer
# 需要导入模块: from osgeo import ogr [as 别名]
# 或者: from osgeo.ogr import wkbPolygon [as 别名]
def ogr_create_layer(ds, name, srs=None, geom_type=None, fields=None):
"""Creates OGR.Layer objects in gdal.Dataset object.
Creates one OGR.Layer with given name in given gdal.Dataset object
using given OGR.GeometryType and FieldDefinitions
Parameters
----------
ds : gdal.Dataset
object
name : string
OGRLayer name
srs : OSR.SpatialReference
object
geom_type : OGR GeometryType
(eg. ogr.wkbPolygon)
fields : list of 2 element tuples
(strings, OGR.DataType) field name, field type
Returns
-------
out : OGR.Layer
object
"""
if geom_type is None:
raise TypeError("geometry_type needed")
lyr = ds.CreateLayer(name, srs=srs, geom_type=geom_type)
if fields is not None:
for fname, fvalue in fields:
lyr.CreateField(ogr.FieldDefn(fname, fvalue))
return lyr