XS-libgeos
view release on metacpan or search on metacpan
geos-3.7.3/capi/geos_ts_c.cpp view on Meta::CPAN
/************************************************************************
*
*
* C-Wrapper for GEOS library
*
* Copyright (C) 2010-2012 Sandro Santilli <strk@kbt.io>
* Copyright (C) 2005-2006 Refractions Research 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.
*
* Author: Sandro Santilli <strk@kbt.io>
* Thread Safety modifications: Chuck Thibert <charles.thibert@ingres.com>
*
***********************************************************************/
#include <geos/platform.h> // for FINITE
#include <geos/geom/Coordinate.h>
#include <geos/geom/Geometry.h>
#include <geos/geom/prep/PreparedGeometry.h>
#include <geos/geom/prep/PreparedGeometryFactory.h>
#include <geos/geom/GeometryCollection.h>
#include <geos/geom/Polygon.h>
#include <geos/geom/Point.h>
#include <geos/geom/MultiPoint.h>
#include <geos/geom/MultiLineString.h>
#include <geos/geom/MultiPolygon.h>
#include <geos/geom/LinearRing.h>
#include <geos/geom/LineSegment.h>
#include <geos/geom/LineString.h>
#include <geos/geom/PrecisionModel.h>
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/CoordinateSequenceFactory.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/IntersectionMatrix.h>
#include <geos/geom/Envelope.h>
#include <geos/index/strtree/STRtree.h>
#include <geos/index/strtree/GeometryItemDistance.h>
#include <geos/index/ItemVisitor.h>
#include <geos/io/WKTReader.h>
#include <geos/io/WKBReader.h>
#include <geos/io/WKTWriter.h>
#include <geos/io/WKBWriter.h>
#include <geos/algorithm/distance/DiscreteHausdorffDistance.h>
#include <geos/algorithm/distance/DiscreteFrechetDistance.h>
#include <geos/algorithm/CGAlgorithms.h>
#include <geos/algorithm/BoundaryNodeRule.h>
#include <geos/algorithm/MinimumDiameter.h>
#include <geos/simplify/DouglasPeuckerSimplifier.h>
#include <geos/simplify/TopologyPreservingSimplifier.h>
#include <geos/noding/GeometryNoder.h>
#include <geos/noding/Noder.h>
#include <geos/operation/buffer/BufferBuilder.h>
#include <geos/operation/buffer/BufferOp.h>
#include <geos/operation/buffer/BufferParameters.h>
#include <geos/operation/distance/DistanceOp.h>
#include <geos/operation/distance/IndexedFacetDistance.h>
#include <geos/operation/linemerge/LineMerger.h>
#include <geos/operation/overlay/OverlayOp.h>
#include <geos/operation/overlay/snap/GeometrySnapper.h>
#include <geos/operation/intersection/Rectangle.h>
#include <geos/operation/intersection/RectangleIntersection.h>
#include <geos/operation/polygonize/Polygonizer.h>
#include <geos/operation/relate/RelateOp.h>
#include <geos/operation/sharedpaths/SharedPathsOp.h>
#include <geos/operation/union/CascadedPolygonUnion.h>
#include <geos/operation/valid/IsValidOp.h>
#include <geos/precision/GeometryPrecisionReducer.h>
#include <geos/linearref/LengthIndexedLine.h>
#include <geos/triangulate/DelaunayTriangulationBuilder.h>
#include <geos/triangulate/VoronoiDiagramBuilder.h>
#include <geos/util/IllegalArgumentException.h>
#include <geos/util/Interrupt.h>
#include <geos/util/UniqueCoordinateArrayFilter.h>
#include <geos/util/Machine.h>
#include <geos/version.h>
// This should go away
#include <cmath> // finite
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <memory>
#ifdef _MSC_VER
#pragma warning(disable : 4099)
#endif
// Some extra magic to make type declarations in geos_c.h work -
// for cross-checking of types in header.
#define GEOSGeometry geos::geom::Geometry
#define GEOSPreparedGeometry geos::geom::prep::PreparedGeometry
#define GEOSCoordSequence geos::geom::CoordinateSequence
#define GEOSBufferParams geos::operation::buffer::BufferParameters
#define GEOSSTRtree geos::index::strtree::STRtree
#define GEOSWKTReader_t geos::io::WKTReader
#define GEOSWKTWriter_t geos::io::WKTWriter
#define GEOSWKBReader_t geos::io::WKBReader
#define GEOSWKBWriter_t geos::io::WKBWriter
#include "geos_c.h"
#include "../geos_revision.h"
// Intentional, to allow non-standard C elements like C99 functions to be
// imported through C++ headers of C library, like <cmath>.
using namespace std;
/// Define this if you want operations triggering Exceptions to
/// be printed.
/// (will use the NOTIFY channel - only implemented for GEOSUnion so far)
///
#undef VERBOSE_EXCEPTIONS
#include <geos/export.h>
#include <geos/precision/MinimumClearance.h>
// import the most frequently used definitions globally
using geos::geom::Geometry;
using geos::geom::LineString;
using geos::geom::LinearRing;
using geos::geom::MultiLineString;
using geos::geom::MultiPolygon;
using geos::geom::Polygon;
using geos::geom::CoordinateSequence;
using geos::geom::GeometryCollection;
using geos::geom::GeometryFactory;
using geos::io::WKTReader;
using geos::io::WKTWriter;
using geos::io::WKBReader;
using geos::io::WKBWriter;
using geos::operation::overlay::OverlayOp;
using geos::operation::overlay::overlayOp;
using geos::operation::geounion::CascadedPolygonUnion;
using geos::operation::distance::IndexedFacetDistance;
using geos::operation::buffer::BufferParameters;
using geos::operation::buffer::BufferBuilder;
using geos::precision::GeometryPrecisionReducer;
using geos::util::IllegalArgumentException;
using geos::algorithm::distance::DiscreteHausdorffDistance;
using geos::algorithm::distance::DiscreteFrechetDistance;
typedef std::unique_ptr<Geometry> GeomPtr;
typedef struct GEOSContextHandle_HS
{
const GeometryFactory *geomFactory;
char msgBuffer[1024];
GEOSMessageHandler noticeMessageOld;
GEOSMessageHandler_r noticeMessageNew;
void *noticeData;
GEOSMessageHandler errorMessageOld;
GEOSMessageHandler_r errorMessageNew;
void *errorData;
int WKBOutputDims;
int WKBByteOrder;
int initialized;
GEOSContextHandle_HS()
:
geomFactory(0),
noticeMessageOld(0),
noticeMessageNew(0),
noticeData(0),
errorMessageOld(0),
errorMessageNew(0),
errorData(0)
{
memset(msgBuffer, 0, sizeof(msgBuffer));
geomFactory = GeometryFactory::getDefaultInstance();
WKBOutputDims = 2;
WKBByteOrder = getMachineByteOrder();
setNoticeHandler(NULL);
setErrorHandler(NULL);
initialized = 1;
}
GEOSMessageHandler
setNoticeHandler(GEOSMessageHandler nf)
{
GEOSMessageHandler f = noticeMessageOld;
noticeMessageOld = nf;
noticeMessageNew = NULL;
noticeData = NULL;
return f;
}
GEOSMessageHandler
setErrorHandler(GEOSMessageHandler nf)
{
GEOSMessageHandler f = errorMessageOld;
errorMessageOld = nf;
geos-3.7.3/capi/geos_ts_c.cpp view on Meta::CPAN
handle->ERROR_MESSAGE("%s", e.what());
return 0;
}
catch (...)
{
SharedPathsOp::clearEdges(forw);
SharedPathsOp::clearEdges(back);
handle->ERROR_MESSAGE("Unknown exception thrown");
return 0;
}
// Now forw and back have the geoms we want to use to construct
// our output GeometryCollections...
const GeometryFactory* factory = g1->getFactory();
size_t count;
std::unique_ptr< std::vector<Geometry*> > out1(
new std::vector<Geometry*>()
);
count = forw.size();
out1->reserve(count);
for (size_t i=0; i<count; ++i) {
out1->push_back(forw[i]);
}
std::unique_ptr<Geometry> out1g (
factory->createMultiLineString(out1.release())
);
std::unique_ptr< std::vector<Geometry*> > out2(
new std::vector<Geometry*>()
);
count = back.size();
out2->reserve(count);
for (size_t i=0; i<count; ++i) {
out2->push_back(back[i]);
}
std::unique_ptr<Geometry> out2g (
factory->createMultiLineString(out2.release())
);
std::unique_ptr< std::vector<Geometry*> > out(
new std::vector<Geometry*>()
);
out->reserve(2);
out->push_back(out1g.release());
out->push_back(out2g.release());
std::unique_ptr<Geometry> outg (
factory->createGeometryCollection(out.release())
);
return outg.release();
}
GEOSGeometry *
GEOSSnap_r(GEOSContextHandle_t extHandle, const GEOSGeometry* g1,
const GEOSGeometry* g2, double tolerance)
{
using namespace geos::operation::overlay::snap;
if ( 0 == extHandle ) return 0;
GEOSContextHandleInternal_t *handle =
reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
if ( handle->initialized == 0 ) return 0;
try{
GeometrySnapper snapper( *g1 );
std::unique_ptr<Geometry> ret = snapper.snapTo(*g2, tolerance);
return ret.release();
}
catch (const std::exception &e)
{
handle->ERROR_MESSAGE("%s", e.what());
return 0;
}
catch (...)
{
handle->ERROR_MESSAGE("Unknown exception thrown");
return 0;
}
}
BufferParameters *
GEOSBufferParams_create_r(GEOSContextHandle_t extHandle)
{
if ( 0 == extHandle ) return NULL;
GEOSContextHandleInternal_t *handle = 0;
handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
if ( 0 == handle->initialized ) return NULL;
try
{
BufferParameters *p = new BufferParameters();
return p;
}
catch (const std::exception &e)
{
handle->ERROR_MESSAGE("%s", e.what());
}
catch (...)
{
handle->ERROR_MESSAGE("Unknown exception thrown");
}
return 0;
}
void
GEOSBufferParams_destroy_r(GEOSContextHandle_t extHandle, BufferParameters* p)
{
(void)extHandle;
delete p;
}
int
GEOSBufferParams_setEndCapStyle_r(GEOSContextHandle_t extHandle,
GEOSBufferParams* p, int style)
{
( run in 0.696 second using v1.01-cache-2.11-cpan-5a3173703d6 )