Skip to content

Commit

Permalink
Reset OGR order to standard;
Browse files Browse the repository at this point in the history
add geometryToIsoWKT function;
  • Loading branch information
djeralfia committed Mar 2, 2024
1 parent a6e7a00 commit 05f081b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/osgEarth/GeometryUtils
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace osgEarth
namespace GeometryUtils
{
extern OSGEARTH_EXPORT std::string geometryToWKT( const Geometry* geometry );
extern OSGEARTH_EXPORT std::string geometryToIsoWKT( const Geometry* geometry );
extern OSGEARTH_EXPORT Geometry* geometryFromWKT( const std::string& wkt, bool rewindPolygons = true);

extern OSGEARTH_EXPORT std::string geometryToGeoJSON( const Geometry* geometry );
Expand Down
18 changes: 18 additions & 0 deletions src/osgEarth/GeometryUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ osgEarth::GeometryUtils::geometryToWKT( const Geometry* geometry )
return result;
}

std::string
osgEarth::GeometryUtils::geometryToIsoWKT( const Geometry* geometry )
{
OGRGeometryH g = OgrUtils::createOgrGeometry( geometry );
std::string result;
if (g)
{
char* buf;
if (OGR_G_ExportToIsoWkt( g, &buf ) == OGRERR_NONE)
{
result = std::string(buf);
OGRFree( buf );
}
OGR_G_DestroyGeometry( g );
}
return result;
}

std::string
osgEarth::GeometryUtils::geometryToGeoJSON( const Geometry* geometry )
{
Expand Down
4 changes: 2 additions & 2 deletions src/osgEarth/OgrUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,15 @@ OgrUtils::encodeShape( const Geometry* geometry, OGRwkbGeometryType shape_type,
{
if (part_type == wkbNone)
{
for (int v = geometry->size() - 1; v >= 0; v--)
for (int v = 0; v < geometry->size(); v++)
{
osg::Vec3d p = (*geometry)[v];
OGR_G_AddPoint(shape_handle, p.x(), p.y(), p.z());
}
}
else if (part_type == wkbPoint)
{
for (int v = geometry->size() - 1; v >= 0; v--)
for (int v = 0; v < geometry->size(); v++)
{
osg::Vec3d p = (*geometry)[v];
OGRGeometryH part_handle = OGR_G_CreateGeometry(part_type);
Expand Down

0 comments on commit 05f081b

Please sign in to comment.