1 /****************************************************************************** 2 * $Id: org_sxf_defs.h 5112c658224b15f39f273fc70a7206df16155405 2016-10-24 15:03:26Z Kurt Schwehr $ 3 * 4 * Project: SXF Translator 5 * Purpose: Include file defining Records Structures for file reading and 6 * basic constants. 7 * Author: Ben Ahmed Daho Ali, bidandou(at)yahoo(dot)fr 8 * Dmitry Baryshnikov, polimax@mail.ru 9 * Alexandr Lisovenko, alexander.lisovenko@gmail.com 10 * 11 ****************************************************************************** 12 * Copyright (c) 2011, Ben Ahmed Daho Ali 13 * Copyright (c) 2013, NextGIS 14 * 15 * Permission is hereby granted, free of charge, to any person obtaining a 16 * copy of this software and associated documentation files (the "Software"), 17 * to deal in the Software without restriction, including without limitation 18 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 19 * and/or sell copies of the Software, and to permit persons to whom the 20 * Software is furnished to do so, subject to the following conditions: 21 * 22 * The above copyright notice and this permission notice shall be included 23 * in all copies or substantial portions of the Software. 24 * 25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 26 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 28 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 30 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 31 * DEALINGS IN THE SOFTWARE. 32 * 33 ****************************************************************************** 34 * Structure of the SXF file : 35 * ---------------------- 36 * - Header 37 * - Passport 38 * - Descriptor of data 39 * - Records 40 * - Title of the record 41 * - The certificate of the object (the geometry) 42 * - sub-objects 43 * - The graphic description of object 44 * - The description of the vector of the tying of the 3d- model of object 45 * - Semantics of object 46 * 47 * Notes : 48 * ------- 49 * Note 1. Flag of the state of data (2 bits): 50 * xxxxxx11- given in the state e (size of the exchange of data). 51 * 52 * Note 2. Flag of the correspondence to projection (1 bit): 53 * xxxxx0xx - do not correspond to the projection (i.e. map it can have turning 54 * relative to true position and certain deformation); 55 * xxxxx1xx - correspond to projection. 56 * 57 * Note 3. Flag of the presence of real coordinates (2 bits): 58 * xxx00xxx - entire certificate of objects is represented in the conditional 59 * system of coordinates (in the samples); 60 * xxx11xxx - entire certificate of objects is represented in the real coordinates 61 * in the locality in accordance with the specifications of sheet 62 * (projection, the coordinate system, unit of measurement), 63 * the data about the scale and the discretion of digitization bear 64 * reference nature. 65 * 66 * Note 4. Flag of the method of coding (2 bits): 67 * x00xxxxx - the classification codes of objects and semantic characteristics 68 * are represented by the decimal numbers, recorded in the binary 69 * form (for example: the code of the object "32100000" will be written 70 * down in the form 0x01E9CEA0, the code of semantics "253" - in the form 0x00FD). 71 * 72 * Note 5. Table of generalization (1 bit): 73 * 0xxxxxxx - the level of generalization is assigned according to the table of the 74 * general maps (it is described in Table 2.4); 75 * 1xxxxxxx - noload condition the level of generalization is assigned according to 76 * the table of the large-scale maps (it is described in Table 2.5). 77 * 78 * Note 6. Flag of coding the texts of the Texts objects (1 bytes): 79 * 0- in the coding ASCIIZ (Dos); 80 * 1- in the coding ANSI (Windows); 81 * 2- in the coding KOI-8 (Unix). 82 * 83 * Note 7. Flag of the accuracy of coordinates (1 bytes): 84 * 0 - are not established; 85 * 1 - the increased accuracy of storage of coordinates (meters, radians or degrees); 86 * 2 - of coordinate are recorded with an accuracy to centimeter (meters, 2 signs after comma); 87 * 3 - coordinates are recorded with an accuracy to millimeter (meters, 3 sign after comma). 88 * 89 * Note 8. Form of the framework (1 byte): 90 * -1- it is not established; 91 * 0- map is unconfined by the framework; 92 * 1- trapeziform without the salient points; 93 * 2- trapeziform with the salient points; 94 * 3- rectangular; 95 * 4- circular; 96 * 5- arbitrary. 97 * 98 * Note 9. Sign of output to the framework (4 bits): 99 * 0000xxxx - there are no outputs to the framework; 100 * 1000xxxx - northern framework; 101 * 0100xxxx - eastern framework; 102 * 0010xxxx - southern framework; 103 * 0001xxxx - western framework. 104 * 105 * Note 10. Size of the element of certificate (1 bit): 106 * xxxxx0xx - 2 bytes (for the integer value); 107 * 4 bytes (for the floating point); 108 * xxxxx1xx - 4 bytes (for the integer value); 109 * 8 bytes (for the floating point). 110 * 111 * Note 11. Sign of certificate with the text (1 bit): 112 * xxxx0xxx - certificate contains only the coordinates of points; 113 * xxxx1xxx - no-load condition certificate contains the text of signature, 114 * is allowed only for the objects of the type "signature" or 115 * "the template of signature". 116 * 117 * Note 12. [Masshtabiruemost] of drawing (sign) (1 bit): 118 * xx0xxxxx - arbitrary symbol of object not scaled; 119 * xx1xxxxx - the arbitrary symbol of object is scaled during the mapping. 120 * 121 * Note 13. Sign of the construction of spline on the certificate (2 bits): 122 * 00xxxxxx - the construction of spline with the visualization is not carried out; 123 * 01xxxxxx - smoothing out spline (cutting angles); 124 * 10xxxxxx - enveloping spline (it penetrates all points of certificate). 125 ****************************************************************************/ 126 127 #ifndef SXF_DEFS_H 128 #define SXF_DEFS_H 129 130 #define IDSXF 0x00465853 /* SXF */ 131 132 #define IDSXFDATA 0x00544144 /* DAT */ 133 #define IDSXFOBJ 0X7FFF7FFF /* Object */ 134 #define IDSXFGRAPH 0X7FFF7FFE /* graphics section */ 135 #define IDSXFVECT3D 0X7FFF7FFD /* 3D vector section */ 136 137 #include <map> 138 139 #include "cpl_port.h" 140 141 enum SXFDataState /* Flag of the state of the data (Note 1) */ 142 { 143 SXF_DS_UNKNOWN = 0, 144 SXF_DS_EXCHANGE = 8 145 }; 146 147 enum SXFCodingType /* Flag of the semantics coding type (Note 4) */ 148 { 149 SXF_SEM_DEC = 0, 150 SXF_SEM_HEX = 1, 151 SXF_SEM_TXT = 2 152 }; 153 154 enum SXFGeneralizationType /* Flag of the source for generalization data (Note 5) */ 155 { 156 SXF_GT_SMALL_SCALE = 0, 157 SXF_GT_LARGE_SCALE = 1 158 }; 159 160 enum SXFTextEncoding /* Flag of text encoding (Note 6) */ 161 { 162 SXF_ENC_DOS = 0, 163 SXF_ENC_WIN = 1, 164 SXF_ENC_KOI_8 = 2 165 }; 166 167 enum SXFCoordinatesAccuracy /* Flag of coordinate storing accuracy (Note 7) */ 168 { 169 SXF_COORD_ACC_UNDEFINED = 0, 170 SXF_COORD_ACC_HIGH = 1, //meters, radians or degree 171 SXF_COORD_ACC_CM = 2, //cantimeters 172 SXF_COORD_ACC_MM = 3, //millimeters 173 SXF_COORD_ACC_DM = 4 //decimeters 174 }; 175 176 typedef struct 177 { 178 // SXFDataState stDataState; /* Flag of the state of the data (Note 1) may be will be needed in future*/ 179 bool bProjectionDataCompliance; /* Flag of the correspondence to the projection (Note 2) */ 180 bool bRealCoordinatesCompliance; /* Flag of the presence of the real coordinates (Note 3) */ 181 SXFCodingType stCodingType; /* Flag of the semantics coding type (Note 4) */ 182 SXFGeneralizationType stGenType; /* Flag of the source for generalization data (Note 5) */ 183 SXFTextEncoding stEnc; /* Flag of text encoding (Note 6) */ 184 SXFCoordinatesAccuracy stCoordAcc; /* Flag of coordinate storing accuracy (Note 7) */ 185 bool bSort; 186 } SXFInformationFlags; 187 188 enum SXFCoordinateMeasUnit 189 { 190 SXF_COORD_MU_METRE = 1, 191 SXF_COORD_MU_DECIMETRE, 192 SXF_COORD_MU_CENTIMETRE, 193 SXF_COORD_MU_MILLIMETRE, 194 SXF_COORD_MU_DEGREE, 195 SXF_COORD_MU_RADIAN 196 } ; 197 198 typedef struct 199 { 200 double stProjCoords[8]; //X(0) & Y(1) South West, X(2) & Y(3) North West, X(4) & Y(5) North East, X(6) & Y(7) South East 201 double stGeoCoords[8]; 202 double stFrameCoords[8]; 203 OGREnvelope Env; 204 OGRSpatialReference *pSpatRef; 205 SXFCoordinateMeasUnit eUnitInPlan; 206 double dfXOr; 207 double dfYOr; 208 double dfFalseNorthing; 209 double dfFalseEasting; 210 GUInt32 nResolution; 211 double dfScale; 212 bool bIsRealCoordinates; 213 SXFCoordinatesAccuracy stCoordAcc; 214 215 } SXFMapDescription; 216 217 enum SXFCoordinateType 218 { 219 SXF_CT_RECTANGULAR = 0, 220 SXF_CT_GEODETIC 221 }; 222 223 /* 224 * List of SXF file format geometry types. 225 */ 226 enum SXFGeometryType 227 { 228 SXF_GT_Unknown = -1, 229 SXF_GT_Line = 0, /* MultiLineString geometric object */ 230 SXF_GT_Polygon = 1, /* Polygon geometric object */ 231 SXF_GT_Point = 2, /* MultiPoint geometric object */ 232 SXF_GT_Text = 3, /* LineString geometric object with associated label */ 233 SXF_GT_Vector = 4, /* Vector geometric object with associated label */ 234 SXF_GT_TextTemplate = 5, /* Text template */ 235 SXF_GT_VectorAngle = 21, /* Rotated symbol */ 236 SXF_GT_VectorScaled = 22 /* Scaled symbol */ 237 }; 238 239 enum SXFValueType 240 { 241 SXF_VT_SHORT = 0, /* 2 byte integer */ 242 SXF_VT_FLOAT = 1, /* 2 byte float */ 243 SXF_VT_INT = 2, /* 4 byte integer*/ 244 SXF_VT_DOUBLE = 3 /* 8 byte float */ 245 }; 246 247 typedef struct 248 { 249 SXFGeometryType eGeomType; // Geometry type (Note 1) 250 SXFValueType eValType; // size of values (Note 3) 251 int bFormat; // Has 3D vector (Note 4) /* Format of the certificate (0- linear size, 1-vector format ) */ 252 GByte bDim; // Dimensionality of the idea (0- 2D, 1- 3D) (Note 6) 253 bool bHasTextSign; // Sign of certificate with the text (Note 8) 254 GUInt32 nPointCount; // Point count 255 GUInt16 nSubObjectCount; // The sub object count 256 257 } SXFRecordDescription; 258 259 typedef struct{ 260 GUInt32 nID; /* Identifier of the beginning of record (0x7FFF7FFF) */ 261 GUInt32 nFullLength; /* The overall length of record (with the title) */ 262 GUInt32 nGeometryLength; /* Length of certificate (in bytes) */ 263 GUInt32 nClassifyCode; /* Classification code */ 264 GUInt16 anGroup[2]; /* 0 - group no, 1 - no in group */ 265 GByte nRef[3]; /* Reference data */ 266 GByte byPadding; 267 GUInt32 nPointCount; /* Point count */ 268 GUInt16 nSubObjectCount; /* The sub object count */ 269 GUInt16 nPointCountSmall; /* Point count in small geometries */ 270 } SXFRecordHeader; 271 272 typedef struct 273 { 274 GUInt16 nCode; //type 275 char nType; 276 char nScale; 277 } SXFRecordAttributeInfo; 278 279 enum SXFRecordAttributeType 280 { 281 SXF_RAT_ASCIIZ_DOS = 0, //text in DOS encoding 282 SXF_RAT_ONEBYTE = 1, //number 1 byte 283 SXF_RAT_TWOBYTE = 2, //number 2 byte 284 SXF_RAT_FOURBYTE = 4, //number 4 byte 285 SXF_RAT_EIGHTBYTE = 8, //float point number 8 byte 286 SXF_RAT_ANSI_WIN = 126, //text in Win encoding 287 SXF_RAT_UNICODE = 127, //text in unicode 288 SXF_RAT_BIGTEXT = 128 //text more than 255 chars 289 }; 290 291 /************************************************************************/ 292 /* SXFPassport */ 293 /************************************************************************/ 294 295 typedef struct{ 296 GUInt16 nYear, nMonth, nDay; 297 } SXFDate; 298 299 struct SXFPassport 300 { 301 GUInt32 version; 302 SXFDate dtCrateDate; 303 CPLString sMapSheet; 304 GUInt32 nScale; 305 CPLString sMapSheetName; 306 SXFInformationFlags informationFlags; 307 SXFMapDescription stMapDescription; 308 }; 309 310 typedef struct 311 { 312 char szID[4]; //the file ID should be "SXF" 313 GUInt32 nHeaderLength; //the Header length 314 GByte nFormatVersion[4]; //the format version (e.g. 4) 315 GUInt32 nCheckSum; //check sum 316 } SXFHeader; 317 318 /************************************************************************/ 319 /* RSCInfo */ 320 /************************************************************************/ 321 322 /* 323 RSC File record 324 */ 325 typedef struct { 326 GUInt32 nOffset; //RSC Section offset in bytes from the beginning of the RSC file 327 GUInt32 nLength; //RSC Section record length 328 GUInt32 nRecordCount; //count of records in the section 329 } RSCSection; 330 331 /* 332 RSC File header 333 */ 334 typedef struct{ 335 char szID[4]; 336 GUInt32 nFileLength; 337 GUInt32 nVersion; 338 GUInt32 nEncoding; 339 GUInt32 nFileState; 340 GUInt32 nFileModState; 341 GUInt32 nLang; //1 - en, 2 - rus 342 GUInt32 nNextID; 343 GByte date[8]; 344 char szMapType[32]; 345 char szClassifyName[32]; 346 char szClassifyCode[8]; 347 GUInt32 nScale; 348 char nScales[4]; 349 RSCSection Objects; 350 RSCSection Semantic; 351 RSCSection ClassifySemantic; 352 RSCSection Defaults; 353 RSCSection Semantics; 354 RSCSection Layers; 355 RSCSection Limits; 356 RSCSection Parameters; 357 RSCSection Print; 358 RSCSection Palettes; 359 RSCSection Fonts; 360 RSCSection Libs; 361 RSCSection ImageParams; 362 RSCSection Tables; 363 GByte nFlagKeysAsCodes; 364 GByte nFlagPaletteMods; 365 GByte Reserved[30]; 366 GUInt32 nFontEnc; 367 GUInt32 nColorsInPalette; 368 } RSCHeader; 369 370 #endif /* SXF_DEFS_H */ 371