Line data Source code
1 : /******************************************************************************
2 : *
3 : * Project: FlatGeobuf driver
4 : * Purpose: GeometryWriter class declarations.
5 : * Author: Björn Harrtell <bjorn at wololo dot org>
6 : *
7 : ******************************************************************************
8 : * Copyright (c) 2018-2019, Björn Harrtell <bjorn at wololo dot org>
9 : *
10 : * Permission is hereby granted, free of charge, to any person obtaining a
11 : * copy of this software and associated documentation files (the "Software"),
12 : * to deal in the Software without restriction, including without limitation
13 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 : * and/or sell copies of the Software, and to permit persons to whom the
15 : * Software is furnished to do so, subject to the following conditions:
16 : *
17 : * The above copyright notice and this permission notice shall be included
18 : * in all copies or substantial portions of the Software.
19 : *
20 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 : * DEALINGS IN THE SOFTWARE.
27 : ****************************************************************************/
28 :
29 : #ifndef FLATGEOBUF_GEOMETRYWRITER_H_INCLUDED
30 : #define FLATGEOBUF_GEOMETRYWRITER_H_INCLUDED
31 :
32 : #include "ogrsf_frmts.h"
33 : #include "ogr_p.h"
34 :
35 : #include "feature_generated.h"
36 :
37 : namespace ogr_flatgeobuf
38 : {
39 :
40 : class GeometryWriter
41 : {
42 : private:
43 : flatbuffers::FlatBufferBuilder &m_fbb;
44 : const OGRGeometry *m_ogrGeometry;
45 : FlatGeobuf::GeometryType m_geometryType;
46 : const bool m_hasZ;
47 : const bool m_hasM;
48 : std::vector<double> m_xy;
49 : std::vector<double> m_z;
50 : std::vector<double> m_m;
51 : std::vector<uint32_t> m_ends;
52 :
53 : void writePoint(const OGRPoint *p);
54 : void writeMultiPoint(const OGRMultiPoint *mp);
55 : uint32_t writeSimpleCurve(const OGRSimpleCurve *sc);
56 : void writeMultiLineString(const OGRMultiLineString *mls);
57 : void writePolygon(const OGRPolygon *p);
58 : const flatbuffers::Offset<FlatGeobuf::Geometry>
59 : writeMultiPolygon(const OGRMultiPolygon *mp, int depth);
60 : const flatbuffers::Offset<FlatGeobuf::Geometry>
61 : writeGeometryCollection(const OGRGeometryCollection *gc, int depth);
62 : const flatbuffers::Offset<FlatGeobuf::Geometry>
63 : writeCompoundCurve(const OGRCompoundCurve *cc, int depth);
64 : const flatbuffers::Offset<FlatGeobuf::Geometry>
65 : writeCurvePolygon(const OGRCurvePolygon *cp, int depth);
66 : const flatbuffers::Offset<FlatGeobuf::Geometry>
67 : writePolyhedralSurface(const OGRPolyhedralSurface *p, int depth);
68 : void writeTIN(const OGRTriangulatedSurface *p);
69 :
70 : const flatbuffers::Offset<FlatGeobuf::Geometry>
71 77 : writePart(const OGRGeometry *part, int depth)
72 : {
73 154 : return GeometryWriter(m_fbb, part, m_hasZ, m_hasM).write(depth);
74 : }
75 :
76 : const flatbuffers::Offset<FlatGeobuf::Geometry>
77 33 : writePart(const OGRGeometry *part,
78 : const FlatGeobuf::GeometryType geometryType, int depth)
79 : {
80 66 : return GeometryWriter(m_fbb, part, geometryType, m_hasZ, m_hasM)
81 66 : .write(depth);
82 : }
83 :
84 : public:
85 230 : GeometryWriter(flatbuffers::FlatBufferBuilder &fbb,
86 : const OGRGeometry *ogrGeometry,
87 : const FlatGeobuf::GeometryType geometryType, const bool hasZ,
88 : const bool hasM)
89 230 : : m_fbb(fbb), m_ogrGeometry(ogrGeometry), m_geometryType(geometryType),
90 230 : m_hasZ(hasZ), m_hasM(hasM)
91 : {
92 230 : }
93 :
94 77 : GeometryWriter(flatbuffers::FlatBufferBuilder &fbb,
95 : const OGRGeometry *ogrGeometry, const bool hasZ,
96 : const bool hasM)
97 77 : : m_fbb(fbb), m_ogrGeometry(ogrGeometry),
98 77 : m_geometryType(GeometryWriter::translateOGRwkbGeometryType(
99 77 : ogrGeometry->getGeometryType())),
100 154 : m_hasZ(hasZ), m_hasM(hasM)
101 : {
102 77 : }
103 :
104 : const flatbuffers::Offset<FlatGeobuf::Geometry> write(int depth);
105 : static FlatGeobuf::GeometryType
106 : translateOGRwkbGeometryType(const OGRwkbGeometryType eGType);
107 : };
108 :
109 : } // namespace ogr_flatgeobuf
110 :
111 : #endif /* ndef FLATGEOBUF_GEOMETRYWRITER_H_INCLUDED */
|