/src/gdal/ogr/ogrsf_frmts/flatgeobuf/geometryreader.h
Line | Count | Source |
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 | | OGRGeometry *readPart(const FlatGeobuf::Geometry *part) |
59 | 1.77k | { |
60 | 1.77k | return GeometryReader(part, m_hasZ, m_hasM).read(); |
61 | 1.77k | } |
62 | | |
63 | | OGRGeometry *readPart(const FlatGeobuf::Geometry *part, |
64 | | const FlatGeobuf::GeometryType geometryType) |
65 | 1.24k | { |
66 | 1.24k | return GeometryReader(part, geometryType, m_hasZ, m_hasM).read(); |
67 | 1.24k | } |
68 | | |
69 | | template <class T> T *readSimpleCurve(const bool halfLength = false) |
70 | 5.85k | { |
71 | 5.85k | if (halfLength) |
72 | 1.73k | m_length = m_length / 2; |
73 | 5.85k | const auto csc = new T(); |
74 | 5.85k | if (readSimpleCurve(csc) != OGRERR_NONE) |
75 | 1.64k | { |
76 | 1.64k | delete csc; |
77 | 1.64k | return nullptr; |
78 | 1.64k | } |
79 | 4.21k | return csc; |
80 | 5.85k | } OGRLineString* ogr_flatgeobuf::GeometryReader::readSimpleCurve<OGRLineString>(bool) Line | Count | Source | 70 | 454 | { | 71 | 454 | if (halfLength) | 72 | 66 | m_length = m_length / 2; | 73 | 454 | const auto csc = new T(); | 74 | 454 | if (readSimpleCurve(csc) != OGRERR_NONE) | 75 | 30 | { | 76 | 30 | delete csc; | 77 | 30 | return nullptr; | 78 | 30 | } | 79 | 424 | return csc; | 80 | 454 | } |
OGRLinearRing* ogr_flatgeobuf::GeometryReader::readSimpleCurve<OGRLinearRing>(bool) Line | Count | Source | 70 | 3.73k | { | 71 | 3.73k | if (halfLength) | 72 | 0 | m_length = m_length / 2; | 73 | 3.73k | const auto csc = new T(); | 74 | 3.73k | if (readSimpleCurve(csc) != OGRERR_NONE) | 75 | 1.61k | { | 76 | 1.61k | delete csc; | 77 | 1.61k | return nullptr; | 78 | 1.61k | } | 79 | 2.12k | return csc; | 80 | 3.73k | } |
OGRCircularString* ogr_flatgeobuf::GeometryReader::readSimpleCurve<OGRCircularString>(bool) Line | Count | Source | 70 | 1.66k | { | 71 | 1.66k | if (halfLength) | 72 | 1.66k | m_length = m_length / 2; | 73 | 1.66k | const auto csc = new T(); | 74 | 1.66k | if (readSimpleCurve(csc) != OGRERR_NONE) | 75 | 0 | { | 76 | 0 | delete csc; | 77 | 0 | return nullptr; | 78 | 0 | } | 79 | 1.66k | return csc; | 80 | 1.66k | } |
|
81 | | |
82 | | public: |
83 | | GeometryReader(const FlatGeobuf::Geometry *geometry, |
84 | | const FlatGeobuf::GeometryType geometryType, const bool hasZ, |
85 | | const bool hasM) |
86 | 3.93k | : m_geometry(geometry), m_geometryType(geometryType), m_hasZ(hasZ), |
87 | 3.93k | m_hasM(hasM) |
88 | 3.93k | { |
89 | 3.93k | } |
90 | | |
91 | | GeometryReader(const FlatGeobuf::Geometry *geometry, const bool hasZ, |
92 | | const bool hasM) |
93 | 1.77k | : m_geometry(geometry), m_geometryType(geometry->type()), m_hasZ(hasZ), |
94 | 1.77k | m_hasM(hasM) |
95 | 1.77k | { |
96 | 1.77k | } |
97 | | |
98 | | OGRGeometry *read(); |
99 | | }; |
100 | | |
101 | | } // namespace ogr_flatgeobuf |
102 | | |
103 | | #endif /* ndef FLATGEOBUF_GEOMETRYREADER_H_INCLUDED */ |