1 : /******************************************************************************
2 : *
3 : * Purpose: Declaration of the CPCIDSKVectorSegment class.
4 : *
5 : ******************************************************************************
6 : * Copyright (c) 2009
7 : * PCI Geomatics, 50 West Wilmot Street, Richmond Hill, Ont, Canada
8 : *
9 : * Permission is hereby granted, free of charge, to any person obtaining a
10 : * copy of this software and associated documentation files (the "Software"),
11 : * to deal in the Software without restriction, including without limitation
12 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 : * and/or sell copies of the Software, and to permit persons to whom the
14 : * Software is furnished to do so, subject to the following conditions:
15 : *
16 : * The above copyright notice and this permission notice shall be included
17 : * in all copies or substantial portions of the Software.
18 : *
19 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 : * DEALINGS IN THE SOFTWARE.
26 : ****************************************************************************/
27 : #ifndef __INCLUDE_SEGMENT_PCIDSKVECTORSEGMENT_H
28 : #define __INCLUDE_SEGMENT_PCIDSKVECTORSEGMENT_H
29 :
30 : #include "pcidsk_config.h"
31 : #include "pcidsk_types.h"
32 : #include "pcidsk_vectorsegment.h"
33 : #include "pcidsk_buffer.h"
34 : #include "segment/cpcidsksegment.h"
35 : #include "segment/vecsegheader.h"
36 : #include "segment/vecsegdataindex.h"
37 :
38 : #include <string>
39 : #include <map>
40 :
41 : namespace PCIDSK
42 : {
43 : class PCIDSKFile;
44 :
45 : const int sec_vert = 0;
46 : const int sec_record = 1;
47 : const int sec_raw = 2;
48 :
49 : /************************************************************************/
50 : /* CPCIDSKVectorSegment */
51 : /************************************************************************/
52 :
53 : class CPCIDSKVectorSegment : virtual public CPCIDSKSegment,
54 : public PCIDSKVectorSegment
55 : {
56 : friend class VecSegHeader;
57 : friend class VecSegDataIndex;
58 :
59 : public:
60 : CPCIDSKVectorSegment( PCIDSKFile *file, int segment,
61 : const char *segment_pointer );
62 :
63 : virtual ~CPCIDSKVectorSegment();
64 :
65 : void Initialize();
66 : void Synchronize();
67 :
68 0 : std::string GetRst() { return ""; }
69 : std::vector<double> GetProjection( std::string &geosys );
70 : void SetProjection(std::string geosys,
71 : std::vector<double> parms);
72 :
73 : int GetFieldCount();
74 : std::string GetFieldName(int);
75 : std::string GetFieldDescription(int);
76 : ShapeFieldType GetFieldType(int);
77 : std::string GetFieldFormat(int);
78 : ShapeField GetFieldDefault(int);
79 :
80 14 : ShapeIterator begin() { return ShapeIterator(this); }
81 974 : ShapeIterator end() { return ShapeIterator(this,NullShapeId); }
82 :
83 : ShapeId FindFirst();
84 : ShapeId FindNext(ShapeId);
85 :
86 : int GetShapeCount();
87 :
88 : void GetVertices( ShapeId, std::vector<ShapeVertex>& );
89 : void GetFields( ShapeId, std::vector<ShapeField>& );
90 :
91 : void AddField( std::string name, ShapeFieldType type,
92 : std::string description,
93 : std::string format,
94 : ShapeField *default_value );
95 :
96 : ShapeId CreateShape( ShapeId id );
97 : void DeleteShape( ShapeId id );
98 : void SetVertices( ShapeId id,
99 : const std::vector<ShapeVertex>& list );
100 : void SetFields( ShapeId id,
101 : const std::vector<ShapeField>& list );
102 :
103 : std::string ConsistencyCheck();
104 :
105 : // Essentially internal stuff.
106 : char *GetData( int section, uint32 offset,
107 : int *bytes_available = NULL,
108 : int min_bytes = 0,
109 : bool update = false );
110 : uint32 ReadField( uint32 offset,
111 : ShapeField& field,
112 : ShapeFieldType field_type,
113 : int section = sec_record );
114 :
115 : uint32 WriteField( uint32 offset,
116 : const ShapeField& field,
117 : PCIDSKBuffer &buffer );
118 : void ReadSecFromFile( int section, char *buffer,
119 : int block_offset,
120 : int block_count );
121 : void WriteSecToFile( int section, char *buffer,
122 : int block_offset,
123 : int block_count );
124 :
125 : private:
126 : bool base_initialized;
127 : bool needs_swap;
128 :
129 : VecSegHeader vh;
130 : VecSegDataIndex di[2];
131 :
132 : int32 shape_count;
133 : ShapeId highest_shapeid_used;
134 : //ShapeId first_shape_id;
135 : //ShapeId last_shape_id;
136 :
137 : int32 shape_index_start; // index of first shape
138 : std::vector<int32> shape_index_ids; // loaded shape ids.
139 : std::vector<uint32> shape_index_vertex_off; // loaded vertex offsets
140 : std::vector<uint32> shape_index_record_off; // loaded record offsets.
141 : bool shape_index_page_dirty;
142 :
143 : ShapeId last_shapes_id;
144 : int last_shapes_index;
145 :
146 : bool shapeid_map_active;
147 : std::map<ShapeId,int> shapeid_map;
148 : int shapeid_pages_certainly_mapped;
149 :
150 : void AccessShapeByIndex( int iIndex );
151 : int IndexFromShapeId( ShapeId id );
152 : void LoadShapeIdPage( int page );
153 : void FlushLoadedShapeIndex();
154 : void PushLoadedIndexIntoMap();
155 : void PopulateShapeIdMap();
156 :
157 : // Cached buffers for GetData();
158 : PCIDSKBuffer raw_loaded_data;
159 : uint32 raw_loaded_data_offset;
160 : bool raw_loaded_data_dirty;
161 :
162 : PCIDSKBuffer vert_loaded_data;
163 : uint32 vert_loaded_data_offset;
164 : bool vert_loaded_data_dirty;
165 :
166 : PCIDSKBuffer record_loaded_data;
167 : uint32 record_loaded_data_offset;
168 : bool record_loaded_data_dirty;
169 :
170 : void FlushDataBuffer( int section );
171 : void LoadHeader();
172 :
173 : std::string ConsistencyCheck_Header();
174 : std::string ConsistencyCheck_DataIndices();
175 : std::string ConsistencyCheck_ShapeIndices();
176 : };
177 : } // end namespace PCIDSK
178 :
179 : #endif // __INCLUDE_SEGMENT_VECTORSEGMENT_H
|