File: distanceToShape.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 (40 lines) | stat: -rwxr-xr-x 1,138 bytes parent folder | download | duplicates (11)
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
#!/usr/bin/perl
#
# Script : distanceToShape.pl
#
# Purpose: Returns distance between two shapes
#
# $Id$
#

use strict;
use warnings;
use POSIX;
use XBase;
use mapscript;
use Getopt::Long;
use File::Copy;

my ($infile1, $infile1_shpid, $infile2, $infile2_shpid, $distance);

GetOptions("infile1=s", \$infile1, "infile1_shpid=s", \$infile1_shpid, "infile2=s", \$infile2, "infile2_shpid=s", \$infile2_shpid);

if(!$infile1 or !$infile1_shpid or !$infile2 or !$infile2_shpid) {
  print "Usage: $0 --infile1=[filename] --infile1_shpid=[shpid] --infile2=[filename] --infile2_shpid=[shpid]\n";
  exit 0;
}

# open the first input shapefile
my $inshpf1 = new mapscript::shapefileObj($infile1, -1) or die "Unable to open shapefile $infile1.";
my $inshpf2 = new mapscript::shapefileObj($infile2, -1) or die "Unable to open shapefile $infile2.";

my $inshape1 = $inshpf1->getShape($infile1_shpid);
my $inshape2 = $inshpf2->getShape($infile2_shpid);

$distance = $inshape1->distanceToShape($inshape2);

undef $inshpf1;
undef $inshpf2;

print "Distance between shape $infile1/$infile1_shpid and shape $infile2/$infile2_shpid is $distance units\n";