WKBWriter.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2005-2006 Refractions Research Inc.
* Copyright (C) 2001-2002 Vivid Solutions Inc.
*
* 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.
*
**********************************************************************
*
* Last port: io/WKBWriter.java rev. 1.1 (JTS-1.7)
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/util/Machine.h> // for getMachineByteOrder
#include <geos/io/OrdinateSet.h>
#include <geos/io/WKBConstants.h>
#include <iosfwd>
#include <cstdint>
#include <cstddef>
// Forward declarations
namespace geos {
namespace geom {
class CoordinateSequence;
class CompoundCurve;
class CurvePolygon;
class Geometry;
class GeometryCollection;
class Point;
class LineString;
class LinearRing;
class Polygon;
class MultiPoint;
class MultiLineString;
class MultiPolygon;
class PrecisionModel;
class SimpleCurve;
} // namespace geom
} // namespace geos
namespace geos {
namespace io {
class GEOS_DLL WKBWriter {
public:
/*
* \brief
* Initializes writer with target coordinate dimension, endianness
* flag and SRID value.
*
* @param dims Supported values are 2, 3 or 4. Note that 4 indicates
* up to 4 dimensions will be written but (e.g.) 2D WKB is still produced
* for 2D geometries. Default since GEOS 3.12 is 4.
* @param bo output byte order - default to native machine byte order.
* Legal values include 0 (big endian/xdr) and 1 (little endian/ndr).
* @param includeSRID true if SRID should be included in WKB (an
* extension).
*/
WKBWriter(
uint8_t dims = 4,
int bo = getMachineByteOrder(),
bool includeSRID = false,
int flv = WKBConstants::wkbExtended);
/*
* \brief
* Destructor.
*/
~WKBWriter() = default;
/*
* \brief
* Returns the output dimension used by the
* <code>WKBWriter</code>.
*/
uint8_t
getOutputDimension() const
{
return defaultOutputDimension;
}
/*
* Sets the output dimension used by the <code>WKBWriter</code>.
*
* @param newOutputDimension Supported values are 2, 3 or 4.
* Note that 4 indicates up to 4 dimensions will be written but
* (e.g.) 2D WKB is still produced for 2D geometries.
*/
void setOutputDimension(uint8_t newOutputDimension);
/*
* \brief
* Returns the byte order used by the
* <code>WKBWriter</code>.
*/
int
getByteOrder() const
{
return byteOrder;
}
/*
* Sets the byte order used by the
* <code>WKBWriter</code>.
*/
void setByteOrder(int newByteOrder);
/*
* \brief
* Returns whether SRID values are output by the
* <code>WKBWriter</code>.
*/
bool
getIncludeSRID() const
{
return includeSRID;
}
/*
* Sets whether SRID values should be output by the
* <code>WKBWriter</code>.
*/
void
setIncludeSRID(bool newIncludeSRID)
{
includeSRID = newIncludeSRID;
}
/*
* \brief
* Returns the WKB flavor the writer will emit.
*/
int
getFlavor() const
{
return flavor;
}
/*
* \brief
* Set the WKB flavor the writer will emit.
*/
void setFlavor(int newFlavor);
void write(const geom::Geometry& g, std::ostream& os);
// throws IOException, ParseException
void writeHEX(const geom::Geometry& g, std::ostream& os);
// throws IOException, ParseException
static int getWkbType(const geom::Geometry&);
private:
// 2, 3, or 4
uint8_t defaultOutputDimension;
OrdinateSet outputOrdinates;
// WKBConstants::wkbwkbXDR | WKBConstants::wkbNDR
int byteOrder;
// WKBConstants::wkbIso | WKBConstants::wkbExtended
int flavor;
bool includeSRID;
std::ostream* outStream;
unsigned char buf[8];
void writePoint(const geom::Point& p);
void writePointEmpty(const geom::Point& p);
// throws IOException
void writeSimpleCurve(const geom::SimpleCurve& ls);
// throws IOException
void writeCompoundCurve(const geom::CompoundCurve& curve);
void writePolygon(const geom::Polygon& p);
// throws IOException
void writeCurvePolygon(const geom::CurvePolygon& p);
void writeGeometryCollection(const geom::GeometryCollection& gc);
// throws IOException, ParseException
void writeCoordinateSequence(const geom::CoordinateSequence& cs, bool sized);
// throws IOException
void writeCoordinate(const geom::CoordinateSequence& cs, std::size_t idx);
// throws IOException
void writeGeometryType(int geometryType, int SRID);
// throws IOException
void writeSRID(int SRID);
// throws IOException
void writeByteOrder();
// throws IOException
void writeInt(int intValue);
// throws IOException
OrdinateSet getOutputOrdinates(OrdinateSet ordinates);
};
} // namespace io
} // namespace geos
geos::geom::CoordinateSequence
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
geos::geom::GeometryCollection
Represents a collection of heterogeneous Geometry objects.
Definition GeometryCollection.h:51
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
geos::geom::LineString
Definition LineString.h:66
geos::geom::LinearRing
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition LinearRing.h:54
geos::geom::MultiLineString
Models a collection of LineStrings.
Definition MultiLineString.h:49
geos::geom::MultiPoint
Definition MultiPoint.h:50
geos::geom::MultiPolygon
Definition MultiPolygon.h:58
geos::geom::Point
Definition Point.h:61
geos::geom::Polygon
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
geos::geom::PrecisionModel
Specifies the precision model of the Coordinate in a Geometry.
Definition PrecisionModel.h:87
geos::io::OrdinateSet
Utility class to manipulate a set of flags indicating whether X, Y, Z, or M dimensions are present....
Definition OrdinateSet.h:29
geos::io::WKBWriter::writeHEX
void writeHEX(const geom::Geometry &g, std::ostream &os)
Write a Geometry to an ostream in binary hex format.
geos::io::WKBWriter::write
void write(const geom::Geometry &g, std::ostream &os)
Write a Geometry to an ostream.
geos::geom
Definition Angle.h:26
geos::io
Contains the interfaces for converting JTS objects to and from other formats.
Definition Geometry.h:65
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38