]> git.mxchange.org Git - flightgear.git/blob - Polygon/names.cxx
Initial revision.
[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_area_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     }
51
52     string area = fields[4].str_v;
53     // strip leading spaces
54     while ( area[0] == ' ' ) {
55         area = area.substr(1, area.length() - 1);
56     }
57     // strip trailing spaces
58     while ( area[area.length() - 1] == ' ' ) {
59         area = area.substr(0, area.length() - 1);
60     }
61     // strip other junk encountered
62     while ( (int)area[area.length() - 1] == 9 ) {
63         area = area.substr(0, area.length() - 1);
64     }
65
66     if ( area == "AirportKeep" ) {
67         return AirportKeepArea;
68     } else if ( area == "AirportIgnore" ) {
69         return AirportIgnoreArea;
70     } else if ( area == "Swamp or Marsh" ) {
71         return MarshArea;
72     } else if ( area == "Bay  Estuary or Ocean" ) {
73         return OceanArea;
74     } else if ( area == "Lake" ) {
75         return LakeArea;
76     } else if ( area == "Lake   Dry" ) {
77         return DryLakeArea;
78     } else if ( area == "Lake   Intermittent" ) {
79         return IntLakeArea;
80     } else if ( area == "Reservoir" ) {
81         return ReservoirArea;
82     } else if ( area == "Reservoir   Intermittent" ) {
83         return IntReservoirArea;
84     } else if ( area == "Stream" ) {
85         return StreamArea;
86     } else if ( area == "Canal" ) {
87         return CanalArea;
88     } else if ( area == "Glacier" ) {
89         return GlacierArea;
90     } else if ( area == "Void Area" ) {
91         return VoidArea;
92     } else if ( area == "Null" ) {
93         return NullArea;
94     } else {
95         cout << "unknown area = '" << area << "'" << endl;
96         // cout << "area = " << area << endl;
97         for ( int i = 0; i < area.length(); i++ ) {
98             cout << i << ") " << (int)area[i] << endl;
99         }
100         return UnknownArea;
101     }
102 }
103
104
105 // return text form of area name
106 string get_area_name( AreaType area ) {
107     if ( area == AirportKeepArea ) {
108         return "AirportKeep";
109     } else if ( area == AirportIgnoreArea ) {
110         return "AirportIgnore";
111     } else if ( area == MarshArea ) {
112         return "Marsh";
113     } else if ( area == OceanArea ) {
114         return "Ocean";
115     } else if ( area == LakeArea ) {
116         return "Lake";
117     } else if ( area == DryLakeArea ) {
118         return "DryLake";
119     } else if ( area == IntLakeArea ) {
120         return "IntermittentLake";
121     } else if ( area == ReservoirArea ) {
122         return "Reservoir";
123     } else if ( area == IntReservoirArea ) {
124         return "IntermittentReservoir";
125     } else if ( area == StreamArea ) {
126         return "Stream";
127     } else if ( area == CanalArea ) {
128         return "Canal";
129     } else if ( area == GlacierArea ) {
130         return "Glacier";
131     } else if ( area == VoidArea ) {
132         return "VoidArea";
133     } else if ( area == NullArea ) {
134         return "Null";
135     } else {
136         cout << "unknown area code = " << (int)area << endl;
137         return "Unknown";
138     }
139 }
140
141
142 // $Log$
143 // Revision 1.1  1999/02/25 21:30:24  curt
144 // Initial revision.
145 //
146 // Revision 1.1  1999/02/23 01:29:05  curt
147 // Additional progress.
148 //