M/c++_api/inc/DM/IO/IImport.hpp
1 #pragma once
2 
3 #include "DM/config.hpp"
4 #include "DM/AutoLink.hpp" //enable autolink
5 
6 #include "DM/IControlObject.hpp"
7 #include "DM/IFilter.hpp"
8 #include "DM/IAddInfoLayout.hpp"
9 #include "DM/IAddInfoStatistics.hpp"
10 #include "DM/IHistogramSet.hpp"
11 #include "DM/IRaster.hpp"
12 
13 #include "DM/IO/IFileHeader.hpp"
14 
15 #include "DM/Log.hpp"
16 #include "DM/IO/DataFormat.hpp"
17 
18 DM_NAMESPACE_BEGIN
19 
20 enum struct ImportError
21 {
22  demoLimitExceeded = -9, ///< demo limit of the DM exceeded
23  unknownFormat, ///< unknown import file format
24  memoryOverflow, ///< memory overflow occurred
25  importStreamNotAccessible, ///< import stream is not accessible
26  headerContentsErroneous, ///< the file header content is erroneous
27  readingData, ///< general error while reading data
28  importStreamClosed, ///< import stream was already closed
29  endOfStreamReached, ///< end of input stream is reached
30  interrupted, ///< import was interrupted
31  successful = 1 ///< no error occured
32 };
33 
34 DM_API const char* toString(ImportError error); ///< get a textual description of an import error (this function is not thread safe)
35 
36 enum struct PolygonMerging
37 {
38  safe = 0, ///< incremental merge of polygon parts (slow but robust)
39  fast = 1 ///< build polygon object at once (fast but fails in case of topological incorrect polygon parts)
40 };
41 
42 class DM_API IDatamanager;
43 
44 /// \brief base class for importing original geometry data file
45 class DM_API IImport : public ObjectBase
46 {
47 public:
48  /// \brief creates new import object
49  /**
50  interface for importing geometry objects for different file formats. if not specified the function automatically detects the file format
51  based on the file content.
52  \param[in] file filename
53  \param[in] format defines file format or use null for auto detection
54  \param[in] filter filter for subselecting/transforming objects during import
55  \param[in] control control object for retrieving import progress information
56  \param[in] collectHdrContents flag for explicitly collecting header information while importing
57  \param[in] maxBulkPoints chunk size for bulk points being imported at once
58  \param[in] defaultLayout default attribute layout for objects while importing (attribute stored within the file, will be extended to this layout)
59  */
60  static IImport* New(const char *file, DataFormat format, FilterHandle filter = FilterHandle(), ControlObjectHandle control = ControlObjectHandle(),
61  bool collectHdrContents = false, unsigned maxBulkPoints = 1000, AddInfoLayoutHandle defaultLayout = AddInfoLayoutHandle());
62 
63  /// \brief creates new import object
64  /**
65  interface for importing geometry objects for different file formats. if not specified the function automatically detects the file format
66  based on the file content.
67  \param[in] instance ptr to parent module instance
68  \param[in] file filename
69  \param[in] format defines file format or use null for auto detection
70  \param[in] filter filter for subselecting/transforming objects during import
71  \param[in] control control object for retrieving import progress information
72  \param[in] collectHdrContents flag for explicitly collecting header information while importing
73  \param[in] maxBulkPoints chunk size for bulk points being imported at once
74  \param[in] defaultLayout default attribute layout for objects while importing (attribute stored within the file, will be extended to this layout)
75  */
76  static IImport* New( void *instance, const char *file, DataFormat format, FilterHandle filter = FilterHandle(), ControlObjectHandle control = ControlObjectHandle(),
77  bool collectHdrContents = false, unsigned maxBulkPoints = 1000, AddInfoLayoutHandle defaultLayout = AddInfoLayoutHandle() );
78 
79  /// deprecated odm import creation functions (use IImportODM::New instead)
80  static IImport* NewODM( Handle< IDatamanager > manager, bool restoreOrder, FilterHandle filter = FilterHandle(), ControlObjectHandle control = ControlObjectHandle(),
81  bool collectHdrContents = false, unsigned maxBulkPoints = 1000 );
82  /// deprecated odm import creation functions (use IImportODM::New instead)
83  static IImport* NewODM( IDatamanager &manager, bool restoreOrder, FilterHandle filter = FilterHandle(), ControlObjectHandle control = ControlObjectHandle(),
84  bool collectHdrContents = false, unsigned maxBulkPoints = 1000 );
85 
86  static IImport* NewGDAL( const char *file, FilterHandle filter = FilterHandle(), ControlObjectHandle control = ControlObjectHandle(),
87  bool collectHdrContents = false, unsigned maxBulkPoints = 1000,
88  unsigned bandNumber = 1, const char *driver = 0 );
89 
90  static IImport* NewWinput( const char *file, bool binary, ColumnSemantic structIdAddInfoCol = ColumnSemantic::null,
91  ColumnSemantic wnpCodeAddInfoCol = ColumnSemantic::null,
93  bool collectHdrContents = false, unsigned maxBulkPoints = 1000,
95 
96 
98  long long polygonsInvalidOrientation; ///< number of polygons that are orientated incorrectly
99  long long polygonsSelfIntersecting; ///< number of polygons that are self intersecting
100  };
101 
102  /// Store the string representation of the import object in representation and return the length of representation.
103  /// Memory for representation must be allocated externally.
104  /// Pass a null pointer to query the length of representation only.
105  /// Note that the stored representation may contain null bytes.
106  virtual unsigned serialize( char *representation = 0 ) const = 0;
107 
108  /// Restore an import object from its string representation. Since the representation may contain null bytes, its size must also be specified.
109  static IImport* unserialize( const char *representation, unsigned repSize );
110 
111 protected:
112  virtual ~IImport() {}
113 
114 public:
115  virtual void setControlObject(ControlObjectHandle control) = 0;
116  virtual ControlObjectHandle getControlObject() const = 0;
117 
118  //get the file header object
119  virtual FileHeaderHandle getHeader() const = 0;
120 
121  virtual void setFilter( FilterHandle filter ) = 0;
122  virtual FilterHandle getFilter() const = 0;
123 
124  virtual void setPolygonMerging(PolygonMerging mode) = 0;
125  virtual PolygonMerging getPolygonMerging() const = 0;
126 
127  /// Returns the filename
128  virtual const char* getFilename() const = 0;
129 
130  /// Returns the file format
131  virtual DataFormat getFileFormat() const = 0;
132 
133  /// Set logging call back function
134  virtual void logTo( LogFn logFn ) = 0;
135 
136  /// read the header in advance
137  virtual bool readHeaderSeparately() = 0;
138 
139  /// read next object from import object
140  virtual ImportError readNext(GeometryHandle &obj) = 0;
141 
142  /// get a statistic of invalid geometries (after import)
143  virtual InvalidObjectStatistic getInvalidGeometries() const = 0;
144 };
145 
146 typedef Handle<IImport> ImportHandle;
147 
148 /// \brief import data and extract/compute an attribute statistics
149 DM_API AddInfoStatisticsHandle importStatistics(IImport &imp, ControlObjectHandle control = ControlObjectHandle());
150 /// \brief import data and extract/compute an attribute statistics including and estimation of the pointDensity (using the overview matrix of the odm)
151 DM_API AddInfoStatisticsHandle importStatistics(IImport &imp, double &pointDensity, ControlObjectHandle control = ControlObjectHandle());
152 
153 /// \brief import data and extract/compute an attribute statistics and specified value frequencies
154 DM_API std::pair<AddInfoStatisticsHandle, HistogramSetHandle> importStatistics(IImport &imp,
155  const IAddInfoLayout &valueFrequencyLayout, int maxDistinctValues = 1000, ControlObjectHandle control = ControlObjectHandle());
156 /// \brief import data and extract/compute an attribute statistics, specified value frequencies and estimation of the pointDensity (using the overview matrix of the odm)
157 DM_API std::pair<AddInfoStatisticsHandle, HistogramSetHandle> importStatistics(IImport &imp, double &pointDensity,
158  const IAddInfoLayout &valueFrequencyLayout, int maxDistinctValues = 1000, ControlObjectHandle control = ControlObjectHandle());
159 
160 /// \brief import data and extract overview rasters
161 DM_API void importStatistics(IImport &imp, AddInfoStatisticsHandle &impStat, double &pointDensity,
162  UnsignedRasterHandle &densityOverview, DoubleRasterHandle &zmatrixOverview,
163  double &xLowerLeftCellCenter, double &yLowerLeftCellCenter, double &cellSize, const double &nullValue,
164  ControlObjectHandle control = ControlObjectHandle());
165 DM_API void importStatistics(IImport &imp, AddInfoStatisticsHandle &impStat, double &pointDensity,
166  UnsignedRasterHandle &densityOverview, DoubleRasterHandle &zmatrixOverview,
167  double &xLowerLeftCellCenter, double &yLowerLeftCellCenter, double &cellSize, const double &nullValue,
168  HistogramSetHandle &histo, const IAddInfoLayout &valueFrequencyLayout, int maxDistinctValues = 1000,
169  ControlObjectHandle control = ControlObjectHandle());
170 
171 DM_NAMESPACE_END
ColumnSemantic
Pre-defined attributes (attributes with semantic)
Definition: ColumnTypes.hpp:38
@ importStreamNotAccessible
import stream is not accessible
long long polygonsSelfIntersecting
number of polygons that are self intersecting
Definition: M/c++_api/inc/DM/IO/IImport.hpp:99
base class for importing original geometry data file
Definition: M/c++_api/inc/DM/IO/IImport.hpp:45
ImportError
Definition: M/c++_api/inc/DM/IO/IImport.hpp:20
long long polygonsInvalidOrientation
number of polygons that are orientated incorrectly
Definition: M/c++_api/inc/DM/IO/IImport.hpp:98
Definition: Handle.hpp:427
DataFormat
list of known data formats
Definition: DataFormat.hpp:9
@ unknownFormat
unknown import file format
@ importStreamClosed
import stream was already closed
Definition: M/c++_api/inc/DM/IO/IImport.hpp:97
@ readingData
general error while reading data
@ demoLimitExceeded
demo limit of the DM exceeded
@ endOfStreamReached
end of input stream is reached
@ headerContentsErroneous
the file header content is erroneous
PolygonMerging
Definition: M/c++_api/inc/DM/IO/IImport.hpp:36
Interface to an Datamanager (ODM) object.
Definition: IDatamanager.hpp:57
@ memoryOverflow
memory overflow occurred
Definition: M/c++_api/inc/DM/ObjectBase.hpp:8
@ interrupted
export was interrupted
@ successful
no error occurred