#!/usr/bin/perl # convert_nodecoords.pl # # grabs edugis (RDX,RDY) coords from node_coords.txt and converts to ETRS98 # # Perl RD coordinate conversion module from: # http://search.cpan.org/~pijll/Geo-Coordinates-RDNAP-0.03/lib/Geo/Coordinates/RDNAP.pm # More info on this subject: http://www.rdnap.nl/ # http://nl.wikipedia.org/wiki/Rijksdriehoeksco%C3%B6rdinaten # # RDNAP coordinates in km; height in meters # WL/edugis coordinates in meters # # Called from node_list.sh # $scriptname="convert_nodecoords.pl"; $author ="Ous"; $versionstring="0.4"; $versiondate="06Jun07"; # License: WL # # History: # ver: date: Desc: # 0.1 31may07 Initial attempt # 0.2 01jun07 Cleanup, subroutines, comments # 0.3 05jun07 Added timestamping output file # 0.4 06jun07 Separated from kml stuff # # Todo: # # Known issues: # ======================================================================================== use Geo::Coordinates::RDNAP qw/from_rd to_rd deg dms/; $coord_file = "./node_coords.txt"; $coordinates_outputfile = "./node_coords_converted.txt"; #===========Main======= &initialize_stuff; &process_nodelist; exit; #====================== #======================= sub initialize_stuff { $date= localtime; print "$date\n"; ($dat_weekday, $dat_month, $dat_day, $dat_time, $dat_year)= split(/\s+/,$date); $lastchange="$dat_day $dat_month $dat_year"; open (NODELIST,$coord_file) or die "Cant't open $coord_file"; open (COORDLIST,">$coordinates_outputfile"); } #======================= #======================= sub process_nodelist { print "Nodename\tShortname\tMasterIP\tStatus\tRDX\tRDY\tLongitude\tLatitude\n"; print "===========\t=========\t==========\t=======\t======\t======\t==========\t===========\n"; print COORDLIST "# Nodelist with RD-coords converted to ETRS89 (long-lat)format\n"; print COORDLIST "# Generated on $lastchange:$dat_time by $scriptname ver.$versionstring auth:$author\n#\n"; print COORDLIST "# Nodename\tStatus\tMasterIP\tRDX\tRDY\tLongitude\tLatitude\n"; print COORDLIST "#===========\t======\t============\t=======\t=======\t==========\t===========\n"; while($line=) { chomp($line); if ($line !~ /^#/) { my(@listline)=(@listline,@line); ($nodename, $master_ip, $nodestatus, $RDX, $RDY) = split(/\t/,$line); $RDX=$RDX/1000; #Wleiden edugis coords in meters! $RDY=$RDY/1000; ($lat, $lon, $h) = from_rd( $RDX, $RDY, 0 ); $lon = sprintf("%.8f", $lon); #truncate to 8 decimals $lat = sprintf("%.8f", $lat); #to please googlemaps $nodename= substr "$nodename ",0,15; $nodesubname = substr $nodename, 0,8; $nodesubname2= substr $nodename, 0,10; print "$nodename\t$nodesubname\t$master_ip\t$nodestatus\t$RDX\t$RDY\t$lon\t$lat\n"; print COORDLIST "$nodename\t$nodestatus\t$master_ip\t$RDX\t$RDY\t$lon\t$lat\n"; } } close(NODELIST); close(COORDLIST); } #=======================i #======================= sub round { my($number) = shift; return int($number + .5 * ($number <=> 0) ); } #======================= #=======================