1 : /******************************************************************************
2 : * $Id: ogropenairlabellayer.cpp 20003 2010-07-10 19:46:28Z rouault $
3 : *
4 : * Project: OpenAir Translator
5 : * Purpose: Implements OGROpenAirLabelLayer class.
6 : * Author: Even Rouault, <even dot rouault at mines dash paris dot org>
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2010, Even Rouault <even dot rouault at mines dash paris dot org>
10 : *
11 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 : #include "ogr_openair.h"
31 : #include "cpl_conv.h"
32 : #include "cpl_string.h"
33 : #include "ogr_p.h"
34 : #include "ogr_srs_api.h"
35 :
36 : CPL_CVSID("$Id: ogropenairlabellayer.cpp 20003 2010-07-10 19:46:28Z rouault $");
37 :
38 : /************************************************************************/
39 : /* OGROpenAirLabelLayer() */
40 : /************************************************************************/
41 :
42 1 : OGROpenAirLabelLayer::OGROpenAirLabelLayer( FILE* fp )
43 :
44 : {
45 1 : fpOpenAir = fp;
46 1 : nNextFID = 0;
47 :
48 1 : poSRS = new OGRSpatialReference(SRS_WKT_WGS84);
49 :
50 2 : poFeatureDefn = new OGRFeatureDefn( "labels" );
51 1 : poFeatureDefn->Reference();
52 1 : poFeatureDefn->SetGeomType( wkbPoint );
53 :
54 1 : OGRFieldDefn oField1( "CLASS", OFTString);
55 1 : poFeatureDefn->AddFieldDefn( &oField1 );
56 1 : OGRFieldDefn oField2( "NAME", OFTString);
57 1 : poFeatureDefn->AddFieldDefn( &oField2 );
58 1 : OGRFieldDefn oField3( "FLOOR", OFTString);
59 1 : poFeatureDefn->AddFieldDefn( &oField3 );
60 1 : OGRFieldDefn oField4( "CEILING", OFTString);
61 1 : poFeatureDefn->AddFieldDefn( &oField4 );
62 1 : }
63 :
64 : /************************************************************************/
65 : /* ~OGROpenAirLabelLayer() */
66 : /************************************************************************/
67 :
68 1 : OGROpenAirLabelLayer::~OGROpenAirLabelLayer()
69 :
70 : {
71 1 : if( poSRS != NULL )
72 1 : poSRS->Release();
73 :
74 1 : poFeatureDefn->Release();
75 :
76 1 : VSIFCloseL( fpOpenAir );
77 1 : }
78 :
79 :
80 : /************************************************************************/
81 : /* ResetReading() */
82 : /************************************************************************/
83 :
84 0 : void OGROpenAirLabelLayer::ResetReading()
85 :
86 : {
87 0 : nNextFID = 0;
88 0 : VSIFSeekL( fpOpenAir, 0, SEEK_SET );
89 0 : }
90 :
91 :
92 : /************************************************************************/
93 : /* GetNextFeature() */
94 : /************************************************************************/
95 :
96 1 : OGRFeature *OGROpenAirLabelLayer::GetNextFeature()
97 : {
98 : OGRFeature *poFeature;
99 :
100 0 : while(TRUE)
101 : {
102 1 : poFeature = GetNextRawFeature();
103 1 : if (poFeature == NULL)
104 0 : return NULL;
105 :
106 1 : if((m_poFilterGeom == NULL
107 : || FilterGeometry( poFeature->GetGeometryRef() ) )
108 : && (m_poAttrQuery == NULL
109 : || m_poAttrQuery->Evaluate( poFeature )) )
110 : {
111 1 : return poFeature;
112 : }
113 : else
114 0 : delete poFeature;
115 : }
116 : }
117 :
118 : /************************************************************************/
119 : /* GetNextRawFeature() */
120 : /************************************************************************/
121 :
122 1 : OGRFeature *OGROpenAirLabelLayer::GetNextRawFeature()
123 : {
124 : const char* pszLine;
125 1 : double dfLat = 0, dfLon = 0;
126 1 : int bHasCoord = FALSE;
127 :
128 13 : while(TRUE)
129 : {
130 14 : pszLine = CPLReadLine2L(fpOpenAir, 1024, NULL);
131 14 : if (pszLine == NULL)
132 0 : return NULL;
133 :
134 14 : if (pszLine[0] == '*' || pszLine[0] == '\0')
135 6 : continue;
136 :
137 8 : if (EQUALN(pszLine, "AC ", 3))
138 : {
139 2 : if (osCLASS.size() != 0)
140 : {
141 1 : osNAME = "";
142 2 : osCEILING = "";
143 2 : osFLOOR = "";
144 : }
145 2 : osCLASS = pszLine + 3;
146 : }
147 6 : else if (EQUALN(pszLine, "AN ", 3))
148 1 : osNAME = pszLine + 3;
149 5 : else if (EQUALN(pszLine, "AH ", 3))
150 1 : osCEILING = pszLine + 3;
151 4 : else if (EQUALN(pszLine, "AL ", 3))
152 1 : osFLOOR = pszLine + 3;
153 3 : else if (EQUALN(pszLine, "AT ", 3))
154 : {
155 1 : bHasCoord = OGROpenAirGetLatLon(pszLine + 3, dfLat, dfLon);
156 : break;
157 : }
158 : }
159 :
160 2 : OGRFeature* poFeature = new OGRFeature(poFeatureDefn);
161 1 : poFeature->SetField(0, osCLASS.c_str());
162 1 : poFeature->SetField(1, osNAME.c_str());
163 1 : poFeature->SetField(2, osFLOOR.c_str());
164 1 : poFeature->SetField(3, osCEILING.c_str());
165 :
166 1 : CPLString osStyle;
167 2 : osStyle.Printf("LABEL(t:\"%s\")", osNAME.c_str());
168 1 : poFeature->SetStyleString(osStyle.c_str());
169 :
170 1 : if (bHasCoord)
171 : {
172 1 : OGRPoint* poPoint = new OGRPoint(dfLon, dfLat);
173 1 : poPoint->assignSpatialReference(poSRS);
174 1 : poFeature->SetGeometryDirectly(poPoint);
175 : }
176 :
177 1 : poFeature->SetFID(nNextFID++);
178 :
179 1 : return poFeature;
180 : }
181 :
182 : /************************************************************************/
183 : /* TestCapability() */
184 : /************************************************************************/
185 :
186 0 : int OGROpenAirLabelLayer::TestCapability( const char * pszCap )
187 :
188 : {
189 0 : return FALSE;
190 : }
191 :
|