ShpDBFFields.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //##########################################################################
  2. //# #
  3. //# CLOUDCOMPARE #
  4. //# #
  5. //# This program is free software; you can redistribute it and/or modify #
  6. //# it under the terms of the GNU General Public License as published by #
  7. //# the Free Software Foundation; version 2 or later of the License. #
  8. //# #
  9. //# This program is distributed in the hope that it will be useful, #
  10. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  11. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  12. //# GNU General Public License for more details. #
  13. //# #
  14. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  15. //# #
  16. //##########################################################################
  17. #ifndef CC_SHAPEFILE_DBF_FIELDS_HEADER
  18. #define CC_SHAPEFILE_DBF_FIELDS_HEADER
  19. #ifdef CC_SHP_SUPPORT
  20. //local
  21. #include "qCC_io.h"
  22. //CCCoreLib
  23. #include <CCGeom.h>
  24. //Qt
  25. #include <QString>
  26. //system
  27. #include <vector>
  28. //Shapelib
  29. #include <shapefil.h>
  30. //! Generic shapefile 'field'
  31. /** Fields contain one value per record (i.e. primitive)
  32. **/
  33. class GenericDBFField
  34. {
  35. public:
  36. //! Default constructor
  37. GenericDBFField(QString name) : m_name(name) {}
  38. //! Returns field name
  39. const QString& name() const { return m_name; }
  40. //! Returns whehter the field is 3D or not
  41. virtual bool is3D() const { return false; }
  42. //to be reimplemented by siblings
  43. virtual DBFFieldType type() const = 0;
  44. virtual int width() const = 0;
  45. virtual int decimal() const = 0;
  46. virtual bool save(DBFHandle handle, int fieldIndex) const { return false; } //1D version
  47. virtual bool save(DBFHandle handle, int xFieldIndex, int yFieldIndex, int zFieldIndex) const { return false; } //3D version
  48. protected:
  49. //! Field name
  50. QString m_name;
  51. };
  52. //! Int-valued shapefile field
  53. class QCC_IO_LIB_API IntegerDBFField : public GenericDBFField
  54. {
  55. public:
  56. //! Default constructor
  57. IntegerDBFField(QString name) : GenericDBFField(name) {}
  58. //inherited from GenericDBFField
  59. virtual DBFFieldType type() const { return FTInteger; }
  60. virtual int width() const { return 6; }
  61. virtual int decimal() const { return 0; }
  62. virtual bool save(DBFHandle handle, int fieldIndex) const;
  63. //! Field values
  64. std::vector<int> values;
  65. };
  66. //! Double-valued shapefile field
  67. class QCC_IO_LIB_API DoubleDBFField : public GenericDBFField
  68. {
  69. public:
  70. //! Default constructor
  71. DoubleDBFField(QString name) : GenericDBFField(name) {}
  72. //inherited from GenericDBFField
  73. virtual DBFFieldType type() const { return FTDouble; }
  74. virtual int width() const { return 8; }
  75. virtual int decimal() const { return 8; }
  76. virtual bool save(DBFHandle handle, int fieldIndex) const;
  77. //! Field values
  78. std::vector<double> values;
  79. };
  80. //! Double-valued 3D shapefile field
  81. class QCC_IO_LIB_API DoubleDBFField3D : public GenericDBFField
  82. {
  83. public:
  84. //! Default constructor
  85. DoubleDBFField3D(QString name) : GenericDBFField(name) {}
  86. virtual ~DoubleDBFField3D() {}
  87. //inherited from GenericDBFField
  88. virtual bool is3D() const { return true; }
  89. virtual DBFFieldType type() const { return FTDouble; }
  90. virtual int width() const { return 8; }
  91. virtual int decimal() const { return 8; }
  92. virtual bool save(DBFHandle handle, int xFieldIndex, int yFieldIndex, int zFieldIndex) const;
  93. //! Field values
  94. std::vector<CCVector3d> values;
  95. };
  96. #endif //CC_SHP_SUPPORT
  97. #endif //CC_SHAPEFILE_DBF_FIELDS_HEADER