[203] | 1 | #!/usr/bin/perl
|
---|
| 2 | #
|
---|
| 3 | # Little wrapper around the usefull Geo::Coordinates::RDNAP cause the Dutch
|
---|
| 4 | # Cadaster Organisation decided to take down their usefull one.
|
---|
| 5 | #
|
---|
| 6 | # License: BSDLike - http://rickvanderzwet.nl/LICENSE
|
---|
| 7 | #
|
---|
| 8 | # Rick van der Zwet <info@rickvanderzwet.nl>
|
---|
| 9 | use lib 'lib';
|
---|
| 10 | use strict;
|
---|
| 11 | use Geo::Coordinates::RDNAP qw/from_rd to_rd dms/;
|
---|
| 12 |
|
---|
| 13 | print "Content-type: text/plain\n\n";
|
---|
| 14 | my @uri = split /\//, $ENV{'REQUEST_URI'};
|
---|
| 15 | if ($#uri lt 5) {
|
---|
[367] | 16 | print "ERROR in parameters size (example /rdnap/rd2etrs/94340/459330/0)\n";
|
---|
[203] | 17 | exit 1;
|
---|
| 18 | }
|
---|
| 19 | shift(@uri);
|
---|
| 20 | my ($script, $command, $raw1, $raw2, $raw3) = @uri;
|
---|
| 21 | $raw1 =~ tr/_//d;
|
---|
| 22 | $raw2 =~ tr/_//d;
|
---|
| 23 |
|
---|
| 24 | my ($res1, $res2, $res3) = 0;
|
---|
| 25 |
|
---|
| 26 | if ($command eq "rd2etrs") {
|
---|
| 27 | ($res1, $res2, $res3) = from_rd($raw1, $raw2, $raw3);
|
---|
[284] | 28 | $res1 = sprintf("%.5f", $res1);
|
---|
| 29 | $res2 = sprintf("%.5f", $res2);
|
---|
| 30 | $res3 = sprintf("%.5f", $res3);
|
---|
[203] | 31 | } elsif( $command eq "etrs2rd") {
|
---|
| 32 | ($res1, $res2, $res3) = to_rd($raw1, $raw2, $raw3);
|
---|
| 33 | $res1 = sprintf("%.0f", $res1);
|
---|
| 34 | $res2 = sprintf("%.0f", $res2);
|
---|
| 35 | $res3 = sprintf("%.2f", $res3);
|
---|
| 36 | } else {
|
---|
| 37 | print "ERROR in parameters size (example /rdnap/rd2etrs/150.000/480.000/0)\n";
|
---|
| 38 | exit 1;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | print join("/",($res1, $res2, $res3));
|
---|
| 42 | print "\n";
|
---|