Yet another small map utility

Paul G. Allen pgallen at randomlogic.com
Mon Oct 25 23:37:00 EDT 1999


I wrote a small map utility using the shapelib API for creating shapefiles (yes,
I know, there are several already, but none were exactly what I wanted). This
particular utility takes several command line arguments and makes a complete
POINT shapefile from them. If you look at my Philadelphia map, you'll see a
couple red SIZE 10 points that were created by this little utility. The command
line format is:

[root at igen /root]# $SHAPELIB/unitoshape
unitoshape [path]<output_file> shapetype LAT LONG ID equip_type msg_time
[string_array] 
    Where string_array is:
        <DBBASE_field_name> <field_type(N|C)> <width> <precision> <field_data>

    string_array may be repeated for as many DBASE fields as necessary,
    up to the max argv[] limit of the OS.

(NOTE: $SHAPELIB is an env. variable that makes things easier for me, it's not
required for the utility. It just points to my shapelib development dir.)

[path]<output_file> = the path and file name of the shapefile to create or
append to (no extension, the utility adds them)
shapetype = The shape type to create. Only supports POINTs for now (that's all I
need right now)
LAT LONG = Dotted decimal latitude and longitude of the shape position
ID = A numerical ID of the shape of type INTEGER
equip_type = A string describing what this shape is (e.g., Warehouse)
msg_time = The time that this shapes data was last updated, a string.

The first seven command line options are required, but the DBASE fields are not.
The reason I wrote this is to take data from a number of different sources, in
any number of different formats, and plot them on a map, as well as create DBASE
files that could be queried by MapServer. A couple simple Perl scripts can (and
will) be written to extract data from an SQL database, an email message, or
whatever, and pipe the data to the unitoshape utility for quick and painless
plotting. Basically, I have a universal interface for data extraction and
insertion with the ability to support additional data formats quickly - maybe
today I have the data in a SQL database, and tomorrow I have it in simple text
files.

If anyone would like this utility, and a couple Perl scripts to go with it, I'll
be posting them soon. I want to add a file locking mechanism first so that the
same shapefile won't be updated by two unitoshape processes at the same time. I
also plan to make the script create a backup of the original shapefile during
updates to prevent corruption and web page access delays when a web browser
tries to access a shapefile that's being updated.

PGA



More information about the mapserver-users mailing list