1 /************************************************************************
4 * C-Wrapper for GEOS library
6 * Copyright (C) 2010-2012 Sandro Santilli <strk@keybit.net>
7 * Copyright (C) 2005-2006 Refractions Research Inc.
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
14 * Author: Sandro Santilli <strk@keybit.net>
15 * Thread Safety modifications: Chuck Thibert <charles.thibert@ingres.com>
17 ***********************************************************************/
19 #include <geos/platform.h> // for FINITE
20 #include <geos/geom/Geometry.h>
21 #include <geos/geom/prep/PreparedGeometry.h>
22 #include <geos/geom/prep/PreparedGeometryFactory.h>
23 #include <geos/geom/GeometryCollection.h>
24 #include <geos/geom/Polygon.h>
25 #include <geos/geom/Point.h>
26 #include <geos/geom/MultiPoint.h>
27 #include <geos/geom/MultiLineString.h>
28 #include <geos/geom/MultiPolygon.h>
29 #include <geos/geom/LinearRing.h>
30 #include <geos/geom/LineString.h>
31 #include <geos/geom/PrecisionModel.h>
32 #include <geos/geom/GeometryFactory.h>
33 #include <geos/geom/CoordinateSequenceFactory.h>
34 #include <geos/geom/Coordinate.h>
35 #include <geos/geom/IntersectionMatrix.h>
36 #include <geos/geom/Envelope.h>
37 #include <geos/index/strtree/STRtree.h>
38 #include <geos/index/strtree/GeometryItemDistance.h>
39 #include <geos/index/ItemVisitor.h>
40 #include <geos/io/WKTReader.h>
41 #include <geos/io/WKBReader.h>
42 #include <geos/io/WKTWriter.h>
43 #include <geos/io/WKBWriter.h>
44 #include <geos/algorithm/distance/DiscreteHausdorffDistance.h>
45 #include <geos/algorithm/CGAlgorithms.h>
46 #include <geos/algorithm/BoundaryNodeRule.h>
47 #include <geos/algorithm/MinimumDiameter.h>
48 #include <geos/simplify/DouglasPeuckerSimplifier.h>
49 #include <geos/simplify/TopologyPreservingSimplifier.h>
50 #include <geos/noding/GeometryNoder.h>
51 #include <geos/noding/Noder.h>
52 #include <geos/operation/buffer/BufferBuilder.h>
53 #include <geos/operation/buffer/BufferOp.h>
54 #include <geos/operation/buffer/BufferParameters.h>
55 #include <geos/operation/distance/DistanceOp.h>
56 #include <geos/operation/linemerge/LineMerger.h>
57 #include <geos/operation/overlay/OverlayOp.h>
58 #include <geos/operation/overlay/snap/GeometrySnapper.h>
59 #include <geos/operation/intersection/Rectangle.h>
60 #include <geos/operation/intersection/RectangleIntersection.h>
61 #include <geos/operation/polygonize/Polygonizer.h>
62 #include <geos/operation/relate/RelateOp.h>
63 #include <geos/operation/sharedpaths/SharedPathsOp.h>
64 #include <geos/operation/union/CascadedPolygonUnion.h>
65 #include <geos/operation/valid/IsValidOp.h>
66 #include <geos/precision/GeometryPrecisionReducer.h>
67 #include <geos/linearref/LengthIndexedLine.h>
68 #include <geos/triangulate/DelaunayTriangulationBuilder.h>
69 #include <geos/triangulate/VoronoiDiagramBuilder.h>
70 #include <geos/util/IllegalArgumentException.h>
71 #include <geos/util/Interrupt.h>
72 #include <geos/util/UniqueCoordinateArrayFilter.h>
73 #include <geos/util/Machine.h>
74 #include <geos/version.h>
76 // This should go away
77 #include <cmath> // finite
90 #pragma warning(disable : 4099)
93 // Some extra magic to make type declarations in geos_c.h work -
94 // for cross-checking of types in header.
95 #define GEOSGeometry geos::geom::Geometry
96 #define GEOSPreparedGeometry geos::geom::prep::PreparedGeometry
97 #define GEOSCoordSequence geos::geom::CoordinateSequence
98 #define GEOSBufferParams geos::operation::buffer::BufferParameters
99 #define GEOSSTRtree geos::index::strtree::STRtree
100 #define GEOSWKTReader_t geos::io::WKTReader
101 #define GEOSWKTWriter_t geos::io::WKTWriter
102 #define GEOSWKBReader_t geos::io::WKBReader
103 #define GEOSWKBWriter_t geos::io::WKBWriter
106 #include "../geos_svn_revision.h"
108 // Intentional, to allow non-standard C elements like C99 functions to be
109 // imported through C++ headers of C library, like <cmath>.
112 /// Define this if you want operations triggering Exceptions to
114 /// (will use the NOTIFY channel - only implemented for GEOSUnion so far)
116 #undef VERBOSE_EXCEPTIONS
118 #include <geos/export.h>
121 // import the most frequently used definitions globally
122 using geos::geom::Geometry
;
123 using geos::geom::LineString
;
124 using geos::geom::Polygon
;
125 using geos::geom::CoordinateSequence
;
126 using geos::geom::GeometryFactory
;
128 using geos::io::WKTReader
;
129 using geos::io::WKTWriter
;
130 using geos::io::WKBReader
;
131 using geos::io::WKBWriter
;
133 using geos::operation::overlay::OverlayOp
;
134 using geos::operation::overlay::overlayOp
;
135 using geos::operation::geounion::CascadedPolygonUnion
;
136 using geos::operation::buffer::BufferParameters
;
137 using geos::operation::buffer::BufferBuilder
;
138 using geos::precision::GeometryPrecisionReducer
;
139 using geos::util::IllegalArgumentException
;
140 using geos::algorithm::distance::DiscreteHausdorffDistance
;
142 typedef std::auto_ptr
<Geometry
> GeomAutoPtr
;
144 typedef struct GEOSContextHandle_HS
146 const GeometryFactory
*geomFactory
;
147 char msgBuffer
[1024];
148 GEOSMessageHandler noticeMessageOld
;
149 GEOSMessageHandler_r noticeMessageNew
;
151 GEOSMessageHandler errorMessageOld
;
152 GEOSMessageHandler_r errorMessageNew
;
158 GEOSContextHandle_HS()
168 memset(msgBuffer
, 0, sizeof(msgBuffer
));
169 geomFactory
= GeometryFactory::getDefaultInstance();
171 WKBByteOrder
= getMachineByteOrder();
172 setNoticeHandler(NULL
);
173 setErrorHandler(NULL
);
178 setNoticeHandler(GEOSMessageHandler nf
)
180 GEOSMessageHandler f
= noticeMessageOld
;
181 noticeMessageOld
= nf
;
182 noticeMessageNew
= NULL
;
189 setErrorHandler(GEOSMessageHandler nf
)
191 GEOSMessageHandler f
= errorMessageOld
;
192 errorMessageOld
= nf
;
193 errorMessageNew
= NULL
;
200 setNoticeHandler(GEOSMessageHandler_r nf
, void *userData
) {
201 GEOSMessageHandler_r f
= noticeMessageNew
;
202 noticeMessageOld
= NULL
;
203 noticeMessageNew
= nf
;
204 noticeData
= userData
;
210 setErrorHandler(GEOSMessageHandler_r ef
, void *userData
)
212 GEOSMessageHandler_r f
= errorMessageNew
;
213 errorMessageOld
= NULL
;
214 errorMessageNew
= ef
;
215 errorData
= userData
;
221 NOTICE_MESSAGE(string fmt
, ...)
223 if (NULL
== noticeMessageOld
&& NULL
== noticeMessageNew
) {
229 int result
= vsnprintf(msgBuffer
, sizeof(msgBuffer
) - 1, fmt
.c_str(), args
);
233 if (noticeMessageOld
) {
234 noticeMessageOld("%s", msgBuffer
);
236 noticeMessageNew(msgBuffer
, noticeData
);
242 ERROR_MESSAGE(string fmt
, ...)
244 if (NULL
== errorMessageOld
&& NULL
== errorMessageNew
) {
250 int result
= vsnprintf(msgBuffer
, sizeof(msgBuffer
) - 1, fmt
.c_str(), args
);
254 if (errorMessageOld
) {
255 errorMessageOld("%s", msgBuffer
);
257 errorMessageNew(msgBuffer
, errorData
);
261 } GEOSContextHandleInternal_t
;
263 // CAPI_ItemVisitor is used internally by the CAPI STRtree
264 // wrappers. It's defined here just to keep it out of the
266 class CAPI_ItemVisitor
: public geos::index::ItemVisitor
{
267 GEOSQueryCallback callback
;
270 CAPI_ItemVisitor (GEOSQueryCallback cb
, void *ud
)
271 : ItemVisitor(), callback(cb
), userdata(ud
) {}
272 void visitItem (void *item
) { callback(item
, userdata
); }
276 //## PROTOTYPES #############################################
278 extern "C" const char GEOS_DLL
*GEOSjtsport();
279 extern "C" char GEOS_DLL
*GEOSasText(Geometry
*g1
);
282 namespace { // anonymous
284 char* gstrdup_s(const char* str
, const std::size_t size
)
286 char* out
= static_cast<char*>(malloc(size
+ 1));
289 // as no strlen call necessary, memcpy may be faster than strcpy
290 std::memcpy(out
, str
, size
+ 1);
295 // we haven't been checking allocation before ticket #371
298 throw(std::runtime_error("Failed to allocate memory for duplicate string"));
304 char* gstrdup(std::string
const& str
)
306 return gstrdup_s(str
.c_str(), str
.size());
309 } // namespace anonymous
314 initGEOS_r(GEOSMessageHandler nf
, GEOSMessageHandler ef
)
316 GEOSContextHandle_t handle
= GEOS_init_r();
319 GEOSContext_setNoticeHandler_r(handle
, nf
);
320 GEOSContext_setErrorHandler_r(handle
, ef
);
329 GEOSContextHandleInternal_t
*handle
= new GEOSContextHandleInternal_t();
331 geos::util::Interrupt::cancel();
333 return static_cast<GEOSContextHandle_t
>(handle
);
337 GEOSContext_setNoticeHandler_r(GEOSContextHandle_t extHandle
, GEOSMessageHandler nf
)
339 GEOSContextHandleInternal_t
*handle
= 0;
340 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
341 if ( 0 == handle
->initialized
)
346 return handle
->setNoticeHandler(nf
);
350 GEOSContext_setErrorHandler_r(GEOSContextHandle_t extHandle
, GEOSMessageHandler nf
)
352 GEOSContextHandleInternal_t
*handle
= 0;
353 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
354 if ( 0 == handle
->initialized
)
359 return handle
->setErrorHandler(nf
);
363 GEOSContext_setNoticeMessageHandler_r(GEOSContextHandle_t extHandle
, GEOSMessageHandler_r nf
, void *userData
) {
364 GEOSContextHandleInternal_t
*handle
= 0;
365 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
366 if ( 0 == handle
->initialized
)
371 return handle
->setNoticeHandler(nf
, userData
);
375 GEOSContext_setErrorMessageHandler_r(GEOSContextHandle_t extHandle
, GEOSMessageHandler_r ef
, void *userData
)
377 GEOSContextHandleInternal_t
*handle
= 0;
378 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
379 if ( 0 == handle
->initialized
)
384 return handle
->setErrorHandler(ef
, userData
);
388 finishGEOS_r(GEOSContextHandle_t extHandle
)
390 // Fix up freeing handle w.r.t. malloc above
396 GEOS_finish_r(GEOSContextHandle_t extHandle
)
398 finishGEOS_r(extHandle
);
402 GEOSFree_r (GEOSContextHandle_t extHandle
, void* buffer
)
404 assert(0 != extHandle
);
409 //-----------------------------------------------------------
410 // relate()-related functions
411 // return 0 = false, 1 = true, 2 = error occured
412 //-----------------------------------------------------------
415 GEOSDisjoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
417 if ( 0 == extHandle
)
422 GEOSContextHandleInternal_t
*handle
= 0;
423 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
424 if ( handle
->initialized
== 0 )
431 bool result
= g1
->disjoint(g2
);
435 // TODO: mloskot is going to replace these double-catch block
436 // with a macro to remove redundant code in this and
437 // following functions.
438 catch (const std::exception
&e
)
440 handle
->ERROR_MESSAGE("%s", e
.what());
444 handle
->ERROR_MESSAGE("Unknown exception thrown");
451 GEOSTouches_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
453 if ( 0 == extHandle
)
458 GEOSContextHandleInternal_t
*handle
= 0;
459 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
460 if ( 0 == handle
->initialized
)
467 bool result
= g1
->touches(g2
);
470 catch (const std::exception
&e
)
472 handle
->ERROR_MESSAGE("%s", e
.what());
476 handle
->ERROR_MESSAGE("Unknown exception thrown");
483 GEOSIntersects_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
485 if ( 0 == extHandle
)
490 GEOSContextHandleInternal_t
*handle
= 0;
491 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
492 if ( 0 == handle
->initialized
)
499 bool result
= g1
->intersects(g2
);
502 catch (const std::exception
&e
)
504 handle
->ERROR_MESSAGE("%s", e
.what());
508 handle
->ERROR_MESSAGE("Unknown exception thrown");
515 GEOSCrosses_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
517 if ( 0 == extHandle
)
522 GEOSContextHandleInternal_t
*handle
= 0;
523 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
524 if ( 0 == handle
->initialized
)
531 bool result
= g1
->crosses(g2
);
534 catch (const std::exception
&e
)
536 handle
->ERROR_MESSAGE("%s", e
.what());
540 handle
->ERROR_MESSAGE("Unknown exception thrown");
547 GEOSWithin_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
549 if ( 0 == extHandle
)
554 GEOSContextHandleInternal_t
*handle
= 0;
555 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
556 if ( 0 == handle
->initialized
)
563 bool result
= g1
->within(g2
);
566 catch (const std::exception
&e
)
568 handle
->ERROR_MESSAGE("%s", e
.what());
572 handle
->ERROR_MESSAGE("Unknown exception thrown");
578 // call g1->contains(g2)
581 // 2 = error was trapped
583 GEOSContains_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
585 if ( 0 == extHandle
)
590 GEOSContextHandleInternal_t
*handle
= 0;
591 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
592 if ( 0 == handle
->initialized
)
599 bool result
= g1
->contains(g2
);
602 catch (const std::exception
&e
)
604 handle
->ERROR_MESSAGE("%s", e
.what());
608 handle
->ERROR_MESSAGE("Unknown exception thrown");
615 GEOSOverlaps_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
617 if ( 0 == extHandle
)
622 GEOSContextHandleInternal_t
*handle
= 0;
623 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
624 if ( 0 == handle
->initialized
)
631 bool result
= g1
->overlaps(g2
);
634 catch (const std::exception
&e
)
636 handle
->ERROR_MESSAGE("%s", e
.what());
640 handle
->ERROR_MESSAGE("Unknown exception thrown");
647 GEOSCovers_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
649 if ( 0 == extHandle
)
654 GEOSContextHandleInternal_t
*handle
= 0;
655 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
656 if ( 0 == handle
->initialized
)
663 bool result
= g1
->covers(g2
);
666 catch (const std::exception
&e
)
668 handle
->ERROR_MESSAGE("%s", e
.what());
672 handle
->ERROR_MESSAGE("Unknown exception thrown");
679 GEOSCoveredBy_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
681 if ( 0 == extHandle
)
686 GEOSContextHandleInternal_t
*handle
= 0;
687 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
688 if ( 0 == handle
->initialized
)
695 bool result
= g1
->coveredBy(g2
);
698 catch (const std::exception
&e
)
700 handle
->ERROR_MESSAGE("%s", e
.what());
704 handle
->ERROR_MESSAGE("Unknown exception thrown");
711 //-------------------------------------------------------------------
712 // low-level relate functions
713 //------------------------------------------------------------------
716 GEOSRelatePattern_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, const char *pat
)
718 if ( 0 == extHandle
)
723 GEOSContextHandleInternal_t
*handle
= 0;
724 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
725 if ( 0 == handle
->initialized
)
733 bool result
= g1
->relate(g2
, s
);
736 catch (const std::exception
&e
)
738 handle
->ERROR_MESSAGE("%s", e
.what());
742 handle
->ERROR_MESSAGE("Unknown exception thrown");
749 GEOSRelatePatternMatch_r(GEOSContextHandle_t extHandle
, const char *mat
,
752 if ( 0 == extHandle
)
757 GEOSContextHandleInternal_t
*handle
= 0;
758 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
759 if ( 0 == handle
->initialized
)
766 using geos::geom::IntersectionMatrix
;
770 IntersectionMatrix
im(m
);
772 bool result
= im
.matches(p
);
775 catch (const std::exception
&e
)
777 handle
->ERROR_MESSAGE("%s", e
.what());
781 handle
->ERROR_MESSAGE("Unknown exception thrown");
788 GEOSRelate_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
790 if ( 0 == extHandle
)
795 GEOSContextHandleInternal_t
*handle
= 0;
796 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
797 if ( 0 == handle
->initialized
)
804 using geos::geom::IntersectionMatrix
;
806 IntersectionMatrix
* im
= g1
->relate(g2
);
812 char *result
= gstrdup(im
->toString());
819 catch (const std::exception
&e
)
821 handle
->ERROR_MESSAGE("%s", e
.what());
825 handle
->ERROR_MESSAGE("Unknown exception thrown");
832 GEOSRelateBoundaryNodeRule_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, int bnr
)
834 if ( 0 == extHandle
)
839 GEOSContextHandleInternal_t
*handle
= 0;
840 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
841 if ( 0 == handle
->initialized
)
848 using geos::operation::relate::RelateOp
;
849 using geos::geom::IntersectionMatrix
;
850 using geos::algorithm::BoundaryNodeRule
;
852 IntersectionMatrix
* im
;
854 case GEOSRELATE_BNR_MOD2
: /* same as OGC */
855 im
= RelateOp::relate(g1
, g2
,
856 BoundaryNodeRule::getBoundaryRuleMod2());
858 case GEOSRELATE_BNR_ENDPOINT
:
859 im
= RelateOp::relate(g1
, g2
,
860 BoundaryNodeRule::getBoundaryEndPoint());
862 case GEOSRELATE_BNR_MULTIVALENT_ENDPOINT
:
863 im
= RelateOp::relate(g1
, g2
,
864 BoundaryNodeRule::getBoundaryMultivalentEndPoint());
866 case GEOSRELATE_BNR_MONOVALENT_ENDPOINT
:
867 im
= RelateOp::relate(g1
, g2
,
868 BoundaryNodeRule::getBoundaryMonovalentEndPoint());
871 handle
->ERROR_MESSAGE("Invalid boundary node rule %d", bnr
);
876 if (0 == im
) return 0;
878 char *result
= gstrdup(im
->toString());
885 catch (const std::exception
&e
)
887 handle
->ERROR_MESSAGE("%s", e
.what());
891 handle
->ERROR_MESSAGE("Unknown exception thrown");
899 //-----------------------------------------------------------------
901 //-----------------------------------------------------------------
905 GEOSisValid_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
907 if ( 0 == extHandle
)
912 GEOSContextHandleInternal_t
*handle
= 0;
913 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
914 if ( 0 == handle
->initialized
)
921 using geos::operation::valid::IsValidOp
;
922 using geos::operation::valid::TopologyValidationError
;
925 TopologyValidationError
*err
= ivo
.getValidationError();
928 handle
->NOTICE_MESSAGE("%s", err
->toString().c_str());
936 catch (const std::exception
&e
)
938 handle
->ERROR_MESSAGE("%s", e
.what());
942 handle
->ERROR_MESSAGE("Unknown exception thrown");
949 GEOSisValidReason_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
951 if ( 0 == extHandle
)
956 GEOSContextHandleInternal_t
*handle
= 0;
957 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
958 if ( 0 == handle
->initialized
)
965 using geos::operation::valid::IsValidOp
;
966 using geos::operation::valid::TopologyValidationError
;
969 char const* const validstr
= "Valid Geometry";
972 TopologyValidationError
*err
= ivo
.getValidationError();
975 std::ostringstream ss
;
977 ss
<< err
->getCoordinate();
978 const std::string errloc
= ss
.str();
979 std::string
errmsg(err
->getMessage());
980 errmsg
+= "[" + errloc
+ "]";
981 result
= gstrdup(errmsg
);
985 result
= gstrdup(std::string(validstr
));
990 catch (const std::exception
&e
)
992 handle
->ERROR_MESSAGE("%s", e
.what());
996 handle
->ERROR_MESSAGE("Unknown exception thrown");
1003 GEOSisValidDetail_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
1004 int flags
, char** reason
, Geometry
** location
)
1006 if ( 0 == extHandle
)
1011 GEOSContextHandleInternal_t
*handle
= 0;
1012 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1013 if ( 0 == handle
->initialized
)
1020 using geos::operation::valid::IsValidOp
;
1021 using geos::operation::valid::TopologyValidationError
;
1024 if ( flags
& GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE
) {
1025 ivo
.setSelfTouchingRingFormingHoleValid(true);
1027 TopologyValidationError
*err
= ivo
.getValidationError();
1031 *location
= handle
->geomFactory
->createPoint(err
->getCoordinate());
1034 std::string
errmsg(err
->getMessage());
1035 *reason
= gstrdup(errmsg
);
1040 if ( location
) *location
= 0;
1041 if ( reason
) *reason
= 0;
1042 return 1; /* valid */
1045 catch (const std::exception
&e
)
1047 handle
->ERROR_MESSAGE("%s", e
.what());
1051 handle
->ERROR_MESSAGE("Unknown exception thrown");
1054 return 2; /* exception */
1057 //-----------------------------------------------------------------
1059 //-----------------------------------------------------------------
1062 GEOSEquals_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1064 if ( 0 == extHandle
)
1069 GEOSContextHandleInternal_t
*handle
= 0;
1070 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1071 if ( 0 == handle
->initialized
)
1078 bool result
= g1
->equals(g2
);
1081 catch (const std::exception
&e
)
1083 handle
->ERROR_MESSAGE("%s", e
.what());
1087 handle
->ERROR_MESSAGE("Unknown exception thrown");
1094 GEOSEqualsExact_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double tolerance
)
1096 if ( 0 == extHandle
)
1101 GEOSContextHandleInternal_t
*handle
= 0;
1102 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1103 if ( 0 == handle
->initialized
)
1110 bool result
= g1
->equalsExact(g2
, tolerance
);
1113 catch (const std::exception
&e
)
1115 handle
->ERROR_MESSAGE("%s", e
.what());
1119 handle
->ERROR_MESSAGE("Unknown exception thrown");
1126 GEOSDistance_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double *dist
)
1130 if ( 0 == extHandle
)
1135 GEOSContextHandleInternal_t
*handle
= 0;
1136 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1137 if ( 0 == handle
->initialized
)
1144 *dist
= g1
->distance(g2
);
1147 catch (const std::exception
&e
)
1149 handle
->ERROR_MESSAGE("%s", e
.what());
1153 handle
->ERROR_MESSAGE("Unknown exception thrown");
1160 GEOSHausdorffDistance_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double *dist
)
1164 if ( 0 == extHandle
)
1169 GEOSContextHandleInternal_t
*handle
= 0;
1170 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1171 if ( 0 == handle
->initialized
)
1178 *dist
= DiscreteHausdorffDistance::distance(*g1
, *g2
);
1181 catch (const std::exception
&e
)
1183 handle
->ERROR_MESSAGE("%s", e
.what());
1187 handle
->ERROR_MESSAGE("Unknown exception thrown");
1194 GEOSHausdorffDistanceDensify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double densifyFrac
, double *dist
)
1198 if ( 0 == extHandle
)
1203 GEOSContextHandleInternal_t
*handle
= 0;
1204 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1205 if ( 0 == handle
->initialized
)
1212 *dist
= DiscreteHausdorffDistance::distance(*g1
, *g2
, densifyFrac
);
1215 catch (const std::exception
&e
)
1217 handle
->ERROR_MESSAGE("%s", e
.what());
1221 handle
->ERROR_MESSAGE("Unknown exception thrown");
1228 GEOSArea_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double *area
)
1232 if ( 0 == extHandle
)
1237 GEOSContextHandleInternal_t
*handle
= 0;
1238 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1239 if ( 0 == handle
->initialized
)
1246 *area
= g
->getArea();
1249 catch (const std::exception
&e
)
1251 handle
->ERROR_MESSAGE("%s", e
.what());
1255 handle
->ERROR_MESSAGE("Unknown exception thrown");
1262 GEOSLength_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double *length
)
1264 assert(0 != length
);
1266 if ( 0 == extHandle
)
1271 GEOSContextHandleInternal_t
*handle
= 0;
1272 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1273 if ( 0 == handle
->initialized
)
1280 *length
= g
->getLength();
1283 catch (const std::exception
&e
)
1285 handle
->ERROR_MESSAGE("%s", e
.what());
1289 handle
->ERROR_MESSAGE("Unknown exception thrown");
1295 CoordinateSequence
*
1296 GEOSNearestPoints_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1298 if ( 0 == extHandle
)
1303 GEOSContextHandleInternal_t
*handle
= 0;
1304 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1305 if ( 0 == handle
->initialized
)
1312 if (g1
->isEmpty() || g2
->isEmpty()) return 0;
1313 return geos::operation::distance::DistanceOp::nearestPoints(g1
, g2
);
1315 catch (const std::exception
&e
)
1317 handle
->ERROR_MESSAGE("%s", e
.what());
1321 handle
->ERROR_MESSAGE("Unknown exception thrown");
1329 GEOSGeomFromWKT_r(GEOSContextHandle_t extHandle
, const char *wkt
)
1331 if ( 0 == extHandle
)
1336 GEOSContextHandleInternal_t
*handle
= 0;
1337 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1338 if ( 0 == handle
->initialized
)
1345 const std::string
wktstring(wkt
);
1346 WKTReader
r(static_cast<GeometryFactory
const*>(handle
->geomFactory
));
1348 Geometry
*g
= r
.read(wktstring
);
1351 catch (const std::exception
&e
)
1353 handle
->ERROR_MESSAGE("%s", e
.what());
1357 handle
->ERROR_MESSAGE("Unknown exception thrown");
1364 GEOSGeomToWKT_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1366 if ( 0 == extHandle
)
1371 GEOSContextHandleInternal_t
*handle
= 0;
1372 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1373 if ( 0 == handle
->initialized
)
1381 char *result
= gstrdup(g1
->toString());
1384 catch (const std::exception
&e
)
1386 handle
->ERROR_MESSAGE("%s", e
.what());
1390 handle
->ERROR_MESSAGE("Unknown exception thrown");
1395 // Remember to free the result!
1397 GEOSGeomToWKB_buf_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, size_t *size
)
1401 if ( 0 == extHandle
)
1406 GEOSContextHandleInternal_t
*handle
= 0;
1407 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1408 if ( 0 == handle
->initialized
)
1413 using geos::io::WKBWriter
;
1416 int byteOrder
= handle
->WKBByteOrder
;
1417 WKBWriter
w(handle
->WKBOutputDims
, byteOrder
);
1418 std::ostringstream
os(std::ios_base::binary
);
1420 std::string
wkbstring(os
.str());
1421 const std::size_t len
= wkbstring
.length();
1423 unsigned char* result
= 0;
1424 result
= static_cast<unsigned char*>(malloc(len
));
1427 std::memcpy(result
, wkbstring
.c_str(), len
);
1432 catch (const std::exception
&e
)
1434 handle
->ERROR_MESSAGE("%s", e
.what());
1438 handle
->ERROR_MESSAGE("Unknown exception thrown");
1445 GEOSGeomFromWKB_buf_r(GEOSContextHandle_t extHandle
, const unsigned char *wkb
, size_t size
)
1447 if ( 0 == extHandle
)
1452 GEOSContextHandleInternal_t
*handle
= 0;
1453 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1454 if ( 0 == handle
->initialized
)
1459 using geos::io::WKBReader
;
1462 std::string
wkbstring(reinterpret_cast<const char*>(wkb
), size
); // make it binary !
1463 WKBReader
r(*(static_cast<GeometryFactory
const*>(handle
->geomFactory
)));
1464 std::istringstream
is(std::ios_base::binary
);
1466 is
.seekg(0, std::ios::beg
); // rewind reader pointer
1467 Geometry
*g
= r
.read(is
);
1470 catch (const std::exception
&e
)
1472 handle
->ERROR_MESSAGE("%s", e
.what());
1476 handle
->ERROR_MESSAGE("Unknown exception thrown");
1482 /* Read/write wkb hex values. Returned geometries are
1483 owned by the caller.*/
1485 GEOSGeomToHEX_buf_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, size_t *size
)
1487 if ( 0 == extHandle
)
1492 GEOSContextHandleInternal_t
*handle
= 0;
1493 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1494 if ( 0 == handle
->initialized
)
1499 using geos::io::WKBWriter
;
1502 int byteOrder
= handle
->WKBByteOrder
;
1503 WKBWriter
w(handle
->WKBOutputDims
, byteOrder
);
1504 std::ostringstream
os(std::ios_base::binary
);
1506 std::string
hexstring(os
.str());
1508 char *result
= gstrdup(hexstring
);
1511 *size
= hexstring
.length();
1514 return reinterpret_cast<unsigned char*>(result
);
1516 catch (const std::exception
&e
)
1518 handle
->ERROR_MESSAGE("%s", e
.what());
1522 handle
->ERROR_MESSAGE("Unknown exception thrown");
1529 GEOSGeomFromHEX_buf_r(GEOSContextHandle_t extHandle
, const unsigned char *hex
, size_t size
)
1531 if ( 0 == extHandle
)
1536 GEOSContextHandleInternal_t
*handle
= 0;
1537 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1538 if ( 0 == handle
->initialized
)
1543 using geos::io::WKBReader
;
1546 std::string
hexstring(reinterpret_cast<const char*>(hex
), size
);
1547 WKBReader
r(*(static_cast<GeometryFactory
const*>(handle
->geomFactory
)));
1548 std::istringstream
is(std::ios_base::binary
);
1550 is
.seekg(0, std::ios::beg
); // rewind reader pointer
1552 Geometry
*g
= r
.readHEX(is
);
1555 catch (const std::exception
&e
)
1557 handle
->ERROR_MESSAGE("%s", e
.what());
1561 handle
->ERROR_MESSAGE("Unknown exception thrown");
1568 GEOSisEmpty_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1570 if ( 0 == extHandle
)
1575 GEOSContextHandleInternal_t
*handle
= 0;
1576 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1577 if ( 0 == handle
->initialized
)
1584 return g1
->isEmpty();
1586 catch (const std::exception
&e
)
1588 handle
->ERROR_MESSAGE("%s", e
.what());
1592 handle
->ERROR_MESSAGE("Unknown exception thrown");
1599 GEOSisSimple_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1601 if ( 0 == extHandle
)
1606 GEOSContextHandleInternal_t
*handle
= 0;
1607 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1608 if ( 0 == handle
->initialized
)
1615 return g1
->isSimple();
1617 catch (const std::exception
&e
)
1619 handle
->ERROR_MESSAGE("%s", e
.what());
1625 handle
->ERROR_MESSAGE("Unknown exception thrown");
1631 GEOSisRing_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
1633 if ( 0 == extHandle
)
1638 GEOSContextHandleInternal_t
*handle
= 0;
1639 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1640 if ( 0 == handle
->initialized
)
1647 const LineString
*ls
= dynamic_cast<const LineString
*>(g
);
1649 return (ls
->isRing());
1654 catch (const std::exception
&e
)
1656 handle
->ERROR_MESSAGE("%s", e
.what());
1662 handle
->ERROR_MESSAGE("Unknown exception thrown");
1669 //free the result of this
1671 GEOSGeomType_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1673 if ( 0 == extHandle
)
1678 GEOSContextHandleInternal_t
*handle
= 0;
1679 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1680 if ( 0 == handle
->initialized
)
1687 std::string s
= g1
->getGeometryType();
1689 char *result
= gstrdup(s
);
1692 catch (const std::exception
&e
)
1694 handle
->ERROR_MESSAGE("%s", e
.what());
1698 handle
->ERROR_MESSAGE("Unknown exception thrown");
1704 // Return postgis geometry type index
1706 GEOSGeomTypeId_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1708 if ( 0 == extHandle
)
1713 GEOSContextHandleInternal_t
*handle
= 0;
1714 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1715 if ( 0 == handle
->initialized
)
1722 return g1
->getGeometryTypeId();
1724 catch (const std::exception
&e
)
1726 handle
->ERROR_MESSAGE("%s", e
.what());
1730 handle
->ERROR_MESSAGE("Unknown exception thrown");
1736 //-------------------------------------------------------------------
1737 // GEOS functions that return geometries
1738 //-------------------------------------------------------------------
1741 GEOSEnvelope_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1743 if ( 0 == extHandle
)
1748 GEOSContextHandleInternal_t
*handle
= 0;
1749 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1750 if ( 0 == handle
->initialized
)
1757 Geometry
*g3
= g1
->getEnvelope();
1760 catch (const std::exception
&e
)
1762 handle
->ERROR_MESSAGE("%s", e
.what());
1766 handle
->ERROR_MESSAGE("Unknown exception thrown");
1773 GEOSIntersection_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1775 if ( 0 == extHandle
)
1780 GEOSContextHandleInternal_t
*handle
= 0;
1781 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1782 if ( 0 == handle
->initialized
)
1789 return g1
->intersection(g2
);
1791 catch (const std::exception
&e
)
1793 handle
->ERROR_MESSAGE("%s", e
.what());
1797 handle
->ERROR_MESSAGE("Unknown exception thrown");
1804 GEOSBuffer_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadrantsegments
)
1806 if ( 0 == extHandle
)
1811 GEOSContextHandleInternal_t
*handle
= 0;
1812 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1813 if ( 0 == handle
->initialized
)
1820 Geometry
*g3
= g1
->buffer(width
, quadrantsegments
);
1823 catch (const std::exception
&e
)
1825 handle
->ERROR_MESSAGE("%s", e
.what());
1829 handle
->ERROR_MESSAGE("Unknown exception thrown");
1836 GEOSBufferWithStyle_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int endCapStyle
, int joinStyle
, double mitreLimit
)
1838 using geos::operation::buffer::BufferParameters
;
1839 using geos::operation::buffer::BufferOp
;
1840 using geos::util::IllegalArgumentException
;
1842 if ( 0 == extHandle
)
1847 GEOSContextHandleInternal_t
*handle
= 0;
1848 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1849 if ( 0 == handle
->initialized
)
1856 BufferParameters bp
;
1857 bp
.setQuadrantSegments(quadsegs
);
1859 if ( endCapStyle
> BufferParameters::CAP_SQUARE
)
1861 throw IllegalArgumentException("Invalid buffer endCap style");
1864 static_cast<BufferParameters::EndCapStyle
>(endCapStyle
)
1867 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1869 throw IllegalArgumentException("Invalid buffer join style");
1872 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1874 bp
.setMitreLimit(mitreLimit
);
1875 BufferOp
op(g1
, bp
);
1876 Geometry
*g3
= op
.getResultGeometry(width
);
1879 catch (const std::exception
&e
)
1881 handle
->ERROR_MESSAGE("%s", e
.what());
1885 handle
->ERROR_MESSAGE("Unknown exception thrown");
1892 GEOSOffsetCurve_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int joinStyle
, double mitreLimit
)
1894 if ( 0 == extHandle
) return NULL
;
1896 GEOSContextHandleInternal_t
*handle
= 0;
1897 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1898 if ( 0 == handle
->initialized
) return NULL
;
1902 BufferParameters bp
;
1903 bp
.setEndCapStyle( BufferParameters::CAP_FLAT
);
1904 bp
.setQuadrantSegments(quadsegs
);
1906 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1908 throw IllegalArgumentException("Invalid buffer join style");
1911 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1913 bp
.setMitreLimit(mitreLimit
);
1915 bool isLeftSide
= true;
1920 BufferBuilder
bufBuilder (bp
);
1921 Geometry
*g3
= bufBuilder
.bufferLineSingleSided(g1
, width
, isLeftSide
);
1925 catch (const std::exception
&e
)
1927 handle
->ERROR_MESSAGE("%s", e
.what());
1931 handle
->ERROR_MESSAGE("Unknown exception thrown");
1937 /* @deprecated in 3.3.0 */
1939 GEOSSingleSidedBuffer_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int joinStyle
, double mitreLimit
, int leftSide
)
1941 if ( 0 == extHandle
) return NULL
;
1943 GEOSContextHandleInternal_t
*handle
= 0;
1944 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1945 if ( 0 == handle
->initialized
) return NULL
;
1949 BufferParameters bp
;
1950 bp
.setEndCapStyle( BufferParameters::CAP_FLAT
);
1951 bp
.setQuadrantSegments(quadsegs
);
1953 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1955 throw IllegalArgumentException("Invalid buffer join style");
1958 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1960 bp
.setMitreLimit(mitreLimit
);
1962 bool isLeftSide
= leftSide
== 0 ? false : true;
1963 BufferBuilder
bufBuilder (bp
);
1964 Geometry
*g3
= bufBuilder
.bufferLineSingleSided(g1
, width
, isLeftSide
);
1968 catch (const std::exception
&e
)
1970 handle
->ERROR_MESSAGE("%s", e
.what());
1974 handle
->ERROR_MESSAGE("Unknown exception thrown");
1981 GEOSConvexHull_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1983 if ( 0 == extHandle
)
1988 GEOSContextHandleInternal_t
*handle
= 0;
1989 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1990 if ( 0 == handle
->initialized
)
1997 Geometry
*g3
= g1
->convexHull();
2000 catch (const std::exception
&e
)
2002 handle
->ERROR_MESSAGE("%s", e
.what());
2006 handle
->ERROR_MESSAGE("Unknown exception thrown");
2014 GEOSMinimumRotatedRectangle_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2016 if ( 0 == extHandle
)
2021 GEOSContextHandleInternal_t
*handle
= 0;
2022 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2023 if ( 0 == handle
->initialized
)
2030 geos::algorithm::MinimumDiameter
m(g
);
2032 Geometry
*g3
= m
.getMinimumRectangle();
2035 catch (const std::exception
&e
)
2037 handle
->ERROR_MESSAGE("%s", e
.what());
2041 handle
->ERROR_MESSAGE("Unknown exception thrown");
2048 GEOSMinimumWidth_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2050 if ( 0 == extHandle
)
2055 GEOSContextHandleInternal_t
*handle
= 0;
2056 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2057 if ( 0 == handle
->initialized
)
2064 geos::algorithm::MinimumDiameter
m(g
);
2066 Geometry
*g3
= m
.getDiameter();
2069 catch (const std::exception
&e
)
2071 handle
->ERROR_MESSAGE("%s", e
.what());
2075 handle
->ERROR_MESSAGE("Unknown exception thrown");
2083 GEOSDifference_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
2085 if ( 0 == extHandle
)
2090 GEOSContextHandleInternal_t
*handle
= 0;
2091 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2092 if ( 0 == handle
->initialized
)
2099 return g1
->difference(g2
);
2101 catch (const std::exception
&e
)
2103 handle
->ERROR_MESSAGE("%s", e
.what());
2107 handle
->ERROR_MESSAGE("Unknown exception thrown");
2114 GEOSBoundary_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2116 if ( 0 == extHandle
)
2121 GEOSContextHandleInternal_t
*handle
= 0;
2122 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2123 if ( 0 == handle
->initialized
)
2130 Geometry
*g3
= g1
->getBoundary();
2133 catch (const std::exception
&e
)
2135 handle
->ERROR_MESSAGE("%s", e
.what());
2139 handle
->ERROR_MESSAGE("Unknown exception thrown");
2146 GEOSSymDifference_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
2148 if ( 0 == extHandle
)
2153 GEOSContextHandleInternal_t
*handle
= 0;
2154 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2155 if ( 0 == handle
->initialized
)
2162 return g1
->symDifference(g2
);
2164 catch (const std::exception
&e
)
2166 handle
->ERROR_MESSAGE("%s", e
.what());
2172 handle
->ERROR_MESSAGE("Unknown exception thrown");
2178 GEOSUnion_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
2180 if ( 0 == extHandle
)
2185 GEOSContextHandleInternal_t
*handle
= 0;
2186 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2187 if ( 0 == handle
->initialized
)
2194 return g1
->Union(g2
);
2196 catch (const std::exception
&e
)
2198 #if VERBOSE_EXCEPTIONS
2199 std::ostringstream s
;
2200 s
<< "Exception on GEOSUnion with following inputs:" << std::endl
;
2201 s
<< "A: "<<g1
->toString() << std::endl
;
2202 s
<< "B: "<<g2
->toString() << std::endl
;
2203 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
2204 #endif // VERBOSE_EXCEPTIONS
2205 handle
->ERROR_MESSAGE("%s", e
.what());
2209 handle
->ERROR_MESSAGE("Unknown exception thrown");
2216 GEOSUnaryUnion_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2218 if ( 0 == extHandle
)
2223 GEOSContextHandleInternal_t
*handle
= 0;
2224 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2225 if ( 0 == handle
->initialized
)
2232 GeomAutoPtr
g3 ( g
->Union() );
2233 return g3
.release();
2235 catch (const std::exception
&e
)
2237 #if VERBOSE_EXCEPTIONS
2238 std::ostringstream s
;
2239 s
<< "Exception on GEOSUnaryUnion with following inputs:" << std::endl
;
2240 s
<< "A: "<<g1
->toString() << std::endl
;
2241 s
<< "B: "<<g2
->toString() << std::endl
;
2242 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
2243 #endif // VERBOSE_EXCEPTIONS
2244 handle
->ERROR_MESSAGE("%s", e
.what());
2248 handle
->ERROR_MESSAGE("Unknown exception thrown");
2255 GEOSNode_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2257 if ( 0 == extHandle
)
2262 GEOSContextHandleInternal_t
*handle
= 0;
2263 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2264 if ( 0 == handle
->initialized
)
2271 std::auto_ptr
<Geometry
> g3
= geos::noding::GeometryNoder::node(*g
);
2272 return g3
.release();
2274 catch (const std::exception
&e
)
2276 #if VERBOSE_EXCEPTIONS
2277 std::ostringstream s
;
2278 s
<< "Exception on GEOSUnaryUnion with following inputs:" << std::endl
;
2279 s
<< "A: "<<g1
->toString() << std::endl
;
2280 s
<< "B: "<<g2
->toString() << std::endl
;
2281 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
2282 #endif // VERBOSE_EXCEPTIONS
2283 handle
->ERROR_MESSAGE("%s", e
.what());
2287 handle
->ERROR_MESSAGE("Unknown exception thrown");
2294 GEOSUnionCascaded_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2296 if ( 0 == extHandle
)
2301 GEOSContextHandleInternal_t
*handle
= 0;
2302 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2303 if ( 0 == handle
->initialized
)
2310 const geos::geom::MultiPolygon
*p
= dynamic_cast<const geos::geom::MultiPolygon
*>(g1
);
2313 handle
->ERROR_MESSAGE("Invalid argument (must be a MultiPolygon)");
2317 using geos::operation::geounion::CascadedPolygonUnion
;
2318 return CascadedPolygonUnion::Union(p
);
2320 catch (const std::exception
&e
)
2322 handle
->ERROR_MESSAGE("%s", e
.what());
2326 handle
->ERROR_MESSAGE("Unknown exception thrown");
2333 GEOSPointOnSurface_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2335 if ( 0 == extHandle
)
2340 GEOSContextHandleInternal_t
*handle
= 0;
2341 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2342 if ( 0 == handle
->initialized
)
2349 Geometry
*ret
= g1
->getInteriorPoint();
2352 const GeometryFactory
* gf
= handle
->geomFactory
;
2353 // return an empty point
2354 return gf
->createPoint();
2358 catch (const std::exception
&e
)
2360 handle
->ERROR_MESSAGE("%s", e
.what());
2364 handle
->ERROR_MESSAGE("Unknown exception thrown");
2371 GEOSClipByRect_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double xmin
, double ymin
, double xmax
, double ymax
)
2373 if ( 0 == extHandle
)
2378 GEOSContextHandleInternal_t
*handle
= 0;
2379 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2380 if ( 0 == handle
->initialized
)
2387 using geos::operation::intersection::Rectangle
;
2388 using geos::operation::intersection::RectangleIntersection
;
2389 Rectangle
rect(xmin
, ymin
, xmax
, ymax
);
2390 std::auto_ptr
<Geometry
> g3
= RectangleIntersection::clip(*g
, rect
);
2391 return g3
.release();
2393 catch (const std::exception
&e
)
2395 #if VERBOSE_EXCEPTIONS
2396 std::ostringstream s
;
2397 s
<< "Exception on GEOSClipByRect with following inputs:" << std::endl
;
2398 s
<< "A: "<<g1
->toString() << std::endl
;
2399 s
<< "B: "<<g2
->toString() << std::endl
;
2400 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
2401 #endif // VERBOSE_EXCEPTIONS
2402 handle
->ERROR_MESSAGE("%s", e
.what());
2406 handle
->ERROR_MESSAGE("Unknown exception thrown");
2412 //-------------------------------------------------------------------
2413 // memory management functions
2414 //------------------------------------------------------------------
2417 GEOSGeom_destroy_r(GEOSContextHandle_t extHandle
, Geometry
*a
)
2419 GEOSContextHandleInternal_t
*handle
= 0;
2421 // FIXME: mloskot: Does this try-catch around delete means that
2422 // destructors in GEOS may throw? If it does, this is a serious
2423 // violation of "never throw an exception from a destructor" principle
2429 catch (const std::exception
&e
)
2431 if ( 0 == extHandle
)
2436 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2437 if ( 0 == handle
->initialized
)
2442 handle
->ERROR_MESSAGE("%s", e
.what());
2446 if ( 0 == extHandle
)
2451 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2452 if ( 0 == handle
->initialized
)
2457 handle
->ERROR_MESSAGE("Unknown exception thrown");
2462 GEOSSetSRID_r(GEOSContextHandle_t extHandle
, Geometry
*g
, int srid
)
2466 if ( 0 == extHandle
)
2471 GEOSContextHandleInternal_t
*handle
= 0;
2472 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2473 if ( 0 == handle
->initialized
)
2483 GEOSGetNumCoordinates_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2487 if ( 0 == extHandle
)
2492 GEOSContextHandleInternal_t
*handle
= 0;
2493 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2494 if ( 0 == handle
->initialized
)
2501 return static_cast<int>(g
->getNumPoints());
2503 catch (const std::exception
&e
)
2505 handle
->ERROR_MESSAGE("%s", e
.what());
2509 handle
->ERROR_MESSAGE("Unknown exception thrown");
2516 * Return -1 on exception, 0 otherwise.
2517 * Converts Geometry to normal form (or canonical form).
2520 GEOSNormalize_r(GEOSContextHandle_t extHandle
, Geometry
*g
)
2524 if ( 0 == extHandle
)
2529 GEOSContextHandleInternal_t
*handle
= 0;
2530 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2531 if ( 0 == handle
->initialized
)
2539 return 0; // SUCCESS
2541 catch (const std::exception
&e
)
2543 handle
->ERROR_MESSAGE("%s", e
.what());
2547 handle
->ERROR_MESSAGE("Unknown exception thrown");
2554 GEOSGetNumInteriorRings_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2556 if ( 0 == extHandle
)
2561 GEOSContextHandleInternal_t
*handle
= 0;
2562 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2563 if ( 0 == handle
->initialized
)
2570 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
2573 handle
->ERROR_MESSAGE("Argument is not a Polygon");
2576 return static_cast<int>(p
->getNumInteriorRing());
2578 catch (const std::exception
&e
)
2580 handle
->ERROR_MESSAGE("%s", e
.what());
2584 handle
->ERROR_MESSAGE("Unknown exception thrown");
2591 // returns -1 on error and 1 for non-multi geometries
2593 GEOSGetNumGeometries_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2595 if ( 0 == extHandle
)
2600 GEOSContextHandleInternal_t
*handle
= 0;
2601 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2602 if ( 0 == handle
->initialized
)
2609 return static_cast<int>(g1
->getNumGeometries());
2611 catch (const std::exception
&e
)
2613 handle
->ERROR_MESSAGE("%s", e
.what());
2617 handle
->ERROR_MESSAGE("Unknown exception thrown");
2625 * Call only on GEOMETRYCOLLECTION or MULTI*.
2626 * Return a pointer to the internal Geometry.
2629 GEOSGetGeometryN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2631 if ( 0 == extHandle
)
2636 GEOSContextHandleInternal_t
*handle
= 0;
2637 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2638 if ( 0 == handle
->initialized
)
2645 return g1
->getGeometryN(n
);
2647 catch (const std::exception
&e
)
2649 handle
->ERROR_MESSAGE("%s", e
.what());
2653 handle
->ERROR_MESSAGE("Unknown exception thrown");
2660 * Call only on LINESTRING
2661 * Returns NULL on exception
2664 GEOSGeomGetPointN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2666 if ( 0 == extHandle
)
2671 GEOSContextHandleInternal_t
*handle
= 0;
2672 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2673 if ( 0 == handle
->initialized
)
2680 using geos::geom::LineString
;
2681 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2684 handle
->ERROR_MESSAGE("Argument is not a LineString");
2687 return ls
->getPointN(n
);
2689 catch (const std::exception
&e
)
2691 handle
->ERROR_MESSAGE("%s", e
.what());
2695 handle
->ERROR_MESSAGE("Unknown exception thrown");
2702 * Call only on LINESTRING
2705 GEOSGeomGetStartPoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2707 if ( 0 == extHandle
)
2712 GEOSContextHandleInternal_t
*handle
= 0;
2713 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2714 if ( 0 == handle
->initialized
)
2721 using geos::geom::LineString
;
2722 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2725 handle
->ERROR_MESSAGE("Argument is not a LineString");
2728 return ls
->getStartPoint();
2730 catch (const std::exception
&e
)
2732 handle
->ERROR_MESSAGE("%s", e
.what());
2736 handle
->ERROR_MESSAGE("Unknown exception thrown");
2743 * Call only on LINESTRING
2746 GEOSGeomGetEndPoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2748 if ( 0 == extHandle
)
2753 GEOSContextHandleInternal_t
*handle
= 0;
2754 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2755 if ( 0 == handle
->initialized
)
2762 using geos::geom::LineString
;
2763 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2766 handle
->ERROR_MESSAGE("Argument is not a LineString");
2769 return ls
->getEndPoint();
2771 catch (const std::exception
&e
)
2773 handle
->ERROR_MESSAGE("%s", e
.what());
2777 handle
->ERROR_MESSAGE("Unknown exception thrown");
2784 * Call only on LINESTRING or MULTILINESTRING
2785 * return 2 on exception, 1 on true, 0 on false
2788 GEOSisClosed_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2790 if ( 0 == extHandle
)
2795 GEOSContextHandleInternal_t
*handle
= 0;
2796 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2797 if ( 0 == handle
->initialized
)
2804 using geos::geom::LineString
;
2805 using geos::geom::MultiLineString
;
2807 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2809 return ls
->isClosed();
2812 const MultiLineString
*mls
= dynamic_cast<const MultiLineString
*>(g1
);
2814 return mls
->isClosed();
2817 handle
->ERROR_MESSAGE("Argument is not a LineString or MultiLineString");
2820 catch (const std::exception
&e
)
2822 handle
->ERROR_MESSAGE("%s", e
.what());
2826 handle
->ERROR_MESSAGE("Unknown exception thrown");
2833 * Call only on LINESTRING
2834 * return 0 on exception, otherwise 1
2837 GEOSGeomGetLength_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *length
)
2839 if ( 0 == extHandle
)
2844 GEOSContextHandleInternal_t
*handle
= 0;
2845 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2846 if ( 0 == handle
->initialized
)
2853 using geos::geom::LineString
;
2854 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2857 handle
->ERROR_MESSAGE("Argument is not a LineString");
2860 *length
= ls
->getLength();
2863 catch (const std::exception
&e
)
2865 handle
->ERROR_MESSAGE("%s", e
.what());
2869 handle
->ERROR_MESSAGE("Unknown exception thrown");
2876 * Call only on LINESTRING
2879 GEOSGeomGetNumPoints_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2881 if ( 0 == extHandle
)
2886 GEOSContextHandleInternal_t
*handle
= 0;
2887 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2888 if ( 0 == handle
->initialized
)
2895 using geos::geom::LineString
;
2896 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2899 handle
->ERROR_MESSAGE("Argument is not a LineString");
2902 return static_cast<int>(ls
->getNumPoints());
2904 catch (const std::exception
&e
)
2906 handle
->ERROR_MESSAGE("%s", e
.what());
2910 handle
->ERROR_MESSAGE("Unknown exception thrown");
2918 * returns 0 on exception, otherwise 1
2921 GEOSGeomGetX_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *x
)
2923 if ( 0 == extHandle
)
2928 GEOSContextHandleInternal_t
*handle
= 0;
2929 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2930 if ( 0 == handle
->initialized
)
2937 using geos::geom::Point
;
2938 const Point
*po
= dynamic_cast<const Point
*>(g1
);
2941 handle
->ERROR_MESSAGE("Argument is not a Point");
2947 catch (const std::exception
&e
)
2949 handle
->ERROR_MESSAGE("%s", e
.what());
2953 handle
->ERROR_MESSAGE("Unknown exception thrown");
2961 * returns 0 on exception, otherwise 1
2964 GEOSGeomGetY_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *y
)
2966 if ( 0 == extHandle
)
2971 GEOSContextHandleInternal_t
*handle
= 0;
2972 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2973 if ( 0 == handle
->initialized
)
2980 using geos::geom::Point
;
2981 const Point
*po
= dynamic_cast<const Point
*>(g1
);
2984 handle
->ERROR_MESSAGE("Argument is not a Point");
2990 catch (const std::exception
&e
)
2992 handle
->ERROR_MESSAGE("%s", e
.what());
2996 handle
->ERROR_MESSAGE("Unknown exception thrown");
3003 * Call only on polygon
3004 * Return a copy of the internal Geometry.
3007 GEOSGetExteriorRing_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
3009 if ( 0 == extHandle
)
3014 GEOSContextHandleInternal_t
*handle
= 0;
3015 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3016 if ( 0 == handle
->initialized
)
3023 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
3026 handle
->ERROR_MESSAGE("Invalid argument (must be a Polygon)");
3029 return p
->getExteriorRing();
3031 catch (const std::exception
&e
)
3033 handle
->ERROR_MESSAGE("%s", e
.what());
3037 handle
->ERROR_MESSAGE("Unknown exception thrown");
3044 * Call only on polygon
3045 * Return a pointer to internal storage, do not destroy it.
3048 GEOSGetInteriorRingN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
3050 if ( 0 == extHandle
)
3055 GEOSContextHandleInternal_t
*handle
= 0;
3056 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3057 if ( 0 == handle
->initialized
)
3064 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
3067 handle
->ERROR_MESSAGE("Invalid argument (must be a Polygon)");
3070 return p
->getInteriorRingN(n
);
3072 catch (const std::exception
&e
)
3074 handle
->ERROR_MESSAGE("%s", e
.what());
3078 handle
->ERROR_MESSAGE("Unknown exception thrown");
3085 GEOSGetCentroid_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3087 if ( 0 == extHandle
)
3092 GEOSContextHandleInternal_t
*handle
= 0;
3093 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3094 if ( 0 == handle
->initialized
)
3101 Geometry
*ret
= g
->getCentroid();
3104 const GeometryFactory
*gf
= handle
->geomFactory
;
3105 return gf
->createPoint();
3109 catch (const std::exception
&e
)
3111 handle
->ERROR_MESSAGE("%s", e
.what());
3115 handle
->ERROR_MESSAGE("Unknown exception thrown");
3122 GEOSGeom_createEmptyCollection_r(GEOSContextHandle_t extHandle
, int type
)
3124 if ( 0 == extHandle
)
3129 GEOSContextHandleInternal_t
*handle
= 0;
3130 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3131 if ( 0 == handle
->initialized
)
3138 sprintf(buf
, "createCollection: requested type %d", type
);
3139 handle
->NOTICE_MESSAGE("%s", buf
);// TODO: Can handle->NOTICE_MESSAGE format that directly?
3144 const GeometryFactory
* gf
= handle
->geomFactory
;
3149 case GEOS_GEOMETRYCOLLECTION
:
3150 g
= gf
->createGeometryCollection();
3152 case GEOS_MULTIPOINT
:
3153 g
= gf
->createMultiPoint();
3155 case GEOS_MULTILINESTRING
:
3156 g
= gf
->createMultiLineString();
3158 case GEOS_MULTIPOLYGON
:
3159 g
= gf
->createMultiPolygon();
3162 handle
->ERROR_MESSAGE("Unsupported type request for GEOSGeom_createEmptyCollection_r");
3169 catch (const std::exception
&e
)
3171 handle
->ERROR_MESSAGE("%s", e
.what());
3175 handle
->ERROR_MESSAGE("Unknown exception thrown");
3182 GEOSGeom_createCollection_r(GEOSContextHandle_t extHandle
, int type
, Geometry
**geoms
, unsigned int ngeoms
)
3184 if ( 0 == extHandle
)
3189 GEOSContextHandleInternal_t
*handle
= 0;
3190 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3191 if ( 0 == handle
->initialized
)
3198 sprintf(buf
, "PostGIS2GEOS_collection: requested type %d, ngeoms: %d",
3200 handle
->NOTICE_MESSAGE("%s", buf
);// TODO: Can handle->NOTICE_MESSAGE format that directly?
3205 const GeometryFactory
* gf
= handle
->geomFactory
;
3206 std::vector
<Geometry
*>* vgeoms
= new std::vector
<Geometry
*>(geoms
, geoms
+ ngeoms
);
3211 case GEOS_GEOMETRYCOLLECTION
:
3212 g
= gf
->createGeometryCollection(vgeoms
);
3214 case GEOS_MULTIPOINT
:
3215 g
= gf
->createMultiPoint(vgeoms
);
3217 case GEOS_MULTILINESTRING
:
3218 g
= gf
->createMultiLineString(vgeoms
);
3220 case GEOS_MULTIPOLYGON
:
3221 g
= gf
->createMultiPolygon(vgeoms
);
3224 handle
->ERROR_MESSAGE("Unsupported type request for PostGIS2GEOS_collection");
3232 catch (const std::exception
&e
)
3234 handle
->ERROR_MESSAGE("%s", e
.what());
3238 handle
->ERROR_MESSAGE("Unknown exception thrown");
3245 GEOSPolygonize_r(GEOSContextHandle_t extHandle
, const Geometry
* const * g
, unsigned int ngeoms
)
3247 if ( 0 == extHandle
)
3252 GEOSContextHandleInternal_t
*handle
= 0;
3253 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3254 if ( 0 == handle
->initialized
)
3264 using geos::operation::polygonize::Polygonizer
;
3266 for (std::size_t i
= 0; i
< ngeoms
; ++i
)
3272 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
3275 std::vector
<Polygon
*> *polys
= plgnzr
.getPolygons();
3279 handle
->NOTICE_MESSAGE("output polygons got");
3282 // We need a vector of Geometry pointers, not Polygon pointers.
3283 // STL vector doesn't allow transparent upcast of this
3284 // nature, so we explicitly convert.
3285 // (it's just a waste of processor and memory, btw)
3287 // XXX mloskot: Why not to extent GeometryFactory to accept
3288 // vector of polygons or extend Polygonizer to return list of Geometry*
3289 // or add a wrapper which semantic is similar to:
3290 // std::vector<as_polygon<Geometry*> >
3291 std::vector
<Geometry
*> *polyvec
= new std::vector
<Geometry
*>(polys
->size());
3293 for (std::size_t i
= 0; i
< polys
->size(); ++i
)
3295 (*polyvec
)[i
] = (*polys
)[i
];
3300 const GeometryFactory
*gf
= handle
->geomFactory
;
3302 // The below takes ownership of the passed vector,
3303 // so we must *not* delete it
3304 out
= gf
->createGeometryCollection(polyvec
);
3306 catch (const std::exception
&e
)
3308 handle
->ERROR_MESSAGE("%s", e
.what());
3312 handle
->ERROR_MESSAGE("Unknown exception thrown");
3319 GEOSPolygonizer_getCutEdges_r(GEOSContextHandle_t extHandle
, const Geometry
* const * g
, unsigned int ngeoms
)
3321 if ( 0 == extHandle
)
3326 GEOSContextHandleInternal_t
*handle
= 0;
3327 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3328 if ( 0 == handle
->initialized
)
3338 using geos::operation::polygonize::Polygonizer
;
3340 for (std::size_t i
= 0; i
< ngeoms
; ++i
)
3346 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
3349 const std::vector
<const LineString
*>& lines
= plgnzr
.getCutEdges();
3352 handle
->NOTICE_MESSAGE("output polygons got");
3355 // We need a vector of Geometry pointers, not Polygon pointers.
3356 // STL vector doesn't allow transparent upcast of this
3357 // nature, so we explicitly convert.
3358 // (it's just a waste of processor and memory, btw)
3359 // XXX mloskot: See comment for GEOSPolygonize_r
3360 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3362 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3364 (*linevec
)[i
] = lines
[i
]->clone();
3367 const GeometryFactory
*gf
= handle
->geomFactory
;
3369 // The below takes ownership of the passed vector,
3370 // so we must *not* delete it
3371 out
= gf
->createGeometryCollection(linevec
);
3373 catch (const std::exception
&e
)
3375 handle
->ERROR_MESSAGE("%s", e
.what());
3379 handle
->ERROR_MESSAGE("Unknown exception thrown");
3386 GEOSPolygonize_full_r(GEOSContextHandle_t extHandle
, const Geometry
* g
,
3387 Geometry
** cuts
, Geometry
** dangles
, Geometry
** invalid
)
3389 if ( 0 == extHandle
)
3394 GEOSContextHandleInternal_t
*handle
= 0;
3395 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3396 if ( 0 == handle
->initialized
)
3404 using geos::operation::polygonize::Polygonizer
;
3406 for (std::size_t i
= 0; i
<g
->getNumGeometries(); ++i
)
3408 plgnzr
.add(g
->getGeometryN(i
));
3412 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
3414 const GeometryFactory
*gf
= handle
->geomFactory
;
3418 const std::vector
<const LineString
*>& lines
= plgnzr
.getCutEdges();
3419 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3420 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3422 (*linevec
)[i
] = lines
[i
]->clone();
3425 // The below takes ownership of the passed vector,
3426 // so we must *not* delete it
3427 *cuts
= gf
->createGeometryCollection(linevec
);
3432 const std::vector
<const LineString
*>& lines
= plgnzr
.getDangles();
3433 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3434 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3436 (*linevec
)[i
] = lines
[i
]->clone();
3439 // The below takes ownership of the passed vector,
3440 // so we must *not* delete it
3441 *dangles
= gf
->createGeometryCollection(linevec
);
3446 const std::vector
<LineString
*>& lines
= plgnzr
.getInvalidRingLines();
3447 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3448 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3450 (*linevec
)[i
] = lines
[i
]->clone();
3453 // The below takes ownership of the passed vector,
3454 // so we must *not* delete it
3455 *invalid
= gf
->createGeometryCollection(linevec
);
3458 std::vector
<Polygon
*> *polys
= plgnzr
.getPolygons();
3459 std::vector
<Geometry
*> *polyvec
= new std::vector
<Geometry
*>(polys
->size());
3460 for (std::size_t i
= 0; i
< polys
->size(); ++i
)
3462 (*polyvec
)[i
] = (*polys
)[i
];
3466 return gf
->createGeometryCollection(polyvec
);
3469 catch (const std::exception
&e
)
3471 handle
->ERROR_MESSAGE("%s", e
.what());
3476 handle
->ERROR_MESSAGE("Unknown exception thrown");
3482 GEOSLineMerge_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3484 if ( 0 == extHandle
)
3489 GEOSContextHandleInternal_t
*handle
= 0;
3490 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3491 if ( 0 == handle
->initialized
)
3500 using geos::operation::linemerge::LineMerger
;
3504 std::vector
<LineString
*>* lines
= lmrgr
.getMergedLineStrings();
3508 handle
->NOTICE_MESSAGE("output lines got");
3511 std::vector
<Geometry
*>*geoms
= new std::vector
<Geometry
*>(lines
->size());
3512 for (std::vector
<Geometry
*>::size_type i
= 0; i
< lines
->size(); ++i
)
3514 (*geoms
)[i
] = (*lines
)[i
];
3519 const GeometryFactory
*gf
= handle
->geomFactory
;
3520 out
= gf
->buildGeometry(geoms
);
3523 //out = gf->createGeometryCollection(geoms);
3525 catch (const std::exception
&e
)
3527 handle
->ERROR_MESSAGE("%s", e
.what());
3531 handle
->ERROR_MESSAGE("Unknown exception thrown");
3538 GEOSGetSRID_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3542 if ( 0 == extHandle
)
3547 GEOSContextHandleInternal_t
*handle
= 0;
3548 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3549 if ( 0 == handle
->initialized
)
3556 return g
->getSRID();
3558 catch (const std::exception
&e
)
3560 handle
->ERROR_MESSAGE("%s", e
.what());
3564 handle
->ERROR_MESSAGE("Unknown exception thrown");
3570 const char* GEOSversion()
3572 static char version
[256];
3573 sprintf(version
, "%s r%d", GEOS_CAPI_VERSION
, GEOS_SVN_REVISION
);
3577 const char* GEOSjtsport()
3579 return GEOS_JTS_PORT
;
3583 GEOSHasZ_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3587 if ( 0 == extHandle
)
3592 GEOSContextHandleInternal_t
*handle
= 0;
3593 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3594 if ( 0 == handle
->initialized
)
3603 assert(0 != g
->getCoordinate());
3605 double az
= g
->getCoordinate()->z
;
3606 //handle->ERROR_MESSAGE("ZCoord: %g", az);
3608 return static_cast<char>(FINITE(az
));
3612 GEOS_getWKBOutputDims_r(GEOSContextHandle_t extHandle
)
3614 if ( 0 == extHandle
)
3619 GEOSContextHandleInternal_t
*handle
= 0;
3620 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3621 if ( 0 == handle
->initialized
)
3626 return handle
->WKBOutputDims
;
3630 GEOS_setWKBOutputDims_r(GEOSContextHandle_t extHandle
, int newdims
)
3632 if ( 0 == extHandle
)
3637 GEOSContextHandleInternal_t
*handle
= 0;
3638 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3639 if ( 0 == handle
->initialized
)
3644 if ( newdims
< 2 || newdims
> 3 )
3646 handle
->ERROR_MESSAGE("WKB output dimensions out of range 2..3");
3649 const int olddims
= handle
->WKBOutputDims
;
3650 handle
->WKBOutputDims
= newdims
;
3656 GEOS_getWKBByteOrder_r(GEOSContextHandle_t extHandle
)
3658 if ( 0 == extHandle
)
3663 GEOSContextHandleInternal_t
*handle
= 0;
3664 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3665 if ( 0 == handle
->initialized
)
3670 return handle
->WKBByteOrder
;
3674 GEOS_setWKBByteOrder_r(GEOSContextHandle_t extHandle
, int byteOrder
)
3676 if ( 0 == extHandle
)
3681 GEOSContextHandleInternal_t
*handle
= 0;
3682 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3683 if ( 0 == handle
->initialized
)
3688 const int oldByteOrder
= handle
->WKBByteOrder
;
3689 handle
->WKBByteOrder
= byteOrder
;
3691 return oldByteOrder
;
3695 CoordinateSequence
*
3696 GEOSCoordSeq_create_r(GEOSContextHandle_t extHandle
, unsigned int size
, unsigned int dims
)
3698 if ( 0 == extHandle
)
3703 GEOSContextHandleInternal_t
*handle
= 0;
3704 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3705 if ( 0 == handle
->initialized
)
3712 const GeometryFactory
*gf
= handle
->geomFactory
;
3713 return gf
->getCoordinateSequenceFactory()->create(size
, dims
);
3715 catch (const std::exception
&e
)
3717 handle
->ERROR_MESSAGE("%s", e
.what());
3721 handle
->ERROR_MESSAGE("Unknown exception thrown");
3728 GEOSCoordSeq_setOrdinate_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
,
3729 unsigned int idx
, unsigned int dim
, double val
)
3732 if ( 0 == extHandle
)
3737 GEOSContextHandleInternal_t
*handle
= 0;
3738 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3739 if ( 0 == handle
->initialized
)
3746 cs
->setOrdinate(idx
, dim
, val
);
3749 catch (const std::exception
&e
)
3751 handle
->ERROR_MESSAGE("%s", e
.what());
3755 handle
->ERROR_MESSAGE("Unknown exception thrown");
3762 GEOSCoordSeq_setX_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3764 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 0, val
);
3768 GEOSCoordSeq_setY_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3770 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 1, val
);
3774 GEOSCoordSeq_setZ_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3776 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 2, val
);
3779 CoordinateSequence
*
3780 GEOSCoordSeq_clone_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
)
3784 if ( 0 == extHandle
)
3789 GEOSContextHandleInternal_t
*handle
= 0;
3790 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3791 if ( 0 == handle
->initialized
)
3800 catch (const std::exception
&e
)
3802 handle
->ERROR_MESSAGE("%s", e
.what());
3806 handle
->ERROR_MESSAGE("Unknown exception thrown");
3813 GEOSCoordSeq_getOrdinate_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
,
3814 unsigned int idx
, unsigned int dim
, double *val
)
3819 if ( 0 == extHandle
)
3824 GEOSContextHandleInternal_t
*handle
= 0;
3825 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3826 if ( 0 == handle
->initialized
)
3833 double d
= cs
->getOrdinate(idx
, dim
);
3838 catch (const std::exception
&e
)
3840 handle
->ERROR_MESSAGE("%s", e
.what());
3844 handle
->ERROR_MESSAGE("Unknown exception thrown");
3851 GEOSCoordSeq_getX_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
3853 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 0, val
);
3857 GEOSCoordSeq_getY_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
3859 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 1, val
);
3863 GEOSCoordSeq_getZ_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
3865 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 2, val
);
3869 GEOSCoordSeq_getSize_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
, unsigned int *size
)
3874 if ( 0 == extHandle
)
3879 GEOSContextHandleInternal_t
*handle
= 0;
3880 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3881 if ( 0 == handle
->initialized
)
3888 const std::size_t sz
= cs
->getSize();
3889 *size
= static_cast<unsigned int>(sz
);
3892 catch (const std::exception
&e
)
3894 handle
->ERROR_MESSAGE("%s", e
.what());
3898 handle
->ERROR_MESSAGE("Unknown exception thrown");
3905 GEOSCoordSeq_getDimensions_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
, unsigned int *dims
)
3910 if ( 0 == extHandle
)
3915 GEOSContextHandleInternal_t
*handle
= 0;
3916 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3917 if ( 0 == handle
->initialized
)
3924 const std::size_t dim
= cs
->getDimension();
3925 *dims
= static_cast<unsigned int>(dim
);
3929 catch (const std::exception
&e
)
3931 handle
->ERROR_MESSAGE("%s", e
.what());
3936 handle
->ERROR_MESSAGE("Unknown exception thrown");
3943 GEOSCoordSeq_destroy_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
)
3945 GEOSContextHandleInternal_t
*handle
= 0;
3951 catch (const std::exception
&e
)
3953 if ( 0 == extHandle
)
3958 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3959 if ( 0 == handle
->initialized
)
3964 handle
->ERROR_MESSAGE("%s", e
.what());
3968 if ( 0 == extHandle
)
3973 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3974 if ( 0 == handle
->initialized
)
3979 handle
->ERROR_MESSAGE("Unknown exception thrown");
3983 const CoordinateSequence
*
3984 GEOSGeom_getCoordSeq_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3986 if ( 0 == extHandle
)
3991 GEOSContextHandleInternal_t
*handle
= 0;
3992 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3993 if ( 0 == handle
->initialized
)
4000 using geos::geom::Point
;
4002 const LineString
*ls
= dynamic_cast<const LineString
*>(g
);
4005 return ls
->getCoordinatesRO();
4008 const Point
*p
= dynamic_cast<const Point
*>(g
);
4011 return p
->getCoordinatesRO();
4014 handle
->ERROR_MESSAGE("Geometry must be a Point or LineString");
4017 catch (const std::exception
&e
)
4019 handle
->ERROR_MESSAGE("%s", e
.what());
4023 handle
->ERROR_MESSAGE("Unknown exception thrown");
4030 GEOSGeom_createEmptyPoint_r(GEOSContextHandle_t extHandle
)
4032 if ( 0 == extHandle
)
4037 GEOSContextHandleInternal_t
*handle
= 0;
4038 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4039 if ( 0 == handle
->initialized
)
4046 const GeometryFactory
*gf
= handle
->geomFactory
;
4047 return gf
->createPoint();
4049 catch (const std::exception
&e
)
4051 handle
->ERROR_MESSAGE("%s", e
.what());
4055 handle
->ERROR_MESSAGE("Unknown exception thrown");
4062 GEOSGeom_createPoint_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
4064 if ( 0 == extHandle
)
4069 GEOSContextHandleInternal_t
*handle
= 0;
4070 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4071 if ( 0 == handle
->initialized
)
4078 const GeometryFactory
*gf
= handle
->geomFactory
;
4079 return gf
->createPoint(cs
);
4081 catch (const std::exception
&e
)
4083 handle
->ERROR_MESSAGE("%s", e
.what());
4087 handle
->ERROR_MESSAGE("Unknown exception thrown");
4094 GEOSGeom_createLinearRing_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
4096 if ( 0 == extHandle
)
4101 GEOSContextHandleInternal_t
*handle
= 0;
4102 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4103 if ( 0 == handle
->initialized
)
4110 const GeometryFactory
*gf
= handle
->geomFactory
;
4112 return gf
->createLinearRing(cs
);
4114 catch (const std::exception
&e
)
4116 handle
->ERROR_MESSAGE("%s", e
.what());
4120 handle
->ERROR_MESSAGE("Unknown exception thrown");
4127 GEOSGeom_createEmptyLineString_r(GEOSContextHandle_t extHandle
)
4129 if ( 0 == extHandle
)
4134 GEOSContextHandleInternal_t
*handle
= 0;
4135 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4136 if ( 0 == handle
->initialized
)
4143 const GeometryFactory
*gf
= handle
->geomFactory
;
4145 return gf
->createLineString();
4147 catch (const std::exception
&e
)
4149 handle
->ERROR_MESSAGE("%s", e
.what());
4153 handle
->ERROR_MESSAGE("Unknown exception thrown");
4160 GEOSGeom_createLineString_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
4162 if ( 0 == extHandle
)
4167 GEOSContextHandleInternal_t
*handle
= 0;
4168 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4169 if ( 0 == handle
->initialized
)
4176 const GeometryFactory
*gf
= handle
->geomFactory
;
4178 return gf
->createLineString(cs
);
4180 catch (const std::exception
&e
)
4182 handle
->ERROR_MESSAGE("%s", e
.what());
4186 handle
->ERROR_MESSAGE("Unknown exception thrown");
4193 GEOSGeom_createEmptyPolygon_r(GEOSContextHandle_t extHandle
)
4195 if ( 0 == extHandle
)
4200 GEOSContextHandleInternal_t
*handle
= 0;
4201 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4202 if ( 0 == handle
->initialized
)
4209 const GeometryFactory
*gf
= handle
->geomFactory
;
4210 return gf
->createPolygon();
4212 catch (const std::exception
&e
)
4214 handle
->ERROR_MESSAGE("%s", e
.what());
4218 handle
->ERROR_MESSAGE("Unknown exception thrown");
4225 GEOSGeom_createPolygon_r(GEOSContextHandle_t extHandle
, Geometry
*shell
, Geometry
**holes
, unsigned int nholes
)
4227 // FIXME: holes must be non-nullptr or may be nullptr?
4228 //assert(0 != holes);
4230 if ( 0 == extHandle
)
4235 GEOSContextHandleInternal_t
*handle
= 0;
4236 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4237 if ( 0 == handle
->initialized
)
4244 using geos::geom::LinearRing
;
4246 std::vector
<Geometry
*> *vholes
= new std::vector
<Geometry
*>(holes
, holes
+ nholes
);
4248 LinearRing
*nshell
= dynamic_cast<LinearRing
*>(shell
);
4251 handle
->ERROR_MESSAGE("Shell is not a LinearRing");
4255 const GeometryFactory
*gf
= handle
->geomFactory
;
4257 return gf
->createPolygon(nshell
, vholes
);
4259 catch (const std::exception
&e
)
4261 handle
->ERROR_MESSAGE("%s", e
.what());
4265 handle
->ERROR_MESSAGE("Unknown exception thrown");
4272 GEOSGeom_clone_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
4276 if ( 0 == extHandle
)
4281 GEOSContextHandleInternal_t
*handle
= 0;
4282 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4283 if ( 0 == handle
->initialized
)
4292 catch (const std::exception
&e
)
4294 handle
->ERROR_MESSAGE("%s", e
.what());
4298 handle
->ERROR_MESSAGE("Unknown exception thrown");
4305 GEOSGeom_setPrecision_r(GEOSContextHandle_t extHandle
, const GEOSGeometry
*g
,
4306 double gridSize
, int flags
)
4308 using namespace geos::geom
;
4312 if ( 0 == extHandle
)
4317 GEOSContextHandleInternal_t
*handle
= 0;
4318 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4319 if ( 0 == handle
->initialized
)
4326 const PrecisionModel
*pm
= g
->getPrecisionModel();
4327 double cursize
= pm
->isFloating() ? 0 : 1.0/pm
->getScale();
4328 std::auto_ptr
<PrecisionModel
> newpm
;
4329 if ( gridSize
) newpm
.reset( new PrecisionModel(1.0/gridSize
) );
4330 else newpm
.reset( new PrecisionModel() );
4331 GeometryFactory::unique_ptr gf
=
4332 GeometryFactory::create( newpm
.get(), g
->getSRID() );
4334 if ( gridSize
&& cursize
!= gridSize
)
4336 // We need to snap the geometry
4337 GeometryPrecisionReducer
reducer( *gf
);
4338 reducer
.setPointwise( flags
& GEOS_PREC_NO_TOPO
);
4339 reducer
.setRemoveCollapsedComponents( ! (flags
& GEOS_PREC_KEEP_COLLAPSED
) );
4340 ret
= reducer
.reduce( *g
).release();
4344 // No need or willing to snap, just change the factory
4345 ret
= gf
->createGeometry(g
);
4349 catch (const std::exception
&e
)
4351 handle
->ERROR_MESSAGE("%s", e
.what());
4355 handle
->ERROR_MESSAGE("Unknown exception thrown");
4362 GEOSGeom_getPrecision_r(GEOSContextHandle_t extHandle
, const GEOSGeometry
*g
)
4364 using namespace geos::geom
;
4368 if ( 0 == extHandle
)
4373 GEOSContextHandleInternal_t
*handle
= 0;
4374 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4375 if ( 0 == handle
->initialized
)
4382 const PrecisionModel
*pm
= g
->getPrecisionModel();
4383 double cursize
= pm
->isFloating() ? 0 : 1.0/pm
->getScale();
4386 catch (const std::exception
&e
)
4388 handle
->ERROR_MESSAGE("%s", e
.what());
4392 handle
->ERROR_MESSAGE("Unknown exception thrown");
4399 GEOSGeom_getDimensions_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
4401 if ( 0 == extHandle
)
4406 GEOSContextHandleInternal_t
*handle
= 0;
4407 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4408 if ( 0 == handle
->initialized
)
4415 return (int) g
->getDimension();
4417 catch (const std::exception
&e
)
4419 handle
->ERROR_MESSAGE("%s", e
.what());
4423 handle
->ERROR_MESSAGE("Unknown exception thrown");
4430 GEOSGeom_getCoordinateDimension_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
4432 if ( 0 == extHandle
)
4437 GEOSContextHandleInternal_t
*handle
= 0;
4438 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4439 if ( 0 == handle
->initialized
)
4446 return g
->getCoordinateDimension();
4448 catch (const std::exception
&e
)
4450 handle
->ERROR_MESSAGE("%s", e
.what());
4454 handle
->ERROR_MESSAGE("Unknown exception thrown");
4461 GEOSSimplify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double tolerance
)
4463 if ( 0 == extHandle
)
4468 GEOSContextHandleInternal_t
*handle
= 0;
4469 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4470 if ( 0 == handle
->initialized
)
4477 using namespace geos::simplify
;
4478 Geometry::AutoPtr
g(DouglasPeuckerSimplifier::simplify(g1
, tolerance
));
4481 catch (const std::exception
&e
)
4483 handle
->ERROR_MESSAGE("%s", e
.what());
4487 handle
->ERROR_MESSAGE("Unknown exception thrown");
4494 GEOSTopologyPreserveSimplify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double tolerance
)
4496 if ( 0 == extHandle
)
4501 GEOSContextHandleInternal_t
*handle
= 0;
4502 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4503 if ( 0 == handle
->initialized
)
4510 using namespace geos::simplify
;
4511 Geometry::AutoPtr
g(TopologyPreservingSimplifier::simplify(g1
, tolerance
));
4514 catch (const std::exception
&e
)
4516 handle
->ERROR_MESSAGE("%s", e
.what());
4520 handle
->ERROR_MESSAGE("Unknown exception thrown");
4529 GEOSWKTReader_create_r(GEOSContextHandle_t extHandle
)
4531 if ( 0 == extHandle
)
4536 GEOSContextHandleInternal_t
*handle
= 0;
4537 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4538 if ( 0 == handle
->initialized
)
4545 using geos::io::WKTReader
;
4546 return new WKTReader((GeometryFactory
*)handle
->geomFactory
);
4548 catch (const std::exception
&e
)
4550 handle
->ERROR_MESSAGE("%s", e
.what());
4554 handle
->ERROR_MESSAGE("Unknown exception thrown");
4561 GEOSWKTReader_destroy_r(GEOSContextHandle_t extHandle
, WKTReader
*reader
)
4563 GEOSContextHandleInternal_t
*handle
= 0;
4569 catch (const std::exception
&e
)
4571 if ( 0 == extHandle
)
4576 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4577 if ( 0 == handle
->initialized
)
4582 handle
->ERROR_MESSAGE("%s", e
.what());
4586 if ( 0 == extHandle
)
4591 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4592 if ( 0 == handle
->initialized
)
4597 handle
->ERROR_MESSAGE("Unknown exception thrown");
4603 GEOSWKTReader_read_r(GEOSContextHandle_t extHandle
, WKTReader
*reader
, const char *wkt
)
4605 assert(0 != reader
);
4607 if ( 0 == extHandle
)
4612 GEOSContextHandleInternal_t
*handle
= 0;
4613 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4614 if ( 0 == handle
->initialized
)
4621 const std::string
wktstring(wkt
);
4622 Geometry
*g
= reader
->read(wktstring
);
4625 catch (const std::exception
&e
)
4627 handle
->ERROR_MESSAGE("%s", e
.what());
4631 handle
->ERROR_MESSAGE("Unknown exception thrown");
4639 GEOSWKTWriter_create_r(GEOSContextHandle_t extHandle
)
4641 if ( 0 == extHandle
)
4646 GEOSContextHandleInternal_t
*handle
= 0;
4647 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4648 if ( 0 == handle
->initialized
)
4655 using geos::io::WKTWriter
;
4656 return new WKTWriter();
4658 catch (const std::exception
&e
)
4660 handle
->ERROR_MESSAGE("%s", e
.what());
4664 handle
->ERROR_MESSAGE("Unknown exception thrown");
4671 GEOSWKTWriter_destroy_r(GEOSContextHandle_t extHandle
, WKTWriter
*Writer
)
4674 GEOSContextHandleInternal_t
*handle
= 0;
4680 catch (const std::exception
&e
)
4682 if ( 0 == extHandle
)
4687 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4688 if ( 0 == handle
->initialized
)
4693 handle
->ERROR_MESSAGE("%s", e
.what());
4697 if ( 0 == extHandle
)
4702 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4703 if ( 0 == handle
->initialized
)
4708 handle
->ERROR_MESSAGE("Unknown exception thrown");
4714 GEOSWKTWriter_write_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, const Geometry
*geom
)
4716 assert(0 != writer
);
4718 if ( 0 == extHandle
)
4723 GEOSContextHandleInternal_t
*handle
= 0;
4724 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4725 if ( 0 == handle
->initialized
)
4732 std::string
sgeom(writer
->write(geom
));
4733 char *result
= gstrdup(sgeom
);
4736 catch (const std::exception
&e
)
4738 handle
->ERROR_MESSAGE("%s", e
.what());
4742 handle
->ERROR_MESSAGE("Unknown exception thrown");
4749 GEOSWKTWriter_setTrim_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, char trim
)
4751 assert(0 != writer
);
4753 if ( 0 == extHandle
)
4758 GEOSContextHandleInternal_t
*handle
= 0;
4759 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4760 if ( 0 == handle
->initialized
)
4765 writer
->setTrim(0 != trim
);
4769 GEOSWKTWriter_setRoundingPrecision_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int precision
)
4771 assert(0 != writer
);
4773 if ( 0 == extHandle
)
4778 GEOSContextHandleInternal_t
*handle
= 0;
4779 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4780 if ( 0 == handle
->initialized
)
4785 writer
->setRoundingPrecision(precision
);
4789 GEOSWKTWriter_setOutputDimension_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int dim
)
4791 assert(0 != writer
);
4793 if ( 0 == extHandle
)
4798 GEOSContextHandleInternal_t
*handle
= 0;
4799 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4800 if ( 0 == handle
->initialized
)
4807 writer
->setOutputDimension(dim
);
4809 catch (const std::exception
&e
)
4811 handle
->ERROR_MESSAGE("%s", e
.what());
4815 handle
->ERROR_MESSAGE("Unknown exception thrown");
4820 GEOSWKTWriter_getOutputDimension_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
)
4822 assert(0 != writer
);
4824 if ( 0 == extHandle
)
4829 GEOSContextHandleInternal_t
*handle
= 0;
4830 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4831 if ( 0 == handle
->initialized
)
4840 dim
= writer
->getOutputDimension();
4842 catch (const std::exception
&e
)
4844 handle
->ERROR_MESSAGE("%s", e
.what());
4848 handle
->ERROR_MESSAGE("Unknown exception thrown");
4855 GEOSWKTWriter_setOld3D_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int useOld3D
)
4857 assert(0 != writer
);
4859 if ( 0 == extHandle
)
4864 GEOSContextHandleInternal_t
*handle
= 0;
4865 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4866 if ( 0 == handle
->initialized
)
4871 writer
->setOld3D(0 != useOld3D
);
4876 GEOSWKBReader_create_r(GEOSContextHandle_t extHandle
)
4878 if ( 0 == extHandle
)
4883 GEOSContextHandleInternal_t
*handle
= 0;
4884 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4885 if ( 0 == handle
->initialized
)
4890 using geos::io::WKBReader
;
4893 return new WKBReader(*(GeometryFactory
*)handle
->geomFactory
);
4895 catch (const std::exception
&e
)
4897 handle
->ERROR_MESSAGE("%s", e
.what());
4901 handle
->ERROR_MESSAGE("Unknown exception thrown");
4908 GEOSWKBReader_destroy_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
)
4910 GEOSContextHandleInternal_t
*handle
= 0;
4916 catch (const std::exception
&e
)
4918 if ( 0 == extHandle
)
4923 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4924 if ( 0 == handle
->initialized
)
4929 handle
->ERROR_MESSAGE("%s", e
.what());
4933 if ( 0 == extHandle
)
4938 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4939 if ( 0 == handle
->initialized
)
4944 handle
->ERROR_MESSAGE("Unknown exception thrown");
4948 struct membuf
: public std::streambuf
4950 membuf(char* s
, std::size_t n
)
4957 GEOSWKBReader_read_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
, const unsigned char *wkb
, size_t size
)
4959 assert(0 != reader
);
4962 if ( 0 == extHandle
)
4967 GEOSContextHandleInternal_t
*handle
= 0;
4968 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4969 if ( 0 == handle
->initialized
)
4976 //std::string wkbstring(reinterpret_cast<const char*>(wkb), size); // make it binary !
4977 //std::istringstream is(std::ios_base::binary);
4978 //is.str(wkbstring);
4979 //is.seekg(0, std::ios::beg); // rewind reader pointer
4981 // http://stackoverflow.com/questions/2079912/simpler-way-to-create-a-c-memorystream-from-char-size-t-without-copying-t
4982 membuf
mb((char*)wkb
, size
);
4985 Geometry
*g
= reader
->read(is
);
4988 catch (const std::exception
&e
)
4990 handle
->ERROR_MESSAGE("%s", e
.what());
4994 handle
->ERROR_MESSAGE("Unknown exception thrown");
5001 GEOSWKBReader_readHEX_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
, const unsigned char *hex
, size_t size
)
5003 assert(0 != reader
);
5006 if ( 0 == extHandle
)
5011 GEOSContextHandleInternal_t
*handle
= 0;
5012 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5013 if ( 0 == handle
->initialized
)
5020 std::string
hexstring(reinterpret_cast<const char*>(hex
), size
);
5021 std::istringstream
is(std::ios_base::binary
);
5023 is
.seekg(0, std::ios::beg
); // rewind reader pointer
5025 Geometry
*g
= reader
->readHEX(is
);
5028 catch (const std::exception
&e
)
5030 handle
->ERROR_MESSAGE("%s", e
.what());
5034 handle
->ERROR_MESSAGE("Unknown exception thrown");
5042 GEOSWKBWriter_create_r(GEOSContextHandle_t extHandle
)
5044 if ( 0 == extHandle
)
5049 GEOSContextHandleInternal_t
*handle
= 0;
5050 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5051 if ( 0 == handle
->initialized
)
5058 using geos::io::WKBWriter
;
5059 return new WKBWriter();
5061 catch (const std::exception
&e
)
5063 handle
->ERROR_MESSAGE("%s", e
.what());
5067 handle
->ERROR_MESSAGE("Unknown exception thrown");
5074 GEOSWKBWriter_destroy_r(GEOSContextHandle_t extHandle
, WKBWriter
*Writer
)
5076 GEOSContextHandleInternal_t
*handle
= 0;
5082 catch (const std::exception
&e
)
5084 if ( 0 == extHandle
)
5089 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5090 if ( 0 == handle
->initialized
)
5095 handle
->ERROR_MESSAGE("%s", e
.what());
5099 if ( 0 == extHandle
)
5104 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5105 if ( 0 == handle
->initialized
)
5110 handle
->ERROR_MESSAGE("Unknown exception thrown");
5115 /* The caller owns the result */
5117 GEOSWKBWriter_write_r(GEOSContextHandle_t extHandle
, WKBWriter
*writer
, const Geometry
*geom
, size_t *size
)
5119 assert(0 != writer
);
5123 if ( 0 == extHandle
)
5128 GEOSContextHandleInternal_t
*handle
= 0;
5129 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5130 if ( 0 == handle
->initialized
)
5137 std::ostringstream
os(std::ios_base::binary
);
5138 writer
->write(*geom
, os
);
5140 const std::string
& wkbstring
= os
.str();
5141 const std::size_t len
= wkbstring
.length();
5143 unsigned char *result
= NULL
;
5144 result
= (unsigned char*) malloc(len
);
5145 std::memcpy(result
, wkbstring
.c_str(), len
);
5149 catch (const std::exception
&e
)
5151 handle
->ERROR_MESSAGE("%s", e
.what());
5155 handle
->ERROR_MESSAGE("Unknown exception thrown");
5160 /* The caller owns the result */
5162 GEOSWKBWriter_writeHEX_r(GEOSContextHandle_t extHandle
, WKBWriter
*writer
, const Geometry
*geom
, size_t *size
)
5164 assert(0 != writer
);
5168 if ( 0 == extHandle
)
5173 GEOSContextHandleInternal_t
*handle
= 0;
5174 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5175 if ( 0 == handle
->initialized
)
5182 std::ostringstream
os(std::ios_base::binary
);
5183 writer
->writeHEX(*geom
, os
);
5184 std::string
wkbstring(os
.str());
5185 const std::size_t len
= wkbstring
.length();
5187 unsigned char *result
= NULL
;
5188 result
= (unsigned char*) malloc(len
);
5189 std::memcpy(result
, wkbstring
.c_str(), len
);
5193 catch (const std::exception
&e
)
5195 handle
->ERROR_MESSAGE("%s", e
.what());
5199 handle
->ERROR_MESSAGE("Unknown exception thrown");
5206 GEOSWKBWriter_getOutputDimension_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
5208 assert(0 != writer
);
5210 if ( 0 == extHandle
)
5217 GEOSContextHandleInternal_t
*handle
= 0;
5218 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5219 if ( 0 != handle
->initialized
)
5223 ret
= writer
->getOutputDimension();
5227 handle
->ERROR_MESSAGE("Unknown exception thrown");
5235 GEOSWKBWriter_setOutputDimension_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, int newDimension
)
5237 assert(0 != writer
);
5239 if ( 0 == extHandle
)
5244 GEOSContextHandleInternal_t
*handle
= 0;
5245 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5246 if ( 0 != handle
->initialized
)
5250 writer
->setOutputDimension(newDimension
);
5252 catch (const std::exception
&e
)
5254 handle
->ERROR_MESSAGE("%s", e
.what());
5258 handle
->ERROR_MESSAGE("Unknown exception thrown");
5264 GEOSWKBWriter_getByteOrder_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
5266 assert(0 != writer
);
5268 if ( 0 == extHandle
)
5275 GEOSContextHandleInternal_t
*handle
= 0;
5276 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5277 if ( 0 != handle
->initialized
)
5281 ret
= writer
->getByteOrder();
5286 handle
->ERROR_MESSAGE("Unknown exception thrown");
5294 GEOSWKBWriter_setByteOrder_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, int newByteOrder
)
5296 assert(0 != writer
);
5298 if ( 0 == extHandle
)
5303 GEOSContextHandleInternal_t
*handle
= 0;
5304 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5305 if ( 0 != handle
->initialized
)
5309 writer
->setByteOrder(newByteOrder
);
5311 catch (const std::exception
&e
)
5313 handle
->ERROR_MESSAGE("%s", e
.what());
5317 handle
->ERROR_MESSAGE("Unknown exception thrown");
5323 GEOSWKBWriter_getIncludeSRID_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
5325 assert(0 != writer
);
5327 if ( 0 == extHandle
)
5334 GEOSContextHandleInternal_t
*handle
= 0;
5335 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5336 if ( 0 != handle
->initialized
)
5340 int srid
= writer
->getIncludeSRID();
5345 handle
->ERROR_MESSAGE("Unknown exception thrown");
5349 return static_cast<char>(ret
);
5353 GEOSWKBWriter_setIncludeSRID_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, const char newIncludeSRID
)
5355 assert(0 != writer
);
5357 if ( 0 == extHandle
)
5362 GEOSContextHandleInternal_t
*handle
= 0;
5363 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5364 if ( 0 != handle
->initialized
)
5368 writer
->setIncludeSRID(newIncludeSRID
);
5372 handle
->ERROR_MESSAGE("Unknown exception thrown");
5378 //-----------------------------------------------------------------
5379 // Prepared Geometry
5380 //-----------------------------------------------------------------
5382 const geos::geom::prep::PreparedGeometry
*
5383 GEOSPrepare_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
5385 if ( 0 == extHandle
)
5390 GEOSContextHandleInternal_t
*handle
= 0;
5391 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5392 if ( 0 == handle
->initialized
)
5397 const geos::geom::prep::PreparedGeometry
* prep
= 0;
5401 prep
= geos::geom::prep::PreparedGeometryFactory::prepare(g
);
5403 catch (const std::exception
&e
)
5405 handle
->ERROR_MESSAGE("%s", e
.what());
5409 handle
->ERROR_MESSAGE("Unknown exception thrown");
5416 GEOSPreparedGeom_destroy_r(GEOSContextHandle_t extHandle
, const geos::geom::prep::PreparedGeometry
*a
)
5418 GEOSContextHandleInternal_t
*handle
= 0;
5424 catch (const std::exception
&e
)
5426 if ( 0 == extHandle
)
5431 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5432 if ( 0 == handle
->initialized
)
5437 handle
->ERROR_MESSAGE("%s", e
.what());
5441 if ( 0 == extHandle
)
5446 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5447 if ( 0 == handle
->initialized
)
5452 handle
->ERROR_MESSAGE("Unknown exception thrown");
5457 GEOSPreparedContains_r(GEOSContextHandle_t extHandle
,
5458 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5463 if ( 0 == extHandle
)
5468 GEOSContextHandleInternal_t
*handle
= 0;
5469 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5470 if ( 0 == handle
->initialized
)
5477 bool result
= pg
->contains(g
);
5480 catch (const std::exception
&e
)
5482 handle
->ERROR_MESSAGE("%s", e
.what());
5486 handle
->ERROR_MESSAGE("Unknown exception thrown");
5493 GEOSPreparedContainsProperly_r(GEOSContextHandle_t extHandle
,
5494 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5499 if ( 0 == extHandle
)
5504 GEOSContextHandleInternal_t
*handle
= 0;
5505 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5506 if ( 0 == handle
->initialized
)
5513 bool result
= pg
->containsProperly(g
);
5516 catch (const std::exception
&e
)
5518 handle
->ERROR_MESSAGE("%s", e
.what());
5522 handle
->ERROR_MESSAGE("Unknown exception thrown");
5529 GEOSPreparedCoveredBy_r(GEOSContextHandle_t extHandle
,
5530 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5535 if ( 0 == extHandle
)
5540 GEOSContextHandleInternal_t
*handle
= 0;
5541 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5542 if ( 0 == handle
->initialized
)
5549 bool result
= pg
->coveredBy(g
);
5552 catch (const std::exception
&e
)
5554 handle
->ERROR_MESSAGE("%s", e
.what());
5558 handle
->ERROR_MESSAGE("Unknown exception thrown");
5565 GEOSPreparedCovers_r(GEOSContextHandle_t extHandle
,
5566 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5571 if ( 0 == extHandle
)
5576 GEOSContextHandleInternal_t
*handle
= 0;
5577 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5578 if ( 0 == handle
->initialized
)
5585 bool result
= pg
->covers(g
);
5588 catch (const std::exception
&e
)
5590 handle
->ERROR_MESSAGE("%s", e
.what());
5594 handle
->ERROR_MESSAGE("Unknown exception thrown");
5601 GEOSPreparedCrosses_r(GEOSContextHandle_t extHandle
,
5602 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5607 if ( 0 == extHandle
)
5612 GEOSContextHandleInternal_t
*handle
= 0;
5613 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5614 if ( 0 == handle
->initialized
)
5621 bool result
= pg
->crosses(g
);
5624 catch (const std::exception
&e
)
5626 handle
->ERROR_MESSAGE("%s", e
.what());
5630 handle
->ERROR_MESSAGE("Unknown exception thrown");
5637 GEOSPreparedDisjoint_r(GEOSContextHandle_t extHandle
,
5638 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5643 if ( 0 == extHandle
)
5648 GEOSContextHandleInternal_t
*handle
= 0;
5649 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5650 if ( 0 == handle
->initialized
)
5657 bool result
= pg
->disjoint(g
);
5660 catch (const std::exception
&e
)
5662 handle
->ERROR_MESSAGE("%s", e
.what());
5666 handle
->ERROR_MESSAGE("Unknown exception thrown");
5673 GEOSPreparedIntersects_r(GEOSContextHandle_t extHandle
,
5674 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5679 if ( 0 == extHandle
)
5684 GEOSContextHandleInternal_t
*handle
= 0;
5685 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5686 if ( 0 == handle
->initialized
)
5693 bool result
= pg
->intersects(g
);
5696 catch (const std::exception
&e
)
5698 handle
->ERROR_MESSAGE("%s", e
.what());
5702 handle
->ERROR_MESSAGE("Unknown exception thrown");
5709 GEOSPreparedOverlaps_r(GEOSContextHandle_t extHandle
,
5710 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5715 if ( 0 == extHandle
)
5720 GEOSContextHandleInternal_t
*handle
= 0;
5721 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5722 if ( 0 == handle
->initialized
)
5729 bool result
= pg
->overlaps(g
);
5732 catch (const std::exception
&e
)
5734 handle
->ERROR_MESSAGE("%s", e
.what());
5738 handle
->ERROR_MESSAGE("Unknown exception thrown");
5745 GEOSPreparedTouches_r(GEOSContextHandle_t extHandle
,
5746 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5751 if ( 0 == extHandle
)
5756 GEOSContextHandleInternal_t
*handle
= 0;
5757 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5758 if ( 0 == handle
->initialized
)
5765 bool result
= pg
->touches(g
);
5768 catch (const std::exception
&e
)
5770 handle
->ERROR_MESSAGE("%s", e
.what());
5774 handle
->ERROR_MESSAGE("Unknown exception thrown");
5781 GEOSPreparedWithin_r(GEOSContextHandle_t extHandle
,
5782 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5787 if ( 0 == extHandle
)
5792 GEOSContextHandleInternal_t
*handle
= 0;
5793 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5794 if ( 0 == handle
->initialized
)
5801 bool result
= pg
->within(g
);
5804 catch (const std::exception
&e
)
5806 handle
->ERROR_MESSAGE("%s", e
.what());
5810 handle
->ERROR_MESSAGE("Unknown exception thrown");
5816 //-----------------------------------------------------------------
5818 //-----------------------------------------------------------------
5820 geos::index::strtree::STRtree
*
5821 GEOSSTRtree_create_r(GEOSContextHandle_t extHandle
,
5822 size_t nodeCapacity
)
5824 if ( 0 == extHandle
)
5829 GEOSContextHandleInternal_t
*handle
= 0;
5830 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5831 if ( 0 == handle
->initialized
)
5836 geos::index::strtree::STRtree
*tree
= 0;
5840 tree
= new geos::index::strtree::STRtree(nodeCapacity
);
5842 catch (const std::exception
&e
)
5844 handle
->ERROR_MESSAGE("%s", e
.what());
5848 handle
->ERROR_MESSAGE("Unknown exception thrown");
5855 GEOSSTRtree_insert_r(GEOSContextHandle_t extHandle
,
5856 geos::index::strtree::STRtree
*tree
,
5857 const geos::geom::Geometry
*g
,
5860 GEOSContextHandleInternal_t
*handle
= 0;
5866 tree
->insert(g
->getEnvelopeInternal(), item
);
5868 catch (const std::exception
&e
)
5870 if ( 0 == extHandle
)
5875 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5876 if ( 0 == handle
->initialized
)
5881 handle
->ERROR_MESSAGE("%s", e
.what());
5885 if ( 0 == extHandle
)
5890 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5891 if ( 0 == handle
->initialized
)
5896 handle
->ERROR_MESSAGE("Unknown exception thrown");
5901 GEOSSTRtree_query_r(GEOSContextHandle_t extHandle
,
5902 geos::index::strtree::STRtree
*tree
,
5903 const geos::geom::Geometry
*g
,
5904 GEOSQueryCallback callback
,
5907 GEOSContextHandleInternal_t
*handle
= 0;
5910 assert(callback
!= 0);
5914 CAPI_ItemVisitor
visitor(callback
, userdata
);
5915 tree
->query(g
->getEnvelopeInternal(), visitor
);
5917 catch (const std::exception
&e
)
5919 if ( 0 == extHandle
)
5924 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5925 if ( 0 == handle
->initialized
)
5930 handle
->ERROR_MESSAGE("%s", e
.what());
5934 if ( 0 == extHandle
)
5939 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5940 if ( 0 == handle
->initialized
)
5945 handle
->ERROR_MESSAGE("Unknown exception thrown");
5950 GEOSSTRtree_nearest_generic_r(GEOSContextHandle_t extHandle
,
5951 geos::index::strtree::STRtree
*tree
,
5953 const geos::geom::Geometry
* itemEnvelope
,
5954 GEOSDistanceCallback distancefn
,
5958 GEOSContextHandleInternal_t
*handle
= 0;
5962 struct CustomItemDistance
: public ItemDistance
{
5963 CustomItemDistance(GEOSDistanceCallback p_distancefn
, void* p_userdata
)
5964 : m_distancefn(p_distancefn
), m_userdata(p_userdata
) {}
5966 GEOSDistanceCallback m_distancefn
;
5969 double distance(const ItemBoundable
* item1
, const ItemBoundable
* item2
) {
5970 const void* a
= item1
->getItem();
5971 const void* b
= item2
->getItem();
5974 if (!m_distancefn(a
, b
, &d
, m_userdata
)) {
5975 throw std::runtime_error(std::string("Failed to compute distance."));
5982 CustomItemDistance
itemDistance(distancefn
, userdata
);
5983 return tree
->nearestNeighbour(itemEnvelope
->getEnvelopeInternal(), item
, &itemDistance
);
5985 GeometryItemDistance itemDistance
= GeometryItemDistance();
5986 return tree
->nearestNeighbour(itemEnvelope
->getEnvelopeInternal(), item
, &itemDistance
);
5989 catch (const std::exception
&e
)
5991 if ( 0 == extHandle
)
5996 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5997 if ( 0 == handle
->initialized
)
6002 handle
->ERROR_MESSAGE("%s", e
.what());
6006 if ( 0 == extHandle
)
6011 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6012 if ( 0 == handle
->initialized
)
6017 handle
->ERROR_MESSAGE("Unknown exception thrown");
6024 GEOSSTRtree_iterate_r(GEOSContextHandle_t extHandle
,
6025 geos::index::strtree::STRtree
*tree
,
6026 GEOSQueryCallback callback
,
6029 GEOSContextHandleInternal_t
*handle
= 0;
6031 assert(callback
!= 0);
6035 CAPI_ItemVisitor
visitor(callback
, userdata
);
6036 tree
->iterate(visitor
);
6038 catch (const std::exception
&e
)
6040 if ( 0 == extHandle
)
6045 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6046 if ( 0 == handle
->initialized
)
6051 handle
->ERROR_MESSAGE("%s", e
.what());
6055 if ( 0 == extHandle
)
6060 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6061 if ( 0 == handle
->initialized
)
6066 handle
->ERROR_MESSAGE("Unknown exception thrown");
6071 GEOSSTRtree_remove_r(GEOSContextHandle_t extHandle
,
6072 geos::index::strtree::STRtree
*tree
,
6073 const geos::geom::Geometry
*g
,
6079 if ( 0 == extHandle
)
6084 GEOSContextHandleInternal_t
*handle
= 0;
6085 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6086 if ( 0 == handle
->initialized
)
6093 bool result
= tree
->remove(g
->getEnvelopeInternal(), item
);
6096 catch (const std::exception
&e
)
6098 handle
->ERROR_MESSAGE("%s", e
.what());
6102 handle
->ERROR_MESSAGE("Unknown exception thrown");
6109 GEOSSTRtree_destroy_r(GEOSContextHandle_t extHandle
,
6110 geos::index::strtree::STRtree
*tree
)
6112 GEOSContextHandleInternal_t
*handle
= 0;
6118 catch (const std::exception
&e
)
6120 if ( 0 == extHandle
)
6125 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6126 if ( 0 == handle
->initialized
)
6131 handle
->ERROR_MESSAGE("%s", e
.what());
6135 if ( 0 == extHandle
)
6140 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6141 if ( 0 == handle
->initialized
)
6146 handle
->ERROR_MESSAGE("Unknown exception thrown");
6151 GEOSProject_r(GEOSContextHandle_t extHandle
,
6155 if ( 0 == extHandle
) return -1.0;
6156 GEOSContextHandleInternal_t
*handle
=
6157 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6158 if ( handle
->initialized
== 0 ) return -1.0;
6160 const geos::geom::Point
* point
= dynamic_cast<const geos::geom::Point
*>(p
);
6162 handle
->ERROR_MESSAGE("third argument of GEOSProject_r must be Point*");
6166 const geos::geom::Coordinate
* inputPt
= p
->getCoordinate();
6169 return geos::linearref::LengthIndexedLine(g
).project(*inputPt
);
6170 } catch (const std::exception
&e
) {
6171 handle
->ERROR_MESSAGE("%s", e
.what());
6174 handle
->ERROR_MESSAGE("Unknown exception thrown");
6181 GEOSInterpolate_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double d
)
6183 if ( 0 == extHandle
) return 0;
6184 GEOSContextHandleInternal_t
*handle
=
6185 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6186 if ( handle
->initialized
== 0 ) return 0;
6189 geos::linearref::LengthIndexedLine
lil(g
);
6190 geos::geom::Coordinate coord
= lil
.extractPoint(d
);
6191 const GeometryFactory
*gf
= handle
->geomFactory
;
6192 Geometry
* point
= gf
->createPoint(coord
);
6194 } catch (const std::exception
&e
) {
6195 handle
->ERROR_MESSAGE("%s", e
.what());
6198 handle
->ERROR_MESSAGE("Unknown exception thrown");
6205 GEOSProjectNormalized_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
6210 GEOSLength_r(extHandle
, g
, &length
);
6211 return GEOSProject_r(extHandle
, g
, p
) / length
;
6216 GEOSInterpolateNormalized_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
6220 GEOSLength_r(extHandle
, g
, &length
);
6221 return GEOSInterpolate_r(extHandle
, g
, d
* length
);
6225 GEOSGeom_extractUniquePoints_r(GEOSContextHandle_t extHandle
,
6226 const GEOSGeometry
* g
)
6228 if ( 0 == extHandle
) return 0;
6229 GEOSContextHandleInternal_t
*handle
= 0;
6230 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6231 if ( handle
->initialized
== 0 ) return 0;
6233 using namespace geos::geom
;
6234 using namespace geos::util
;
6239 /* 1: extract points */
6240 std::vector
<const Coordinate
*> coords
;
6241 UniqueCoordinateArrayFilter
filter(coords
);
6242 g
->apply_ro(&filter
);
6244 /* 2: for each point, create a geometry and put into a vector */
6245 std::vector
<Geometry
*>* points
= new std::vector
<Geometry
*>();
6246 points
->reserve(coords
.size());
6247 const GeometryFactory
* factory
= g
->getFactory();
6248 for (std::vector
<const Coordinate
*>::iterator it
=coords
.begin(),
6252 Geometry
* point
= factory
->createPoint(*(*it
));
6253 points
->push_back(point
);
6256 /* 3: create a multipoint */
6257 return factory
->createMultiPoint(points
);
6260 catch (const std::exception
&e
)
6262 handle
->ERROR_MESSAGE("%s", e
.what());
6267 handle
->ERROR_MESSAGE("Unknown exception thrown");
6272 int GEOSOrientationIndex_r(GEOSContextHandle_t extHandle
,
6273 double Ax
, double Ay
, double Bx
, double By
, double Px
, double Py
)
6275 GEOSContextHandleInternal_t
*handle
= 0;
6277 using geos::geom::Coordinate
;
6278 using geos::algorithm::CGAlgorithms
;
6280 if ( 0 == extHandle
)
6285 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6286 if ( 0 == handle
->initialized
)
6293 Coordinate
A(Ax
, Ay
);
6294 Coordinate
B(Bx
, By
);
6295 Coordinate
P(Px
, Py
);
6296 return CGAlgorithms::orientationIndex(A
, B
, P
);
6298 catch (const std::exception
&e
)
6300 handle
->ERROR_MESSAGE("%s", e
.what());
6305 handle
->ERROR_MESSAGE("Unknown exception thrown");
6311 GEOSSharedPaths_r(GEOSContextHandle_t extHandle
, const GEOSGeometry
* g1
, const GEOSGeometry
* g2
)
6313 using namespace geos::operation::sharedpaths
;
6315 if ( 0 == extHandle
) return 0;
6316 GEOSContextHandleInternal_t
*handle
=
6317 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6318 if ( handle
->initialized
== 0 ) return 0;
6320 SharedPathsOp::PathList forw
, back
;
6322 SharedPathsOp::sharedPathsOp(*g1
, *g2
, forw
, back
);
6324 catch (const std::exception
&e
)
6326 SharedPathsOp::clearEdges(forw
);
6327 SharedPathsOp::clearEdges(back
);
6328 handle
->ERROR_MESSAGE("%s", e
.what());
6333 SharedPathsOp::clearEdges(forw
);
6334 SharedPathsOp::clearEdges(back
);
6335 handle
->ERROR_MESSAGE("Unknown exception thrown");
6339 // Now forw and back have the geoms we want to use to construct
6340 // our output GeometryCollections...
6342 const GeometryFactory
* factory
= g1
->getFactory();
6345 std::auto_ptr
< std::vector
<Geometry
*> > out1(
6346 new std::vector
<Geometry
*>()
6348 count
= forw
.size();
6349 out1
->reserve(count
);
6350 for (size_t i
=0; i
<count
; ++i
) {
6351 out1
->push_back(forw
[i
]);
6353 std::auto_ptr
<Geometry
> out1g (
6354 factory
->createMultiLineString(out1
.release())
6357 std::auto_ptr
< std::vector
<Geometry
*> > out2(
6358 new std::vector
<Geometry
*>()
6360 count
= back
.size();
6361 out2
->reserve(count
);
6362 for (size_t i
=0; i
<count
; ++i
) {
6363 out2
->push_back(back
[i
]);
6365 std::auto_ptr
<Geometry
> out2g (
6366 factory
->createMultiLineString(out2
.release())
6369 std::auto_ptr
< std::vector
<Geometry
*> > out(
6370 new std::vector
<Geometry
*>()
6373 out
->push_back(out1g
.release());
6374 out
->push_back(out2g
.release());
6376 std::auto_ptr
<Geometry
> outg (
6377 factory
->createGeometryCollection(out
.release())
6380 return outg
.release();
6385 GEOSSnap_r(GEOSContextHandle_t extHandle
, const GEOSGeometry
* g1
,
6386 const GEOSGeometry
* g2
, double tolerance
)
6388 using namespace geos::operation::overlay::snap
;
6390 if ( 0 == extHandle
) return 0;
6391 GEOSContextHandleInternal_t
*handle
=
6392 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6393 if ( handle
->initialized
== 0 ) return 0;
6396 GeometrySnapper
snapper( *g1
);
6397 std::auto_ptr
<Geometry
> ret
= snapper
.snapTo(*g2
, tolerance
);
6398 return ret
.release();
6400 catch (const std::exception
&e
)
6402 handle
->ERROR_MESSAGE("%s", e
.what());
6407 handle
->ERROR_MESSAGE("Unknown exception thrown");
6413 GEOSBufferParams_create_r(GEOSContextHandle_t extHandle
)
6415 if ( 0 == extHandle
) return NULL
;
6417 GEOSContextHandleInternal_t
*handle
= 0;
6418 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6419 if ( 0 == handle
->initialized
) return NULL
;
6423 BufferParameters
*p
= new BufferParameters();
6426 catch (const std::exception
&e
)
6428 handle
->ERROR_MESSAGE("%s", e
.what());
6432 handle
->ERROR_MESSAGE("Unknown exception thrown");
6439 GEOSBufferParams_destroy_r(GEOSContextHandle_t extHandle
, BufferParameters
* p
)
6446 GEOSBufferParams_setEndCapStyle_r(GEOSContextHandle_t extHandle
,
6447 GEOSBufferParams
* p
, int style
)
6449 if ( 0 == extHandle
) return 0;
6451 GEOSContextHandleInternal_t
*handle
= 0;
6452 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6453 if ( 0 == handle
->initialized
) return 0;
6457 if ( style
> BufferParameters::CAP_SQUARE
)
6459 throw IllegalArgumentException("Invalid buffer endCap style");
6461 p
->setEndCapStyle(static_cast<BufferParameters::EndCapStyle
>(style
));
6464 catch (const std::exception
&e
)
6466 handle
->ERROR_MESSAGE("%s", e
.what());
6470 handle
->ERROR_MESSAGE("Unknown exception thrown");
6477 GEOSBufferParams_setJoinStyle_r(GEOSContextHandle_t extHandle
,
6478 GEOSBufferParams
* p
, int style
)
6480 if ( 0 == extHandle
) return 0;
6482 GEOSContextHandleInternal_t
*handle
= 0;
6483 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6484 if ( 0 == handle
->initialized
) return 0;
6488 if ( style
> BufferParameters::JOIN_BEVEL
) {
6489 throw IllegalArgumentException("Invalid buffer join style");
6491 p
->setJoinStyle(static_cast<BufferParameters::JoinStyle
>(style
));
6494 catch (const std::exception
&e
)
6496 handle
->ERROR_MESSAGE("%s", e
.what());
6500 handle
->ERROR_MESSAGE("Unknown exception thrown");
6507 GEOSBufferParams_setMitreLimit_r(GEOSContextHandle_t extHandle
,
6508 GEOSBufferParams
* p
, double limit
)
6510 if ( 0 == extHandle
) return 0;
6512 GEOSContextHandleInternal_t
*handle
= 0;
6513 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6514 if ( 0 == handle
->initialized
) return 0;
6518 p
->setMitreLimit(limit
);
6521 catch (const std::exception
&e
)
6523 handle
->ERROR_MESSAGE("%s", e
.what());
6527 handle
->ERROR_MESSAGE("Unknown exception thrown");
6534 GEOSBufferParams_setQuadrantSegments_r(GEOSContextHandle_t extHandle
,
6535 GEOSBufferParams
* p
, int segs
)
6537 if ( 0 == extHandle
) return 0;
6539 GEOSContextHandleInternal_t
*handle
= 0;
6540 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6541 if ( 0 == handle
->initialized
) return 0;
6545 p
->setQuadrantSegments(segs
);
6548 catch (const std::exception
&e
)
6550 handle
->ERROR_MESSAGE("%s", e
.what());
6554 handle
->ERROR_MESSAGE("Unknown exception thrown");
6561 GEOSBufferParams_setSingleSided_r(GEOSContextHandle_t extHandle
,
6562 GEOSBufferParams
* p
, int ss
)
6564 if ( 0 == extHandle
) return 0;
6566 GEOSContextHandleInternal_t
*handle
= 0;
6567 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6568 if ( 0 == handle
->initialized
) return 0;
6572 p
->setSingleSided( (ss
!= 0) );
6575 catch (const std::exception
&e
)
6577 handle
->ERROR_MESSAGE("%s", e
.what());
6581 handle
->ERROR_MESSAGE("Unknown exception thrown");
6588 GEOSBufferWithParams_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const BufferParameters
* bp
, double width
)
6590 using geos::operation::buffer::BufferOp
;
6592 if ( 0 == extHandle
) return NULL
;
6594 GEOSContextHandleInternal_t
*handle
= 0;
6595 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6596 if ( 0 == handle
->initialized
) return NULL
;
6600 BufferOp
op(g1
, *bp
);
6601 Geometry
*g3
= op
.getResultGeometry(width
);
6604 catch (const std::exception
&e
)
6606 handle
->ERROR_MESSAGE("%s", e
.what());
6610 handle
->ERROR_MESSAGE("Unknown exception thrown");
6617 GEOSDelaunayTriangulation_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double tolerance
, int onlyEdges
)
6619 if ( 0 == extHandle
) return NULL
;
6621 GEOSContextHandleInternal_t
*handle
= 0;
6622 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6623 if ( 0 == handle
->initialized
) return NULL
;
6625 using geos::triangulate::DelaunayTriangulationBuilder
;
6629 DelaunayTriangulationBuilder builder
;
6630 builder
.setTolerance(tolerance
);
6631 builder
.setSites(*g1
);
6633 if ( onlyEdges
) return builder
.getEdges( *g1
->getFactory() ).release();
6634 else return builder
.getTriangles( *g1
->getFactory() ).release();
6637 catch (const std::exception
&e
)
6639 handle
->ERROR_MESSAGE("%s", e
.what());
6643 handle
->ERROR_MESSAGE("Unknown exception thrown");
6649 GEOSVoronoiDiagram_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*env
, double tolerance
,int onlyEdges
)
6651 if ( 0 == extHandle
) return NULL
;
6653 GEOSContextHandleInternal_t
*handle
= 0;
6654 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6655 if ( 0 == handle
->initialized
) return NULL
;
6657 using geos::triangulate::VoronoiDiagramBuilder
;
6661 VoronoiDiagramBuilder builder
;
6662 builder
.setSites(*g1
);
6663 builder
.setTolerance(tolerance
);
6664 if(env
) builder
.setClipEnvelope(env
->getEnvelopeInternal());
6665 if(onlyEdges
) return builder
.getDiagramEdges(*g1
->getFactory()).release();
6666 else return builder
.getDiagram(*g1
->getFactory()).release();
6668 catch(const std::exception
&e
)
6670 handle
->ERROR_MESSAGE("%s", e
.what());
6674 handle
->ERROR_MESSAGE("Unknow exception thrown");