8 #ifndef VTDATA_FEATURES
9 #define VTDATA_FEATURES
11 #include "shapelib/shapefil.h"
12 #include "ogrsf_frmts.h"
47 Field(
const char *name, FieldType ftype);
51 void SetNumRecords(
int iNum);
53 void SetValue(uint iRecord,
const char *
string);
54 void SetValue(uint iRecord,
int value);
55 void SetValue(uint iRecord,
double value);
56 void SetValue(uint iRecord,
bool value);
58 void GetValue(uint iRecord,
vtString &
string);
59 void GetValue(uint iRecord,
short &value);
60 void GetValue(uint iRecord,
int &value);
61 void GetValue(uint iRecord,
float &value);
62 void GetValue(uint iRecord,
double &value);
63 void GetValue(uint iRecord,
bool &value);
65 void CopyValue(uint FromRecord,
int ToRecord);
66 void GetValueAsString(uint iRecord,
vtString &str);
67 void SetValueFromString(uint iRecord,
const vtString &str);
68 void SetValueFromString(uint iRecord,
const char *str);
71 int m_width, m_decimals;
79 vtStringArray m_string;
83 const char *DescribeFieldType(FieldType type);
84 const char *DescribeFieldType(DBFFieldType type);
85 DBFFieldType ConvertFieldType(FieldType type);
86 FieldType ConvertFieldType(DBFFieldType type);
112 bool SaveToSHP(
const char *filename,
bool progress_callback(
int)=0)
const;
113 bool LoadFromOGR(OGRLayer *pLayer,
bool progress_callback(
int)=0);
114 virtual void LoadGeomFromSHP(
SHPHandle hSHP,
bool progress_callback(
int)=0) = 0;
115 bool LoadFromSHP(
const char *fname,
bool progress_callback(
int)=0);
116 bool LoadDataFromDBF(
const char *filename,
bool progress_callback(
int)=0);
118 bool LoadDataFromCSV(
const char *filename,
bool progress_callback(
int)=0);
119 bool SaveToKML(
const char *filename,
bool progress_callback(
int)=0)
const;
121 void SetFilename(
const vtString &str) { m_strFilename = str; }
122 vtString GetFilename()
const {
return m_strFilename; }
125 virtual uint GetNumEntities()
const = 0;
127 void AllocateFeatures();
135 virtual void Reserve(
int iNum) = 0;
136 virtual bool ComputeExtent(
DRECT &rect)
const = 0;
137 virtual void Offset(
const DPoint2 &p,
bool bSelectedOnly =
false) = 0;
138 virtual bool TransformCoords(OCT *pTransform,
bool progress_callback(
int)=0) = 0;
139 virtual bool AppendGeometryFrom(
vtFeatureSet *pFromSet) = 0;
140 virtual int NumTotalVertices()
const {
return 0; }
143 void SetToDelete(
int iFeature);
144 void ApplyDeletion();
147 void Select(uint iEnt,
bool set =
true)
150 m_Features[iEnt]->flags |= FF_SELECTED;
152 m_Features[iEnt]->flags &= ~FF_SELECTED;
154 bool IsSelected(uint iEnt)
156 return ((m_Features[iEnt]->flags & FF_SELECTED) != 0);
158 uint NumSelected()
const;
160 void InvertSelection();
161 int SelectByCondition(
int iField,
int iCondition,
const char *szValue);
162 void DeleteSelected();
163 bool IsDeleted(uint iEnt)
165 return ((m_Features[iEnt]->flags & FF_DELETE) != 0);
167 int DoBoxSelect(
const DRECT &rect, SelectionType st);
170 void Pick(uint iEnt,
bool set =
true)
173 m_Features[iEnt]->flags |= FF_PICKED;
175 m_Features[iEnt]->flags &= ~FF_PICKED;
177 bool IsPicked(uint iEnt)
179 return ((m_Features[iEnt]->flags & FF_PICKED) != 0);
184 uint GetNumFields()
const {
return m_fields.GetSize(); }
185 Field *GetField(
int i) {
return m_fields.
GetAt(i); }
186 const Field *GetField(
int i)
const {
return m_fields.
GetAt(i); }
187 Field *GetField(
const char *name);
189 int AddField(
const char *name, FieldType ftype,
int string_length = 40);
193 void SetValue(uint record, uint field,
const char *
string);
194 void SetValue(uint record, uint field,
int value);
195 void SetValue(uint record, uint field,
double value);
196 void SetValue(uint record, uint field,
bool value);
198 void GetValueAsString(uint record, uint field,
vtString &str)
const;
199 void SetValueFromString(uint iRecord, uint iField,
const vtString &str);
200 void SetValueFromString(uint iRecord, uint iField,
const char *str);
202 int GetIntegerValue(uint iRecord, uint iField)
const;
203 short GetShortValue(uint iRecord, uint iField)
const;
204 float GetFloatValue(uint iRecord, uint iField)
const;
205 double GetDoubleValue(uint iRecord, uint iField)
const;
206 bool GetBoolValue(uint iRecord, uint iField)
const;
208 void SetProjection(
const vtProjection &proj) { m_proj = proj; }
211 vtFeature *GetFeature(uint iIndex)
const {
return m_Features[iIndex]; }
215 virtual bool IsInsideRect(
int iElem,
const DRECT &rect) = 0;
216 virtual void CopyGeometry(uint from, uint to) = 0;
217 virtual void SaveGeomToSHP(
SHPHandle hSHP,
bool progress_callback(
int)=0)
const = 0;
218 virtual void SetNumGeometries(
int iNum) = 0;
220 void CopyEntity(uint from, uint to);
222 void ParseDBFRecords(
DBFHandle db,
bool progress_callback(
int)=0);
224 OGRwkbGeometryType m_eGeomType;
227 std::vector<vtFeature*> m_Features;
244 uint GetNumEntities()
const;
245 void SetNumGeometries(
int iNum);
247 bool ComputeExtent(
DRECT &rect)
const;
248 void Offset(
const DPoint2 &p,
bool bSelectedOnly =
false);
249 bool TransformCoords(OCT *pTransform,
bool progress_callback(
int)=0);
252 int AddPoint(
const DPoint2 &p);
253 void SetPoint(uint num,
const DPoint2 &p);
254 DPoint2 &GetPoint(uint num) {
return m_Point2[num]; }
255 const DPoint2 &GetPoint(uint num)
const {
return m_Point2[num]; }
257 int FindClosestPoint(
const DPoint2 &p,
double epsilon);
259 void GetPoint(uint num,
DPoint2 &p)
const;
262 virtual bool IsInsideRect(
int iElem,
const DRECT &rect);
263 virtual void CopyGeometry(uint from, uint to);
264 virtual void SaveGeomToSHP(
SHPHandle hSHP,
bool progress_callback(
int)=0)
const;
265 virtual void LoadGeomFromSHP(
SHPHandle hSHP,
bool progress_callback(
int)=0);
279 uint GetNumEntities()
const;
280 void SetNumGeometries(
int iNum);
282 bool ComputeExtent(
DRECT &rect)
const;
283 void Offset(
const DPoint2 &p,
bool bSelectedOnly =
false);
284 bool TransformCoords(OCT *pTransform,
bool progress_callback(
int)=0);
287 int AddPoint(
const DPoint3 &p);
288 void SetPoint(uint num,
const DPoint3 &p);
289 void GetPoint(uint num,
DPoint3 &p)
const;
290 DPoint3 &GetPoint(uint num) {
return m_Point3[num]; }
291 const DPoint3 &GetPoint(uint num)
const {
return m_Point3[num]; }
292 const DLine3 &GetAllPoints()
const {
return m_Point3; }
293 bool ComputeHeightRange(
float &fmin,
float &fmax);
296 virtual bool IsInsideRect(
int iElem,
const DRECT &rect);
297 virtual void CopyGeometry(uint from, uint to);
298 virtual void SaveGeomToSHP(
SHPHandle hSHP,
bool progress_callback(
int)=0)
const;
299 virtual void LoadGeomFromSHP(
SHPHandle hSHP,
bool progress_callback(
int)=0);
314 uint GetNumEntities()
const;
315 void SetNumGeometries(
int iNum);
317 bool ComputeExtent(
DRECT &rect)
const;
318 void Offset(
const DPoint2 &p,
bool bSelectedOnly =
false);
319 bool TransformCoords(OCT *pTransform,
bool progress_callback(
int)=0);
322 int AddPolyLine(
const DLine2 &pl);
323 const DLine2 &GetPolyLine(uint num)
const {
return m_Line[num]; }
324 DLine2 &GetPolyLine(uint num) {
return m_Line[num]; }
325 int NumTotalVertices()
const;
328 virtual bool IsInsideRect(
int iElem,
const DRECT &rect);
329 virtual void CopyGeometry(uint from, uint to);
330 virtual void SaveGeomToSHP(
SHPHandle hSHP,
bool progress_callback(
int)=0)
const;
331 virtual void LoadGeomFromSHP(
SHPHandle hSHP,
bool progress_callback(
int)=0);
346 uint GetNumEntities()
const;
347 void SetNumGeometries(
int iNum);
349 bool ComputeExtent(
DRECT &rect)
const;
350 void Offset(
const DPoint2 &p,
bool bSelectedOnly =
false);
351 bool TransformCoords(OCT *pTransform,
bool progress_callback(
int)=0);
354 int AddPolyLine(
const DLine3 &pl);
355 const DLine3 &GetPolyLine(uint num)
const {
return m_Line[num]; }
356 DLine3 &GetPolyLine(uint num) {
return m_Line[num]; }
357 bool ComputeHeightRange(
float &fmin,
float &fmax);
358 int NumTotalVertices()
const;
362 virtual bool IsInsideRect(
int iElem,
const DRECT &rect);
363 virtual void CopyGeometry(uint from, uint to);
364 virtual void SaveGeomToSHP(
SHPHandle hSHP,
bool progress_callback(
int)=0)
const;
365 virtual void LoadGeomFromSHP(
SHPHandle hSHP,
bool progress_callback(
int)=0);
368 std::vector<DLine3> m_Line;
372 typedef std::vector<int> IntVector;
373 typedef IntVector *IntVectorPtr;
384 const IntVector *GetIndexForPoint(
const DPoint2 &p)
const;
389 IntVectorPtr *m_pArray;
404 uint GetNumEntities()
const;
405 void SetNumGeometries(
int iNum);
407 bool ComputeExtent(
DRECT &rect)
const;
408 void Offset(
const DPoint2 &p,
bool bSelectedOnly =
false);
409 bool TransformCoords(OCT *pTransform,
bool progress_callback(
int)=0);
413 void SetPolygon(uint num,
const DPolygon2 &poly) { m_Poly[num] = poly; }
414 const DPolygon2 &GetPolygon(uint num)
const {
return m_Poly[num]; }
415 DPolygon2 &GetPolygon(uint num) {
return m_Poly[num]; }
420 int FixGeometry(
double dEpsilon);
424 void CreateIndex(
int iSize);
428 virtual bool IsInsideRect(
int iElem,
const DRECT &rect);
429 virtual void CopyGeometry(uint from, uint to);
430 virtual void SaveGeomToSHP(
SHPHandle hSHP,
bool progress_callback(
int)=0)
const;
431 virtual void LoadGeomFromSHP(
SHPHandle hSHP,
bool progress_callback(
int)=0);
451 vtFeatureSet *ReadFeaturesFromWFS(
const char *szServerURL,
const char *layername);
457 OGRwkbGeometryType GetFeatureGeomType(
const char *filename);
458 OGRwkbGeometryType ShapelibToOGR(
int nSHPType);
459 int OGRToShapelib(OGRwkbGeometryType eGeomType);
460 vtString MakeDBFName(
const char *filename);
461 int GetIntFromString(
const char *buf,
int len);
462 bool GeometryTypeIs3D(OGRwkbGeometryType type);
463 vtString GetShapeTypeName(
int nShapeType);
466 void DPolygon2ToOGR(
const DPolygon2 &dp, OGRPolygon &op);
467 void OGRToDPolygon2(
const OGRPolygon &op,
DPolygon2 &dp);
469 #endif // VTDATA_FEATURES