File: transform.dox

package info (click to toggle)
gdal 1.10.1%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 84,320 kB
  • ctags: 74,726
  • sloc: cpp: 677,199; ansic: 162,820; python: 13,816; cs: 11,163; sh: 10,446; java: 5,279; perl: 4,429; php: 2,971; xml: 1,500; yacc: 934; makefile: 494; sql: 112
file content (42 lines) | stat: -rw-r--r-- 1,308 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*! \page transform Transforming a dataset

The code here does not have any warranty. It is recommended that
before using any of this code, you look into it and try to understand
what it does, what input it needs, etc. Do not blindly execute
anything!

This example will transform a vector dataset from spatial reference
system EPSG 2392 to EPSG 2393. The geometries are translated 
by (dx, dy) = (2500000, 6600000) before applying the transformation.

\code
use Geo::GDAL;

$dsname = shift @ARGV;
$lname = shift @ARGV;

$datasource = Geo::OGR::Open($dsname) or die;
$layer1 = $datasource->Layer($lname) or die;
$sr1 = Geo::OSR::SpatialReference->create(EPSG => 2392);

$dsname = shift @ARGV;
$lname = shift @ARGV;

$datasource = Geo::OGR::Driver('ESRI Shapefile')->Create($dsname) or die;
$sr2 = Geo::OSR::SpatialReference->create(EPSG => 2393);
$layer2 = $datasource->CreateLayer
    ({ Name => $lname, SRS => $sr2, GeometryType => $layer1->GetLayerDefn->GeometryType});
$layer2->Schema( $layer1->Schema );

$tr = Geo::OSR::CoordinateTransformation->new($sr1, $sr2) or die;

$layer1->ResetReading();
while ($feature = $layer1->GetNextFeature()) {
    my $geom = $feature->GetGeometry();
    $geom->Move(2500000, 6600000);
    $geom->Transform($tr);
    $layer2->InsertFeature($feature);    
}
\endcode

*/