30 #include "wx/wxprec.h"
36 #include <wx/filename.h>
38 #include "gdal/cpl_csv.h"
41 #include "chartbase.h"
47 #include <unordered_map>
49 WX_DEFINE_ARRAY_PTR(
float *, SENCFloatPtrArray);
52 #define SENC_NO_ERROR 0
53 #define ERROR_SENCFILE_NOT_FOUND 1
54 #define ERROR_SENC_VERSION_MISMATCH 2
55 #define ERROR_CANNOT_CREATE_SENC_DIR 3
56 #define ERROR_CANNOT_CREATE_TEMP_SENC_FILE 4
57 #define ERROR_INGESTING000 5
58 #define ERROR_REGISTRAR_NOT_SET 6
59 #define ERROR_BASEFILE_ATTRIBUTES 7
60 #define ERROR_SENCFILE_ABORT 8
63 #define HEADER_SENC_VERSION 1
64 #define HEADER_CELL_NAME 2
65 #define HEADER_CELL_PUBLISHDATE 3
66 #define HEADER_CELL_EDITION 4
67 #define HEADER_CELL_UPDATEDATE 5
68 #define HEADER_CELL_UPDATE 6
69 #define HEADER_CELL_NATIVESCALE 7
70 #define HEADER_CELL_SENCCREATEDATE 8
72 #define FEATURE_ID_RECORD 64
73 #define FEATURE_ATTRIBUTE_RECORD 65
75 #define FEATURE_GEOMETRY_RECORD_POINT 80
76 #define FEATURE_GEOMETRY_RECORD_LINE 81
77 #define FEATURE_GEOMETRY_RECORD_AREA 82
78 #define FEATURE_GEOMETRY_RECORD_MULTIPOINT 83
80 #define VECTOR_EDGE_NODE_TABLE_RECORD 96
81 #define VECTOR_CONNECTED_NODE_TABLE_RECORD 97
83 #define CELL_COVR_RECORD 98
84 #define CELL_NOCOVR_RECORD 99
85 #define CELL_EXTENT_RECORD 100
94 uint32_t record_length;
99 uint32_t record_length;
100 unsigned char payload;
104 uint16_t record_type;
105 uint32_t record_length;
106 uint16_t feature_type_code;
108 uint8_t feature_primitive;
112 uint16_t feature_type_code;
114 uint8_t feature_primitive;
118 uint16_t record_type;
119 uint32_t record_length;
120 uint16_t attribute_type;
121 unsigned char attribute_value_type;
125 uint16_t record_type;
126 uint32_t record_length;
127 uint16_t attribute_type;
128 unsigned char attribute_value_type;
133 uint16_t attribute_type_code;
134 unsigned char attribute_value_type;
137 uint32_t attribute_value_int;
138 double attribute_value_double;
139 char *attribute_value_char_ptr;
144 uint16_t record_type;
145 uint32_t record_length;
156 uint16_t record_type;
157 uint32_t record_length;
162 uint32_t point_count;
170 uint32_t point_count;
175 uint16_t record_type;
176 uint32_t record_length;
181 uint32_t edgeVector_count;
189 uint32_t edgeVector_count;
194 uint16_t record_type;
195 uint32_t record_length;
200 uint32_t contour_count;
201 uint32_t triprim_count;
202 uint32_t edgeVector_count;
210 uint32_t contour_count;
211 uint32_t triprim_count;
212 uint32_t edgeVector_count;
217 uint16_t record_type;
218 uint32_t record_length;
219 unsigned char payload;
223 uint16_t record_type;
224 uint32_t record_length;
228 uint16_t record_type;
229 uint32_t record_length;
230 unsigned char payload;
234 uint16_t record_type;
235 uint32_t record_length;
239 uint16_t record_type;
240 uint32_t record_length;
241 unsigned char payload;
245 uint16_t record_type;
246 uint32_t record_length;
250 uint32_t point_count;
255 uint16_t record_type;
256 uint32_t record_length;
257 unsigned char payload;
261 uint16_t record_type;
262 uint32_t record_length;
266 uint32_t point_count;
271 uint16_t record_type;
272 uint32_t record_length;
273 double extent_sw_lat;
274 double extent_sw_lon;
275 double extent_nw_lat;
276 double extent_nw_lon;
277 double extent_ne_lat;
278 double extent_ne_lon;
279 double extent_se_lat;
280 double extent_se_lon;
284 double extent_sw_lat;
285 double extent_sw_lon;
286 double extent_nw_lat;
287 double extent_nw_lon;
288 double extent_ne_lat;
289 double extent_ne_lon;
290 double extent_se_lat;
291 double extent_se_lon;
299 #define ATTRIBUTE_ID_PRIM 50000
301 const char *MyCSVGetField(
const char *pszFilename,
const char *pszKeyFieldName,
302 const char *pszKeyFieldValue,
303 CSVCompareCriteria eCriteria,
304 const char *pszTargetField);
307 class wxGenericProgressDialog;
312 class LineGeometryDescriptor;
313 class wxFFileInputStream;
315 typedef std::vector<S57Obj *> S57ObjVector;
316 typedef std::vector<VE_Element *> VE_ElementVector;
317 typedef std::vector<VC_Element *> VC_ElementVector;
327 virtual bool Open(
const wxString &senc_file_name) = 0;
328 virtual void Close() = 0;
331 virtual bool IsOk() = 0;
332 virtual bool isAvailable() = 0;
333 virtual void Shutdown() = 0;
345 bool Open(
const wxString &senc_file_name);
356 wxFFileInputStream *m_instream;
368 virtual bool Open(
const wxString &ofileName) = 0;
371 virtual void Close() = 0;
372 virtual bool IsOk() = 0;
384 bool Open(
const wxString &ofileName);
393 wxFFileOutputStream *m_outstream;
406 wxString getLastError() {
return errorMessage; }
407 void setVerbose(
bool verbose);
408 void setNoErrDialog(
bool val) { m_NoErrDialog = val; }
410 int ingestHeader(
const wxString &senc_file_name);
411 int ingest(
const wxString &senc_file_name, S57ObjVector *pObjectVector,
412 VE_ElementVector *pVEArray, VC_ElementVector *pVCArray);
414 int ingest200(
const wxString &senc_file_name, S57ObjVector *pObjectVector,
415 VE_ElementVector *pVEArray, VC_ElementVector *pVCArray);
418 void SetLODMeters(
double meters) { m_LOD_meters = meters; }
419 void setRegistrar(S57ClassRegistrar *registrar) { m_poRegistrar = registrar; }
420 void setRefLocn(
double lat,
double lon) {
424 void setOutstream(
Osenc_outstream *stream) { m_pauxOutstream = stream; }
425 void setInstream(
Osenc_instream *stream) { m_pauxInstream = stream; }
427 wxString getUpdateDate() {
return m_LastUpdateDate; }
428 wxString getBaseDate() {
return m_sdate000; }
430 wxString getSENCFileCreateDate() {
return m_readFileCreateDate; }
432 int getSencReadVersion() {
return m_senc_file_read_version; }
433 wxString getSENCReadBaseEdition() {
return m_read_base_edtn; }
434 int getSENCReadLastUpdate() {
return m_read_last_applied_update; }
435 int getSENCReadScale() {
return m_Chart_Scale; }
436 wxString getReadName() {
return m_Name; }
437 wxString getReadID() {
return m_ID; }
438 Extent &getReadExtent() {
return m_extent; }
440 SENCFloatPtrArray &getSENCReadAuxPointArray() {
return m_AuxPtrArray; }
441 std::vector<int> &getSENCReadAuxPointCountArray() {
return m_AuxCntArray; }
442 SENCFloatPtrArray &getSENCReadNOCOVRPointArray() {
return m_NoCovrPtrArray; }
443 std::vector<int> &getSENCReadNOCOVRPointCountArray() {
444 return m_NoCovrCntArray;
447 int createSenc200(
const wxString &FullPath000,
const wxString &SENCFileName,
448 bool b_showProg =
true);
451 S57Reader *poReader);
453 S57Reader *poReader);
455 void InitializePersistentBuffer(
void);
456 unsigned char *getBuffer(
size_t length);
458 int getNativeScale() {
return m_native_scale; }
459 int GetBaseFileInfo(
const wxString &FullPath000,
460 const wxString &SENCFileName);
462 std::unique_lock<std::mutex> lockCR;
467 int ingestCell(OGRS57DataSource *poS57DS,
const wxString &FullPath000,
468 const wxString &working_dir);
469 int ValidateAndCountUpdates(
const wxFileName file000,
const wxString CopyDir,
470 wxString &LastUpdateDate,
bool b_copyfiles);
471 int GetUpdateFileArray(
const wxFileName file000, wxArrayString *UpFiles);
472 bool GetBaseFileAttr(
const wxString &FullPath000);
473 unsigned char *getObjectVectorIndexTable(S57Reader *poReader,
474 OGRFeature *poFeature,
477 OGRFeature *GetChartFirstM_COVR(
int &catcov, S57Reader *pENCReader,
478 S57ClassRegistrar *poRegistrar);
479 OGRFeature *GetChartNextM_COVR(
int &catcov, S57Reader *pENCReader);
480 bool CreateCOVRTables(S57Reader *pENCReader, S57ClassRegistrar *poRegistrar);
483 void CreateSENCRecord124(OGRFeature *pFeature,
Osenc_outstream *stream,
484 int mode, S57Reader *poReader);
485 void CreateSENCVectorEdgeTable(
Osenc_outstream *stream, S57Reader *poReader);
486 void CreateSENCConnNodeTable(
Osenc_outstream *stream, S57Reader *poReader);
488 bool CreateSENCRecord200(OGRFeature *pFeature,
Osenc_outstream *stream,
489 int mode, S57Reader *poReader);
490 bool WriteFIDRecord200(
Osenc_outstream *stream,
int nOBJL,
int featureID,
493 std::string payload);
498 bool CreateAreaFeatureGeometryRecord200(S57Reader *poReader,
499 OGRFeature *pFeature,
501 bool CreateLineFeatureGeometryRecord200(S57Reader *poReader,
502 OGRFeature *pFeature,
504 bool CreateMultiPointFeatureGeometryRecord200(OGRFeature *pFeature,
507 std::string GetFeatureAcronymFromTypecode(
int typeCode);
508 std::string GetAttributeAcronymFromTypecode(
int typeCode);
511 unsigned char **bytes_consumed);
512 bool CalculateExtent(S57Reader *poReader, S57ClassRegistrar *poRegistrar);
514 wxString errorMessage;
518 wxString m_FullPath000;
521 int m_senc_file_read_version;
522 int m_senc_file_create_version;
523 wxString m_read_base_edtn;
524 int m_read_last_applied_update;
528 wxDateTime m_date000;
535 int m_last_applied_update;
536 wxString m_LastUpdateDate;
538 wxString m_readFileCreateDate;
542 std::unordered_map<int, int> m_vector_helper_hash;
544 S57ClassRegistrar *m_poRegistrar;
545 wxArrayString m_tmpup_array;
547 wxGenericProgressDialog *m_ProgDialog;
549 unsigned char *pBuffer;
557 int *m_pCOVRTablePoints;
559 float **m_pCOVRTable;
562 int m_nNoCOVREntries;
563 int *m_pNoCOVRTablePoints;
565 float **m_pNoCOVRTable;
569 SENCFloatPtrArray m_AuxPtrArray;
570 std::vector<int> m_AuxCntArray;
571 SENCFloatPtrArray m_NoCovrPtrArray;
572 std::vector<int> m_NoCovrCntArray;
581 wxArrayString *m_UpFiles;
582 bool m_bPrivateRegistrar;