1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
#!/usr/bin/perl
#
#
# Copyright (C) 2006-2012 Tom Russo
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# see file COPYING for details
#--------------------------------------------------------------------------
# This script produces an ESRI point shapefile from an APRS overlay
# file (*.pos), according to the "Rolling your own shapefile maps"
# section of README.MAPS The point file will display using the TIGER
# Landmark Point dbfawk file.
#
# This enables fast generation of point maps in Shapefile format
# from APRS overlay files.
#
# Typical usage:
# pos2shp.pl file.pos myshape
#--------------------------------------------------------------------------
if ($#ARGV != 1)
{
print "Usage: $0 <file.pos> <shapefile base name>\n";
exit 1;
}
open(INOBJ,"<$ARGV[0]") || die "Cannot open input overlay file $ARGV[0]\n";
$cmd[0]="shpcreate $ARGV[1] point";
$cmd[1]="dbfcreate $ARGV[1] -n ID 8 0 -s CFCC 4 -s NAME 30";
$outfile=$ARGV[1];
foreach $command (@cmd)
{
system($command);
if ($? == -1)
{
print "failed to execute: $!\n";
}
elsif ($? & 127)
{
printf "child died with signal %d, %s coredump\n",
($? & 127), ($? & 128) ? 'with' : 'without';
}
elsif ($?&0xF0)
{
printf "child exited with value %d\n", $? >> 8;
}
}
# We now have the shapefile and dbf file created, start populating from the
# overlay file:
$i=0;
$first_line = 1;
while (<INOBJ>)
{
chomp($_);
# Skip the first line if it starts with a '*' (comment line).
next if ($first_line && (substr($_,0,1) eq '*') );
$first_line = 0;
$temp = $_;
@bits = split('!', $temp);
# Sanity check --- don't try to convert if the line doesn't
# conform to what we expect. We should have two items in the
# array at this point.
next if (length(@bits) < 1);
$name2 = $bits[0];
$rest = $bits[1];
$name = substr($name2,0,9); # Chop at 9 chars
$name =~ s/\w+\s+$//; # Remove trailing spaces
$lat=substr($rest,0,8);
$symtab=substr($rest,8,1);
$long=substr($rest,9,9);
$sym=substr($rest,18,1);
# TODO: Do something with the comment field? It appears that if we
# add too much here we get strange results when displayed in Xastir.
$comment=substr($rest,19,100);
# $name = $name . ":" . $comment;
$i++; # bump the ID number so every point has a unique one
$lat_deg=substr($lat,0,2);
$lat_min=substr($lat,2,5);
$lat_hem=substr($lat,7,1);
$long_deg=substr($long,0,3);
$long_min=substr($long,3,5);
$long_hem=substr($long,8,1);
$lat=$lat_deg+$lat_min/60;
$lat *= -1 if ($lat_hem eq "S");
$long=$long_deg+$long_min/60;
$long *= -1 if ($long_hem eq "W");
# Construct symbol
if ($symtab ne "/" && $symtab ne "\\")
{
print "overlay symbol, symtab is $symtab\n";
$overlay=$symtab;
$symtab="\\";
print " reset values symtab is $symtab, overlay is $overlay\n";
}
else
{
$overlay=" ";
}
$cmd[0]="shpadd $outfile $long $lat";
$cmd[1]="dbfadd $outfile $i \'X$symtab$sym$overlay\' $name";
print $cmd[1]."\n";
foreach $command (@cmd)
{
system($command);
if ($? == -1)
{
print "failed to execute: $!\n";
}
elsif ($? & 127)
{
printf "child died with signal %d, %s coredump\n",
($? & 127), ($? & 128) ? 'with' : 'without';
}
elsif ($?&0xF0)
{
printf "child exited with value %d\n", $? >> 8;
}
}
}
|