SFCGAL  2.3.0
Namespaces | Classes | Functions
SFCGAL::io Namespace Reference

Main Input/output namespace. More...

Namespaces

 OBJ
 OBJ file format tools.
 
 STL
 
 VKT
 VKT file format tools.
 
 VTK
 

Classes

class  BinarySerializer
 Binary serialization wrapper for SFCGAL geometries. More...
 
class  BinaryUnserializer
 Binary deserialization wrapper for SFCGAL geometries. More...
 
struct  GeoJSONOptions
 Options for GeoJSON serialization. More...
 

Functions

auto writeBinaryGeometry (const SFCGAL::Geometry &geom) -> std::string
 Convert a Geometry to its binary representation. More...
 
auto writeBinaryPrepared (const SFCGAL::PreparedGeometry &preparedGeom) -> std::string
 Convert a PreparedGeometry to its binary representation. More...
 
auto readBinaryGeometry (const std::string &str) -> std::unique_ptr< SFCGAL::Geometry >
 Read a Geometry from a binary representation. More...
 
auto readBinaryPrepared (const std::string &str) -> std::unique_ptr< SFCGAL::PreparedGeometry >
 Read a PreparedGeometry from a binary representation. More...
 
auto readEwkt (std::istream &s) -> std::unique_ptr< PreparedGeometry >
 Read a EWKT prepared geometry from an input stream. More...
 
auto readEwkt (const std::string &s) -> std::unique_ptr< PreparedGeometry >
 Read a EWKT geometry from a string. More...
 
auto readEwkt (const char *str, size_t len) -> std::unique_ptr< PreparedGeometry >
 Read a EWKT geometry from a char array. More...
 
auto readGeoJSON (const std::string &json) -> std::unique_ptr< Geometry >
 Read a Geometry from a GeoJSON string. More...
 
auto readGeoJSON (const char *str, size_t len) -> std::unique_ptr< Geometry >
 Read a Geometry from a GeoJSON char array. More...
 
auto readGeoJSON (const nlohmann::json &json) -> std::unique_ptr< Geometry >
 Read a Geometry from a parsed JSON object. More...
 
auto readGeoJSONPrepared (const std::string &json) -> std::unique_ptr< PreparedGeometry >
 Read a PreparedGeometry (Geometry + SRID) from GeoJSON. More...
 
auto readGeoJSONPrepared (const char *str, size_t len) -> std::unique_ptr< PreparedGeometry >
 Read a PreparedGeometry (Geometry + SRID) from a GeoJSON char array. More...
 
auto readGeoJSONPrepared (const nlohmann::json &json) -> std::unique_ptr< PreparedGeometry >
 Read a PreparedGeometry from a parsed JSON object. More...
 
auto writeGeoJSON (const Geometry &geometry, const GeoJSONOptions &options={}) -> std::string
 Write a Geometry to GeoJSON string. More...
 
auto writeGeoJSONObject (const Geometry &geometry, const GeoJSONOptions &options={}) -> nlohmann::json
 Write a Geometry to a JSON object. More...
 
auto writeGeoJSON (const PreparedGeometry &prepared, const GeoJSONOptions &options={}) -> std::string
 Write a PreparedGeometry to GeoJSON string. More...
 
auto isNativeGeoJSONType (GeometryType geomType) -> bool
 Check if a geometry type is natively supported by GeoJSON (RFC 7946). More...
 
auto geoJSONTypeName (const Geometry &geometry, bool strict=true) -> std::string
 Get the GeoJSON type name for a geometry. More...
 
SFCGAL_API osg::Geometry * toOsgGeometry (const Geometry &g)
 [helper] converts a SFCGAL::Geometry to an OSG geometry More...
 
auto readWkb (std::istream &stream, bool asHexString=false) -> std::unique_ptr< Geometry >
 Read a WKB geometry from an input stream. More...
 
auto readWkb (const std::string &s, bool asHexString=false) -> std::unique_ptr< Geometry >
 Read a WKB geometry from a string. More...
 
auto readWkb (const char *str, size_t len, bool asHexString=false) -> std::unique_ptr< Geometry >
 Read a WKB geometry from a char array. More...
 
auto readEwkb (std::istream &stream, bool asHexString) -> std::unique_ptr< PreparedGeometry >
 Read a WKB geometry from an input stream. More...
 
auto readEwkb (const std::string &s, bool asHexString=false) -> std::unique_ptr< PreparedGeometry >
 Read a EWKB geometry from a string. More...
 
auto readEwkb (const char *str, size_t len, bool asHexString) -> std::unique_ptr< PreparedGeometry >
 Read a WKB geometry from a char*. More...
 
auto readWkt (std::istream &s) -> std::unique_ptr< Geometry >
 Read a WKT geometry from an input stream. More...
 
auto readWkt (const std::string &s) -> std::unique_ptr< Geometry >
 Read a WKT geometry from a string. More...
 
auto readWkt (const char *str, size_t len) -> std::unique_ptr< Geometry >
 Read a WKT geometry from a char array. More...
 

Detailed Description

Main Input/output namespace.

Function Documentation

SFCGAL_API auto SFCGAL::io::geoJSONTypeName ( const Geometry &  geometry,
bool  strict = true 
) -> std::string

Get the GeoJSON type name for a geometry.

In strict mode, returns the RFC 7946 equivalent type. In extension mode, returns the SFCGAL type name.

Parameters
geometryGeometry
strictUse strict RFC 7946 types
Returns
Type name string
SFCGAL_API auto SFCGAL::io::isNativeGeoJSONType ( GeometryType  geomType) -> bool

Check if a geometry type is natively supported by GeoJSON (RFC 7946).

Parameters
geomTypeGeometry type ID
Returns
true if type is Point, LineString, Polygon, Multi*, or GeometryCollection
SFCGAL_API auto SFCGAL::io::readBinaryGeometry ( const std::string &  str) -> std::unique_ptr< SFCGAL::Geometry >

Read a Geometry from a binary representation.

Parameters
strbinary representation
Returns
A SFCGAL::Geometry
SFCGAL_API auto SFCGAL::io::readBinaryPrepared ( const std::string &  str) -> std::unique_ptr< SFCGAL::PreparedGeometry >

Read a PreparedGeometry from a binary representation.

Parameters
strbinary representation
Returns
A SFCGAL::PreparedGeometry
SFCGAL_API auto SFCGAL::io::readEwkb ( std::istream &  stream,
bool  asHexString = false 
) -> std::unique_ptr< PreparedGeometry >

Read a WKB geometry from an input stream.

Read a EWKB geometry from an input stream.

Parameters
streamThe input stream to read from
asHexStringWhether the EWKB data is encoded as hex string
Returns
A unique pointer to the prepared geometry
SFCGAL_API auto SFCGAL::io::readEwkb ( const std::string &  s,
bool  asHexString = false 
) -> std::unique_ptr< PreparedGeometry >

Read a EWKB geometry from a string.

Parameters
sThe string containing EWKB data
asHexStringWhether the EWKB data is encoded as hex string
Returns
A unique pointer to the prepared geometry
SFCGAL_API auto SFCGAL::io::readEwkb ( const char *  str,
size_t  len,
bool  asHexString = false 
) -> std::unique_ptr< PreparedGeometry >

Read a WKB geometry from a char*.

Read a EWKB geometry from a char array.

Parameters
strThe character array containing EWKB data
lenThe length of the character array
asHexStringWhether the EWKB data is encoded as hex string
Returns
A unique pointer to the prepared geometry
SFCGAL_API auto SFCGAL::io::readEwkt ( std::istream &  s) -> std::unique_ptr< PreparedGeometry >

Read a EWKT prepared geometry from an input stream.

Parameters
sThe input stream to read from
Returns
A unique pointer to the prepared geometry
SFCGAL_API auto SFCGAL::io::readEwkt ( const std::string &  s) -> std::unique_ptr< PreparedGeometry >

Read a EWKT geometry from a string.

Parameters
sThe string containing EWKT data
Returns
A unique pointer to the prepared geometry
SFCGAL_API auto SFCGAL::io::readEwkt ( const char *  str,
size_t  len 
) -> std::unique_ptr< PreparedGeometry >

Read a EWKT geometry from a char array.

Parameters
strThe character array containing EWKT data
lenThe length of the character array
Returns
A unique pointer to the prepared geometry
SFCGAL_API auto SFCGAL::io::readGeoJSON ( const std::string &  json) -> std::unique_ptr< Geometry >

Read a Geometry from a GeoJSON string.

Supports Geometry, Feature, and FeatureCollection. For Feature/FeatureCollection, only the geometry part is extracted.

Parameters
jsonGeoJSON string
Returns
Parsed geometry
Exceptions
std::runtime_erroron parse error
SFCGAL_API auto SFCGAL::io::readGeoJSON ( const char *  str,
size_t  len 
) -> std::unique_ptr< Geometry >

Read a Geometry from a GeoJSON char array.

Supports Geometry, Feature, and FeatureCollection. For Feature/FeatureCollection, only the geometry part is extracted.

Parameters
strThe GeoJSON character array
lenThe length of the character array
Returns
Parsed geometry
Exceptions
std::runtime_erroron parse error
SFCGAL_API auto SFCGAL::io::readGeoJSON ( const nlohmann::json &  json) -> std::unique_ptr< Geometry >

Read a Geometry from a parsed JSON object.

Parameters
jsonnlohmann::json object
Returns
Parsed geometry
Exceptions
std::runtime_erroron invalid geometry
SFCGAL_API auto SFCGAL::io::readGeoJSONPrepared ( const std::string &  json) -> std::unique_ptr< PreparedGeometry >

Read a PreparedGeometry (Geometry + SRID) from GeoJSON.

If CRS is specified in GeoJSON, extracts the EPSG code as SRID.

Parameters
jsonGeoJSON string
Returns
PreparedGeometry with geometry and SRID
SFCGAL_API auto SFCGAL::io::readGeoJSONPrepared ( const char *  str,
size_t  len 
) -> std::unique_ptr< PreparedGeometry >

Read a PreparedGeometry (Geometry + SRID) from a GeoJSON char array.

If CRS is specified in GeoJSON, extracts the EPSG code as SRID.

Parameters
strThe GeoJSON character array
lenThe length of the character array
Returns
PreparedGeometry with geometry and SRID
SFCGAL_API auto SFCGAL::io::readGeoJSONPrepared ( const nlohmann::json &  json) -> std::unique_ptr< PreparedGeometry >

Read a PreparedGeometry from a parsed JSON object.

Parameters
jsonnlohmann::json object
Returns
PreparedGeometry with geometry and SRID
SFCGAL_API auto SFCGAL::io::readWkb ( std::istream &  stream,
bool  asHexString = false 
) -> std::unique_ptr< Geometry >

Read a WKB geometry from an input stream.

Parameters
streamThe input stream to read from
asHexStringWhether the WKB data is encoded as hex string
Returns
A unique pointer to the geometry
SFCGAL_API auto SFCGAL::io::readWkb ( const std::string &  s,
bool  asHexString = false 
) -> std::unique_ptr< Geometry >

Read a WKB geometry from a string.

Parameters
sThe string containing WKB data
asHexStringWhether the WKB data is encoded as hex string
Returns
A unique pointer to the geometry
SFCGAL_API auto SFCGAL::io::readWkb ( const char *  str,
size_t  len,
bool  asHexString = false 
) -> std::unique_ptr< Geometry >

Read a WKB geometry from a char array.

Parameters
strThe character array containing WKB data
lenThe length of the character array
asHexStringWhether the WKB data is encoded as hex string
Returns
A unique pointer to the geometry
SFCGAL_API auto SFCGAL::io::readWkt ( std::istream &  s) -> std::unique_ptr< Geometry >

Read a WKT geometry from an input stream.

Parameters
sThe input stream to read from
Returns
A unique pointer to the geometry
SFCGAL_API auto SFCGAL::io::readWkt ( const std::string &  s) -> std::unique_ptr< Geometry >

Read a WKT geometry from a string.

Parameters
sThe string containing WKT data
Returns
A unique pointer to the geometry
SFCGAL_API auto SFCGAL::io::readWkt ( const char *  str,
size_t  len 
) -> std::unique_ptr< Geometry >

Read a WKT geometry from a char array.

Parameters
strThe character array containing WKT data
lenThe length of the character array
Returns
A unique pointer to the geometry
SFCGAL_API osg::Geometry* SFCGAL::io::toOsgGeometry ( const Geometry &  g)

[helper] converts a SFCGAL::Geometry to an OSG geometry

Parameters
gThe SFCGAL geometry to convert
Returns
A pointer to the OSG geometry
SFCGAL_API auto SFCGAL::io::writeBinaryGeometry ( const SFCGAL::Geometry &  geom) -> std::string

Convert a Geometry to its binary representation.

Parameters
geomGeometry to convert
Returns
The binary representation as a string
Warning
resulting string may contain 0s
SFCGAL_API auto SFCGAL::io::writeBinaryPrepared ( const SFCGAL::PreparedGeometry &  preparedGeom) -> std::string

Convert a PreparedGeometry to its binary representation.

Parameters
preparedGeomPreparedGeometry to convert
Returns
The binary representation as a string
Warning
resulting string may contain 0s
SFCGAL_API auto SFCGAL::io::writeGeoJSON ( const Geometry &  geometry,
const GeoJSONOptions &  options = {} 
) -> std::string

Write a Geometry to GeoJSON string.

Parameters
geometryGeometry to serialize
optionsSerialization options
Returns
GeoJSON string
Note
M values are dropped
SFCGAL_API auto SFCGAL::io::writeGeoJSON ( const PreparedGeometry &  prepared,
const GeoJSONOptions &  options = {} 
) -> std::string

Write a PreparedGeometry to GeoJSON string.

If SRID is non-zero, includes a CRS member (non-standard but useful).

Parameters
preparedPreparedGeometry to serialize
optionsSerialization options
Returns
GeoJSON string
Note
M values are dropped
SFCGAL_API auto SFCGAL::io::writeGeoJSONObject ( const Geometry &  geometry,
const GeoJSONOptions &  options = {} 
) -> nlohmann::json

Write a Geometry to a JSON object.

Parameters
geometryGeometry to serialize
optionsSerialization options
Returns
nlohmann::json object
Note
M values are dropped