/src/gdal/frmts/pcidsk/sdk/segment/cpcidskvectorsegment.h
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Purpose: Declaration of the CPCIDSKVectorSegment class. |
4 | | * |
5 | | ****************************************************************************** |
6 | | * Copyright (c) 2009 |
7 | | * PCI Geomatics, 90 Allstate Parkway, Markham, Ontario, Canada. |
8 | | * |
9 | | * SPDX-License-Identifier: MIT |
10 | | ****************************************************************************/ |
11 | | #ifndef INCLUDE_SEGMENT_PCIDSKVECTORSEGMENT_H |
12 | | #define INCLUDE_SEGMENT_PCIDSKVECTORSEGMENT_H |
13 | | |
14 | | #include "pcidsk_config.h" |
15 | | #include "pcidsk_types.h" |
16 | | #include "pcidsk_vectorsegment.h" |
17 | | #include "pcidsk_buffer.h" |
18 | | #include "segment/cpcidsksegment.h" |
19 | | #include "segment/vecsegheader.h" |
20 | | #include "segment/vecsegdataindex.h" |
21 | | |
22 | | #include <string> |
23 | | #include <map> |
24 | | |
25 | | namespace PCIDSK |
26 | | { |
27 | | class PCIDSKFile; |
28 | | |
29 | | const int sec_vert = 0; |
30 | | const int sec_record = 1; |
31 | | const int sec_raw = 2; |
32 | | |
33 | | /************************************************************************/ |
34 | | /* CPCIDSKVectorSegment */ |
35 | | /************************************************************************/ |
36 | | |
37 | | class CPCIDSKVectorSegment final: virtual public CPCIDSKSegment, |
38 | | public PCIDSKVectorSegment |
39 | | { |
40 | | friend class VecSegHeader; |
41 | | friend class VecSegDataIndex; |
42 | | |
43 | | public: |
44 | | CPCIDSKVectorSegment( PCIDSKFile *file, int segment, |
45 | | const char *segment_pointer ); |
46 | | |
47 | | ~CPCIDSKVectorSegment() override; |
48 | | |
49 | | void Initialize() override; |
50 | | void Synchronize() override; |
51 | | |
52 | 0 | std::string GetRst() override { return ""; } |
53 | | std::vector<double> GetProjection( std::string &geosys ) override; |
54 | | void SetProjection(const std::string& geosys, |
55 | | const std::vector<double>& params) override; |
56 | | |
57 | | int GetFieldCount() override; |
58 | | std::string GetFieldName(int) override; |
59 | | std::string GetFieldDescription(int) override; |
60 | | ShapeFieldType GetFieldType(int) override; |
61 | | std::string GetFieldFormat(int) override; |
62 | | ShapeField GetFieldDefault(int) override; |
63 | | |
64 | 0 | ShapeIterator begin() override { return ShapeIterator(this); } |
65 | 0 | ShapeIterator end() override { return ShapeIterator(this,NullShapeId); } |
66 | | |
67 | | ShapeId FindFirst() override; |
68 | | ShapeId FindNext(ShapeId) override; |
69 | | |
70 | | int GetShapeCount() override; |
71 | | |
72 | | void GetVertices( ShapeId, std::vector<ShapeVertex>& ) override; |
73 | | void GetFields( ShapeId, std::vector<ShapeField>& ) override; |
74 | | |
75 | | void AddField( const std::string& name, ShapeFieldType type, |
76 | | const std::string& description, |
77 | | const std::string& format, |
78 | | ShapeField *default_value ) override; |
79 | | |
80 | | ShapeId CreateShape( ShapeId id ) override; |
81 | | void DeleteShape( ShapeId id ) override; |
82 | | void SetVertices( ShapeId id, |
83 | | const std::vector<ShapeVertex>& list ) override; |
84 | | void SetFields( ShapeId id, |
85 | | const std::vector<ShapeField>& list ) override; |
86 | | |
87 | | std::string ConsistencyCheck() override; |
88 | | |
89 | | // Essentially internal stuff. |
90 | | char *GetData( int section, uint32 offset, |
91 | | int *bytes_available = nullptr, |
92 | | int min_bytes = 0, |
93 | | bool update = false ); |
94 | | uint32 ReadField( uint32 offset, |
95 | | ShapeField& field, |
96 | | ShapeFieldType field_type, |
97 | | int section = sec_record ); |
98 | | |
99 | | uint32 WriteField( uint32 offset, |
100 | | const ShapeField& field, |
101 | | PCIDSKBuffer &buffer ); |
102 | | void ReadSecFromFile( int section, char *buffer, |
103 | | int block_offset, |
104 | | int block_count ); |
105 | | void WriteSecToFile( int section, char *buffer, |
106 | | int block_offset, |
107 | | int block_count ); |
108 | | |
109 | | private: |
110 | | bool base_initialized; |
111 | | bool needs_swap; |
112 | | |
113 | | VecSegHeader vh; |
114 | | VecSegDataIndex di[2]; |
115 | | |
116 | | int32 total_shape_count; |
117 | | int32 valid_shape_count; |
118 | | ShapeId highest_shapeid_used; |
119 | | //ShapeId first_shape_id; |
120 | | //ShapeId last_shape_id; |
121 | | |
122 | | int32 shape_index_start; // index of first shape |
123 | | std::vector<int32> shape_index_ids; // loaded shape ids. |
124 | | std::vector<uint32> shape_index_vertex_off; // loaded vertex offsets |
125 | | std::vector<uint32> shape_index_record_off; // loaded record offsets. |
126 | | bool shape_index_page_dirty; |
127 | | |
128 | | ShapeId last_shapes_id; |
129 | | int last_shapes_index; |
130 | | |
131 | | bool shapeid_map_active; |
132 | | std::map<ShapeId,int> shapeid_map; |
133 | | int shapeid_pages_certainly_mapped; |
134 | | |
135 | | void AccessShapeByIndex( int iIndex ); |
136 | | int IndexFromShapeId( ShapeId id ); |
137 | | void LoadShapeIdPage( int page ); |
138 | | void FlushLoadedShapeIndex(); |
139 | | void PushLoadedIndexIntoMap(); |
140 | | void PopulateShapeIdMap(); |
141 | | |
142 | | // Cached buffers for GetData(); |
143 | | PCIDSKBuffer raw_loaded_data; |
144 | | uint32 raw_loaded_data_offset; |
145 | | bool raw_loaded_data_dirty; |
146 | | |
147 | | PCIDSKBuffer vert_loaded_data; |
148 | | uint32 vert_loaded_data_offset; |
149 | | bool vert_loaded_data_dirty; |
150 | | |
151 | | PCIDSKBuffer record_loaded_data; |
152 | | uint32 record_loaded_data_offset; |
153 | | bool record_loaded_data_dirty; |
154 | | |
155 | | bool vh_dirty = false; |
156 | | |
157 | | void FlushDataBuffer( int section ); |
158 | | void LoadHeader(); |
159 | | void FlushSegHeaderIfNeeded(); |
160 | | |
161 | | std::string ConsistencyCheck_Header(); |
162 | | std::string ConsistencyCheck_DataIndices(); |
163 | | std::string ConsistencyCheck_ShapeIndices(); |
164 | | |
165 | | ShapeId FindNextValidByIndex(int nIndex); |
166 | | }; |
167 | | } // end namespace PCIDSK |
168 | | |
169 | | #endif // INCLUDE_SEGMENT_VECTORSEGMENT_H |