Everything Java Apache Geospatial Open Source. Hello Shinning Stars!!! Vincent Massol, Raphael Luta, Santiago Gala, Carsten Z.

Sunday, April 22, 2007

Concerning MapServer config files there is a lot of grunt work necessary to configure a new set of data using an existing map design. The map file is just one part of the configuration. One needs to set up query templates and initialization files. The majority of this work can be done by using some simple tools for reading shape files.

find /cygdrive/c/GIS/MarionCoIL -name "*shp" > shapefiles.txt

This find command gives us a list of all shape files in a given directory. We want to find all the attributes for each shape file so we use the ogrinfo command.

ogrinfo -summary C:\GIS\MarionCoIL\GISData\ALI Census > Census.txt
ogrinfo -summary C:\GIS\MarionCoIL\GISData\ALI Tiger > Tiger.txt
ogrinfo -summary C:\GIS\MarionCoIL\GISData\Delivery Streets_Geo > Streets_Geo.txt
ogrinfo -summary C:\GIS\MarionCoIL\GISData\Delivery Streets_Proj > Streets_Proj.txt
ogrinfo -summary C:\GIS\MarionCoIL\GISData\NAD83E Airports > Airports.txt
ogrinfo -summary C:\GIS\MarionCoIL\GISData\NAD83E centraliadissolve > centraliadissolve.txt
ogrinfo -summary C:\GIS\MarionCoIL\GISData\NAD83E clippedstreets > clippedstreets.txt
ogrinfo -summary C:\GIS\MarionCoIL\GISData\NAD83E Hydrology > Hydrology.txt
ogrinfo -summary C:\GIS\MarionCoIL\GISData\NAD83E JeffersonCounty > JeffersonCounty.txt
ogrinfo -summary C:\GIS\MarionCoIL\GISData\NAD83E landmarks > landmarks.txt
ogrinfo -summary C:\GIS\MarionCoIL\GISData\NAD83E Rail > Rail.txt
ogrinfo -summary C:\GIS\MarionCoIL\GISData\NAD83E tgr17121cty00 > tgr17121cty00.txt
ogrinfo -summary C:\GIS\MarionCoIL\GISData\NAD83E tgr17121plc00 > tgr17121plc00.txt
ogrinfo -summary C:\GIS\MarionCoIL\GISData\NAD83E TigerRoads > TigerRoads.txt
ogrinfo -summary C:\GIS\MarionCoIL\GISData\NAD83E WashingtonCounty > WashingtonCounty.txt
ogrinfo -summary ogrinfo -summary C:\GIS\MarionCoIL\GISData\NAD83E Water > Water.txt

The above script will write a file for each shapefile containing the attributes. The following is an example of the output.

INFO: Open of `C:\GIS\MarionCoIL\GISData\NAD83E'
using driver `ESRI Shapefile' successful.

Layer name: Hydrology
Geometry: Line String
Feature Count: 2238
Extent: (752169.261907, 658660.185483) - (881047.118353, 786642.635521)
Layer SRS WKT:
PROJCS["Custom",
GEOGCS["GCS_North_American_1983",
DATUM["North_American_Datum_1983",
SPHEROID["GRS_1980",6378137,298.257222101]],
PRIMEM["Greenwich",0],
UNIT["Degree",0.017453292519943295]],
PROJECTION["Transverse_Mercator"],
PARAMETER["False_Easting",984250],
PARAMETER["False_Northing",0],
PARAMETER["Central_Meridian",-88.33333333333333],
PARAMETER["Scale_Factor",0.999975],
PARAMETER["Latitude_Of_Origin",36.66666666666666],
UNIT["Foot_US",0.30480060960121924]]
TLID: Integer (10.0)
FNODE: Integer (8.0)
TNODE: Integer (8.0)
LENGTH: Real (10.5)
FEDIRP: String (2.0)
FENAME: String (30.0)
FETYPE: String (4.0)
FEDIRS: String (2.0)
CFCC: String (3.0)
FRADDL: Real (11.0)
TOADDL: Real (11.0)
FRADDR: Real (11.0)
TOADDR: Real (11.0)
ZIPL: String (5.0)
ZIPR: String (5.0)
CENSUS1: String (1.0)
CENSUS2: String (1.0)
CFCC1: String (1.0)
CFCC2: String (2.0)
SOURCE: String (1.0)

We are only interested in the end of the file so we use grep with a regular expression to get only the lines containing attribute names.

grep -e ": [Integer\|String\|Real].*([0-9]*\.[0-9]*)" Hydrology.txt

This results in the following output.

TLID: Integer (10.0)
FNODE: Integer (8.0)
TNODE: Integer (8.0)
LENGTH: Real (10.5)
FEDIRP: String (2.0)
FENAME: String (30.0)
FETYPE: String (4.0)
FEDIRS: String (2.0)
CFCC: String (3.0)
FRADDL: Real (11.0)
TOADDL: Real (11.0)
FRADDR: Real (11.0)
TOADDR: Real (11.0)
ZIPL: String (5.0)
ZIPR: String (5.0)
CENSUS1: String (1.0)
CENSUS2: String (1.0)
CFCC1: String (1.0)
CFCC2: String (2.0)
SOURCE: String (1.0)