IDatamanager.hpp
1 #ifndef DM_IDATAMANAGER_HPP_INCLUDED
2 #define DM_IDATAMANAGER_HPP_INCLUDED
3 
4 #ifdef _MSC_VER
5  #pragma once
6 #endif
7 
8 #include "DM/config.hpp"
9 #include "DM/Handle.hpp"
10 #include "DM/IGeometry.hpp"
11 #include "DM/IPoint.hpp"
12 #include "DM/IPolyline.hpp"
13 #include "DM/IWindow.hpp"
14 #include "DM/IBox.hpp"
15 #include "DM/IPolygon.hpp"
16 #include "DM/IFile.hpp"
17 #include "DM/Iterator.hpp"
18 #include "DM/IPointIndex.hpp"
19 #include "DM/IPolylineIndex.hpp"
20 #include "DM/IRaster.hpp"
21 #include "DM/IParameterSet.hpp"
22 #include "DM/IAddInfoStatistics.hpp"
23 #include "DM/BoundaryOption.hpp"
24 #include "DM/IDatamanagerHeader.hpp"
25 #include "DM/IHistogramSet.hpp"
26 #include "DM/IFilter.hpp"
27 #include "DM/IOverview.hpp"
28 #include "DM/IText.hpp"
29 
30 #include "DM/IControlObject.hpp"
31 
32 #include "DM/AutoLink.hpp" //enable autolink
33 
34 DM_NAMESPACE_BEGIN
35 
36 class IImport;
37 class IExport;
38 
39 /// \brief Interface to an Datamanager (ODM) object
40 /**
41  Datamanager objects are the central objects that can be managed by the DMlib. It allows managing
42  huge geometry data sets with fast spatial access. For efficiency reasons points and other geometry
43  objects (lines, polygons, etc.) are managed by different spatial indices. The interface gives access
44  to the point index (see getPointIndex) and the other spatial index (see getPolylineIndex stores
45  line and polygon data) separately or via the datamanager interface itself in a wrapped manner.
46 
47  When create a datamanger instance, the datamanager uses a set of standard parameter which are appropriate
48  for most data sets. However, it is possible to change these values using a ParameterSets object. The following
49  parameters are supported:
50 
51  Name | type | default | Comment
52  ----------------------|---------|-----------|-------------------------------------------
53  StoreOrder | bool | false | Flag if the order should be stored
54  PointsInMemory | int | 8*200000 | Number of points that are kept in memory
55  AverageTilePointCount | int | 200000 | Average point count per tile
56  TileSize | double | auto | Tile size for tiling mode
57 
58 */
59 class DM_API IDatamanager : public ObjectBase
60 {
61 public:
62  /// Create a new datamanager instance from an existing ODM file or by creating an ODM file
63  /// \param[in] filename odm filename (incl. extension)
64  /// \param[in] openIfExists if true the existing ODM is opened, otherwise a new ODM file is created (which overrides a possible exisitng ODM file)
65  /// \param[in] readOnly if true the ODM is opened in read only mode, which never stores any modification made to the ODM object in memory
66  /// \param[in] threadSafety if true a thread safe instance of the ODM is created. Otherwise a standard instance is created which may provide a bit better performance
67  static IDatamanager* New(const char *filename, bool openIfExists = true, bool readOnly = false, bool threadSafety = true);
68  static IDatamanager* New(const char *filename, const IParameterSet &, bool openIfExists = true, bool readOnly = false, bool threadSafety = true);
69 
70  /// Create a new datamanager instance from an existing ODM file or by creating an ODM file
71  /** Don't use this function outside OPALS, since it requires a pointer to an OPALS module instance as a first parameter
72  */
73  static IDatamanager* New(void *instance, const char *filename, bool openIfExists = true, bool readOnly = false, bool threadSafety = true);
74  static IDatamanager* New(void *instance, const char *filename, const IParameterSet &, bool openIfExists = true, bool readOnly = false, bool threadSafety = true);
75 
76  /// Load an existing datamanager file (Convenient wrapper for IDatamanager::New)
77  /// \param[in] filename odm filename (incl. extension)
78  /// \param[in] readOnly if true the ODM is opened in read only mode, which never stores any modification made to the ODM object in memory
79  /// \param[in] threadSafety if true a thread safe instance of the ODM is created. Otherwise a standard instance is created which may provide a bit better performance
80  static IDatamanager* load(const char *filename, bool readOnly = false, bool threadSafety = true);
81  /// Create a new datamanager file (Convenient wrapper for IDatamanager::New)
82  /// \param[in] filename odm filename (incl. extension)
83  /// \param[in] threadSafety if true a thread safe instance of the ODM is created. Otherwise a standard instance is created which may provide a bit better performance
84  static IDatamanager* create(const char *filename, bool threadSafety = true);
85 
86 
87  /// checks if the odm file exists
88  /// \param[in] filename valid names are <name>.odm, <name>.odm.dat and <name>.odm.idx
89  /// \return true if odm files exists, otherwise false
90  static bool existsODM(const char *filename);
91  /// checks if the specified file is a valid odm file (requires read access)
92  /// \param[in] filename valid names are <name>.odm, <name>.odm.dat and <name>.odm.idx
93  /// \return true if valid odm file. otherwise false
94  static bool isValidODM(const char *filename);
95  static bool isValidODM(const char *filename, TextHandle &errorMsg);
96 
97  /// get the full header information of an odm, without actually openning the odm (much faster)
98  static DatamanagerHeaderHandle getHeaderODM(const char *filename);
99  /// get the limits of an odm, without actually openning the odm (internally uses getHeaderODM)
100  static BoxHandle getLimitODM(const char *filename);
101  /// get the overview object of an odm, without actually openning the odm
102  static OverviewHandle getOverviewODM(const char *filename);
103 
104  static void SetPointInMemoryLimit(unsigned limit);
105 
106 
107  // Iterator typedefs ============================================================================
108  typedef ConstIterator<IGeometry> const_iterator_geometry; ///< Geometry iterator
109  typedef ConstIterator<IPoint> const_iterator_point; ///< Point iterator
110  typedef ConstIterator<IPolyline> const_iterator_line; ///< Polyline iterator
111  typedef ConstIterator<IFile> const_iterator_file; ///< File iterator
112 
113  typedef InsertIterator<IGeometry> insert_iterator_geometry; ///< Geometry insert iterator (used in searchGeometry function)
114  typedef InsertIterator<IPoint> insert_iterator_point; ///< Point insert iterator (used in searchPoint functions)
115  typedef InsertIterator<IPolyline> insert_iterator_line; ///< Polyline insert iterator (used in searchPolyline functions)
116 
117 
118 protected:
119  virtual ~IDatamanager() {}
120 
121 public:
122  // General memeber functions ====================================================================
123  virtual BoxHandle getLimit() const = 0;
124 
125  virtual int64_t sizeGeometry() const = 0;
126  virtual int64_t sizePoint() const = 0;
127  virtual int64_t sizePolyline() const = 0;
128  virtual int64_t sizePolylinePoint() const = 0;
129  virtual int64_t sizePolygon() const = 0;
130  virtual int64_t sizePolygonPoint() const = 0;
131 
132  /*virtual void clear()=0;*/
133 
134  virtual DatamanagerHeaderHandle getHeader() const = 0;
135 
136  virtual bool storesOrder() const = 0;
137  virtual bool threadSafe() const = 0;
138  virtual int indexDim() const = 0;
139 
140  virtual PointIndexHandle getPointIndex() = 0;
141  virtual PolylineIndexHandle getPolylineIndex() = 0;
142 
143  /// Get the boundary polygon of the data set
144  /// \param[in] type type of boundary output polygon (\see BoundaryOption::Type)
145  /// \param[in] alphaRadius in case of alpha shapes a radius can be specified (if radius is zero, the smalles possible radius is select to result as sinlge part alpha shape)
146  /// The approximative boundaries are computed on the fly, whereas the exact outlines needed to be computed using opalsBounds
147  virtual PolygonHandle getBoundary(BoundaryOption::Type type, double alphaRadius = 0.) const = 0;
148  virtual bool getBoundaryFlag(BoundaryOption::Type type) const = 0;
149 
150 
151  /// access object by its id
152  virtual GeometryHandle getGeometry(int64_t id) const = 0;
153 
154  // Overview matrix function =====================================================================
155  /// Get a matrix of point counts in native resolution
156  virtual UnsignedRasterHandle getDensityOverview(double &xLowerLeftCellCenter, double &yLowerLeftCellCenter, double &cellSize) = 0;
157  virtual DoubleRasterHandle getZMatrixOverview(double &xLowerLeftCellCenter, double &yLowerLeftCellCenter, double &cellSize, const double &nullValue = 0) = 0;
158  /*virtual void getDensityMatrix(const GdxLimit2d &limit, unsigned int rows, unsigned int cols, int *mat) const=0;
159  virtual void getPointPolylinesMatrix(const GdxLimit2d &limit, unsigned int rows, unsigned int cols, int *mat) const=0;
160  virtual void getFileMatrix(const GdxLimit2d &limit, unsigned int rows, unsigned int cols, int *mat) const=0;
161  */
162 
163  // IO functions =================================================================================
164  virtual void save() = 0;
165 
166  // Import / Export functions ====================================================================
167  virtual bool doImport( IImport &impObj, DM::ControlObjectHandle control = ControlObjectHandle() ) = 0;
168  virtual bool doExport( IExport &expObj, bool restoreOrder = false, DM::ControlObjectHandle control = ControlObjectHandle() ) = 0;
169  virtual bool doExport( IExport &expObj, BoxHandle box, DM::ControlObjectHandle control = ControlObjectHandle() ) = 0;
170 
171 
172  // Iterator function ============================================================================
173  virtual const_iterator_geometry beginGeometry(E_IteratorOrder order = eORDER_INTERNAL) const = 0;
174  virtual const_iterator_geometry endGeometry(E_IteratorOrder order = eORDER_INTERNAL) const = 0;
175 
176  virtual const_iterator_point beginPoint(E_IteratorOrder order = eORDER_INTERNAL) const = 0;
177  virtual const_iterator_point endPoint(E_IteratorOrder order = eORDER_INTERNAL) const = 0;
178 
179  virtual const_iterator_line beginPolyline(E_IteratorOrder order = eORDER_INTERNAL) const = 0;
180  virtual const_iterator_line endPolyline(E_IteratorOrder order = eORDER_INTERNAL) const = 0;
181 
182  virtual const_iterator_file beginFile() const=0;
183  virtual const_iterator_file endFile() const=0;
184 
185  virtual PointIndexLeafHandle getPointIndexLeaf(const_iterator_geometry &it) = 0;
186 
187  // Spatial access functions =====================================================================
188  virtual void searchGeometry(const IWindow &win, insert_iterator_geometry &instIt, bool includeRightBoundary = true) = 0;
189  virtual void searchGeometry(const IBox &box, insert_iterator_geometry &instIt, bool includeRightBoundary = true) = 0;
190  virtual void searchGeometry(const IPolygon &p, insert_iterator_geometry &instIt) = 0;
191 
192  virtual void searchPoint(const IWindow &win, insert_iterator_point &instIt, bool includeRightBoundary = true) = 0;
193  virtual void searchPoint(const IBox &box, insert_iterator_point &instIt, bool includeRightBoundary = true) = 0;
194  virtual void searchPoint(const IPolygon &p, insert_iterator_point &instIt) = 0;
195 
196  virtual void searchPolyline (const IWindow &win, insert_iterator_line &instIt, bool includeRightBoundary = true) = 0;
197  virtual void searchPolyline (const IBox &box, insert_iterator_line &instIt, bool includeRightBoundary = true) = 0;
198  virtual void searchPolyline (const IPolygon &p, insert_iterator_line &instIt) = 0;
199 
200  // Edit function ================================================================================
201  /// adds point to the datamanager (secure that addinfo of the point is NOT linked to another datamanager or
202  /// set the cloneAddInfo flag)
203  /// \param[in] p point object
204  /// \param[in] cloneAddInfo flag if the addinfo object should be cloned, before adapting
205  /// file and layer id in addinfo object
206  /// \param[in] fileId the point is inserted into the given file (it is assumed that the given file exists) or
207  /// to the default file in case of -1
208  /// \param[in] layerId the point is inserted into the given layer of the given file (layer and file entry must exist) or
209  /// to the default layer in case of -1
210  /// \return point id
211  virtual int64_t addPoint(const IPoint &p, bool cloneAddInfo = true, int fileId = -1, int layerId = -1 ) = 0;
212 
213  /// replace an existing point within the datamanager (the point is identified by its id)
214  /// \param[in] p point object
215  /// \param[in] attributeOnly flag if complete point should be replace (i.e. coordinates have changed) or only the attribute object is updated
216  virtual void replacePoint(const IPoint &p, bool attributeOnly = false) = 0;
217 
218  /// remove a point from from the datamanager by its id
219  /// \param[in] id point id
220  virtual void deletePoint(int64_t id) = 0;
221 
222 
223  /// adds a polyline to the datamanager (secure that addinfo of the polyline is NOT linked to another datamanager or
224  /// set the cloneAddInfo flag)
225  /// \param[in] l polyline object
226  /// \param[in] cloneAddInfo flag if the addinfo object should be cloned, before adapting
227  /// file and layer id in addinfo object
228  /// \param[in] fileId the point is inserted into the given file (it is assumed that the given file exists) or
229  /// to the default file in case of -1
230  /// \param[in] layerId the point is inserted into the given layer of the given file (layer and file entry must exist) or
231  /// to the default layer in case of -1
232  /// \return polyline id
233  virtual int64_t addPolyline(const IPolyline &l, bool cloneAddInfo = true, int fileId = -1, int layerId = -1 ) = 0;
234 
235  /// replace an existing polyline within the datamanager (the object is identified by its id)
236  /// \param[in] l polyline object
237  /// \param[in] attributeOnly flag if complete line should be replace (i.e. coordinates have changed) or only the attribute objects is updated
238  virtual void replacePolyline(const IPolyline &l, bool attributeOnly = false) = 0;
239 
240  /// remove a polyline object from from the datamanager by its id
241  /// \param[in] id polyline id
242  virtual void deletePolyline(int64_t id) = 0;
243 
244 
245 
246 
247  /// adds a polygon to the datamanager (secure that addinfo of the polygon is NOT linked to another datamanager or
248  /// set the cloneAddInfo flag)
249  /// \param[in] p polygon object
250  /// \param[in] cloneAddInfo flag if the addinfo object should be cloned, before adapting
251  /// file and layer id in addinfo object
252  /// \param[in] fileId the point is inserted into the given file (it is assumed that the given file exists) or
253  /// to the default file in case of -1
254  /// \param[in] layerId the point is inserted into the given layer of the given file (layer and file entry must exist) or
255  /// to the default layer in case of -1
256  /// \return polyline id
257  virtual int64_t addPolygon(const IPolygon &p, bool cloneAddInfo = true, int fileId = -1, int layerId = -1 ) = 0;
258 
259  /// replace an existing polygon within the datamanager (the object is identified by its id)
260  /// \param[in] p polygon object
261  /// \param[in] attributeOnly flag if complete polygon should be replace (i.e. coordinates have changed) or only the attribute objects is updated
262  virtual void replacePolygon(const IPolygon &p, bool attributeOnly = false) = 0;
263 
264  /// remove a polygon object from from the datamanager by its id
265  /// \param[in] id polygon id
266  virtual void deletePolygon(int64_t id) = 0;
267 
268 
269  /*virtual void beginUpdate(void)=0;
270  virtual void endUpdate(void)=0;
271 
272  virtual int addFile (const GdxFile &f)=0;
273  virtual int64_t addPoint(const GdxPoint &p)=0;
274  virtual int64_t addPolyline (const GdxPolyline &l)=0;
275 
276  virtual void deleteFile (unsigned int ngfilid)=0;
277  virtual void deletePoint(int64_t ngpntid)=0;
278  virtual void deletePolyline (int64_t nglinid)=0;
279 
280  virtual void replaceFile (const GdxFile &f, bool attributsOnly)=0;
281  virtual void replacePoint(const GdxPoint &p, bool attributsOnly)=0;
282  virtual void replacePolyline (const GdxPolyline &l, bool attributsOnly)=0; */
283 
284  ///get the statistics of all addinfo objects
285  virtual AddInfoStatisticsHandle getAddInfoStatistics() const = 0;
286 
287  /// get filename of manager;
288  virtual const char * getFilename() const = 0;
289 
290  /// output statistics parameter how the data are actually stored on disk
291  virtual void outputDiskmanagerStatistics() const = 0;
292 
293  /// drop all freeable memory object
294  virtual void freeMemory() const = 0;
295 
296  /// mark the odm that processing should be interrupted
297  virtual void interrupt(bool inter = true) = 0;
298  /// check if the interrupt flag was set
299  virtual bool isInterrupted() const = 0;
300 
301  virtual bool isManagerCorrupt() const = 0;
302 
303  /// \brief get histograms of all attributes described by the layout
304  virtual HistogramSetHandle getHistogramSet(const IAddInfoLayout &layout, int maxDistinctValues = 1000, FilterHandle filter = FilterHandle()) = 0;
305 
306  // Coordinate reference system function ================================================================================
307  /// \brief get the coordinate reference system as a WKT string
308  virtual const char* getCRS() const = 0;
309  /// \brief set the coordinate reference system from a WKT string
310  virtual void setCRS(const char *crs) = 0;
311 };
312 
313 typedef Handle< IDatamanager > DatamanagerHandle;
314 
315 DM_NAMESPACE_END
316 
317 #endif // DM_IDATAMANAGER_HPP_INCLUDED