OpenCPN Partial API docs
Loading...
Searching...
No Matches
s57.h
1/******************************************************************************
2 *
3 * Project: S-57 Translator
4 * Purpose: Declarations for S-57 translator not including the
5 * binding onto OGRLayer/DataSource/Driver which are found in
6 * ogr_s57.h.
7 * Author: Frank Warmerdam, warmerda@home.com
8 *
9 ******************************************************************************
10 * Copyright (c) 1999, Frank Warmerdam
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included
20 * in all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 * DEALINGS IN THE SOFTWARE.
29 ******************************************************************************
30 *
31 *
32 */
33
34#ifndef _S57_H_INCLUDED
35#define _S57_H_INCLUDED
36
37#include "gdal/ogr_feature.h"
38#include "iso8211.h"
39#include "S57ClassRegistrar.h"
40
41class S57Reader;
42
43char **S57FileCollector(const char *pszDataset);
44
45#define EMPTY_NUMBER_MARKER 2147483641 /* MAXINT-6 */
46
47/* -------------------------------------------------------------------- */
48/* Various option strings. */
49/* -------------------------------------------------------------------- */
50#define S57O_UPDATES "UPDATES"
51#define S57O_LNAM_REFS "LNAM_REFS"
52#define S57O_SPLIT_MULTIPOINT "SPLIT_MULTIPOINT"
53#define S57O_ADD_SOUNDG_DEPTH "ADD_SOUNDG_DEPTH"
54#define S57O_PRESERVE_EMPTY_NUMBERS "PRESERVE_EMPTY_NUMBERS"
55#define S57O_RETURN_PRIMITIVES "RETURN_PRIMITIVES"
56#define S57O_RETURN_LINKAGES "RETURN_LINKAGES"
57
58#define S57M_UPDATES 0x01
59#define S57M_LNAM_REFS 0x02
60#define S57M_SPLIT_MULTIPOINT 0x04
61#define S57M_ADD_SOUNDG_DEPTH 0x08
62#define S57M_PRESERVE_EMPTY_NUMBERS 0x10
63#define S57M_RETURN_PRIMITIVES 0x20
64#define S57M_RETURN_LINKAGES 0x40
65
66/* -------------------------------------------------------------------- */
67/* RCNM values. */
68/* -------------------------------------------------------------------- */
69
70#define RCNM_FE 100 /* Feature record */
71
72#define RCNM_VI 110 /* Isolated Node */
73#define RCNM_VC 120 /* Connected Node */
74#define RCNM_VE 130 /* Edge */
75#define RCNM_VF 140 /* Face */
76
77#define OGRN_VI "IsolatedNode"
78#define OGRN_VC "ConnectedNode"
79#define OGRN_VE "Edge"
80#define OGRN_VF "Face"
81
82/* -------------------------------------------------------------------- */
83/* FRID PRIM values. */
84/* -------------------------------------------------------------------- */
85#define PRIM_P 1 /* point feature */
86#define PRIM_L 2 /* line feature */
87#define PRIM_A 3 /* area feature */
88#define PRIM_N 4 /* non-spatial feature */
89
90/************************************************************************/
91/* S57ClassRegistrar */
92/************************************************************************/
93
94#define MAX_CLASSES 23000
95#define MAX_ATTRIBUTES 25000
96
97/************************************************************************/
98/* DDFRecordIndex */
99/* */
100/* Maintain an index of DDF records based on an integer key. */
101/************************************************************************/
102
103typedef struct {
104 int nKey;
105 DDFRecord *poRecord;
107
109 int bSorted;
110
111 int nRecordCount;
112 int nRecordMax;
113
114 int nLastObjlPos; /* rjensen. added for FindRecordByObjl() */
115 int nLastObjl; /* rjensen. added for FindRecordByObjl() */
116
117 DDFIndexedRecord *pasRecords;
118
119 void Sort();
120
121public:
124
125 void AddRecord(int nKey, DDFRecord *);
126 int RemoveRecord(int nKey);
127
128 DDFRecord *FindRecord(int nKey);
129
130 DDFRecord *FindRecordByObjl(
131 int nObjl); /* rjensen. added for FindRecordByObjl() */
132
133 void Clear();
134
135 int GetCount() { return nRecordCount; }
136 DDFRecord *GetByIndex(int i);
137};
138
139/************************************************************************/
140/* S57Reader */
141/************************************************************************/
142typedef bool (*CallBackFunction)(void);
143
145 S57ClassRegistrar *poRegistrar;
146
147 int nFDefnCount;
148 OGRFeatureDefn **papoFDefnList;
149
150 char *pszModuleName;
151 char *pszDSNM;
152
153 DDFModule *poModule;
154
155 int nCOMF; /* Coordinate multiplier */
156 int nSOMF; /* Vertical (sounding) multiplier */
157 int nCSCL; /* Chart Scale (from DSPM record) */
158
159 int bFileIngested;
160 DDFRecordIndex oVI_Index;
161 DDFRecordIndex oVC_Index;
162 DDFRecordIndex oVE_Index;
163 DDFRecordIndex oVF_Index;
164
165 int nNextVIIndex;
166 int nNextVCIndex;
167 int nNextVEIndex;
168 int nNextVFIndex;
169
170 int nNextFEIndex;
171 DDFRecordIndex oFE_Index;
172
173 char **papszOptions;
174
175 int nOptionFlags;
176
177 int iPointOffset;
178 OGRFeature *poMultiPoint;
179
180 void ClearPendingMultiPoint();
181 OGRFeature *NextPendingMultiPoint();
182
183 OGRFeature *AssembleFeature(DDFRecord *, OGRFeatureDefn *);
184
185 void ApplyObjectClassAttributes(DDFRecord *, OGRFeature *);
186 void GenerateLNAMAndRefs(DDFRecord *, OGRFeature *);
187 void GenerateFSPTAttributes(DDFRecord *, OGRFeature *);
188
189 void AssembleSoundingGeometry(DDFRecord *, OGRFeature *);
190 void AssemblePointGeometry(DDFRecord *, OGRFeature *);
191 void AssembleLineGeometry(DDFRecord *, OGRFeature *);
192 void AssembleAreaGeometry(DDFRecord *, OGRFeature *);
193
194 OGRFeatureDefn *FindFDefn(DDFRecord *);
195 int ParseName(DDFField *, int = 0, int * = NULL);
196
197 int ApplyRecordUpdate(DDFRecord *, DDFRecord *);
198
199 int bMissingWarningIssued;
200 int bAttrWarningIssued;
201
202 int Nall;
203 int Aall;
204
205public:
206 S57Reader(const char *);
207 ~S57Reader();
208
209 int FetchPoint(int, int, double *, double *, double * = NULL, int * = NULL);
210
211 void SetClassBased(S57ClassRegistrar *);
212 void SetOptions(char **);
213 int GetOptionFlags() { return nOptionFlags; }
214
215 int Open(int bTestOpen);
216 void Close();
217 DDFModule *GetModule() { return poModule; }
218 const char *GetDSNM() { return pszDSNM; }
219 int GetCSCL() { return nCSCL; }
220
221 int Ingest(CallBackFunction pcallback = NULL);
222 int ApplyUpdates(DDFModule *, int);
223 int FindAndApplyUpdates(const char *pszPath = NULL);
224
225 void Rewind();
226 OGRFeature *ReadNextFeature(OGRFeatureDefn * = NULL);
227 OGRFeature *ReadFeature(int nFID, OGRFeatureDefn * = NULL);
228 OGRFeature *ReadVector(int nFID, int nRCNM);
229
230 int GetNextFEIndex(int nRCNM = 100);
231 void SetNextFEIndex(int nNewIndex, int nRCNM = 100);
232
233 void AddFeatureDefn(OGRFeatureDefn *);
234
235 int CollectClassList(int *, int);
236
237 OGRErr GetExtent(OGREnvelope *psExtent, int bForce);
238
239 int GetNall() { return Nall; }
240 int GetAall() { return Aall; }
241
242 int GetFeatureCount() { return oFE_Index.GetCount(); }
243};
244
245/************************************************************************/
246/* S57Writer */
247/************************************************************************/
248
250public:
251 S57Writer();
252 ~S57Writer();
253
254 void SetClassBased(S57ClassRegistrar *);
255 int CreateS57File(const char *pszFilename);
256 int Close();
257
258 int WriteGeometry(DDFRecord *, int, double *, double *, double *);
259 int WriteATTF(DDFRecord *, OGRFeature *);
260 int WritePrimitive(OGRFeature *poFeature);
261 int WriteCompleteFeature(OGRFeature *poFeature);
262 int WriteDSID(const char *pszDSNM = NULL, const char *pszISDT = NULL,
263 const char *pszSTED = NULL, int nAGEN = 0,
264 const char *pszCOMT = NULL);
265 int WriteDSPM(int nScale = 0);
266
267private:
268 DDFModule *poModule;
269 S57ClassRegistrar *poRegistrar;
270
271 int nNext0001Index;
272
273 DDFRecord *MakeRecord();
274
275 int nCOMF; /* Coordinate multiplier */
276 int nSOMF; /* Vertical (sounding) multiplier */
277};
278
279/* -------------------------------------------------------------------- */
280/* Functions to create OGRFeatureDefns. */
281/* -------------------------------------------------------------------- */
282void CPL_DLL S57GenerateStandardAttributes(OGRFeatureDefn *, int);
283OGRFeatureDefn CPL_DLL *S57GenerateGeomFeatureDefn(OGRwkbGeometryType, int);
284OGRFeatureDefn CPL_DLL *S57GenerateObjectClassDefn(S57ClassRegistrar *, int,
285 int);
286OGRFeatureDefn CPL_DLL *S57GenerateVectorPrimitiveFeatureDefn(int, int);
287
288#endif /* ndef _S57_H_INCLUDED */
Definition: s57.h:144
Definition: s57.h:249