Geo::Vector Class Reference

A geospatial layer that consists of Geo::OGR::Features. More...

Inherited by Geo::Vector::Layer.

Inheritance diagram for Geo::Vector:

Inheritance graph
[legend]
List of all members.

Public Class Methods

list geometry_types ()
 Returns a list of valid geometry types.
list render_as_modes ()
 Returns a list of valid render as modes.
ref hash layers (scalar driver, scalar data_source)
 Lists the layers that are available in a data source.
void delete_layer (scalar driver, scalar data_source, scalar layer)
 Attempts to delete a layer from a datasource.
Geo::Vector new (scalar data_source)
 Create a new Geo::Vector object for the first layer in a given OGR data souce.
Geo::Vector new (hash params)
 Create a new Geo::Vector object.

Public Object Methods

 driver ()
 The driver of the object.
 dump (hash parameters)
 Print the contents of the layer.
 init_iterate (hash options)
 Reset reading features from the object iteratively.
 next_feature ()
 Return a feature iteratively or undef if no more features.
 get_next ()
scalar buffer (hash params)
 Create a new Geo::Vector object, whose features are buffer areas to the original.
scalar within (scalar other, hash params)
 Return the features from this layer that are within the features of other.
scalar add (scalar other, hash params)
 Add features from the other layer to this layer.
scalar feature_count ()
 Count the number of features in the layer.
Geo::OSR::SpatialReference srs (hash params)
 Get or set (set is not yet implemented) the spatial reference system of the layer.
scalar field_count (hash params)
 For a layer object returns the number of fields in the layer schema. For a feature set object requires a named parameter that specifies the feature.
scalar geometry_type (hash params)
 For a layer object returns the geometry type of the layer. For a feature set object requires a named parameter that specifies the feature.
hashref schema (hashref schema)
 Get or set the schema of the layer.
hashref schema (scalar feature, hashref schema)
 Get or set the schema of a feature in a feature collection.
Geo::OGR::FeatureDefn defn ()
 Create a FeatureDefn object, which is needed to create feature objects for this layer.
list value_range (hash params)
 Returns a list of the value range of the field.
list value_range (scalar field_name)
 Returns a list of the value range of the field.
hashref feature (scalar fid, scalar feature)
 Get, add or update a feature.
Geo::OGR::Geometry geometry (scalar fid, scalar geometry)
 Get, set or add a geometry.
Geo::OGR::Feature make_feature (hash feature)
 Creates a Geo::OGR::Feature object from attribute data and a Geo::OGC::Geometry object.
void add_feature (hash feature)
 Adds a feature to the layer.
listref features (hash params)
 Returns features satisfying the given requirement.
list world (hash params)
 Get the bounding box (xmin, ymin, xmax, ymax) of the layer or one of its features.
Geo::Vector copy (hash params)
 Copy selected or all features from the layer into a new layer.
Geo::Raster rasterize (hash params)
 Creates a new Geo::Raster from this Geo::Vector object.
void overlay_graph (Gtk2::Gdk::Pixmap pixmap)
 Creates from the objects graph an overlay graph (incl. vertices and edges) as a pixmap.

Public Functions

retval MIN ()
retval MAX ()

Classes

class  Feature
class  Layer
class  Layer
class  Layer
class  Layer
class  Layer
class  Layer
class  Layer
class  Layer
class  Layer
class  Layer

Detailed Description

A geospatial layer that consists of Geo::OGR::Features.

This module should be discussed in geo-perl@list.hut.fi.

The homepage of this module is http://geoinformatics.tkk.fi/twiki/bin/view/Main/GeoinformaticaSoftware.

Author:
Ari Jolma

Copyright (c) 2005- by Ari Jolma

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available.


Member Function Documentation

scalar Geo::Vector::add ( scalar  other,
hash  params 
)

Add features from the other layer to this layer.

Parameters:
other A Geo::Vector object
params Named parameters, used for creating the new object, if one is created, and for iterating through the features of other.
Returns:
(If used in non-void context) A new Geo::Vector object, which contain features from both this and from the other.

void Geo::Vector::add_feature ( hash  feature  ) 

Adds a feature to the layer.

Parameters:
feature As in make_feature.

scalar Geo::Vector::buffer ( hash  params  ) 

Create a new Geo::Vector object, whose features are buffer areas to the original.

Deprecated:
Parameters:
[in] params Named parameters: (see also the named parameters of Geo::Vector::new).
  • distance => float (default is 1.0). The width of the buffer.
  • quad_segs => int (default is 30). The number of segments used to approximate a 90 degree (quadrant) of curvature.
  • copy_attributes => true/false (default is false).
  • driver default is 'Memory'.
  • layer default is 'buffer'.
Returns:
The new Geo::Vector object.

Geo::Vector Geo::Vector::copy ( hash  params  ) 

Copy selected or all features from the layer into a new layer.

Parameters:
[in] params is a list of named parameters. They are forwarded to constructor (new) and init_iterate. If no value is given the defaults are taken from this layer.
Returns:
A Geo::Vector object.

Geo::OGR::FeatureDefn Geo::Vector::defn (  ) 

Create a FeatureDefn object, which is needed to create feature objects for this layer.

Returns:
a Geo::OGR::FeatureDefn object.

void Geo::Vector::delete_layer ( scalar  driver,
scalar  data_source,
scalar  layer 
)

Attempts to delete a layer from a datasource.

Parameters:
[in] driver 
[in] data_source 
[in] layer Name of the layer that should be deleted.

Geo::Vector::driver (  ) 

The driver of the object.

Returns:
The name of the OGR driver as a string. Returns 'Memory' if the object is not an OGR layer.

Geo::Vector::dump ( hash  parameters  ) 

Print the contents of the layer.

hashref Geo::Vector::feature ( scalar  fid,
scalar  feature 
)

Get, add or update a feature.

Example of retrieving:

$feature = $vector->feature($i);

Example of updating:

$vector->feature($i, $feature);

Example of adding:

 $vector->feature($feature);

Parameters:
[in] fid The FID of the feature if updating
[in] feature Geo::OGR::Feature object to add or to update.
Returns:
an Geo::OGR::Feature object
Exceptions:
The fid is higher than the feature count.

scalar Geo::Vector::feature_count (  ) 

Count the number of features in the layer.

Todo:
Add $force parameter.
Returns:
The number of features in the layer. The valued may be approximate.

listref Geo::Vector::features ( hash  params  ) 

Returns features satisfying the given requirement.

Parameters:
[in] params is a list named parameters
  • that_contain => an Geo::OGR::Geometry. The returned features are such that the geometry is within them. If the geometry is a multigeometry, then the features that have at least one of the geometries within.
  • that_are_within => an Geo::OGR::Geometry. The returned features are those that are within the geometry. If the geometry is a multigeometry, then the features are within at least one of the geometries.
  • that_intersect => Geo::OGR::Geometry object. The returned features are those that intersect with the geometry. If the geometry is a multigeometry, then the features intersect with at least one of the geometries.
  • filter
  • filter_rect
  • with_id => Reference to an array of feature indexes (fids).
  • from => If defined, the number of features that are skipped + 1.
  • limit => If defined, maximum number of features returned.
Returns:
A reference to an array of features.

scalar Geo::Vector::field_count ( hash  params  ) 

For a layer object returns the number of fields in the layer schema. For a feature set object requires a named parameter that specifies the feature.

Deprecated:

Each feature in a feature set object may have its own schema.

Returns:
For a layer object returns the number of fields in the layer schema. For a feature set object requires a named parameter that specifies the feature.

Geo::OGR::Geometry Geo::Vector::geometry ( scalar  fid,
scalar  geometry 
)

Get, set or add a geometry.

Parameters:
$fid (optional) The feature id, whose geometry to set or get.
$geometry (optional) The geometry, which to set or add.
Returns:
A geometry object.

scalar Geo::Vector::geometry_type ( hash  params  ) 

For a layer object returns the geometry type of the layer. For a feature set object requires a named parameter that specifies the feature.

Parameters:
[in] params Named parameters:
  • flatten => true/false. Default is false.
  • feature => integer. Index of the feature whose geometry type is queried.
Returns:
For a layer object returns the geometry type of the layer. For a feature set object returns specified features geometry type.

list Geo::Vector::geometry_types (  ) 

Returns a list of valid geometry types.

Returns:
a list of valid geometry types (as strings).

Geo::Vector::get_next (  ) 

Geo::Vector::init_iterate ( hash  options  ) 

Reset reading features from the object iteratively.

Parameters:
options Named parameters, all are optional.
  • selected_features => reference to a list of features, which to iterate through.
  • filter => a spatial filter
  • filter_rect => reference to an array defining a spatial rectangle filter (min_x, min_y, max_x, max_y)
Todo:
filter for feature collections

ref hash Geo::Vector::layers ( scalar  driver,
scalar  data_source 
)

Lists the layers that are available in a data source.

Returns:
A hashref to a (layer_name => geometry_type) hash.

Geo::OGR::Feature Geo::Vector::make_feature ( hash  feature  ) 

Creates a Geo::OGR::Feature object from attribute data and a Geo::OGC::Geometry object.

Parameters:
[in] feature a hash whose keys are field names or 'geometry' and values are field values, or, for geometry, well-known text or an object which responds to AsText method by returning well-known text.
Returns:
Geo::OGR::Feature object.
Note:
If the parameter is already a Geo::OGR::Feature object nothing is done to the feature.

retval Geo::Vector::MAX (  ) 

retval Geo::Vector::MIN (  ) 

Geo::Vector Geo::Vector::new ( hash  params  ) 

Create a new Geo::Vector object.

A Geo::Vector object is either a wrapped Geo::OGR::Layer or a collection of Geo::OGR::Feature objects. Without any parameters an empty OGR memory layer without any attributes is created. A feature collection object does not have a unique schema.

Parameters:
params Named parameters, all are optional: (see also the named parameters of the Geo::Vector::layer method)
  • driver => string Name of the OGR driver for creating or opening a data source. If not given, an attempt is made to open the data source using the data source parameter.
  • create_options => reference to a hash of data source creation options. May be empty. Forwarded to Geo::OGR::CreateDataSource. Required to create other than memory data sources.
  • data_source => string OGR data source to create or open. Opening a data source is first attempted unless create_options is given. If open fails, creation is attempted.
  • open => string The layer to open.
  • update => boolean Set true if open in update mode.
  • layer => string [deprecated] Same as open.
  • create => string The layer to create.
  • layer_options forwarded to Geo::OGR::DataSource::CreateLayer.
  • SQL => string SQL-string, forwarded to Geo::OGR::DataSource::ExecuteSQL. An alternative to open and create.
  • geometry_type => string The geometry type for the new layer. Default is 'Unknown'.
  • schema, as in method Geo::Vector::schema.
  • encoding => string, the encoding of the attribute values of the features.
  • srs => either a string which defines a spatial reference system (e.g. 'EPSG:XXXX') or a Geo::OSR::SpatialReference object. The srs for the new layer. Default is 'EPSG:4326'.
  • features => a reference to a list of features to be inserted into the collection. May be empty. If given, the resulting object is a feature collection object, and not an OGR layer.
  • geometries => a reference to a list of geometries to be inserted as new features into the collection. Creates features without attributes for the geometries. May be empty. If given, the resulting object is a feature collection object, and not an OGR layer. Do not mix with features.
Returns:
A new Geo::Vector object

Geo::Vector Geo::Vector::new ( scalar  data_source  ) 

Create a new Geo::Vector object for the first layer in a given OGR data souce.

An example of creating a Geo::Vector object for a ESRI shapefile:

$v = Geo::Vector->new("borders.shp");

Parameters:
data_source An OGR data source string
Returns:
A new Geo::Vector object

Geo::Vector::next_feature (  ) 

Return a feature iteratively or undef if no more features.

void Geo::Vector::overlay_graph ( Gtk2::Gdk::Pixmap  pixmap  ) 

Creates from the objects graph an overlay graph (incl. vertices and edges) as a pixmap.

Parameters:
[in,out] pixmap Gtk2::Gdk::Pixmap

Geo::Raster Geo::Vector::rasterize ( hash  params  ) 

Creates a new Geo::Raster from this Geo::Vector object.

The new Geo::Raster has the size and extent of the Geo::Raster $this and draws the layer on it. The raster is boolean integer raster unless value_field is given. If value_field is floating point value, the returned raster is a floating point raster. render_as hash is optional, but if given should be one of 'Native', 'Points', 'Lines', or 'Polygons'. $fid (optional) is the number of the feature to render.

Parameters:
[in] params is a list of named parameters:
  • like (optional). A Geo::Raster object, from which the resulting Geo::Raster object's size and extent are copied.
  • M (optional). Height of the resulting Geo::Raster object. Has to be given if hash like is not given. If like is given, then M will not be used.
  • N (optional). Width of the resulting Geo::Raster object. Has to be given if hash like is not given. If like is given, then N will not be used.
  • world (optional). The world (bounding box) of the resulting raster layer. Useless to give if parameter like is given, because then it's world will be used.
  • render_as (optional). Rendering mode, which should be 'Native', 'Points', 'Lines' or 'Polygons'.
  • feature (optional). Number of the feature to render.
  • value_field (optional). Value fields name.
Returns:
A new Geo::Raster, which has the size and extent of the given as
Todo:
make this work for schema free layers parameters and values

list Geo::Vector::render_as_modes (  ) 

Returns a list of valid render as modes.

Returns:
a list of valid render as modes (as strings).

hashref Geo::Vector::schema ( scalar  feature,
hashref  schema 
)

Get or set the schema of a feature in a feature collection.

Parameters:
[in] feature the index of the feature, whose schema to get or set.
[in] schema (optional) a reference to a hash specifying the schema.
Returns:
the schema.

hashref Geo::Vector::schema ( hashref  schema  ) 

Get or set the schema of the layer.

Schema is a hash whose keyes are GeometryType, FID, and Fields. Fields is a reference to a list of field schemas. A field schema is a hash whose keys are Name, Type, Justify, Width, and Precision. This is similar to schemas in Geo::OGR.

Parameters:
[in] schema (optional) a reference to a hash specifying the schema.
Returns:
the schema.

Geo::OSR::SpatialReference Geo::Vector::srs ( hash  params  ) 

Get or set (set is not yet implemented) the spatial reference system of the layer.

SRS (Spatial reference system) is a geographic coordinate system code number in the EPSG database (European Petroleum Survey Group, http://www.epsg.org/). Default value is 4326, which is for WGS84.

Parameters:
[in] params (optional) Named parameters:
  • format => string. Name of the wanted return format, like 'Wkt'. Wkt is for Well-known text and is defined by the The OpenGIS Consortium specification for the exchange (and easy persistance) of geometry data in ASCII format.
Returns:
Returns the current spatial reference system of the layer as a Geo::OSR::SpatialReference or wkt string.

list Geo::Vector::value_range ( scalar  field_name  ) 

Returns a list of the value range of the field.

Parameters:
[in] field_name The name of the field, whose min and max values are looked up.
Returns:
An array that has as it's first value the ranges minimum and as second the maximum -- array(min, max).

list Geo::Vector::value_range ( hash  params  ) 

Returns a list of the value range of the field.

Parameters:
[in] params Named parameters:
  • field_name => string. The attribute whose min and max values are looked up.
  • filter => reference to a Geo::OGR::Geometry (optional). Used by Geo::OGR::SetSpatialFilter() if the layer is an OGR layer.
  • filter_rect => reference to an array defining the rect (min_x, min_y, max_x, max_y) (optional). Used by the Geo::OGR::SetSpatialFilterRect() if the layer is an OGR layer.
Returns:
An array that has as it's first value the ranges minimum and as second the maximum -- array(min, max).

scalar Geo::Vector::within ( scalar  other,
hash  params 
)

Return the features from this layer that are within the features of other.

Deprecated:
Todo:
Add some optimizations.
Returns:
A new Geo::Vector object

list Geo::Vector::world ( hash  params  ) 

Get the bounding box (xmin, ymin, xmax, ymax) of the layer or one of its features.

The method uses Geo::OGR::Geometry::GetEnvelope() or Geo::OGR::Layer::GetExtent().

Example of getting a bounding box:

@bb = $vector->world(feature=><feature_index>);

Parameters:
[in] params is a list of named parameters:
  • feature => feature_index (optional).
Returns:
Returns the bounding box (minX, minY, maxX, maxY) as an array. If a single feature is defined with it's index as parameter, then the method returns that feature's bounding box, else the whole layer's bounding box.


The documentation for this class was generated from the following file:
Generated on Sat Mar 20 00:18:33 2010 for Geoinformatica by  doxygen 1.4.7