Skip to content

Commit

Permalink
WKBReader: Support curved geometry types (#1106)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston authored Jun 18, 2024
1 parent 2aa9820 commit 5dc668b
Show file tree
Hide file tree
Showing 6 changed files with 351 additions and 116 deletions.
2 changes: 1 addition & 1 deletion include/geos/geom/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace geos { // geos
namespace geom { // geos::geom

/// Geometry types
enum GeometryTypeId {
enum GeometryTypeId : int {
/// a point
GEOS_POINT,
/// a linestring
Expand Down
110 changes: 110 additions & 0 deletions include/geos/geom/GeometryTypeName.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2024 ISciences, LLC
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************/

#pragma once

namespace geos {
namespace geom {

class Curve;
class CurvePolygon;
class GeometryCollection;
class LineString;
class LinearRing;
class MultiCurve;
class MultiLineString;
class MultiPoint;
class MultiPolygon;
class MultiSurface;
class Point;
class Polygon;
class SimpleCurve;
class Surface;

// These structures allow templates to have compile-time access to a type's human-readable name.
template<typename T>
struct GeometryTypeName {};

template<>
struct GeometryTypeName<geom::Curve> {
static constexpr const char* name = "Curve";
};

template<>
struct GeometryTypeName<geom::CurvePolygon> {
static constexpr const char* name = "CurvePolygon";
};

template<>
struct GeometryTypeName<geom::GeometryCollection> {
static constexpr const char* name = "GeometryCollection";
};

template<>
struct GeometryTypeName<geom::LineString> {
static constexpr const char* name = "LineString";
};

template<>
struct GeometryTypeName<geom::LinearRing> {
static constexpr const char* name = "LinearRing";
};

template<>
struct GeometryTypeName<geom::MultiCurve> {
static constexpr const char* name = "MultiCurve";
};

template<>
struct GeometryTypeName<geom::MultiLineString> {
static constexpr const char* name = "MultiLineString";
};

template<>
struct GeometryTypeName<geom::MultiPoint> {
static constexpr const char* name = "MultiPoint";
};

template<>
struct GeometryTypeName<geom::MultiPolygon> {
static constexpr const char* name = "MultiPolygon";
};

template<>
struct GeometryTypeName<geom::MultiSurface> {
static constexpr const char* name = "MultiSurface";
};

template<>
struct GeometryTypeName<geom::Point> {
static constexpr const char* name = "Point";
};

template<>
struct GeometryTypeName<geom::Polygon> {
static constexpr const char* name = "Polygon";
};

template<>
struct GeometryTypeName<geom::SimpleCurve> {
static constexpr const char* name = "SimpleCurve";
};

template<>
struct GeometryTypeName<geom::Surface> {
static constexpr const char* name = "Surface";
};

}
}
34 changes: 30 additions & 4 deletions include/geos/io/WKBReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
#pragma once

#include <geos/export.h>

#include <geos/geom/Geometry.h>
#include <geos/geom/GeometryTypeName.h>
#include <geos/io/ByteOrderDataInStream.h> // for composition

#include <iosfwd> // ostream, istream
#include <memory>
// #include <vector>
#include <array>

#define BAD_GEOM_TYPE_MSG "Bad geometry type encountered in"

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
Expand All @@ -41,17 +40,24 @@ namespace geom {

class GeometryFactory;
class Coordinate;
class CircularString;
class CompoundCurve;
class CurvePolygon;
class Geometry;
enum GeometryTypeId : int;
class GeometryCollection;
class Point;
class LineString;
class LinearRing;
class Polygon;
class MultiCurve;
class MultiPoint;
class MultiLineString;
class MultiPolygon;
class MultiSurface;
class PrecisionModel;
class CoordinateSequence;
class SimpleCurve;

} // namespace geom
} // namespace geos
Expand Down Expand Up @@ -148,22 +154,42 @@ class GEOS_DLL WKBReader {

std::unique_ptr<geom::LinearRing> readLinearRing();

std::unique_ptr<geom::CircularString> readCircularString();

std::unique_ptr<geom::CompoundCurve> readCompoundCurve();

std::unique_ptr<geom::Polygon> readPolygon();

std::unique_ptr<geom::CurvePolygon> readCurvePolygon();

std::unique_ptr<geom::MultiPoint> readMultiPoint();

std::unique_ptr<geom::MultiLineString> readMultiLineString();

std::unique_ptr<geom::MultiCurve> readMultiCurve();

std::unique_ptr<geom::MultiPolygon> readMultiPolygon();

std::unique_ptr<geom::MultiSurface> readMultiSurface();

std::unique_ptr<geom::GeometryCollection> readGeometryCollection();

std::unique_ptr<geom::CoordinateSequence> readCoordinateSequence(unsigned int); // throws IOException

void minMemSize(int geomType, uint64_t size);
void minMemSize(geom::GeometryTypeId geomType, uint64_t size) const;

void readCoordinate(); // throws IOException

template<typename T>
std::unique_ptr<T> readChild()
{
auto g = readGeometry();
if (dynamic_cast<const T*>(g.get())) {
return std::unique_ptr<T>(static_cast<T*>(g.release()));
}
throw io::ParseException(std::string("Expected ") + geom::GeometryTypeName<T>::name + " but got " + g->getGeometryType());
}

// Declare type as noncopyable
WKBReader(const WKBReader& other) = delete;
WKBReader& operator=(const WKBReader& rhs) = delete;
Expand Down
Loading

0 comments on commit 5dc668b

Please sign in to comment.