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 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #ifndef FLATGEOBUF_GEOMETRYWRITER_H_INCLUDED 14 : #define FLATGEOBUF_GEOMETRYWRITER_H_INCLUDED 15 : 16 : #include "ogrsf_frmts.h" 17 : #include "ogr_p.h" 18 : 19 : #if defined(__clang__) 20 : #pragma clang diagnostic push 21 : #pragma clang diagnostic ignored "-Wweak-vtables" 22 : #endif 23 : #include "feature_generated.h" 24 : #if defined(__clang__) 25 : #pragma clang diagnostic pop 26 : #endif 27 : 28 : namespace ogr_flatgeobuf 29 : { 30 : 31 : class GeometryWriter 32 : { 33 : private: 34 : flatbuffers::FlatBufferBuilder &m_fbb; 35 : const OGRGeometry *m_ogrGeometry; 36 : FlatGeobuf::GeometryType m_geometryType; 37 : const bool m_hasZ; 38 : const bool m_hasM; 39 : std::vector<double> m_xy; 40 : std::vector<double> m_z; 41 : std::vector<double> m_m; 42 : std::vector<uint32_t> m_ends; 43 : 44 : void writePoint(const OGRPoint *p); 45 : void writeMultiPoint(const OGRMultiPoint *mp); 46 : uint32_t writeSimpleCurve(const OGRSimpleCurve *sc); 47 : void writeMultiLineString(const OGRMultiLineString *mls); 48 : void writePolygon(const OGRPolygon *p); 49 : const flatbuffers::Offset<FlatGeobuf::Geometry> 50 : writeMultiPolygon(const OGRMultiPolygon *mp, int depth); 51 : const flatbuffers::Offset<FlatGeobuf::Geometry> 52 : writeGeometryCollection(const OGRGeometryCollection *gc, int depth); 53 : const flatbuffers::Offset<FlatGeobuf::Geometry> 54 : writeCompoundCurve(const OGRCompoundCurve *cc, int depth); 55 : const flatbuffers::Offset<FlatGeobuf::Geometry> 56 : writeCurvePolygon(const OGRCurvePolygon *cp, int depth); 57 : const flatbuffers::Offset<FlatGeobuf::Geometry> 58 : writePolyhedralSurface(const OGRPolyhedralSurface *p, int depth); 59 : void writeTIN(const OGRTriangulatedSurface *p); 60 : 61 : const flatbuffers::Offset<FlatGeobuf::Geometry> 62 77 : writePart(const OGRGeometry *part, int depth) 63 : { 64 154 : return GeometryWriter(m_fbb, part, m_hasZ, m_hasM).write(depth); 65 : } 66 : 67 : const flatbuffers::Offset<FlatGeobuf::Geometry> 68 33 : writePart(const OGRGeometry *part, 69 : const FlatGeobuf::GeometryType geometryType, int depth) 70 : { 71 66 : return GeometryWriter(m_fbb, part, geometryType, m_hasZ, m_hasM) 72 66 : .write(depth); 73 : } 74 : 75 : public: 76 236 : GeometryWriter(flatbuffers::FlatBufferBuilder &fbb, 77 : const OGRGeometry *ogrGeometry, 78 : const FlatGeobuf::GeometryType geometryType, const bool hasZ, 79 : const bool hasM) 80 236 : : m_fbb(fbb), m_ogrGeometry(ogrGeometry), m_geometryType(geometryType), 81 236 : m_hasZ(hasZ), m_hasM(hasM) 82 : { 83 236 : } 84 : 85 77 : GeometryWriter(flatbuffers::FlatBufferBuilder &fbb, 86 : const OGRGeometry *ogrGeometry, const bool hasZ, 87 : const bool hasM) 88 77 : : m_fbb(fbb), m_ogrGeometry(ogrGeometry), 89 77 : m_geometryType(GeometryWriter::translateOGRwkbGeometryType( 90 77 : ogrGeometry->getGeometryType())), 91 154 : m_hasZ(hasZ), m_hasM(hasM) 92 : { 93 77 : } 94 : 95 : const flatbuffers::Offset<FlatGeobuf::Geometry> write(int depth); 96 : static FlatGeobuf::GeometryType 97 : translateOGRwkbGeometryType(const OGRwkbGeometryType eGType); 98 : }; 99 : 100 : } // namespace ogr_flatgeobuf 101 : 102 : #endif /* ndef FLATGEOBUF_GEOMETRYWRITER_H_INCLUDED */