File: shp_in_shp.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 (46 lines) | stat: -rw-r--r-- 1,250 bytes parent folder | download | duplicates (6)
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
46
#!/usr/bin/perl
#
# Script : shp_in_shp.pl
#
# Purpose: Tests whether a shape is within another shape
#
# $Id$
#

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

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

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

# shpid can be zero, which looks false, so use defined()
if(!$infile1 or !defined($infile1_shpid) or !$infile2 or !defined($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);

$within = $inshape1->within($inshape2);

if ($within == 1) {
  $within = "WITHIN";
}
elsif ($within == 0) {
  $within = "NOT WITHIN";
}

undef $inshpf1;
undef $inshpf2;

print "Shape $infile1/$infile1_shpid is $within shape $infile2/$infile2_shpid\n";