1 : /******************************************************************************
2 : * $Id: sdtspointreader.cpp 10645 2007-01-18 02:22:39Z warmerdam $
3 : *
4 : * Project: SDTS Translator
5 : * Purpose: Implementation of SDTSPointReader and SDTSRawPoint classes.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 1999, Frank Warmerdam
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 "sdts_al.h"
31 :
32 : CPL_CVSID("$Id: sdtspointreader.cpp 10645 2007-01-18 02:22:39Z warmerdam $");
33 :
34 : /************************************************************************/
35 : /* ==================================================================== */
36 : /* SDTSRawPoint */
37 : /* */
38 : /* This is a simple class for holding the data related with a */
39 : /* point feature. */
40 : /* ==================================================================== */
41 : /************************************************************************/
42 :
43 : /************************************************************************/
44 : /* SDTSRawPoint() */
45 : /************************************************************************/
46 :
47 258 : SDTSRawPoint::SDTSRawPoint()
48 :
49 : {
50 258 : nAttributes = 0;
51 258 : }
52 :
53 : /************************************************************************/
54 : /* ~STDSRawPoint() */
55 : /************************************************************************/
56 :
57 258 : SDTSRawPoint::~SDTSRawPoint()
58 :
59 : {
60 258 : }
61 :
62 : /************************************************************************/
63 : /* Read() */
64 : /* */
65 : /* Read a record from the passed SDTSPointReader, and assign the */
66 : /* values from that record to this point. This is the bulk of */
67 : /* the work in this whole file. */
68 : /************************************************************************/
69 :
70 258 : int SDTSRawPoint::Read( SDTS_IREF * poIREF, DDFRecord * poRecord )
71 :
72 : {
73 : /* ==================================================================== */
74 : /* Loop over fields in this record, looking for those we */
75 : /* recognise, and need. */
76 : /* ==================================================================== */
77 1102 : for( int iField = 0; iField < poRecord->GetFieldCount(); iField++ )
78 : {
79 844 : DDFField *poField = poRecord->GetField( iField );
80 : const char *pszFieldName;
81 :
82 844 : CPLAssert( poField != NULL );
83 844 : pszFieldName = poField->GetFieldDefn()->GetName();
84 :
85 844 : if( EQUAL(pszFieldName,"PNTS") )
86 258 : oModId.Set( poField );
87 :
88 586 : else if( EQUAL(pszFieldName,"ATID") )
89 0 : ApplyATID( poField );
90 :
91 586 : else if( EQUAL(pszFieldName,"ARID") )
92 : {
93 70 : oAreaId.Set( poField );
94 : }
95 516 : else if( EQUAL(pszFieldName,"SADR") )
96 : {
97 258 : poIREF->GetSADR( poField, 1, &dfX, &dfY, &dfZ );
98 : }
99 : }
100 :
101 258 : return TRUE;
102 : }
103 :
104 : /************************************************************************/
105 : /* Dump() */
106 : /************************************************************************/
107 :
108 0 : void SDTSRawPoint::Dump( FILE * fp )
109 :
110 : {
111 : int i;
112 :
113 0 : fprintf( fp, "SDTSRawPoint %s: ", oModId.GetName() );
114 :
115 0 : if( oAreaId.nRecord != -1 )
116 0 : fprintf( fp, " AreaId=%s", oAreaId.GetName() );
117 :
118 0 : for( i = 0; i < nAttributes; i++ )
119 0 : fprintf( fp, " ATID[%d]=%s", i, paoATID[i].GetName() );
120 :
121 0 : fprintf( fp, " Vertex = (%.2f,%.2f,%.2f)\n", dfX, dfY, dfZ );
122 0 : }
123 :
124 :
125 : /************************************************************************/
126 : /* ==================================================================== */
127 : /* SDTSPointReader */
128 : /* */
129 : /* This is the class used to read a point module. */
130 : /* ==================================================================== */
131 : /************************************************************************/
132 :
133 : /************************************************************************/
134 : /* SDTSPointReader() */
135 : /************************************************************************/
136 :
137 6 : SDTSPointReader::SDTSPointReader( SDTS_IREF * poIREFIn )
138 :
139 : {
140 6 : poIREF = poIREFIn;
141 6 : }
142 :
143 : /************************************************************************/
144 : /* ~SDTSLineReader() */
145 : /************************************************************************/
146 :
147 6 : SDTSPointReader::~SDTSPointReader()
148 : {
149 6 : }
150 :
151 : /************************************************************************/
152 : /* Close() */
153 : /************************************************************************/
154 :
155 0 : void SDTSPointReader::Close()
156 :
157 : {
158 0 : oDDFModule.Close();
159 0 : }
160 :
161 : /************************************************************************/
162 : /* Open() */
163 : /* */
164 : /* Open the requested line file, and prepare to start reading */
165 : /* data records. */
166 : /************************************************************************/
167 :
168 6 : int SDTSPointReader::Open( const char * pszFilename )
169 :
170 : {
171 6 : return( oDDFModule.Open( pszFilename ) );
172 : }
173 :
174 : /************************************************************************/
175 : /* GetNextPoint() */
176 : /* */
177 : /* Fetch the next feature as an STDSRawPoint. */
178 : /************************************************************************/
179 :
180 264 : SDTSRawPoint * SDTSPointReader::GetNextPoint()
181 :
182 : {
183 : DDFRecord *poRecord;
184 :
185 : /* -------------------------------------------------------------------- */
186 : /* Read a record. */
187 : /* -------------------------------------------------------------------- */
188 264 : if( oDDFModule.GetFP() == NULL )
189 0 : return NULL;
190 :
191 264 : poRecord = oDDFModule.ReadRecord();
192 :
193 264 : if( poRecord == NULL )
194 6 : return NULL;
195 :
196 : /* -------------------------------------------------------------------- */
197 : /* Transform into a point feature. */
198 : /* -------------------------------------------------------------------- */
199 258 : SDTSRawPoint *poRawPoint = new SDTSRawPoint();
200 :
201 258 : if( poRawPoint->Read( poIREF, poRecord ) )
202 : {
203 258 : return( poRawPoint );
204 : }
205 : else
206 : {
207 0 : delete poRawPoint;
208 0 : return NULL;
209 : }
210 : }
211 :
|