1 : /******************************************************************************
2 : *
3 : * Purpose: PCIDSK Vector Segment public interface. Declaration.
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 :
28 : #ifndef __INCLUDE_PCIDSK_VECTORSEGMENT_H
29 : #define __INCLUDE_PCIDSK_VECTORSEGMENT_H
30 :
31 : #include <string>
32 : #include <vector>
33 : #include <iterator>
34 : #include "pcidsk_shape.h"
35 :
36 : namespace PCIDSK
37 : {
38 : class ShapeIterator;
39 :
40 : /************************************************************************/
41 : /* PCIDSKVectorSegment */
42 : /************************************************************************/
43 :
44 : /**
45 : \brief Interface to PCIDSK vector segment.
46 :
47 : The vector segment contains a set of vector features with a common set
48 : of attribute data (fields). Each feature has a numeric identifier (ShapeId),
49 : a set of field values, and a set of geometric vertices. The layer as a
50 : whole has a description of the attribute fields, and an RST (Representation
51 : Style Table).
52 :
53 : The geometry and attribute fields of shapes can be fetched with the
54 : GetVertices() and GetFields() methods by giving the ShapeId of the desired
55 : feature. The set of shapeid's can be identified using the FindFirst(),
56 : and FindNext() methods or the STL compatible ShapeIterator (begin() and
57 : end() methods).
58 :
59 : The PCIDSKSegment interface for the segment can be used to fetch the
60 : LAYER_TYPE metadata describing how the vertices should be interpreted
61 : as a geometry. Some layers will also have a RingStart attribute field
62 : which is used in conjunction with the LAYER_TYPE to interprete the
63 : geometry. Some vector segments may have no LAYER_TYPE metadata in which
64 : case single vertices are interpreted as points, and multiple vertices
65 : as linestrings.
66 :
67 : More details are available in the GDB.HLP description of the GDB vector
68 : data model.
69 :
70 : Note that there are no mechanisms for fast spatial or attribute searches
71 : in a PCIDSK vector segment. Accessing features randomly (rather than
72 : in the order shapeids are returned by FindFirst()/FindNext() or ShapeIterator
73 : ) may result in reduced performance, and the use of large amounts of memory
74 : for large vector segments.
75 :
76 : */
77 :
78 : class PCIDSK_DLL PCIDSKVectorSegment
79 0 : {
80 : public:
81 0 : virtual ~PCIDSKVectorSegment() {}
82 :
83 : /**
84 : \brief Fetch RST.
85 :
86 : No attempt is made to parse the RST, it is up to the caller to decode it.
87 :
88 : NOTE: There is some header info on RST format that may be needed to do this
89 : for older RSTs.
90 :
91 : @return RST as a string.
92 : */
93 : virtual std::string GetRst() = 0;
94 :
95 :
96 : /**
97 : \brief Get field count.
98 :
99 : Note that this includes any system attributes, like RingStart, that would
100 : not normally be shown to the user.
101 :
102 : @return the number of attribute fields defined on this layer.
103 : */
104 :
105 : virtual int GetFieldCount() = 0;
106 :
107 : /**
108 : \brief Get field name.
109 :
110 : @param field_index index of the field requested from zero to GetFieldCount()-1.
111 : @return the field name.
112 : */
113 : virtual std::string GetFieldName(int field_index) = 0;
114 :
115 : /**
116 : \brief Get field description.
117 :
118 : @param field_index index of the field requested from zero to GetFieldCount()-1.
119 : @return the field description, often empty.
120 : */
121 : virtual std::string GetFieldDescription(int field_index) = 0;
122 :
123 : /**
124 : \brief Get field type.
125 :
126 : @param field_index index of the field requested from zero to GetFieldCount()-1.
127 : @return the field type.
128 : */
129 : virtual ShapeFieldType GetFieldType(int field_index) = 0;
130 :
131 : /**
132 : \brief Get field format.
133 :
134 : @param field_index index of the field requested from zero to GetFieldCount()-1.
135 : @return the field format as a C style format string suitable for use with printf.
136 : */
137 : virtual std::string GetFieldFormat(int field_index) = 0;
138 :
139 : /**
140 : \brief Get field default.
141 :
142 : @param field_index index of the field requested from zero to GetFieldCount()-1.
143 : @return the field default value.
144 : */
145 : virtual ShapeField GetFieldDefault(int field_index) = 0;
146 :
147 : /**
148 : \brief Get iterator to first shape.
149 : @return iterator.
150 : */
151 : virtual ShapeIterator begin() = 0;
152 :
153 : /**
154 : \brief Get iterator to end of shape lib (a wrapper for NullShapeId).
155 : @return iterator.
156 : */
157 : virtual ShapeIterator end() = 0;
158 :
159 : /**
160 : \brief Fetch first shapeid in the layer.
161 : @return first shape's shapeid.
162 : */
163 : virtual ShapeId FindFirst() = 0;
164 :
165 : /**
166 : \brief Fetch the next shape id after the indicated shape id.
167 : @param id the previous shapes id.
168 : @return next shape's shapeid.
169 : */
170 : virtual ShapeId FindNext(ShapeId id) = 0;
171 :
172 : /**
173 : \brief Fetch the vertices for the indicated shape.
174 : @param id the shape to fetch
175 : @param list the list is updated with the vertices for this shape.
176 : */
177 : virtual void GetVertices( ShapeId id,
178 : std::vector<ShapeVertex>& list ) = 0;
179 :
180 : /**
181 : \brief Fetch the fields for the indicated shape.
182 : @param id the shape to fetch
183 : @param list the field list is updated with the field values for this shape.
184 : */
185 : virtual void GetFields( ShapeId id,
186 : std::vector<ShapeField>& list ) = 0;
187 : };
188 :
189 : /************************************************************************/
190 : /* ShapeIterator */
191 : /************************************************************************/
192 :
193 : //! Iterator over shapeids in a vector segment.
194 :
195 : class ShapeIterator : public std::iterator<std::input_iterator_tag, ShapeId>
196 : {
197 : ShapeId id;
198 : PCIDSKVectorSegment *seg;
199 :
200 : public:
201 0 : ShapeIterator(PCIDSKVectorSegment *seg_in)
202 0 : : seg(seg_in) { id = seg->FindFirst(); }
203 0 : ShapeIterator(PCIDSKVectorSegment *seg_in, ShapeId id_in )
204 0 : : id(id_in), seg(seg_in) {}
205 : ShapeIterator(const ShapeIterator& mit) : id(mit.id), seg(mit.seg) {}
206 : ShapeIterator& operator++() { id=seg->FindNext(id); return *this;}
207 : ShapeIterator& operator++(int) { id=seg->FindNext(id); return *this;}
208 : bool operator==(const ShapeIterator& rhs) {return id == rhs.id;}
209 : bool operator!=(const ShapeIterator& rhs) {return id != rhs.id;}
210 : ShapeId& operator*() {return id;}
211 : };
212 :
213 : } // end namespace PCIDSK
214 :
215 : #endif // __INCLUDE_PCIDSK_VECTORSEGMENT_H
|