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">

  1. !/usr/bin/perl
  1. -- Requires this module for geographic projection

use Geo::Proj4 ;

  1. -- Source spatial reference system is WGS84 lat-lon EPSG:4326

my $s_srs = Geo::Proj4->new("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") ;

  1. -- 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") ;


  1. The world file for the original map is:
  2. 1417.058
  3. 0
  4. 0
  5. -1414.885
  6. 256554.529
  7. 4508104.914000
  1. The world file for the map at 300x262 pixels is:
  2. 2026.393
  3. 0.000
  4. 0.000
  5. -2019.721
  6. 256554.529
  7. 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

  1. - 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 ;

  1. Convert pairs of degree coordinates to projected pixel coordinates on the map
  2. Input looks like: Babler State Park | 38.62, -90.69444
  1. Output looks like:
  2. # #     # #

my $Header = '

' . "\n" ; my $LineFmt = '' . "\n" ;

my $DebugFmt = "%d %d %s %s\n" ;

my $Trailer = "\n" . '

' . "\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>