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 41 class S57Reader; 42 43 char **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 99 /************************************************************************/ 100 /* DDFRecordIndex */ 101 /* */ 102 /* Maintain an index of DDF records based on an integer key. */ 103 /************************************************************************/ 104 105 typedef struct 106 { 107 int nKey; 108 DDFRecord *poRecord; 109 } DDFIndexedRecord; 110 111 class DDFRecordIndex 112 { 113 int bSorted; 114 115 int nRecordCount; 116 int nRecordMax; 117 118 int nLastObjlPos; /* rjensen. added for FindRecordByObjl() */ 119 int nLastObjl; /* rjensen. added for FindRecordByObjl() */ 120 121 DDFIndexedRecord *pasRecords; 122 123 void Sort(); 124 125 public: 126 DDFRecordIndex(); 127 ~DDFRecordIndex(); 128 129 void AddRecord( int nKey, DDFRecord * ); 130 int RemoveRecord( int nKey ); 131 132 DDFRecord *FindRecord( int nKey ); 133 134 DDFRecord *FindRecordByObjl( int nObjl ); /* rjensen. added for FindRecordByObjl() */ 135 136 void Clear(); 137 GetCount()138 int GetCount() { return nRecordCount; } 139 DDFRecord *GetByIndex( int i ); 140 }; 141 142 /************************************************************************/ 143 /* S57Reader */ 144 /************************************************************************/ 145 typedef bool (*CallBackFunction)(void); 146 147 class S57Reader 148 { 149 S57ClassRegistrar *poRegistrar; 150 151 int nFDefnCount; 152 OGRFeatureDefn **papoFDefnList; 153 154 char *pszModuleName; 155 char *pszDSNM; 156 157 DDFModule *poModule; 158 159 int nCOMF; /* Coordinate multiplier */ 160 int nSOMF; /* Vertical (sounding) multiplier */ 161 int nCSCL; /* Chart Scale (from DSPM record) */ 162 163 int bFileIngested; 164 DDFRecordIndex oVI_Index; 165 DDFRecordIndex oVC_Index; 166 DDFRecordIndex oVE_Index; 167 DDFRecordIndex oVF_Index; 168 169 int nNextVIIndex; 170 int nNextVCIndex; 171 int nNextVEIndex; 172 int nNextVFIndex; 173 174 int nNextFEIndex; 175 DDFRecordIndex oFE_Index; 176 177 char **papszOptions; 178 179 int nOptionFlags; 180 181 int iPointOffset; 182 OGRFeature *poMultiPoint; 183 184 void ClearPendingMultiPoint(); 185 OGRFeature *NextPendingMultiPoint(); 186 187 OGRFeature *AssembleFeature( DDFRecord *, OGRFeatureDefn * ); 188 189 void ApplyObjectClassAttributes( DDFRecord *, OGRFeature *); 190 void GenerateLNAMAndRefs( DDFRecord *, OGRFeature * ); 191 void GenerateFSPTAttributes( DDFRecord *, OGRFeature * ); 192 193 void AssembleSoundingGeometry( DDFRecord *, OGRFeature * ); 194 void AssemblePointGeometry( DDFRecord *, OGRFeature * ); 195 void AssembleLineGeometry( DDFRecord *, OGRFeature * ); 196 void AssembleAreaGeometry( DDFRecord *, OGRFeature * ); 197 198 199 OGRFeatureDefn *FindFDefn( DDFRecord * ); 200 int ParseName( DDFField *, int = 0, int * = NULL ); 201 202 int ApplyRecordUpdate( DDFRecord *, DDFRecord * ); 203 204 int bMissingWarningIssued; 205 int bAttrWarningIssued; 206 207 int Nall; 208 int Aall; 209 210 211 public: 212 S57Reader( const char * ); 213 ~S57Reader(); 214 215 int FetchPoint( int, int, 216 double *, double *, double * = NULL, int * = NULL ); 217 218 void SetClassBased( S57ClassRegistrar * ); 219 void SetOptions( char ** ); GetOptionFlags()220 int GetOptionFlags() { return nOptionFlags; } 221 222 int Open( int bTestOpen ); 223 void Close(); GetModule()224 DDFModule *GetModule() { return poModule; } GetDSNM()225 const char *GetDSNM() { return pszDSNM; } GetCSCL()226 int GetCSCL() { return nCSCL; } 227 228 int Ingest(CallBackFunction pcallback = NULL); 229 int ApplyUpdates( DDFModule *, int ); 230 int FindAndApplyUpdates( const char *pszPath=NULL ); 231 232 void Rewind(); 233 OGRFeature *ReadNextFeature( OGRFeatureDefn * = NULL ); 234 OGRFeature *ReadFeature( int nFID, OGRFeatureDefn * = NULL ); 235 OGRFeature *ReadVector( int nFID, int nRCNM ); 236 237 int GetNextFEIndex( int nRCNM = 100 ); 238 void SetNextFEIndex( int nNewIndex, int nRCNM = 100 ); 239 240 void AddFeatureDefn( OGRFeatureDefn * ); 241 242 int CollectClassList( int *, int); 243 244 OGRErr GetExtent( OGREnvelope *psExtent, int bForce ); 245 GetNall()246 int GetNall(){ return Nall; } GetAall()247 int GetAall(){ return Aall; } 248 GetFeatureCount()249 int GetFeatureCount() { return oFE_Index.GetCount(); } 250 251 }; 252 253 /************************************************************************/ 254 /* S57Writer */ 255 /************************************************************************/ 256 257 class S57Writer 258 { 259 public: 260 S57Writer(); 261 ~S57Writer(); 262 263 void SetClassBased( S57ClassRegistrar * ); 264 int CreateS57File( const char *pszFilename ); 265 int Close(); 266 267 int WriteGeometry( DDFRecord *, int, double *, double *, 268 double * ); 269 int WriteATTF( DDFRecord *, OGRFeature * ); 270 int WritePrimitive( OGRFeature *poFeature ); 271 int WriteCompleteFeature( OGRFeature *poFeature ); 272 int WriteDSID( const char *pszDSNM = NULL, 273 const char *pszISDT = NULL, 274 const char *pszSTED = NULL, 275 int nAGEN = 0, 276 const char *pszCOMT = NULL ); 277 int WriteDSPM( int nScale = 0 ); 278 279 private: 280 DDFModule *poModule; 281 S57ClassRegistrar *poRegistrar; 282 283 int nNext0001Index; 284 285 DDFRecord *MakeRecord(); 286 287 int nCOMF; /* Coordinate multiplier */ 288 int nSOMF; /* Vertical (sounding) multiplier */ 289 }; 290 291 /* -------------------------------------------------------------------- */ 292 /* Functions to create OGRFeatureDefns. */ 293 /* -------------------------------------------------------------------- */ 294 void CPL_DLL S57GenerateStandardAttributes( OGRFeatureDefn *, int ); 295 OGRFeatureDefn CPL_DLL *S57GenerateGeomFeatureDefn( OGRwkbGeometryType, int ); 296 OGRFeatureDefn CPL_DLL *S57GenerateObjectClassDefn( S57ClassRegistrar *, 297 int, int ); 298 OGRFeatureDefn CPL_DLL *S57GenerateVectorPrimitiveFeatureDefn( int, int ); 299 300 #endif /* ndef _S57_H_INCLUDED */ 301