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 : * 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_GEOMETRYREADER_H_INCLUDED 30 : #define FLATGEOBUF_GEOMETRYREADER_H_INCLUDED 31 : 32 : #include "feature_generated.h" 33 : #include "ogr_p.h" 34 : 35 : namespace ogr_flatgeobuf 36 : { 37 : 38 : class GeometryReader 39 : { 40 : private: 41 : const FlatGeobuf::Geometry *m_geometry; 42 : const FlatGeobuf::GeometryType m_geometryType; 43 : const bool m_hasZ; 44 : const bool m_hasM; 45 : 46 : const double *m_xy = nullptr; 47 : uint32_t m_xylength = 0; 48 : uint32_t m_length = 0; 49 : uint32_t m_offset = 0; 50 : 51 : OGRPoint *readPoint(); 52 : OGRMultiPoint *readMultiPoint(); 53 : OGRErr readSimpleCurve(OGRSimpleCurve *c); 54 : OGRMultiLineString *readMultiLineString(); 55 : OGRPolygon *readPolygon(); 56 : OGRMultiPolygon *readMultiPolygon(); 57 : OGRGeometryCollection *readGeometryCollection(); 58 : OGRCompoundCurve *readCompoundCurve(); 59 : OGRCurvePolygon *readCurvePolygon(); 60 : OGRMultiCurve *readMultiCurve(); 61 : OGRMultiSurface *readMultiSurface(); 62 : OGRPolyhedralSurface *readPolyhedralSurface(); 63 : OGRTriangulatedSurface *readTIN(); 64 : OGRTriangle *readTriangle(); 65 : 66 76 : OGRGeometry *readPart(const FlatGeobuf::Geometry *part) 67 : { 68 76 : return GeometryReader(part, m_hasZ, m_hasM).read(); 69 : } 70 : 71 44 : OGRGeometry *readPart(const FlatGeobuf::Geometry *part, 72 : const FlatGeobuf::GeometryType geometryType) 73 : { 74 44 : return GeometryReader(part, geometryType, m_hasZ, m_hasM).read(); 75 : } 76 : 77 550 : template <class T> T *readSimpleCurve(const bool halfLength = false) 78 : { 79 550 : if (halfLength) 80 58 : m_length = m_length / 2; 81 550 : const auto csc = new T(); 82 550 : if (readSimpleCurve(csc) != OGRERR_NONE) 83 : { 84 0 : delete csc; 85 0 : return nullptr; 86 : } 87 550 : return csc; 88 : } 89 : 90 : public: 91 726 : GeometryReader(const FlatGeobuf::Geometry *geometry, 92 : const FlatGeobuf::GeometryType geometryType, const bool hasZ, 93 : const bool hasM) 94 726 : : m_geometry(geometry), m_geometryType(geometryType), m_hasZ(hasZ), 95 726 : m_hasM(hasM) 96 : { 97 726 : } 98 : 99 76 : GeometryReader(const FlatGeobuf::Geometry *geometry, const bool hasZ, 100 : const bool hasM) 101 152 : : m_geometry(geometry), m_geometryType(geometry->type()), m_hasZ(hasZ), 102 76 : m_hasM(hasM) 103 : { 104 76 : } 105 : 106 : OGRGeometry *read(); 107 : }; 108 : 109 : } // namespace ogr_flatgeobuf 110 : 111 : #endif /* ndef FLATGEOBUF_GEOMETRYREADER_H_INCLUDED */