NAME
Geo::Vector - Perl extension for geospatial vectors
SYNOPSIS
use Geo::Vector;
use Geo::Vector qw(:all);
EXPORT
None by default. :all imports @ogr_geom_types, %ogr_geom_types, and %COLOR_SCHEMES.
@ogr_geom_types is a list of ogr type names: 'wkbUnknown','wkbPoint',...
keys of %ogr_geom_types are the values $ogr::wkbUnknown, ... and the values are the type names.
%COLOR_SCHEMES = (Grayscale => 0, Rainbow => 1, Colortable => 2, 'Single color' => 3);
DESCRIPTION
Geo::Vector is an extra layer on top of Perl module ogr. ogr module allows using OGR (from GDAL) from Perl. Geo::Vector adds the required functionality to use ogr layers in Gtk2::Ex::Geo. Geo::Vector may also add extra functionality like rasterization, vectorization, rendering etc. which may be useful in stand-alone scripts.
BASIC FUNCTIONALITY
Constructors
Simply open a geospatial vector file:
$v = new Geo::Vector("borders.shp");
or use named parameters:
$v = new Geo::Vector(filename=>"borders.shp");
$v = new Geo::Vector(datasource=>".", layer=>"borders.shp");
Named parameters:
- driver
-
Default is ''. Used only when creating a new layer. If not false, ogr_datasource is created using the specified driver and ogr::Driver::CreateDataSource. This parameter may be an ogr::Driver object, number, or driver name.
- driver_options
-
Default is []. Given directly to ogr::CreateDataSource.
- filename
-
Default is ''. Parsed to datasource and layer if given.
- datasource
-
Default is ''. Datasource string as used in ogr::Driver::CreateDataSource and ogr::Open.
- layer
-
Default is ''. Layer string as used in ogr::Driver::CreateDataSource and ogr::Open.
- update
-
Default is ''. True/False as used in ogr::Open.
- srs
-
Default is ''. TODO.
- geom_type
-
Default is $ogr::wkbUnknown. Used in ogr::Datasource::CreateLayer.
- sql
-
Default is ''. If not null string, layer is obtained with ogr::Datasource::ExecuteSQL and ReleaseResultSet is called automatically in destruction.
Drivers
%d = Geo::Vector::drivers();
Keys of %d are numbers. Retrieves values by ogr::GetDriver. $d{<number>}->{name} is the name of the driver.
Feature count
$feature_count = $vector->feature_count;
Get/set color scheme
$color_scheme = $vector->color_scheme($color_scheme);
Sets the color_scheme if $color_scheme is defined. Color schemes are keys of %Geo::Vector::COLOR_SCHEMES. The returned value is a value from %Geo::Vector::COLOR_SCHEMES.
Get color table
$ct = $vector->get_color_table($create_allowed);
Returns the color table of this layer. Color tables (not in OGR) can be used to specify individual colors for features. Color table is an gdal::ColorTable object.
Bounding box
@bb = $vector->world(feature=><feature_index>);
Returns the bounding box (minX,minY,maxX,maxY) of a feature or the whole layer. Uses ogr::Geometry::GetEnvelope() or ogr::Layer::GetExtent.
Rasterize
$raster = $vector->rasterize(like=>$this, RenderAs=>$mode,
feature=>$fid, value_field=>$fname);
Creates a new Geo::Raster, which 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. $mode is optional, but if given either 1 (points), 2 (lines), or 3 (polygons). $fid (optional) is the number of the feature to render.
SEE ALSO
gdal and ogr
This module should be discussed in geo-perl@list.hut.fi.
The homepage of this module is http://libral.sf.net.
AUTHOR
Ari Jolma, <ari.jolma at tkk.fi>
COPYRIGHT AND LICENSE
Copyright (C) 2005-2006 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.