Template:State parks of Missouri map UTM/source
This is the perl source code used to generate the template. The data it reads from stdin is in Template:State parks of Missouri map UTM/data. This uses a base map projected into a known coordinate system so that geo-located points can be accurately placed on the map. For that it relies on the external module Geo::Proj4.
<syntaxhighlight lang="perl">
- !/usr/bin/perl
- -- Requires this module for geographic projection
use Geo::Proj4 ;
- -- Source spatial reference system is WGS84 lat-lon EPSG:4326
my $s_srs = Geo::Proj4->new("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") ;
- -- and for the target srs we know the map is in this UTM 15 N coordinate space EPSG:26915
my $t_srs = Geo::Proj4->new("+proj=utm +zone=15 +ellps=GRS80 +datum=NAD83 +units=m +no_defs") ;
- The world file for the original map is:
- 1417.058
- 0
- 0
- -1414.885
- 256554.529
- 4508104.914000
- The world file for the map at 300x262 pixels is:
- 2026.393
- 0.000
- 0.000
- -2019.721
- 256554.529
- 4508104.914
my @imgsize = (300, 262) ; #- size to be rendered on 'pedia pages. my @pixsiz = (2026.393, -2019.721) ; my @balladj = (0, -11) ; #- adjust for placement of corner of the balls/dots on wiki page
- - From the world file and image size, corners are at...
my $northutm = 4508104.914000 ; # meters north my $westutm = 256554.529 ; # meters west my $southutm = $northutm + ($imgsiz[1] * $pixsiz[1]) ; # meters south my $eastutm = $westutm + ($imgsiz[0] * $pixsiz[0]) ; # meters east
my $utmhigh = $northutm - $southutm ; my $utmwide = $westutm - $eastutm ;
- Convert pairs of degree coordinates to projected pixel coordinates on the map
- Input looks like: Babler State Park | 38.62, -90.69444
- Output looks like:
- # # # #
my $Header = '
' . "\n" ;
my $Extra = "\n" . . "\n" ;
my $usefmt = $LineFmt ;
print $Header ;
while (<>) {
next unless /^([^\|]*\S)\s*\|\s*(\d+\.?\d*),?\s+(-\d+\.\d*)/ ; my $name = $1 ; my $latdeg = $2 ; my $londeg = $3 ;
#- Project point to UTM meters #- from man page: my $projected_point = $from->transform($to, $point); my $prpt = $s_srs->transform($t_srs, [$londeg, $latdeg]);
my $xpos = ($prpt->[0] - $westutm) / $pixsiz[0] + $balladj[0] ; my $ypos = ($prpt->[1] - $northutm) / $pixsiz[1] + $balladj[1] ;
my $color = "Blue" ; $color = "Red" if $name =~ /state park/i ;
printf $usefmt, $xpos, $ypos, $color, $name ;
}
print $Trailer ;
exit 0 ;
</syntaxhighlight>