]> git.mxchange.org Git - flightgear.git/blob - Polygon/names.cxx
Added more reverse lookup support.
[flightgear.git] / Polygon / names.cxx
1 // names.cxx -- process shapefiles names
2 //
3 // Written by Curtis Olson, started February 1999.
4 //
5 // Copyright (C) 1999  Curtis L. Olson  - curt@flightgear.org
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22 // (Log is kept at end of this file)
23  
24 #include <Include/compiler.h>
25
26 #include STL_STRING
27
28 #include "names.hxx"
29
30
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
36
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;
42     // }
43
44     // this is the whole name record
45     dbf_rec = dbf->getRecord( rec );
46
47     // parse it into individual fields
48     if ( dbf_rec ) {
49         fields = dbf->recordDeform( dbf_rec );
50     } else {
51         return UnknownArea;
52     }
53
54     string area = fields[4].str_v;
55     // strip leading spaces
56     while ( area[0] == ' ' ) {
57         area = area.substr(1, area.length() - 1);
58     }
59     // strip trailing spaces
60     while ( area[area.length() - 1] == ' ' ) {
61         area = area.substr(0, area.length() - 1);
62     }
63     // strip other junk encountered
64     while ( (int)area[area.length() - 1] == 9 ) {
65         area = area.substr(0, area.length() - 1);
66     }
67
68     return get_area_type( area );
69 }
70
71
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") ) {
80         return MarshArea;
81     } else if ( (area == "Bay  Estuary or Ocean")
82                 || (area == "Ocean") ) {
83         return OceanArea;
84     } else if ( area == "Lake" ) {
85         return LakeArea;
86     } else if ( area == "Lake   Dry" ) {
87         return DryLakeArea;
88     } else if ( (area == "Lake   Intermittent")
89                 || (area == "IntermittentLake") ) {
90         return IntLakeArea;
91     } else if ( area == "Reservoir" ) {
92         return ReservoirArea;
93     } else if ( area == "Reservoir   Intermittent" ) {
94         return IntReservoirArea;
95     } else if ( area == "Stream" ) {
96         return StreamArea;
97     } else if ( area == "Canal" ) {
98         return CanalArea;
99     } else if ( area == "Glacier" ) {
100         return GlacierArea;
101     } else if ( area == "Void Area" ) {
102         return VoidArea;
103     } else if ( area == "Null" ) {
104         return NullArea;
105     } else {
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;
110         // }
111         return UnknownArea;
112     }
113 }
114
115
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 ) {
123         return "Marsh";
124     } else if ( area == OceanArea ) {
125         return "Ocean";
126     } else if ( area == LakeArea ) {
127         return "Lake";
128     } else if ( area == DryLakeArea ) {
129         return "DryLake";
130     } else if ( area == IntLakeArea ) {
131         return "IntermittentLake";
132     } else if ( area == ReservoirArea ) {
133         return "Reservoir";
134     } else if ( area == IntReservoirArea ) {
135         return "IntermittentReservoir";
136     } else if ( area == StreamArea ) {
137         return "Stream";
138     } else if ( area == CanalArea ) {
139         return "Canal";
140     } else if ( area == GlacierArea ) {
141         return "Glacier";
142     } else if ( area == VoidArea ) {
143         return "VoidArea";
144     } else if ( area == NullArea ) {
145         return "Null";
146     } else {
147         cout << "unknown area code = " << (int)area << endl;
148         return "Unknown";
149     }
150 }
151
152
153 // $Log$
154 // Revision 1.3  1999/03/02 01:03:58  curt
155 // Added more reverse lookup support.
156 //
157 // Revision 1.2  1999/03/01 15:35:52  curt
158 // Generalized the routines a bit to make them more useful.
159 //
160 // Revision 1.1  1999/02/25 21:30:24  curt
161 // Initial revision.
162 //
163 // Revision 1.1  1999/02/23 01:29:05  curt
164 // Additional progress.
165 //