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.
#!/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:
#
#<div style="position: relative;">
#
# <div style="position: absolute; left: 53px; top: 262px; padding: 0;">
# <span style="position:relative; overflow:hidden; width:5px; height:5px; z-index:2;">
# [[Image:Red pog.svg|5px]]
# <span style="position:absolute; top:0; left:0; padding-top:3px; z-index:3;">
# [[Camden State Park|
# <span style="float:left; width:5px; height:5px; font-size:10px; line-height:5px; word-spacing:2px; cursor:pointer;">
#
# </span>
# ]]
# </span>
# </span>
# </div>
#
# [[File:Missouri Locator Map.PNG|300px|]]
#</div>
#<noinclude>[[Category:Dynamic map templates|Missouri State Parks]]</noinclude>
my $Header = '<div style="position: relative;">' . "\n" ;
my $LineFmt = '<div style="position: absolute; left: %dpx; top: %dpx; padding: 0;"><span style="position:relative; overflow:hidden; width:5px; height:5px; z-index:2;">[[Image:%s pog.svg|5px]]<span style="position:absolute; top:0; left:0; padding-top:3px; z-index:3;">[[%s|<span style="float:left; width:5px; height:5px; font-size:10px; line-height:5px; word-spacing:2px; cursor:pointer;"> </span>]]</span></span></div>' . "\n" ;
my $DebugFmt = "%d %d %s %s\n" ;
my $Trailer = "\n" . '[[File:Missouri Locator Map UTM.png|300px|]]</div>' . "\n" ;
my $Extra = "\n" . '<noinclude>[[Category:Dynamic map templates|Missouri State Parks]]</noinclude>' . "\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 ;