本文整理汇总了Python中osgeo.ogr.wkbLineString方法的典型用法代码示例。如果您正苦于以下问题:Python ogr.wkbLineString方法的具体用法?Python ogr.wkbLineString怎么用?Python ogr.wkbLineString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osgeo.ogr
的用法示例。
在下文中一共展示了ogr.wkbLineString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_layer
# 需要导入模块: from osgeo import ogr [as 别名]
# 或者: from osgeo.ogr import wkbLineString [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.
示例2: setUp
# 需要导入模块: from osgeo import ogr [as 别名]
# 或者: from osgeo.ogr import wkbLineString [as 别名]
def setUp(self):
def createlayer(driver):
lyr = shp.CreateLayer("edges", None, ogr.wkbLineString)
namedef = ogr.FieldDefn("Name", ogr.OFTString)
namedef.SetWidth(32)
lyr.CreateField(namedef)
return lyr
drv = ogr.GetDriverByName("ESRI Shapefile")
testdir = os.path.join(tempfile.gettempdir(), 'shpdir')
shppath = os.path.join(tempfile.gettempdir(), 'tmpshp.shp')
self.deletetmp(drv, testdir, shppath)
os.mkdir(testdir)
shp = drv.CreateDataSource(shppath)
lyr = createlayer(shp)
self.names = ['a', 'b', 'c', 'c'] # edgenames
self.paths = ([(1.0, 1.0), (2.0, 2.0)],
[(2.0, 2.0), (3.0, 3.0)],
[(0.9, 0.9), (4.0, 0.9), (4.0, 2.0)])
self.simplified_names = ['a', 'b', 'c'] # edgenames
self.simplified_paths = ([(1.0, 1.0), (2.0, 2.0)],
[(2.0, 2.0), (3.0, 3.0)],
[(0.9, 0.9), (4.0, 2.0)])
for path, name in zip(self.paths, self.names):
feat = ogr.Feature(lyr.GetLayerDefn())
g = ogr.Geometry(ogr.wkbLineString)
for p in path:
g.AddPoint_2D(*p)
feat.SetGeometry(g)
feat.SetField("Name", name)
lyr.CreateFeature(feat)
self.shppath = shppath
self.testdir = testdir
self.drv = drv
示例3: make_tiles
# 需要导入模块: from osgeo import ogr [as 别名]
# 或者: from osgeo.ogr import wkbLineString [as 别名]
def make_tiles(self):
# Generate the vrt files for zoom ranges
i = 0
tmp_res = -1
vrt_file = None
for tz in range(self.tminz,self.tmaxz+1):
res = self.zoom_resolutions[tz][0] # I check only with resx, because resy will be positively correlated
if res != tmp_res:
if i>0:
self.vrts[vrt_file][1] = tz-1
tmp_res = res
resx = self.zoom_resolutions[tz][0]
resy = self.zoom_resolutions[tz][1]
self.make_vrt(resx,resy,i)
vrt_file = "cesium_%s.vrt" % i
self.vrts[vrt_file] = [tz,None]
i += 1
if tz == self.tmaxz:
self.vrts[vrt_file][1] = tz
self.ti_cum = 0
if self.options.createtileindexshp and self.tilelayer is None:
driver = ogr.GetDriverByName('Esri Shapefile')
shptileindexfile = os.path.join(self.output,'tilesindex.shp')
if os.path.exists(shptileindexfile):
for f in glob.glob(self.output+'/tilesindex.*'):
os.remove(f)
shptileindex = driver.CreateDataSource(shptileindexfile)
self.tilelayer = shptileindex.CreateLayer('tiles', None, ogr.wkbLineString)
self.tilelayer.CreateField(ogr.FieldDefn('id', ogr.OFTInteger))
self.tilelayer.CreateField(ogr.FieldDefn('zoom', ogr.OFTInteger))
self.tilelayer.CreateField(ogr.FieldDefn('tile', ogr.OFTString))
self.tilelayer.CreateField(ogr.FieldDefn('children', ogr.OFTInteger))
# Generate parent tiles
self.generate_fake_parent_tiles()
# For each vrt (i.e. zoom range) generate the tiles
self.steps = len(self.vrts)
self.step = 1
for vrt in self.vrts.keys():
self.process_vrt(vrt)
if not self.options.keepfiles:
try:
os.remove(vrt)
except:
pass
self.step += 1
self.create_layerjsonfile()
if self.options.createtileindexshp and self.tilelayer is not None:
shptileindex.Destroy()
shptileindex = self.tilelayer = feat = geom = None
print """Processing finished. Tiles written to "%s".""" % self.output