]> git.mxchange.org Git - flightgear.git/blob - Polygon/names.cxx
6d94f88c1b5b0842961e33a15d3f325fdb107a34
[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         return OceanArea;
83     } else if ( area == "Lake" ) {
84         return LakeArea;
85     } else if ( area == "Lake   Dry" ) {
86         return DryLakeArea;
87     } else if ( (area == "Lake   Intermittent")
88                 || (area == "IntermittentLake") ) {
89         return IntLakeArea;
90     } else if ( area == "Reservoir" ) {
91         return ReservoirArea;
92     } else if ( area == "Reservoir   Intermittent" ) {
93         return IntReservoirArea;
94     } else if ( area == "Stream" ) {
95         return StreamArea;
96     } else if ( area == "Canal" ) {
97         return CanalArea;
98     } else if ( area == "Glacier" ) {
99         return GlacierArea;
100     } else if ( area == "Void Area" ) {
101         return VoidArea;
102     } else if ( area == "Null" ) {
103         return NullArea;
104     } else {
105         cout << "unknown area = '" << area << "'" << endl;
106         // cout << "area = " << area << endl;
107         // for ( int i = 0; i < area.length(); i++ ) {
108         //  cout << i << ") " << (int)area[i] << endl;
109         // }
110         return UnknownArea;
111     }
112 }
113
114
115 // return text from of area name
116 string get_area_name( AreaType area ) {
117     if ( area == AirportKeepArea ) {
118         return "AirportKeep";
119     } else if ( area == AirportIgnoreArea ) {
120         return "AirportIgnore";
121     } else if ( area == MarshArea ) {
122         return "Marsh";
123     } else if ( area == OceanArea ) {
124         return "Ocean";
125     } else if ( area == LakeArea ) {
126         return "Lake";
127     } else if ( area == DryLakeArea ) {
128         return "DryLake";
129     } else if ( area == IntLakeArea ) {
130         return "IntermittentLake";
131     } else if ( area == ReservoirArea ) {
132         return "Reservoir";
133     } else if ( area == IntReservoirArea ) {
134         return "IntermittentReservoir";
135     } else if ( area == StreamArea ) {
136         return "Stream";
137     } else if ( area == CanalArea ) {
138         return "Canal";
139     } else if ( area == GlacierArea ) {
140         return "Glacier";
141     } else if ( area == VoidArea ) {
142         return "VoidArea";
143     } else if ( area == NullArea ) {
144         return "Null";
145     } else {
146         cout << "unknown area code = " << (int)area << endl;
147         return "Unknown";
148     }
149 }
150
151
152 // $Log$
153 // Revision 1.2  1999/03/01 15:35:52  curt
154 // Generalized the routines a bit to make them more useful.
155 //
156 // Revision 1.1  1999/02/25 21:30:24  curt
157 // Initial revision.
158 //
159 // Revision 1.1  1999/02/23 01:29:05  curt
160 // Additional progress.
161 //