1 : /******************************************************************************
2 : * $Id: ogropenairlabellayer.cpp 20996 2010-10-28 18:38:15Z 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 20996 2010-10-28 18:38:15Z rouault $");
37 :
38 : /************************************************************************/
39 : /* OGROpenAirLabelLayer() */
40 : /************************************************************************/
41 :
42 2 : OGROpenAirLabelLayer::OGROpenAirLabelLayer( VSILFILE* fp )
43 :
44 : {
45 2 : fpOpenAir = fp;
46 2 : nNextFID = 0;
47 :
48 2 : poSRS = new OGRSpatialReference(SRS_WKT_WGS84);
49 :
50 4 : poFeatureDefn = new OGRFeatureDefn( "labels" );
51 2 : poFeatureDefn->Reference();
52 2 : poFeatureDefn->SetGeomType( wkbPoint );
53 :
54 2 : OGRFieldDefn oField1( "CLASS", OFTString);
55 2 : poFeatureDefn->AddFieldDefn( &oField1 );
56 2 : OGRFieldDefn oField2( "NAME", OFTString);
57 2 : poFeatureDefn->AddFieldDefn( &oField2 );
58 2 : OGRFieldDefn oField3( "FLOOR", OFTString);
59 2 : poFeatureDefn->AddFieldDefn( &oField3 );
60 2 : OGRFieldDefn oField4( "CEILING", OFTString);
61 2 : poFeatureDefn->AddFieldDefn( &oField4 );
62 2 : }
63 :
64 : /************************************************************************/
65 : /* ~OGROpenAirLabelLayer() */
66 : /************************************************************************/
67 :
68 2 : OGROpenAirLabelLayer::~OGROpenAirLabelLayer()
69 :
70 : {
71 2 : if( poSRS != NULL )
72 2 : poSRS->Release();
73 :
74 2 : poFeatureDefn->Release();
75 :
76 2 : VSIFCloseL( fpOpenAir );
77 2 : }
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 2 : OGRFeature *OGROpenAirLabelLayer::GetNextFeature()
97 : {
98 : OGRFeature *poFeature;
99 :
100 0 : while(TRUE)
101 : {
102 2 : poFeature = GetNextRawFeature();
103 2 : if (poFeature == NULL)
104 0 : return NULL;
105 :
106 2 : if((m_poFilterGeom == NULL
107 : || FilterGeometry( poFeature->GetGeometryRef() ) )
108 : && (m_poAttrQuery == NULL
109 : || m_poAttrQuery->Evaluate( poFeature )) )
110 : {
111 2 : return poFeature;
112 : }
113 : else
114 0 : delete poFeature;
115 : }
116 : }
117 :
118 : /************************************************************************/
119 : /* GetNextRawFeature() */
120 : /************************************************************************/
121 :
122 2 : OGRFeature *OGROpenAirLabelLayer::GetNextRawFeature()
123 : {
124 : const char* pszLine;
125 2 : double dfLat = 0, dfLon = 0;
126 2 : int bHasCoord = FALSE;
127 :
128 26 : while(TRUE)
129 : {
130 28 : pszLine = CPLReadLine2L(fpOpenAir, 1024, NULL);
131 28 : if (pszLine == NULL)
132 0 : return NULL;
133 :
134 28 : if (pszLine[0] == '*' || pszLine[0] == '\0')
135 12 : continue;
136 :
137 16 : if (EQUALN(pszLine, "AC ", 3))
138 : {
139 4 : if (osCLASS.size() != 0)
140 : {
141 2 : osNAME = "";
142 4 : osCEILING = "";
143 4 : osFLOOR = "";
144 : }
145 4 : osCLASS = pszLine + 3;
146 : }
147 12 : else if (EQUALN(pszLine, "AN ", 3))
148 2 : osNAME = pszLine + 3;
149 10 : else if (EQUALN(pszLine, "AH ", 3))
150 2 : osCEILING = pszLine + 3;
151 8 : else if (EQUALN(pszLine, "AL ", 3))
152 2 : osFLOOR = pszLine + 3;
153 6 : else if (EQUALN(pszLine, "AT ", 3))
154 : {
155 2 : bHasCoord = OGROpenAirGetLatLon(pszLine + 3, dfLat, dfLon);
156 : break;
157 : }
158 : }
159 :
160 4 : OGRFeature* poFeature = new OGRFeature(poFeatureDefn);
161 2 : poFeature->SetField(0, osCLASS.c_str());
162 2 : poFeature->SetField(1, osNAME.c_str());
163 2 : poFeature->SetField(2, osFLOOR.c_str());
164 2 : poFeature->SetField(3, osCEILING.c_str());
165 :
166 2 : CPLString osStyle;
167 4 : osStyle.Printf("LABEL(t:\"%s\")", osNAME.c_str());
168 2 : poFeature->SetStyleString(osStyle.c_str());
169 :
170 2 : if (bHasCoord)
171 : {
172 2 : OGRPoint* poPoint = new OGRPoint(dfLon, dfLat);
173 2 : poPoint->assignSpatialReference(poSRS);
174 2 : poFeature->SetGeometryDirectly(poPoint);
175 : }
176 :
177 2 : poFeature->SetFID(nNextFID++);
178 :
179 2 : 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 :
|