Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: FlatGeobuf driver 4 : * Purpose: GeometryReader 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_GEOMETRYREADER_H_INCLUDED 14 : #define FLATGEOBUF_GEOMETRYREADER_H_INCLUDED 15 : 16 : #if defined(__clang__) 17 : #pragma clang diagnostic push 18 : #pragma clang diagnostic ignored "-Wweak-vtables" 19 : #endif 20 : #include "feature_generated.h" 21 : #if defined(__clang__) 22 : #pragma clang diagnostic pop 23 : #endif 24 : 25 : #include "ogr_p.h" 26 : 27 : namespace ogr_flatgeobuf 28 : { 29 : 30 : class GeometryReader 31 : { 32 : private: 33 : const FlatGeobuf::Geometry *m_geometry; 34 : const FlatGeobuf::GeometryType m_geometryType; 35 : const bool m_hasZ; 36 : const bool m_hasM; 37 : 38 : const double *m_xy = nullptr; 39 : uint32_t m_xylength = 0; 40 : uint32_t m_length = 0; 41 : uint32_t m_offset = 0; 42 : 43 : OGRPoint *readPoint(); 44 : OGRMultiPoint *readMultiPoint(); 45 : OGRErr readSimpleCurve(OGRSimpleCurve *c); 46 : OGRMultiLineString *readMultiLineString(); 47 : OGRPolygon *readPolygon(); 48 : OGRMultiPolygon *readMultiPolygon(); 49 : OGRGeometryCollection *readGeometryCollection(); 50 : OGRCompoundCurve *readCompoundCurve(); 51 : OGRCurvePolygon *readCurvePolygon(); 52 : OGRMultiCurve *readMultiCurve(); 53 : OGRMultiSurface *readMultiSurface(); 54 : OGRPolyhedralSurface *readPolyhedralSurface(); 55 : OGRTriangulatedSurface *readTIN(); 56 : OGRTriangle *readTriangle(); 57 : 58 76 : OGRGeometry *readPart(const FlatGeobuf::Geometry *part) 59 : { 60 76 : return GeometryReader(part, m_hasZ, m_hasM).read(); 61 : } 62 : 63 44 : OGRGeometry *readPart(const FlatGeobuf::Geometry *part, 64 : const FlatGeobuf::GeometryType geometryType) 65 : { 66 44 : return GeometryReader(part, geometryType, m_hasZ, m_hasM).read(); 67 : } 68 : 69 551 : template <class T> T *readSimpleCurve(const bool halfLength = false) 70 : { 71 551 : if (halfLength) 72 58 : m_length = m_length / 2; 73 551 : const auto csc = new T(); 74 551 : if (readSimpleCurve(csc) != OGRERR_NONE) 75 : { 76 0 : delete csc; 77 0 : return nullptr; 78 : } 79 551 : return csc; 80 : } 81 : 82 : public: 83 737 : GeometryReader(const FlatGeobuf::Geometry *geometry, 84 : const FlatGeobuf::GeometryType geometryType, const bool hasZ, 85 : const bool hasM) 86 737 : : m_geometry(geometry), m_geometryType(geometryType), m_hasZ(hasZ), 87 737 : m_hasM(hasM) 88 : { 89 737 : } 90 : 91 76 : GeometryReader(const FlatGeobuf::Geometry *geometry, const bool hasZ, 92 : const bool hasM) 93 152 : : m_geometry(geometry), m_geometryType(geometry->type()), m_hasZ(hasZ), 94 76 : m_hasM(hasM) 95 : { 96 76 : } 97 : 98 : OGRGeometry *read(); 99 : }; 100 : 101 : } // namespace ogr_flatgeobuf 102 : 103 : #endif /* ndef FLATGEOBUF_GEOMETRYREADER_H_INCLUDED */