Geo::GDAL::FFI - A foreign function interface to GDAL
use Geo::GDAL::FFI; my $gdal = Geo::GDAL::FFI->new(); my $sr = Geo::GDAL::FFI::SpatialReference->new(EPSG => 3067); my $layer = $gdal ->GetDriver('ESRI Shapefile') ->Create('test.shp') ->CreateLayer({ Name => 'test', SpatialReference => $sr, GeometryType => 'Point', Fields => [ { Name => 'name', Type => 'String' } ] }); my $f = Geo::GDAL::FFI::Feature->new($layer->Defn); $f->SetField(name => 'a'); my $g = Geo::GDAL::FFI::Geometry->new('Point'); $g->SetPoint(1, 2); $f->SetGeomField($g); $layer->CreateFeature($f); undef $layer; # this flushes and closes the shapefile files $layer = $gdal->Open('test.shp')->GetLayer; $layer->ResetReading; while (my $feature = $layer->GetNextFeature) { my $value = $feature->GetField('name'); my $geom = $feature->GetGeomField; say $value, ' ', $geom->AsText; }
This is a foreign function interface to the GDAL geospatial data access library.
'$named_arguments' below means a reference to a hash whose keys are argument names.
The progress function parameter used in many methods should be a reference to a subroutine. The subroutine is called with three parameters ($fraction, $msg, $data), where $fraction is a number, $msg is a string, and $data is a pointer that is given as the progress data parameter.
new
Create a new Geo::GDAL::FFI object.
Capabilities
Returns the list of capabilities (strings) an Object can have.
OpenFlags
Returns the list of opening flags to be used in the Open method.
DataTypes
Returns the list of raster cell data types to be used in e.g. the CreateDataset method of the Driver class.
FieldTypes
Returns the list of field types.
FieldSubtypes
Returns the list of field subtypes.
Justifications
Returns the list of field justifications.
ColorInterpretations
Returns the list of color interpretations.
GeometryTypes
Returns the list of geometry types.
GetVersionInfo
Returns version information from the underlying GDAL library.
GetDrivers
Returns a list of all available driver objects.
GetDriver($name)
Returns the specific driver object.
Open($name, $named_arguments)
Open a dataset. $name is the name of the dataset. Named arguments are the following.
Flags
Optional, default is a reference to an empty array.
AllowedDrivers
Optional, default is all drivers. Use a reference to an array of driver names to limit drivers to test.
SiblingFiles
Optional, default is to probe the file system. You may use a reference to an array of auxiliary file names.
Options
Optional, a reference to an array of driver specific open options.
The base class for classes Driver, SpatialReference, Dataset, Band, and Layer.
GetDescription
HasCapability($capability)
GetMetadataDomainList
GetMetadata($domain)
SetMetadata($metadata, $domain)
GetMetadataItem($item, $domain)
SetMetadataItem($item, $value, $domain)
A format driver. Use the Driver method of a Geo::GDAL::FFI object to obtain one.
GetName
Returns the name of the driver.
Create($name, $named_arguments)
Create a dataset. $name is the name for the dataset to create.
Named arguments are the following.
Width
Optional, but required to create a raster dataset.
Height
Optional, default is the same as width.
Bands
Optional, the number of raster bands in the dataset, default is one.
DataType
Optional, the data type (string) for the raster cells, default is 'Byte'.
Source
Optional, the dataset to copy.
Progress
Optional, used only in dataset copy, a reference to a subroutine.
ProgressData
Optional, used only in dataset copy, a reference.
Strict
Optional, used only in dataset copy, default is false (0).
Optional, driver specific creation options, default is reference to an empty hash.
Create($name, $width, $height)
A simple syntax for calling Create to create a raster dataset.
new($arg, @args)
Create a new SpatialReference object. If only one argument is given, it is taken as the well known text (WKT) associated with the spatial reference system (SRS). If there are more than one argument, the first argument is taken as a format and the rest of the arguments are taken as arguments to the format. The list of formats known to GDAL (at the time of this writing) is EPSG, EPSGA, Wkt, Proj4, ESRI, PCI, USGS, XML, Dict, Panorama, Ozi, MICoordSys, ERM, Url.
Export($format, @args)
Export a SpatialReference object to a format. The list of formats known to GDAL (at the time of this writing) is Wkt, PrettyWkt, Proj4, PCI, USGS, XML, Panorama, MICoordSys, ERM.
Set($setter, @args)
Set projection parameters in a SpatialReference object. The list of projection parameters known to GDAL (at the time of this writing) is Axes, ACEA, AE, Bonne, CEA, CS, EC, Eckert, EckertIV, EckertVI, Equirectangular, Equirectangular2, GS, GH, IGH, GEOS, GaussSchreiberTMercator, Gnomonic, HOM, HOMAC, HOM2PNO, IWMPolyconic, Krovak, LAEA, LCC, LCC1SP, LCCB, MC, Mercator, Mercator2SP, Mollweide, NZMG, OS, Orthographic, Polyconic, PS, Robinson, Sinusoidal, Stereographic, SOC, TM, TMVariant, TMG, TMSO, TPED, VDG, Wagner, QSC, SCH
Obtain a dataset object by opening it with the Open method of Geo::GDAL::FFI object or by creating it with the Create method of a Driver object.
GetDriver
GetInfo(@options)
Translate($name, @options)
Convert a raster dataset into another raster dataset. $name is the name of the target dataset. This is the same as the gdal_translate command line program, so the options are the same. See http://www.gdal.org/gdal_translate.html.
GetWidth
GetHeight
GetSize
Returns the size (width, height) of the bands of this raster dataset.
GetBand
GetBands
Returns a list of Band objects representing the bands of this raster dataset.
CreateLayer($named_arguments)
Create a new vector layer into this vector dataset.
Name
Optional, string, default is ''.
GeometryType
Optional, default is 'Unknown', the type of the first geometry field; note: if type is 'None', the layer schema does not initially contain any geometry fields.
SpatialReference
Optional, a SpatialReference object, the spatial reference for the first geometry field.
Optional, driver specific options in an anonymous hash.
Fields
Optional, a reference to an array of Field objects or schemas, the fields to create into the layer.
GeometryFields
Optional, a reference to an array of GeometryField objects or schemas, the geometry fields to create into the layer; note that if this argument is defined then the arguments GeometryType and SpatialReference are ignored.
GetLayer($name)
If $name is strictly an integer, then returns the (name-1)th layer in the dataset, otherwise returns the layer whose name is $name. Without arguments returns the first layer.
CopyLayer($layer, $name, $options)
A band (channel) in a raster dataset. Use the Band method of a dataset object to obtain a band object.
GetDataType
GetBlockSize
GetNoDataValue
SetNoDataValue
Read($xoff, $yoff, $xsize, $ysize, $bufxsize, $bufysize)
ReadBlock($xoff, $yoff)
Write($data, $xoff, $yoff, $xsize, $ysize)
WriteBlock($data, $xoff, $yoff)
GetColorInterpretation
SetColorInterpretation
GetColorTable
SetColorTable
SetPiddle($pdl, $xoff, $yoff, $xsize, $ysize)
Read data from a piddle into this Band.
GetPiddle($xoff, $yoff, $xsize, $ysize, $xdim, $ydim)
Read data from this Band into a piddle.
A set of (vector) features having a same schema (the same Defn object). Obtain a layer object by the CreateLayer or GetLayer method of a vector dataset object.
GetDefn
Returns the FeatureDefn object for this layer.
ResetReading
GetNextFeature
GetFeature
SetFeature
CreateFeature
DeleteFeature
new($named_arguments)
Create a new FeatureDefn object.
The named arguments (optional) are the following.
Optional; the name for this feature class; default is the empty string.
Optional, a reference to an array of FieldDefn objects or schemas.
Optional, a reference to an array of GeomFieldDefn objects or schemas.
Optional, the type for the first geometry field; default is Unknown. Note that this argument is ignored if GeometryFields is given.
StyleIgnored
GetSchema
Returns the definition as a perl data structure.
GetFieldDefn($name)
Get the specified non spatial field object. If the argument is explicitly an integer and not a string, it is taken as the field index.
GetFieldDefns
GetGeomFieldDefn($name)
Get the specified spatial field object. If the argument is explicitly an integer and not a string, it is taken as the field index.
GetGeomFieldDefns
SetGeometryIgnored($arg)
Ignore the first geometry field when reading features from a layer. To not ignore the first geometry field call this method with defined but false (0) argument.
IsGeometryIgnored
Is the first geometry field ignored when reading features from a layer.
There should not usually be any reason to directly access this method except for the ignore methods. This object is created/read from/to the Perl data structure in the CreateLayer method of a dataset, or in the constructor or schema method of FeatureDefn.
The schema of a FieldDefn is (Name, Type, Default, Subtype, Justify, Width, Precision, NotNullable).
SetIgnored($arg)
Ignore this field when reading features from a layer. To not ignore this field call this method with defined but false (0) argument.
IsIgnored
Is this field ignored when reading features from a layer.
The schema of a GeomFieldDefn is (Name, Type, SpatialReference, NotNullable).
new($defn)
Create a new Feature object. The argument is a FeatureDefn object, which you can get from a Layer object (Defn method), another Feature object (Defn method), or by explicitly creating a new FeatureDefn object.
Returns the FeatureDefn object for this Feature.
GetFID
SetFID
Clone
Equals($feature)
SetField($fname, ...)
Set the value of field $fname. If no parameters after the name is given, the field is unset. If the parameters after the name is undefined, sets the field to NULL. Otherwise sets the field according to the field type.
GetField($fname)
SetGeomField($fname, $geom)
$fname is optional and by default the first geometry field.
GetGeomField($fname)
new($type)
$type must be one of Geo::GDAL::FFI::GeometryTypes().
new($format, $arg, $sr)
$format must be one of Geo::GDAL::FFI::GeometryFormats(), e.g., 'WKT'.
$sr should be a SpatialRef object if given.
Clones this geometry and returns the clone.
GetType($mode)
Returns the type of this geometry. If $mode is 'flatten', returns the type without Z, M, or ZM postfix.
GetPointCount
Returns the point count of this geometry.
SetPoint($x, $y, $z, $m)
Set the coordinates of a point geometry. The usage of $z and $m in the method depend on the actual 3D or measured status of the geometry.
SetPoint($coords)
$coords = [$x, $y, $z, $m]
SetPoint($i, $x, $y, $z, $m)
Set the coordinates of the ith (zero based index) point in a curve geometry. The usage of $z and $m in the method depend on the actual 3D or measured status of the geometry.
Note that setting the nth point of a curve may create all points 0..n-2.
SetPoint($i, $coords)
Set the coordinates of the ith (zero based index) point in this curve. $coords must be a reference to an array of the coordinates. The usage of $z and $m in the method depend on the 3D or measured status of the geometry.
GetPoint($i)
Get the coordinates of the ith (zero based index) point in this curve. This method can also be used to set the coordinates of a point geometry and then the $i must be zero if it is given.
Returns the coordinates either as a list or a reference to an anonymous array depending on the context. The coordinates contain $z and $m depending on the 3D or measured status of the geometry.
GetPoints
Returns the coordinates of the vertices of this geometry in an obvious array based data structure. Note that different geometry types have similar data structures.
SetPoints($points)
Sets the coordinates of the vertices of this geometry from an obvious array based data structure. Note that different geometry types have similar data structures. If the geometry contains subgeometries (like polygon contains rings for example) the data structure is assumed to adhere to this structure. Uses SetPoint and may thus add points to curves.
GetGeometryCount
GetGeometry($i)
Returns the ith subgeometry (zero based index) in this geometry. The returned geometry object is only a wrapper to the underlying C++ reference and thus changing that geometry will change the parent.
AddGeometry($geom)
RemoveGeometry($i)
AsText
Intersects
Equals
Disjoint
Touches
Crosses
Within
Contains
Overlaps
Boundary
ConvexHull
Buffer
Intersection
Union
Difference
SymDifference
Distance
Distance3D
Length
Area
Centroid
Empty
IsEmpty
IsValid
IsSimple
IsRing
This software is released under the Artistic License. See perlartistic.
Ari Jolma - Ari.Jolma at gmail.com
Alien::gdal, FFI::Platypus, www.gdal.org
To install Geo::GDAL::FFI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Geo::GDAL::FFI
CPAN shell
perl -MCPAN -e shell install Geo::GDAL::FFI
For more information on module installation, please visit the detailed CPAN module installation guide.