Line data Source code
1 : /******************************************************************************
2 : *
3 : * Project: SDTS Translator
4 : * Purpose: Implementation of SDTSPointReader and SDTSRawPoint classes.
5 : * Author: Frank Warmerdam, warmerdam@pobox.com
6 : *
7 : ******************************************************************************
8 : * Copyright (c) 1999, Frank Warmerdam
9 : *
10 : * Permission is hereby granted, free of charge, to any person obtaining a
11 : * copy of this software and associated documentation files (the "Software"),
12 : * to deal in the Software without restriction, including without limitation
13 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 : * and/or sell copies of the Software, and to permit persons to whom the
15 : * Software is furnished to do so, subject to the following conditions:
16 : *
17 : * The above copyright notice and this permission notice shall be included
18 : * in all copies or substantial portions of the Software.
19 : *
20 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 : * DEALINGS IN THE SOFTWARE.
27 : ****************************************************************************/
28 :
29 : #include "sdts_al.h"
30 :
31 : /************************************************************************/
32 : /* ==================================================================== */
33 : /* SDTSRawPoint */
34 : /* */
35 : /* This is a simple class for holding the data related with a */
36 : /* point feature. */
37 : /* ==================================================================== */
38 : /************************************************************************/
39 :
40 : /************************************************************************/
41 : /* SDTSRawPoint() */
42 : /************************************************************************/
43 :
44 129 : SDTSRawPoint::SDTSRawPoint() : dfX(0.0), dfY(0.0), dfZ(0.0)
45 : {
46 129 : nAttributes = 0;
47 129 : }
48 :
49 : /************************************************************************/
50 : /* ~STDSRawPoint() */
51 : /************************************************************************/
52 :
53 258 : SDTSRawPoint::~SDTSRawPoint()
54 : {
55 258 : }
56 :
57 : /************************************************************************/
58 : /* Read() */
59 : /* */
60 : /* Read a record from the passed SDTSPointReader, and assign the */
61 : /* values from that record to this point. This is the bulk of */
62 : /* the work in this whole file. */
63 : /************************************************************************/
64 :
65 129 : int SDTSRawPoint::Read(SDTS_IREF *poIREF, DDFRecord *poRecord)
66 :
67 : {
68 : /* ==================================================================== */
69 : /* Loop over fields in this record, looking for those we */
70 : /* recognise, and need. */
71 : /* ==================================================================== */
72 551 : for (int iField = 0; iField < poRecord->GetFieldCount(); iField++)
73 : {
74 422 : DDFField *poField = poRecord->GetField(iField);
75 422 : if (poField == nullptr)
76 0 : return FALSE;
77 422 : DDFFieldDefn *poFieldDefn = poField->GetFieldDefn();
78 422 : if (poFieldDefn == nullptr)
79 0 : return FALSE;
80 :
81 422 : const char *pszFieldName = poFieldDefn->GetName();
82 :
83 422 : if (EQUAL(pszFieldName, "PNTS"))
84 129 : oModId.Set(poField);
85 :
86 293 : else if (EQUAL(pszFieldName, "ATID"))
87 0 : ApplyATID(poField);
88 :
89 293 : else if (EQUAL(pszFieldName, "ARID"))
90 : {
91 35 : oAreaId.Set(poField);
92 : }
93 258 : else if (EQUAL(pszFieldName, "SADR"))
94 : {
95 129 : poIREF->GetSADR(poField, 1, &dfX, &dfY, &dfZ);
96 : }
97 : }
98 :
99 129 : return TRUE;
100 : }
101 :
102 : /************************************************************************/
103 : /* Dump() */
104 : /************************************************************************/
105 :
106 0 : void SDTSRawPoint::Dump(FILE *fp)
107 :
108 : {
109 0 : fprintf(fp, "SDTSRawPoint %s: ", oModId.GetName());
110 :
111 0 : if (oAreaId.nRecord != -1)
112 0 : fprintf(fp, " AreaId=%s", oAreaId.GetName());
113 :
114 0 : for (int i = 0; i < nAttributes; i++)
115 0 : fprintf(fp, " ATID[%d]=%s", i, paoATID[i].GetName());
116 :
117 0 : fprintf(fp, " Vertex = (%.2f,%.2f,%.2f)\n", dfX, dfY, dfZ);
118 0 : }
119 :
120 : /************************************************************************/
121 : /* ==================================================================== */
122 : /* SDTSPointReader */
123 : /* */
124 : /* This is the class used to read a point module. */
125 : /* ==================================================================== */
126 : /************************************************************************/
127 :
128 : /************************************************************************/
129 : /* SDTSPointReader() */
130 : /************************************************************************/
131 :
132 3 : SDTSPointReader::SDTSPointReader(SDTS_IREF *poIREFIn) : poIREF(poIREFIn)
133 : {
134 3 : }
135 :
136 : /************************************************************************/
137 : /* ~SDTSLineReader() */
138 : /************************************************************************/
139 :
140 6 : SDTSPointReader::~SDTSPointReader()
141 : {
142 6 : }
143 :
144 : /************************************************************************/
145 : /* Close() */
146 : /************************************************************************/
147 :
148 0 : void SDTSPointReader::Close()
149 :
150 : {
151 0 : oDDFModule.Close();
152 0 : }
153 :
154 : /************************************************************************/
155 : /* Open() */
156 : /* */
157 : /* Open the requested line file, and prepare to start reading */
158 : /* data records. */
159 : /************************************************************************/
160 :
161 3 : int SDTSPointReader::Open(const char *pszFilename)
162 :
163 : {
164 3 : return oDDFModule.Open(pszFilename);
165 : }
166 :
167 : /************************************************************************/
168 : /* GetNextPoint() */
169 : /* */
170 : /* Fetch the next feature as an STDSRawPoint. */
171 : /************************************************************************/
172 :
173 132 : SDTSRawPoint *SDTSPointReader::GetNextPoint()
174 :
175 : {
176 : /* -------------------------------------------------------------------- */
177 : /* Read a record. */
178 : /* -------------------------------------------------------------------- */
179 132 : if (oDDFModule.GetFP() == nullptr)
180 0 : return nullptr;
181 :
182 132 : DDFRecord *poRecord = oDDFModule.ReadRecord();
183 :
184 132 : if (poRecord == nullptr)
185 3 : return nullptr;
186 :
187 : /* -------------------------------------------------------------------- */
188 : /* Transform into a point feature. */
189 : /* -------------------------------------------------------------------- */
190 129 : SDTSRawPoint *poRawPoint = new SDTSRawPoint();
191 :
192 129 : if (poRawPoint->Read(poIREF, poRecord))
193 : {
194 129 : return poRawPoint;
195 : }
196 :
197 0 : delete poRawPoint;
198 0 : return nullptr;
199 : }
|