### Navigation

- index
- modules
- next
- previous
- Home »
- Contents »
- InaSAFE’s API documentation »
- Package::safe »
- Package::safe.storage »

# Module: safe.storage.vector

Vector Module

Tip

Provides functionality for manipulation of vector data. The data can be in-memory or file based.

Resources for understanding vector data formats and the OGR library: Treatise on vector data model: http://www.esri.com/news/arcuser/0401/topo.html OGR C++ reference: http://www.gdal.org/ogr

class `safe.storage.vector.``Vector`(data=None, projection=None, geometry=None, geometry_type=None, name=None, keywords=None, style_info=None, sublayer=None)

  Class for abstraction of vector data.

  `copy`()

    Return copy of vector layer

    This copy will be equal to self in the sense defined by __eq__

  `get_attribute_names`()

    Get available attribute names

    These are the ones that can be used with get_data

  `get_bounding_box`()

    Get bounding box coordinates for vector layer.

    Format is [West, South, East, North]

  `get_data`(attribute=None, index=None, copy=False)

    Get vector attributes

    Note:

      Data is returned as a list where each entry is a dictionary of attributes for one feature. Entries in get_geometry() and get_data() are related as 1-to-1

      If optional argument attribute is specified and a valid name, then the list of values for that attribute is returned.

      If optional argument index is specified on the that value will be returned. Any value of index is ignored if attribute is None.

      If optional argument copy is True and all attributes are requested, a copy will be returned. Otherwise a pointer to the data is returned.

  `get_extrema`(attribute=None)

    Get min and max values from specified attribute

    Return min, max

  `get_geometry`(copy=False, as_geometry_objects=False)

    Return geometry for vector layer.

    Depending on the feature type, geometry is

    point list of 2x1 array of longitudes and latitudes) line list of arrays of coordinates polygon list of arrays of coordinates

    Optional boolean argument as_geometry_objects will change the return value to a list of geometry objects rather than a list of arrays. This currently only applies to polygon geometries

  `get_geometry_name`()

    Return geometry name for vector layer

  `get_geometry_type`()

    Return geometry type for vector layer

  `get_topN`(attribute, N=10)

    Get top N features

    Args:
      - attribute: The name of attribute where values are sought
      - N: How many
    Returns:
      - layer: New vector layer with selected features
  `read_from_file`(filename)

    Read and unpack vector data.

    It is assumed that the file contains only one layer with the pertinent features. Further it is assumed for the moment that all geometries are points.

    - A feature is a geometry and a set of attributes.
    - A geometry refers to location and can be point, line, polygon or combinations thereof.
    - The attributes or obtained through GetField()

    The full OGR architecture is documented at * http://www.gdal.org/ogr/ogr_arch.html * http://www.gdal.org/ogr/ogr_apitut.html

    Examples are at * danieljlewis.org/files/2010/09/basicpythonmap.pdf * http://invisibleroads.com/tutorials/gdal-shapefile-points-save.html * http://www.packtpub.com/article/geospatial-data-python-geometry

    Limitation of the Shapefile are documented in http://resources.esri.com/help/9.3/ArcGISDesktop/com/Gp_ToolRef/ geoprocessing_tool_reference/ geoprocessing_considerations_for_shapefile_output.htm

  `write_to_file`(filename, sublayer=None)

    Save vector data to file

    Args:

      - filename: filename with extension .shp or .gml

      - sublayer: Optional string for writing a sublayer. Ignored

          unless we are writing to an sqlite file.

    Note:

      Shp limitation, if attribute names are longer than 10 characters they will be truncated. This is due to limitations in the shp file driver and has to be done here since gdal v1.7 onwards has changed its handling of this issue: http://www.gdal.org/ogr/drv_shapefile.html

      For this reason we recommend writing to spatialite.

`safe.storage.vector.``convert_line_to_points`(V, delta)

  Convert line vector data to point vector data

  Args:
    - V: Vector layer with line data
    - delta: Incremental step to find the points
  Returns:
    - Vector layer with point data and the same attributes as V

`safe.storage.vector.``convert_polygons_to_centroids`(V)

  Convert polygon vector data to point vector data

  Args:
    - V: Vector layer with polygon data
  Returns:
    - Vector layer with point data and the same attributes as V

This module forms part of the InaSAFE tool.

### Navigation

- index
- modules
- next
- previous
- Home »
- Contents »
- InaSAFE’s API documentation »
- Package::safe »
- Package::safe.storage »