本文整理汇总了Python中layer.Layer.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python Layer.__init__方法的具体用法?Python Layer.__init__怎么用?Python Layer.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类layer.Layer
的用法示例。
在下文中一共展示了Layer.__init__方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import __init__ [as 别名]
def __init__(self, data=None, projection=None, geotransform=None,
name=None, keywords=None, style_info=None):
"""Initialise object with either data or filename
NOTE: Doc strings in constructor are not harvested and exposed in
online documentation. Hence the details are specified in the
class docstring.
"""
# Invoke common layer constructor
Layer.__init__(self,
name=name,
projection=projection,
keywords=keywords,
style_info=style_info)
# Input checks
if data is None:
# Instantiate empty object
self.geotransform = None
self.rows = self.columns = 0
return
# Initialisation
if isinstance(data, basestring):
self.read_from_file(data)
elif isinstance(data, QgsRasterLayer):
self.read_from_qgis_native(data)
else:
# Assume that data is provided as a numpy array
# with extra keyword arguments supplying metadata
self.data = numpy.array(data, dtype='d', copy=False)
proj4 = self.get_projection(proj4=True)
if 'longlat' in proj4 and 'WGS84' in proj4:
# This is only implemented for geographic coordinates
# Omit check for projected coordinate systems
check_geotransform(geotransform)
self.geotransform = geotransform
self.rows = data.shape[0]
self.columns = data.shape[1]
self.number_of_bands = 1
# We assume internal numpy layers are using nan correctly
# FIXME (Ole): If read from file is refactored to load the data
# this should be taken care of there
self.nodata_value = numpy.nan
示例2: __init__
# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import __init__ [as 别名]
def __init__(self, data=None, projection=None, geometry=None,
geometry_type=None, name=None, keywords=None,
style_info=None, sublayer=None):
"""Initialise object with either geometry or filename
NOTE: Doc strings in constructor are not harvested and exposed in
online documentation. Hence the details are specified in the
class docstring.
"""
# Invoke common layer constructor
Layer.__init__(self,
name=name,
projection=projection,
keywords=keywords,
style_info=style_info,
sublayer=sublayer)
# Input checks
if data is None and geometry is None:
# Instantiate empty object
self.geometry_type = None
self.extent = [0, 0, 0, 0]
return
if isinstance(data, basestring):
self.read_from_file(data)
else:
# Assume that data is provided as sequences provided as
# arguments to the Vector constructor
# with extra keyword arguments supplying metadata
msg = 'Geometry must be specified'
verify(geometry is not None, msg)
msg = 'Geometry must be a sequence'
verify(is_sequence(geometry), msg)
if len(geometry) > 0 and isinstance(geometry[0], Polygon):
self.geometry_type = ogr.wkbPolygon
self.geometry = geometry
else:
self.geometry_type = get_geometry_type(geometry, geometry_type)
if self.is_polygon_data:
# Convert to objects if input is a list of simple arrays
self.geometry = [Polygon(outer_ring=x) for x in geometry]
else:
# Convert to list if input is an array
if isinstance(geometry, numpy.ndarray):
self.geometry = geometry.tolist()
else:
self.geometry = geometry
if data is None:
# Generate default attribute as OGR will do that anyway
# when writing
data = []
for i in range(len(geometry)):
data.append({'ID': i})
# Check data
self.data = data
if data is not None:
msg = 'Data must be a sequence'
verify(is_sequence(data), msg)
msg = ('The number of entries in geometry and data '
'must be the same')
verify(len(geometry) == len(data), msg)
# Establish extent
if len(geometry) == 0:
# Degenerate layer
self.extent = [0, 0, 0, 0]
return
# Compute bounding box for each geometry type
minx = miny = sys.maxint
maxx = maxy = -minx
if self.is_point_data:
A = numpy.array(self.get_geometry())
minx = min(A[:, 0])
maxx = max(A[:, 0])
miny = min(A[:, 1])
maxy = max(A[:, 1])
elif self.is_line_data:
for g in self.get_geometry():
A = numpy.array(g)
minx = min(minx, min(A[:, 0]))
maxx = max(maxx, max(A[:, 0]))
miny = min(miny, min(A[:, 1]))
maxy = max(maxy, max(A[:, 1]))
elif self.is_polygon_data:
# Do outer ring only
for g in self.get_geometry(as_geometry_objects=False):
A = numpy.array(g)
minx = min(minx, min(A[:, 0]))
maxx = max(maxx, max(A[:, 0]))
miny = min(miny, min(A[:, 1]))
#.........这里部分代码省略.........
示例3: __init__
# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import __init__ [as 别名]
def __init__(self, tree, act_citation):
Layer.__init__(self, tree)
self.act_citation = act_citation
示例4: __init__
# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import __init__ [as 别名]
def __init__(self, data=None, projection=None, geotransform=None,
name='', keywords=None, style_info=None):
"""Initialise object with either data or filename
Input
data: Can be either
* a filename of a raster file format known to GDAL
* an MxN array of raster data
* None (FIXME (Ole): Remove this option)
projection: Geospatial reference in WKT format.
Only used if data is provide as a numeric array,
if None, WGS84 geographic is assumed
geotransform: GDAL geotransform (6-tuple).
(top left x, w-e pixel resolution, rotation,
top left y, rotation, n-s pixel resolution).
See e.g. http://www.gdal.org/gdal_tutorial.html
Only used if data is provide as a numeric array,
name: Optional name for layer.
Only used if data is provide as a numeric array,
keywords: Optional dictionary with keywords that describe the
layer. When the layer is stored, these keywords will
be written into an associated file with extension
.keywords.
Keywords can for example be used to display text
about the layer in a web application.
style_info: Dictionary with information about how this layer
should be styled. See impact_functions/styles.py
for examples.
Note that if data is a filename, all other arguments are ignored
as they will be inferred from the file.
"""
# Invoke common layer constructor
Layer.__init__(self,
name=name,
projection=projection,
keywords=keywords,
style_info=style_info)
# Input checks
if data is None:
# Instantiate empty object
self.geotransform = None
self.rows = self.columns = 0
return
# Initialisation
if isinstance(data, basestring):
self.read_from_file(data)
else:
# Assume that data is provided as an array
# with extra keyword arguments supplying metadata
self.data = numpy.array(data, dtype='d', copy=False)
self.geotransform = geotransform
self.rows = data.shape[0]
self.columns = data.shape[1]
self.number_of_bands = 1
示例5: __init__
# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import __init__ [as 别名]
def __init__(self, data=None, projection=None, geometry=None,
geometry_type=None, name=None, keywords=None,
style_info=None, sublayer=None):
"""Initialise object with either geometry or filename
Args:
* data: Can be either
* A filename of a vector file format known to GDAL.
* List of dictionaries of field names and attribute values
associated with each point coordinate.
* None
* projection: Geospatial reference in WKT format.
Only used if geometry is provided as a numeric array,
if None, WGS84 geographic is assumed.
* geometry: A list of either point coordinates or polygons/lines
(see note below).
* geometry_type: Desired interpretation of geometry.
Valid options are 'point', 'line', 'polygon' or
the ogr types: 1, 2, 3.
If None, a geometry_type will be inferred from the data.
* name: Optional name for layer. If None, basename is used.
* keywords: Optional dictionary with keywords that describe the
layer. When the layer is stored, these keywords will
be written into an associated file with extension
'.keywords'.
Keywords can for example be used to display text about the
layer in an application.
* style_info: Dictionary with information about how this layer
should be styled. See impact_functions/styles.py
for examples.
* sublayer: str Optional sublayer (band name in the case of raster,
table name in case of sqlite etc.) to load. Only applicable
to those dataformats supporting more than one layer in the
data file.
Returns:
* An instance of class Vector.
Raises:
* Propogates any exceptions encountered.
Notes:
If data is a filename, all other arguments are ignored
as they will be inferred from the file.
The geometry type will be inferred from the dimensions of geometry.
If each entry is one set of coordinates the type will be
ogr.wkbPoint,
if it is an array of coordinates the type will be ogr.wkbPolygon.
To cast array entries as lines set geometry_type explicitly to
'line' in the call to Vector. Otherwise, they will default to
polygons.
Each polygon or line feature take the form of an Nx2 array
representing vertices where line segments are joined.
If polygons have holes, their geometry must be passed in as a
list of polygon geometry objects
(as defined in module geometry.py)
"""
# Invoke common layer constructor
Layer.__init__(self,
name=name,
projection=projection,
keywords=keywords,
style_info=style_info,
sublayer=sublayer)
# Input checks
if data is None and geometry is None:
# Instantiate empty object
self.geometry_type = None
self.extent = [0, 0, 0, 0]
return
if isinstance(data, basestring):
self.read_from_file(data)
else:
# Assume that data is provided as sequences provided as
# arguments to the Vector constructor
# with extra keyword arguments supplying metadata
msg = 'Geometry must be specified'
verify(geometry is not None, msg)
msg = 'Geometry must be a sequence'
verify(is_sequence(geometry), msg)
if len(geometry) > 0 and isinstance(geometry[0], Polygon):
self.geometry_type = ogr.wkbPolygon
self.geometry = geometry
else:
self.geometry_type = get_geometry_type(geometry, geometry_type)
# Convert to objects if input is a list of simple arrays
if self.is_polygon_data:
#.........这里部分代码省略.........
示例6: __init__
# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import __init__ [as 别名]
def __init__(self, tree, notices):
Layer.__init__(self, tree)
self.notices = notices
示例7: __init__
# 需要导入模块: from layer import Layer [as 别名]
# 或者: from layer.Layer import __init__ [as 别名]
def __init__(self, data=None, projection=None, geometry=None,
geometry_type=None,
name='', keywords=None, style_info=None):
"""Initialise object with either geometry or filename
Input
data: Can be either
* a filename of a vector file format known to GDAL
* List of dictionaries of fields associated with
point coordinates
* None
projection: Geospatial reference in WKT format.
Only used if geometry is provide as a numeric array,
if None, WGS84 geographic is assumed
geometry: A list of either point coordinates or polygons/lines
(see note below)
geometry_type: Desired interpretation of geometry.
Valid options are 'point', 'line', 'polygon' or
the ogr types: 1, 2, 3
If None, a geometry_type will be inferred
name: Optional name for layer.
Only used if geometry is provide as a numeric array
keywords: Optional dictionary with keywords that describe the
layer. When the layer is stored, these keywords will
be written into an associated file with extension
.keywords.
Keywords can for example be used to display text
about the layer in a web application.
style_info: Dictionary with information about how this layer
should be styled. See impact_functions/styles.py
for examples.
Notes
If data is a filename, all other arguments are ignored
as they will be inferred from the file.
The geometry type will be inferred from the dimensions of geometry.
If each entry is one set of coordinates the type will be ogr.wkbPoint,
if it is an array of coordinates the type will be ogr.wkbPolygon.
Each polygon or line feature take the form of an Nx2 array representing
vertices where line segments are joined
"""
# Invoke common layer constructor
Layer.__init__(self,
name=name,
projection=projection,
keywords=keywords,
style_info=style_info)
# Input checks
if data is None and geometry is None:
# Instantiate empty object
self.geometry_type = None
self.extent = [0, 0, 0, 0]
return
if isinstance(data, basestring):
self.read_from_file(data)
else:
# Assume that data is provided as sequences provided as
# arguments to the Vector constructor
# with extra keyword arguments supplying metadata
msg = 'Geometry must be specified'
verify(geometry is not None, msg)
msg = 'Geometry must be a sequence'
verify(is_sequence(geometry), msg)
self.geometry = geometry
self.geometry_type = get_geometry_type(geometry, geometry_type)
if data is None:
# Generate default attribute as OGR will do that anyway
# when writing
data = []
for i in range(len(geometry)):
data.append({'ID': i})
# Check data
self.data = data
if data is not None:
msg = 'Data must be a sequence'
verify(is_sequence(data), msg)
msg = ('The number of entries in geometry and data '
'must be the same')
verify(len(geometry) == len(data), msg)