File: dump.pl

package info (click to toggle)
mapserver 8.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 18,020 kB
  • sloc: ansic: 139,708; cpp: 111,541; python: 3,004; xml: 1,722; yacc: 1,108; cs: 997; lex: 747; sh: 606; java: 588; perl: 489; makefile: 370; tcl: 158; ruby: 55
file content (45 lines) | stat: -rwxr-xr-x 1,173 bytes parent folder | download | duplicates (16)
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
43
44
45
#!/usr/bin/perl

use strict;
use warnings;
use mapscript;
use Getopt::Long;

my $file;
my %types = ( '1' => 'point',
	      '3' => 'arc',
	      '5' => 'polygon',
	      '8' => 'multipoint'
	    );

GetOptions("file=s", \$file);

if(!$file) {
  print "Syntax: dump.pl --file=[filename]\n";
  exit 0;
}

my $shapefile = new mapscript::shapefileObj($file, -1) or die "Unable to open shapefile $file";

print "Shapefile opened (type=". $types{$shapefile->{type}} .") with ".
$shapefile->{numshapes} ." shape(s)\n";

my $shape = new mapscript::shapeObj(-1);

for(my $i=0; $i<$shapefile->{numshapes}; $i++) {
    
    $shapefile->get($i, $shape);

    print "Shape $i has ". $shape->{numlines} ." part(s) - ";
    printf "bounds (%f,%f) (%f,%f)\n", $shape->{bounds}->{minx}, $shape->{bounds}->{miny}, $shape->{bounds}->{maxx}, $shape->{bounds}->{maxy};

    for(my $j=0; $j<$shape->{numlines}; $j++) {
        my $part = $shape->get($j);
        print "Part $j has ". $part->{numpoints} ." point(s)\n";

        for(my $k=0; $k<$part->{numpoints}; $k++) {
            my $point = $part->get($k);
            print "$k: ". $point->{x} .", ". $point->{y} ."\n";
        }
    }
}