本文整理匯總了Python中ogr.Geometry方法的典型用法代碼示例。如果您正苦於以下問題:Python ogr.Geometry方法的具體用法?Python ogr.Geometry怎麽用?Python ogr.Geometry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ogr
的用法示例。
在下文中一共展示了ogr.Geometry方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_temp_shape
# 需要導入模塊: import ogr [as 別名]
# 或者: from ogr import Geometry [as 別名]
def create_temp_shape(self, name, point_list):
vector_file = os.path.join(self.temp_dir.name, name)
shape_driver = ogr.GetDriverByName("ESRI Shapefile") # Depreciated; replace at some point
vector_data_source = shape_driver.CreateDataSource(vector_file)
vector_layer = vector_data_source.CreateLayer("geometry", self.srs, geom_type=ogr.wkbPolygon)
ring = ogr.Geometry(ogr.wkbLinearRing)
for point in point_list:
ring.AddPoint(point[0], point[1])
poly = ogr.Geometry(ogr.wkbPolygon)
poly.AddGeometry(ring)
vector_feature_definition = vector_layer.GetLayerDefn()
vector_feature = ogr.Feature(vector_feature_definition)
vector_feature.SetGeometry(poly)
vector_layer.CreateFeature(vector_feature)
vector_layer.CreateField(ogr.FieldDefn("class", ogr.OFTInteger))
feature = ogr.Feature(vector_layer.GetLayerDefn())
feature.SetField("class", 3)
vector_data_source.FlushCache()
self.vectors.append(vector_data_source) # Check this is the right thing to be saving here
self.vector_paths.append(vector_file)
示例2: test_write_polygon
# 需要導入模塊: import ogr [as 別名]
# 或者: from ogr import Geometry [as 別名]
def test_write_polygon(managed_geotiff_dir):
test_dir = managed_geotiff_dir
ring = ogr.Geometry(ogr.wkbLinearRing)
ring.AddPoint(1,1)
ring.AddPoint(1,5)
ring.AddPoint(5,1)
ring.AddPoint(1,1)
poly = ogr.Geometry(ogr.wkbPolygon)
poly.AddGeometry(ring)
result_path = os.path.join(test_dir.path, "test_poly")
pyeo.write_polygon(poly, result_path)
assert os.path.exists(result_path)
示例3: create_100x100_shp
# 需要導入模塊: import ogr [as 別名]
# 或者: from ogr import Geometry [as 別名]
def create_100x100_shp(self, name):
"""Cretes a shapefile with a vector layer named "geometry" containing a 100mx100m square , top left corner
being at wgs coords 10,10.
This polygon has a field, 'class' with a value of 3. Left in for back-compatability"""
# TODO Generalise this
vector_file = os.path.join(self.temp_dir.name, name)
shape_driver = ogr.GetDriverByName("ESRI Shapefile") # Depreciated; replace at some point
vector_data_source = shape_driver.CreateDataSource(vector_file)
vector_layer = vector_data_source.CreateLayer("geometry", self.srs, geom_type=ogr.wkbPolygon)
ring = ogr.Geometry(ogr.wkbLinearRing)
ring.AddPoint(10.0, 10.0)
ring.AddPoint(10.0, 110.0)
ring.AddPoint(110.0, 110.0)
ring.AddPoint(110.0, 10.0)
ring.AddPoint(10.0, 10.0)
poly = ogr.Geometry(ogr.wkbPolygon)
poly.AddGeometry(ring)
vector_feature_definition = vector_layer.GetLayerDefn()
vector_feature = ogr.Feature(vector_feature_definition)
vector_feature.SetGeometry(poly)
vector_layer.CreateFeature(vector_feature)
vector_layer.CreateField(ogr.FieldDefn("class", ogr.OFTInteger))
feature = ogr.Feature(vector_layer.GetLayerDefn())
feature.SetField("class", 3)
vector_data_source.FlushCache()
self.vectors.append(vector_data_source) # Check this is the right thing to be saving here
self.vector_paths.append(vector_file)
示例4: shp_to_wkt
# 需要導入模塊: import ogr [as 別名]
# 或者: from ogr import Geometry [as 別名]
def shp_to_wkt(shapefile, buffer=None, convex=False, envelope=False):
'''A helper function to translate a shapefile into WKT
'''
# get filepaths and proj4 string
shpfile = os.path.abspath(shapefile)
prjfile = shpfile[:-4] + '.prj'
proj4 = get_proj4(prjfile)
lyr_name = os.path.basename(shapefile)[:-4]
shp = ogr.Open(os.path.abspath(shapefile))
lyr = shp.GetLayerByName(lyr_name)
geom = ogr.Geometry(ogr.wkbGeometryCollection)
for feat in lyr:
geom.AddGeometry(feat.GetGeometryRef())
wkt = geom.ExportToWkt()
if proj4 != '+proj=longlat +datum=WGS84 +no_defs':
print(' INFO: Reprojecting AOI file to Lat/Long (WGS84)')
wkt = reproject_geometry(wkt, proj4, 4326).ExportToWkt()
# do manipulations if needed
wkt = wkt_manipulations(wkt, buffer=buffer, convex=convex,
envelope=envelope)
return wkt
示例5: to_ogr_multi_type
# 需要導入模塊: import ogr [as 別名]
# 或者: from ogr import Geometry [as 別名]
def to_ogr_multi_type(self, geom, ogr_type):
"""
Convert ogr geometry to multi-type when supplied the ogr.type.
:param geom: The ogr geometry
:type geom: OGRGeometry
:param ogr_type: The ogr geometry type
:type ogr_type: String
:return: WkB geometry and the output layer geometry type.
:rtype: Tuple
"""
multi_geom = ogr.Geometry(ogr_type)
multi_geom.AddGeometry(geom)
geom_wkb = multi_geom.ExportToWkt()
geom_type = multi_geom.GetGeometryName()
return geom_wkb, geom_type