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