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