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 :
36 : #include <string>
37 : #include <map>
38 :
39 : namespace PCIDSK
40 : {
41 : class PCIDSKFile;
42 :
43 : /************************************************************************/
44 : /* CPCIDSKVectorSegment */
45 : /************************************************************************/
46 :
47 : class CPCIDSKVectorSegment : public CPCIDSKSegment,
48 : public PCIDSKVectorSegment
49 : {
50 : public:
51 : CPCIDSKVectorSegment( PCIDSKFile *file, int segment,
52 : const char *segment_pointer );
53 :
54 : virtual ~CPCIDSKVectorSegment();
55 :
56 0 : std::string GetRst() { return ""; }
57 :
58 : int GetFieldCount();
59 : std::string GetFieldName(int);
60 : std::string GetFieldDescription(int);
61 : ShapeFieldType GetFieldType(int);
62 : std::string GetFieldFormat(int);
63 : ShapeField GetFieldDefault(int);
64 :
65 0 : ShapeIterator begin() { return ShapeIterator(this); }
66 0 : ShapeIterator end() { return ShapeIterator(this,NullShapeId); }
67 :
68 : ShapeId FindFirst();
69 : ShapeId FindNext(ShapeId);
70 :
71 : void GetVertices( ShapeId, std::vector<ShapeVertex>& );
72 : void GetFields( ShapeId, std::vector<ShapeField>& );
73 :
74 : private:
75 : bool base_initialized;
76 : bool needs_swap;
77 :
78 : uint32 section_offsets[4];
79 :
80 : // Field Definitions
81 : std::vector<std::string> field_names;
82 : std::vector<std::string> field_descriptions;
83 : std::vector<ShapeFieldType> field_types;
84 : std::vector<std::string> field_formats;
85 : std::vector<ShapeField> field_defaults;
86 :
87 : // Information from the Shape Section of the header.
88 : bool vertex_block_initialized;
89 : uint32 vertex_block_count;
90 : uint32 vertex_bytes;
91 : std::vector<uint32> vertex_block_index;
92 :
93 : bool record_block_initialized;
94 : uint32 record_block_count;
95 : uint32 record_bytes;
96 : std::vector<uint32> record_block_index;
97 :
98 : int32 shape_count;
99 : //ShapeId first_shape_id;
100 : //ShapeId last_shape_id;
101 :
102 : uint32 shape_index_byte_offset; // within segment
103 : int32 shape_index_start; // index of first shape
104 : std::vector<int32> shape_index_ids; // loaded shape ids.
105 : std::vector<uint32> shape_index_vertex_off; // loaded vertex offsets
106 : std::vector<uint32> shape_index_record_off; // loaded record offsets.
107 :
108 : ShapeId last_shapes_id;
109 : int last_shapes_index;
110 :
111 : bool shapeid_map_active;
112 : std::map<ShapeId,int> shapeid_map;
113 : int shapeid_pages_certainly_mapped;
114 :
115 : void AccessShapeByIndex( int iIndex );
116 : int IndexFromShapeId( ShapeId id );
117 :
118 : // Cached buffers for GetData();
119 : PCIDSKBuffer raw_loaded_data;
120 : uint32 raw_loaded_data_offset;
121 :
122 : PCIDSKBuffer vert_loaded_data;
123 : uint32 vert_loaded_data_offset;
124 :
125 : PCIDSKBuffer record_loaded_data;
126 : uint32 record_loaded_data_offset;
127 :
128 : static const int sec_raw ;
129 : static const int sec_vert;
130 : static const int sec_record;
131 :
132 : char *GetData( int section, uint32 offset,
133 : int *bytes_available = NULL,
134 : int min_bytes = 0 );
135 : void ReadSecFromFile( int section, char *buffer,
136 : int block_offset,
137 : int block_count );
138 : void Initialize();
139 :
140 : uint32 ReadField( uint32 offset,
141 : ShapeField& field,
142 : ShapeFieldType field_type,
143 : int section = sec_record );
144 : };
145 : } // end namespace PCIDSK
146 :
147 : #endif // __INCLUDE_SEGMENT_VECTORSEGMENT_H
|