1 // names.cxx -- process shapefiles names
3 // Written by Curtis Olson, started February 1999.
5 // Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 // (Log is kept at end of this file)
24 #include <Include/compiler.h>
31 // return the type of the shapefile record
32 AreaType get_shapefile_type(GDBFile *dbf, int rec) {
33 GDBFieldDesc *fdesc[128]; // 128 is an arbitrary number here
34 GDBFValue *fields; //an array of field values
35 char* dbf_rec; //a record containing all the fields
37 // grab the meta-information for all the fields
38 // this applies to all the records in the DBF file.
39 // for ( int i = 0; i < dbf->numFields(); i++ ) {
40 // fdesc[i] = dbf->getFieldDesc(i);
41 // cout << i << ") " << fdesc[i]->name << endl;
44 // this is the whole name record
45 dbf_rec = dbf->getRecord( rec );
47 // parse it into individual fields
49 fields = dbf->recordDeform( dbf_rec );
54 string area = fields[4].str_v;
55 // strip leading spaces
56 while ( area[0] == ' ' ) {
57 area = area.substr(1, area.length() - 1);
59 // strip trailing spaces
60 while ( area[area.length() - 1] == ' ' ) {
61 area = area.substr(0, area.length() - 1);
63 // strip other junk encountered
64 while ( (int)area[area.length() - 1] == 9 ) {
65 area = area.substr(0, area.length() - 1);
68 return get_area_type( area );
72 // return area type from text name
73 AreaType get_area_type( string area ) {
74 if ( area == "AirportKeep" ) {
75 return AirportKeepArea;
76 } else if ( area == "AirportIgnore" ) {
77 return AirportIgnoreArea;
78 } else if ( (area == "Swamp or Marsh")
79 || (area == "Marsh") ) {
81 } else if ( (area == "Bay Estuary or Ocean")
82 || (area == "Ocean") ) {
84 } else if ( area == "Lake" ) {
86 } else if ( area == "Lake Dry" ) {
88 } else if ( (area == "Lake Intermittent")
89 || (area == "IntermittentLake") ) {
91 } else if ( area == "Reservoir" ) {
93 } else if ( area == "Reservoir Intermittent" ) {
94 return IntReservoirArea;
95 } else if ( area == "Stream" ) {
97 } else if ( area == "Canal" ) {
99 } else if ( area == "Glacier" ) {
101 } else if ( area == "Void Area" ) {
103 } else if ( area == "Null" ) {
106 cout << "unknown area = '" << area << "'" << endl;
107 // cout << "area = " << area << endl;
108 // for ( int i = 0; i < area.length(); i++ ) {
109 // cout << i << ") " << (int)area[i] << endl;
116 // return text from of area name
117 string get_area_name( AreaType area ) {
118 if ( area == AirportKeepArea ) {
119 return "AirportKeep";
120 } else if ( area == AirportIgnoreArea ) {
121 return "AirportIgnore";
122 } else if ( area == MarshArea ) {
124 } else if ( area == OceanArea ) {
126 } else if ( area == LakeArea ) {
128 } else if ( area == DryLakeArea ) {
130 } else if ( area == IntLakeArea ) {
131 return "IntermittentLake";
132 } else if ( area == ReservoirArea ) {
134 } else if ( area == IntReservoirArea ) {
135 return "IntermittentReservoir";
136 } else if ( area == StreamArea ) {
138 } else if ( area == CanalArea ) {
140 } else if ( area == GlacierArea ) {
142 } else if ( area == VoidArea ) {
144 } else if ( area == NullArea ) {
147 cout << "unknown area code = " << (int)area << endl;
154 // Revision 1.3 1999/03/02 01:03:58 curt
155 // Added more reverse lookup support.
157 // Revision 1.2 1999/03/01 15:35:52 curt
158 // Generalized the routines a bit to make them more useful.
160 // Revision 1.1 1999/02/25 21:30:24 curt
163 // Revision 1.1 1999/02/23 01:29:05 curt
164 // Additional progress.