File: shpinfo.pl

package info (click to toggle)
mapserver 7.0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 16,500 kB
  • ctags: 20,398
  • sloc: ansic: 172,418; cpp: 57,449; python: 2,972; xml: 1,676; cs: 997; yacc: 855; lex: 758; java: 588; perl: 428; makefile: 375; sh: 190; tcl: 158; ruby: 55
file content (41 lines) | stat: -rwxr-xr-x 1,220 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
#!/usr/bin/perl

use strict;
use warnings;
use XBase;
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: shpinfo.pl --file=[filename]\n";
  exit 0;
}

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

print "Shapefile $file:\n\n";
print "\ttype: ". $types{$shapefile->{type}} ."\n"; 
print "\tnumber of features: ". $shapefile->{numshapes} ."\n";
printf "\tbounds: (%f,%f) (%f,%f)\n", $shapefile->{bounds}->{minx}, $shapefile->{bounds}->{miny}, $shapefile->{bounds}->{maxx}, $shapefile->{bounds}->{maxy};

my $table = new XBase $file.'.dbf' or die XBase->errstr;

print "\nXbase table $file.dbf:\n\n";

print "\tnumber of records: ". ($table->last_record+1) ."\n";
print "\tnumber of fields: ". ($table->last_field+1) ."\n\n";

print "\tName             Type Length Decimals\n";
print "\t---------------- ---- ------ --------\n";
foreach ($table->field_names) {
  printf "\t%-16s %4s %6d %8d\n", $_, $table->field_type($_), $table->field_length($_), $table->field_decimal($_)
}