Shape file creation? An example!
Doug Nebert
ddnebert at usgs.gov
Wed Nov 10 05:52:03 PST 1999
Kieran:
Yesterday, ironically, I did just this kind of thing based on
the simple script example in the shapelib directory as a script.
I wrote a perl script to receive the output from an earthquake
checker program (finger quake at gldfs.cr.usgs.gov) -- a fixed column
format file and fed it to the shapelib executables. It does use
the "system" invocations but this should work with perl on either
UNIX or NT since the invocations are the same in shapelib. Here
is the little script. One thing to note is that you need to enter
coordinates and attributes in the same order. (Something I could
not make work was the ability to load numeric fields so I loaded
all fields as text fields. -n option is either poorly documented
or broken.):
#!/usr/bin/perl
# Assign location of shapelib executables
$qd = "/var/quakes";
# Assign location of mapserver data
$dd = "/var/mapserver/global/data";
system("rm -f $dd/quake.*");
system("$qd/shpcreate $dd/quakes point");
# This line creates 4 DBF text fields with lenghts 8, 8, 5, and 3
system("$qd/dbfcreate $dd/quakes.dbf -s Date 8, -s Time 8, -s Depth 5,
-s Mag 3");
while (<>) {
if (/^99/) {
$dat = substr($_,0,8);
$tim = substr($_,9,8);
$lat = substr($_,18,5);
if ( substr($_,24,1) eq 'S' ) {
$lat = $lat * -1 ;
}
$long = substr($_,26,6);
if ( substr($_,32,1) eq 'W' ) {
$long = $long * -1 ;
}
$depth = substr($_,34,5);
$mag = substr($_,40,3);
$place = substr($_,49,28);
# print "$place $lat $long\n";
# This line pushes the point coordinates into the shapefile
system("$qd/shpadd $dd/quakes $long $lat");
# This line pushes the four attributes into the DBF file
system("$qd/dbfadd $dd/quakes.dbf $dat, $tim, $depth, $mag");
}
}
exit;
Kieran Ames wrote:
>
> I'm shooting from the hip here...
> Does anyone know if there is anything like "txt2shp.exe" that could take
> a text file (or ODBC result) that contains points and looks like this:
>
> NAME LONG LAT ATTR_1 ATTR_2 ATTR_3 etc.....
>
> and convert it to the appropriate shp, dbf, shx files?
>
> TIA
>
> Kieran
--
Douglas D. Nebert
Clearinghouse Coordinator
FGDC Secretariat Phone: +1 703 648 4151 Fax: +1 703 648-5755
Pager Messaging: http://fgdclearhs.er.usgs.gov/dougmsg.html
More information about the MapServer-users
mailing list