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