File: distanceToPoint.pl

package info (click to toggle)
mapserver 7.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 16,620 kB
  • sloc: ansic: 176,974; cpp: 58,161; python: 2,969; xml: 1,676; cs: 997; yacc: 856; lex: 766; java: 588; perl: 428; makefile: 374; sh: 184; tcl: 158; ruby: 55
file content (39 lines) | stat: -rwxr-xr-x 875 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
#!/usr/bin/perl
#
# Script : distanceToPoint.pl
#
# Purpose: Returns distance between a shape and a point
#
# $Id$
#

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

my ($infile, $infile_shpid, $x, $y, $distance);

GetOptions("infile=s", \$infile, "infile_shpid=s", \$infile_shpid, "x=s", \$x, "y=s", \$y);

if(!$infile or !$infile_shpid or !$x or !$y) {
  print "Usage: $0 --infile=[filename] --infile_shpid=[shpid] --x=[x] --y=[y]\n";
  exit 0;
}

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

my $inshape = $inshpf->getShape($infile_shpid);

my $inpt = new mapscript::pointObj($x, $y);

$distance = $inshape->distanceToPoint($inpt);

undef $inshpf;

print "Distance between shape $infile/$infile_shpid and point $x $y is $distance\n";