1 /************************************************************************
4 * C-Wrapper for GEOS library
6 * Copyright (C) 2010-2012 Sandro Santilli <strk@kbt.io>
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@kbt.io>
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/distance/DiscreteFrechetDistance.h>
46 #include <geos/algorithm/CGAlgorithms.h>
47 #include <geos/algorithm/BoundaryNodeRule.h>
48 #include <geos/algorithm/MinimumDiameter.h>
49 #include <geos/simplify/DouglasPeuckerSimplifier.h>
50 #include <geos/simplify/TopologyPreservingSimplifier.h>
51 #include <geos/noding/GeometryNoder.h>
52 #include <geos/noding/Noder.h>
53 #include <geos/operation/buffer/BufferBuilder.h>
54 #include <geos/operation/buffer/BufferOp.h>
55 #include <geos/operation/buffer/BufferParameters.h>
56 #include <geos/operation/distance/DistanceOp.h>
57 #include <geos/operation/distance/IndexedFacetDistance.h>
58 #include <geos/operation/linemerge/LineMerger.h>
59 #include <geos/operation/overlay/OverlayOp.h>
60 #include <geos/operation/overlay/snap/GeometrySnapper.h>
61 #include <geos/operation/intersection/Rectangle.h>
62 #include <geos/operation/intersection/RectangleIntersection.h>
63 #include <geos/operation/polygonize/Polygonizer.h>
64 #include <geos/operation/relate/RelateOp.h>
65 #include <geos/operation/sharedpaths/SharedPathsOp.h>
66 #include <geos/operation/union/CascadedPolygonUnion.h>
67 #include <geos/operation/valid/IsValidOp.h>
68 #include <geos/precision/GeometryPrecisionReducer.h>
69 #include <geos/linearref/LengthIndexedLine.h>
70 #include <geos/triangulate/DelaunayTriangulationBuilder.h>
71 #include <geos/triangulate/VoronoiDiagramBuilder.h>
72 #include <geos/util/IllegalArgumentException.h>
73 #include <geos/util/Interrupt.h>
74 #include <geos/util/UniqueCoordinateArrayFilter.h>
75 #include <geos/util/Machine.h>
76 #include <geos/version.h>
78 // This should go away
79 #include <cmath> // finite
92 #pragma warning(disable : 4099)
95 // Some extra magic to make type declarations in geos_c.h work -
96 // for cross-checking of types in header.
97 #define GEOSGeometry geos::geom::Geometry
98 #define GEOSPreparedGeometry geos::geom::prep::PreparedGeometry
99 #define GEOSCoordSequence geos::geom::CoordinateSequence
100 #define GEOSBufferParams geos::operation::buffer::BufferParameters
101 #define GEOSSTRtree geos::index::strtree::STRtree
102 #define GEOSWKTReader_t geos::io::WKTReader
103 #define GEOSWKTWriter_t geos::io::WKTWriter
104 #define GEOSWKBReader_t geos::io::WKBReader
105 #define GEOSWKBWriter_t geos::io::WKBWriter
108 #include "../geos_revision.h"
110 // Intentional, to allow non-standard C elements like C99 functions to be
111 // imported through C++ headers of C library, like <cmath>.
114 /// Define this if you want operations triggering Exceptions to
116 /// (will use the NOTIFY channel - only implemented for GEOSUnion so far)
118 #undef VERBOSE_EXCEPTIONS
120 #include <geos/export.h>
121 #include <geos/precision/MinimumClearance.h>
124 // import the most frequently used definitions globally
125 using geos::geom::Geometry
;
126 using geos::geom::LineString
;
127 using geos::geom::Polygon
;
128 using geos::geom::CoordinateSequence
;
129 using geos::geom::GeometryFactory
;
131 using geos::io::WKTReader
;
132 using geos::io::WKTWriter
;
133 using geos::io::WKBReader
;
134 using geos::io::WKBWriter
;
136 using geos::operation::overlay::OverlayOp
;
137 using geos::operation::overlay::overlayOp
;
138 using geos::operation::geounion::CascadedPolygonUnion
;
139 using geos::operation::distance::IndexedFacetDistance
;
140 using geos::operation::buffer::BufferParameters
;
141 using geos::operation::buffer::BufferBuilder
;
142 using geos::precision::GeometryPrecisionReducer
;
143 using geos::util::IllegalArgumentException
;
144 using geos::algorithm::distance::DiscreteHausdorffDistance
;
145 using geos::algorithm::distance::DiscreteFrechetDistance
;
147 typedef std::auto_ptr
<Geometry
> GeomAutoPtr
;
149 typedef struct GEOSContextHandle_HS
151 const GeometryFactory
*geomFactory
;
152 char msgBuffer
[1024];
153 GEOSMessageHandler noticeMessageOld
;
154 GEOSMessageHandler_r noticeMessageNew
;
156 GEOSMessageHandler errorMessageOld
;
157 GEOSMessageHandler_r errorMessageNew
;
163 GEOSContextHandle_HS()
173 memset(msgBuffer
, 0, sizeof(msgBuffer
));
174 geomFactory
= GeometryFactory::getDefaultInstance();
176 WKBByteOrder
= getMachineByteOrder();
177 setNoticeHandler(NULL
);
178 setErrorHandler(NULL
);
183 setNoticeHandler(GEOSMessageHandler nf
)
185 GEOSMessageHandler f
= noticeMessageOld
;
186 noticeMessageOld
= nf
;
187 noticeMessageNew
= NULL
;
194 setErrorHandler(GEOSMessageHandler nf
)
196 GEOSMessageHandler f
= errorMessageOld
;
197 errorMessageOld
= nf
;
198 errorMessageNew
= NULL
;
205 setNoticeHandler(GEOSMessageHandler_r nf
, void *userData
) {
206 GEOSMessageHandler_r f
= noticeMessageNew
;
207 noticeMessageOld
= NULL
;
208 noticeMessageNew
= nf
;
209 noticeData
= userData
;
215 setErrorHandler(GEOSMessageHandler_r ef
, void *userData
)
217 GEOSMessageHandler_r f
= errorMessageNew
;
218 errorMessageOld
= NULL
;
219 errorMessageNew
= ef
;
220 errorData
= userData
;
226 NOTICE_MESSAGE(string fmt
, ...)
228 if (NULL
== noticeMessageOld
&& NULL
== noticeMessageNew
) {
234 int result
= vsnprintf(msgBuffer
, sizeof(msgBuffer
) - 1, fmt
.c_str(), args
);
238 if (noticeMessageOld
) {
239 noticeMessageOld("%s", msgBuffer
);
241 noticeMessageNew(msgBuffer
, noticeData
);
247 ERROR_MESSAGE(string fmt
, ...)
249 if (NULL
== errorMessageOld
&& NULL
== errorMessageNew
) {
255 int result
= vsnprintf(msgBuffer
, sizeof(msgBuffer
) - 1, fmt
.c_str(), args
);
259 if (errorMessageOld
) {
260 errorMessageOld("%s", msgBuffer
);
262 errorMessageNew(msgBuffer
, errorData
);
266 } GEOSContextHandleInternal_t
;
268 // CAPI_ItemVisitor is used internally by the CAPI STRtree
269 // wrappers. It's defined here just to keep it out of the
271 class CAPI_ItemVisitor
: public geos::index::ItemVisitor
{
272 GEOSQueryCallback callback
;
275 CAPI_ItemVisitor (GEOSQueryCallback cb
, void *ud
)
276 : ItemVisitor(), callback(cb
), userdata(ud
) {}
277 void visitItem (void *item
) { callback(item
, userdata
); }
281 //## PROTOTYPES #############################################
283 extern "C" const char GEOS_DLL
*GEOSjtsport();
284 extern "C" char GEOS_DLL
*GEOSasText(Geometry
*g1
);
287 namespace { // anonymous
289 char* gstrdup_s(const char* str
, const std::size_t size
)
291 char* out
= static_cast<char*>(malloc(size
+ 1));
294 // as no strlen call necessary, memcpy may be faster than strcpy
295 std::memcpy(out
, str
, size
+ 1);
300 // we haven't been checking allocation before ticket #371
303 throw(std::runtime_error("Failed to allocate memory for duplicate string"));
309 char* gstrdup(std::string
const& str
)
311 return gstrdup_s(str
.c_str(), str
.size());
314 } // namespace anonymous
319 initGEOS_r(GEOSMessageHandler nf
, GEOSMessageHandler ef
)
321 GEOSContextHandle_t handle
= GEOS_init_r();
324 GEOSContext_setNoticeHandler_r(handle
, nf
);
325 GEOSContext_setErrorHandler_r(handle
, ef
);
334 GEOSContextHandleInternal_t
*handle
= new GEOSContextHandleInternal_t();
336 geos::util::Interrupt::cancel();
338 return static_cast<GEOSContextHandle_t
>(handle
);
342 GEOSContext_setNoticeHandler_r(GEOSContextHandle_t extHandle
, GEOSMessageHandler nf
)
344 GEOSContextHandleInternal_t
*handle
= 0;
345 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
346 if ( 0 == handle
->initialized
)
351 return handle
->setNoticeHandler(nf
);
355 GEOSContext_setErrorHandler_r(GEOSContextHandle_t extHandle
, GEOSMessageHandler nf
)
357 GEOSContextHandleInternal_t
*handle
= 0;
358 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
359 if ( 0 == handle
->initialized
)
364 return handle
->setErrorHandler(nf
);
368 GEOSContext_setNoticeMessageHandler_r(GEOSContextHandle_t extHandle
, GEOSMessageHandler_r nf
, void *userData
) {
369 GEOSContextHandleInternal_t
*handle
= 0;
370 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
371 if ( 0 == handle
->initialized
)
376 return handle
->setNoticeHandler(nf
, userData
);
380 GEOSContext_setErrorMessageHandler_r(GEOSContextHandle_t extHandle
, GEOSMessageHandler_r ef
, void *userData
)
382 GEOSContextHandleInternal_t
*handle
= 0;
383 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
384 if ( 0 == handle
->initialized
)
389 return handle
->setErrorHandler(ef
, userData
);
393 finishGEOS_r(GEOSContextHandle_t extHandle
)
395 // Fix up freeing handle w.r.t. malloc above
401 GEOS_finish_r(GEOSContextHandle_t extHandle
)
403 finishGEOS_r(extHandle
);
407 GEOSFree_r (GEOSContextHandle_t extHandle
, void* buffer
)
409 assert(0 != extHandle
);
414 //-----------------------------------------------------------
415 // relate()-related functions
416 // return 0 = false, 1 = true, 2 = error occured
417 //-----------------------------------------------------------
420 GEOSDisjoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
422 if ( 0 == extHandle
)
427 GEOSContextHandleInternal_t
*handle
= 0;
428 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
429 if ( handle
->initialized
== 0 )
436 bool result
= g1
->disjoint(g2
);
440 // TODO: mloskot is going to replace these double-catch block
441 // with a macro to remove redundant code in this and
442 // following functions.
443 catch (const std::exception
&e
)
445 handle
->ERROR_MESSAGE("%s", e
.what());
449 handle
->ERROR_MESSAGE("Unknown exception thrown");
456 GEOSTouches_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
458 if ( 0 == extHandle
)
463 GEOSContextHandleInternal_t
*handle
= 0;
464 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
465 if ( 0 == handle
->initialized
)
472 bool result
= g1
->touches(g2
);
475 catch (const std::exception
&e
)
477 handle
->ERROR_MESSAGE("%s", e
.what());
481 handle
->ERROR_MESSAGE("Unknown exception thrown");
488 GEOSIntersects_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
490 if ( 0 == extHandle
)
495 GEOSContextHandleInternal_t
*handle
= 0;
496 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
497 if ( 0 == handle
->initialized
)
504 bool result
= g1
->intersects(g2
);
507 catch (const std::exception
&e
)
509 handle
->ERROR_MESSAGE("%s", e
.what());
513 handle
->ERROR_MESSAGE("Unknown exception thrown");
520 GEOSCrosses_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
522 if ( 0 == extHandle
)
527 GEOSContextHandleInternal_t
*handle
= 0;
528 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
529 if ( 0 == handle
->initialized
)
536 bool result
= g1
->crosses(g2
);
539 catch (const std::exception
&e
)
541 handle
->ERROR_MESSAGE("%s", e
.what());
545 handle
->ERROR_MESSAGE("Unknown exception thrown");
552 GEOSWithin_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
554 if ( 0 == extHandle
)
559 GEOSContextHandleInternal_t
*handle
= 0;
560 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
561 if ( 0 == handle
->initialized
)
568 bool result
= g1
->within(g2
);
571 catch (const std::exception
&e
)
573 handle
->ERROR_MESSAGE("%s", e
.what());
577 handle
->ERROR_MESSAGE("Unknown exception thrown");
583 // call g1->contains(g2)
586 // 2 = error was trapped
588 GEOSContains_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
590 if ( 0 == extHandle
)
595 GEOSContextHandleInternal_t
*handle
= 0;
596 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
597 if ( 0 == handle
->initialized
)
604 bool result
= g1
->contains(g2
);
607 catch (const std::exception
&e
)
609 handle
->ERROR_MESSAGE("%s", e
.what());
613 handle
->ERROR_MESSAGE("Unknown exception thrown");
620 GEOSOverlaps_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
622 if ( 0 == extHandle
)
627 GEOSContextHandleInternal_t
*handle
= 0;
628 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
629 if ( 0 == handle
->initialized
)
636 bool result
= g1
->overlaps(g2
);
639 catch (const std::exception
&e
)
641 handle
->ERROR_MESSAGE("%s", e
.what());
645 handle
->ERROR_MESSAGE("Unknown exception thrown");
652 GEOSCovers_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
654 if ( 0 == extHandle
)
659 GEOSContextHandleInternal_t
*handle
= 0;
660 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
661 if ( 0 == handle
->initialized
)
668 bool result
= g1
->covers(g2
);
671 catch (const std::exception
&e
)
673 handle
->ERROR_MESSAGE("%s", e
.what());
677 handle
->ERROR_MESSAGE("Unknown exception thrown");
684 GEOSCoveredBy_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
686 if ( 0 == extHandle
)
691 GEOSContextHandleInternal_t
*handle
= 0;
692 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
693 if ( 0 == handle
->initialized
)
700 bool result
= g1
->coveredBy(g2
);
703 catch (const std::exception
&e
)
705 handle
->ERROR_MESSAGE("%s", e
.what());
709 handle
->ERROR_MESSAGE("Unknown exception thrown");
716 //-------------------------------------------------------------------
717 // low-level relate functions
718 //------------------------------------------------------------------
721 GEOSRelatePattern_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, const char *pat
)
723 if ( 0 == extHandle
)
728 GEOSContextHandleInternal_t
*handle
= 0;
729 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
730 if ( 0 == handle
->initialized
)
738 bool result
= g1
->relate(g2
, s
);
741 catch (const std::exception
&e
)
743 handle
->ERROR_MESSAGE("%s", e
.what());
747 handle
->ERROR_MESSAGE("Unknown exception thrown");
754 GEOSRelatePatternMatch_r(GEOSContextHandle_t extHandle
, const char *mat
,
757 if ( 0 == extHandle
)
762 GEOSContextHandleInternal_t
*handle
= 0;
763 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
764 if ( 0 == handle
->initialized
)
771 using geos::geom::IntersectionMatrix
;
775 IntersectionMatrix
im(m
);
777 bool result
= im
.matches(p
);
780 catch (const std::exception
&e
)
782 handle
->ERROR_MESSAGE("%s", e
.what());
786 handle
->ERROR_MESSAGE("Unknown exception thrown");
793 GEOSRelate_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
795 if ( 0 == extHandle
)
800 GEOSContextHandleInternal_t
*handle
= 0;
801 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
802 if ( 0 == handle
->initialized
)
809 using geos::geom::IntersectionMatrix
;
811 IntersectionMatrix
* im
= g1
->relate(g2
);
817 char *result
= gstrdup(im
->toString());
824 catch (const std::exception
&e
)
826 handle
->ERROR_MESSAGE("%s", e
.what());
830 handle
->ERROR_MESSAGE("Unknown exception thrown");
837 GEOSRelateBoundaryNodeRule_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, int bnr
)
839 if ( 0 == extHandle
)
844 GEOSContextHandleInternal_t
*handle
= 0;
845 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
846 if ( 0 == handle
->initialized
)
853 using geos::operation::relate::RelateOp
;
854 using geos::geom::IntersectionMatrix
;
855 using geos::algorithm::BoundaryNodeRule
;
857 IntersectionMatrix
* im
;
859 case GEOSRELATE_BNR_MOD2
: /* same as OGC */
860 im
= RelateOp::relate(g1
, g2
,
861 BoundaryNodeRule::getBoundaryRuleMod2());
863 case GEOSRELATE_BNR_ENDPOINT
:
864 im
= RelateOp::relate(g1
, g2
,
865 BoundaryNodeRule::getBoundaryEndPoint());
867 case GEOSRELATE_BNR_MULTIVALENT_ENDPOINT
:
868 im
= RelateOp::relate(g1
, g2
,
869 BoundaryNodeRule::getBoundaryMultivalentEndPoint());
871 case GEOSRELATE_BNR_MONOVALENT_ENDPOINT
:
872 im
= RelateOp::relate(g1
, g2
,
873 BoundaryNodeRule::getBoundaryMonovalentEndPoint());
876 handle
->ERROR_MESSAGE("Invalid boundary node rule %d", bnr
);
881 if (0 == im
) return 0;
883 char *result
= gstrdup(im
->toString());
890 catch (const std::exception
&e
)
892 handle
->ERROR_MESSAGE("%s", e
.what());
896 handle
->ERROR_MESSAGE("Unknown exception thrown");
904 //-----------------------------------------------------------------
906 //-----------------------------------------------------------------
910 GEOSisValid_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
912 if ( 0 == extHandle
)
917 GEOSContextHandleInternal_t
*handle
= 0;
918 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
919 if ( 0 == handle
->initialized
)
926 using geos::operation::valid::IsValidOp
;
927 using geos::operation::valid::TopologyValidationError
;
930 TopologyValidationError
*err
= ivo
.getValidationError();
933 handle
->NOTICE_MESSAGE("%s", err
->toString().c_str());
941 catch (const std::exception
&e
)
943 handle
->ERROR_MESSAGE("%s", e
.what());
947 handle
->ERROR_MESSAGE("Unknown exception thrown");
954 GEOSisValidReason_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
956 if ( 0 == extHandle
)
961 GEOSContextHandleInternal_t
*handle
= 0;
962 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
963 if ( 0 == handle
->initialized
)
970 using geos::operation::valid::IsValidOp
;
971 using geos::operation::valid::TopologyValidationError
;
974 char const* const validstr
= "Valid Geometry";
977 TopologyValidationError
*err
= ivo
.getValidationError();
980 std::ostringstream ss
;
982 ss
<< err
->getCoordinate();
983 const std::string errloc
= ss
.str();
984 std::string
errmsg(err
->getMessage());
985 errmsg
+= "[" + errloc
+ "]";
986 result
= gstrdup(errmsg
);
990 result
= gstrdup(std::string(validstr
));
995 catch (const std::exception
&e
)
997 handle
->ERROR_MESSAGE("%s", e
.what());
1001 handle
->ERROR_MESSAGE("Unknown exception thrown");
1008 GEOSisValidDetail_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
1009 int flags
, char** reason
, Geometry
** location
)
1011 if ( 0 == extHandle
)
1016 GEOSContextHandleInternal_t
*handle
= 0;
1017 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1018 if ( 0 == handle
->initialized
)
1025 using geos::operation::valid::IsValidOp
;
1026 using geos::operation::valid::TopologyValidationError
;
1029 if ( flags
& GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE
) {
1030 ivo
.setSelfTouchingRingFormingHoleValid(true);
1032 TopologyValidationError
*err
= ivo
.getValidationError();
1036 *location
= handle
->geomFactory
->createPoint(err
->getCoordinate());
1039 std::string
errmsg(err
->getMessage());
1040 *reason
= gstrdup(errmsg
);
1045 if ( location
) *location
= 0;
1046 if ( reason
) *reason
= 0;
1047 return 1; /* valid */
1050 catch (const std::exception
&e
)
1052 handle
->ERROR_MESSAGE("%s", e
.what());
1056 handle
->ERROR_MESSAGE("Unknown exception thrown");
1059 return 2; /* exception */
1062 //-----------------------------------------------------------------
1064 //-----------------------------------------------------------------
1067 GEOSEquals_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1069 if ( 0 == extHandle
)
1074 GEOSContextHandleInternal_t
*handle
= 0;
1075 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1076 if ( 0 == handle
->initialized
)
1083 bool result
= g1
->equals(g2
);
1086 catch (const std::exception
&e
)
1088 handle
->ERROR_MESSAGE("%s", e
.what());
1092 handle
->ERROR_MESSAGE("Unknown exception thrown");
1099 GEOSEqualsExact_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double tolerance
)
1101 if ( 0 == extHandle
)
1106 GEOSContextHandleInternal_t
*handle
= 0;
1107 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1108 if ( 0 == handle
->initialized
)
1115 bool result
= g1
->equalsExact(g2
, tolerance
);
1118 catch (const std::exception
&e
)
1120 handle
->ERROR_MESSAGE("%s", e
.what());
1124 handle
->ERROR_MESSAGE("Unknown exception thrown");
1131 GEOSDistance_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double *dist
)
1135 if ( 0 == extHandle
)
1140 GEOSContextHandleInternal_t
*handle
= 0;
1141 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1142 if ( 0 == handle
->initialized
)
1149 *dist
= g1
->distance(g2
);
1152 catch (const std::exception
&e
)
1154 handle
->ERROR_MESSAGE("%s", e
.what());
1158 handle
->ERROR_MESSAGE("Unknown exception thrown");
1165 GEOSDistanceIndexed_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double *dist
)
1169 if ( 0 == extHandle
)
1174 GEOSContextHandleInternal_t
*handle
= 0;
1175 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1176 if ( 0 == handle
->initialized
)
1183 *dist
= IndexedFacetDistance::distance(g1
, g2
);
1186 catch (const std::exception
&e
)
1188 handle
->ERROR_MESSAGE("%s", e
.what());
1192 handle
->ERROR_MESSAGE("Unknown exception thrown");
1199 GEOSHausdorffDistance_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double *dist
)
1203 if ( 0 == extHandle
)
1208 GEOSContextHandleInternal_t
*handle
= 0;
1209 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1210 if ( 0 == handle
->initialized
)
1217 *dist
= DiscreteHausdorffDistance::distance(*g1
, *g2
);
1220 catch (const std::exception
&e
)
1222 handle
->ERROR_MESSAGE("%s", e
.what());
1226 handle
->ERROR_MESSAGE("Unknown exception thrown");
1233 GEOSHausdorffDistanceDensify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double densifyFrac
, double *dist
)
1237 if ( 0 == extHandle
)
1242 GEOSContextHandleInternal_t
*handle
= 0;
1243 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1244 if ( 0 == handle
->initialized
)
1251 *dist
= DiscreteHausdorffDistance::distance(*g1
, *g2
, densifyFrac
);
1254 catch (const std::exception
&e
)
1256 handle
->ERROR_MESSAGE("%s", e
.what());
1260 handle
->ERROR_MESSAGE("Unknown exception thrown");
1267 GEOSFrechetDistance_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double *dist
)
1271 if ( 0 == extHandle
)
1276 GEOSContextHandleInternal_t
*handle
= 0;
1277 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1278 if ( 0 == handle
->initialized
)
1285 *dist
= DiscreteFrechetDistance::distance(*g1
, *g2
);
1288 catch (const std::exception
&e
)
1290 handle
->ERROR_MESSAGE("%s", e
.what());
1294 handle
->ERROR_MESSAGE("Unknown exception thrown");
1301 GEOSFrechetDistanceDensify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double densifyFrac
, double *dist
)
1305 if ( 0 == extHandle
)
1310 GEOSContextHandleInternal_t
*handle
= 0;
1311 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1312 if ( 0 == handle
->initialized
)
1319 *dist
= DiscreteFrechetDistance::distance(*g1
, *g2
, densifyFrac
);
1322 catch (const std::exception
&e
)
1324 handle
->ERROR_MESSAGE("%s", e
.what());
1328 handle
->ERROR_MESSAGE("Unknown exception thrown");
1335 GEOSArea_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double *area
)
1339 if ( 0 == extHandle
)
1344 GEOSContextHandleInternal_t
*handle
= 0;
1345 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1346 if ( 0 == handle
->initialized
)
1353 *area
= g
->getArea();
1356 catch (const std::exception
&e
)
1358 handle
->ERROR_MESSAGE("%s", e
.what());
1362 handle
->ERROR_MESSAGE("Unknown exception thrown");
1369 GEOSLength_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double *length
)
1371 assert(0 != length
);
1373 if ( 0 == extHandle
)
1378 GEOSContextHandleInternal_t
*handle
= 0;
1379 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1380 if ( 0 == handle
->initialized
)
1387 *length
= g
->getLength();
1390 catch (const std::exception
&e
)
1392 handle
->ERROR_MESSAGE("%s", e
.what());
1396 handle
->ERROR_MESSAGE("Unknown exception thrown");
1402 CoordinateSequence
*
1403 GEOSNearestPoints_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1405 if ( 0 == extHandle
)
1410 GEOSContextHandleInternal_t
*handle
= 0;
1411 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1412 if ( 0 == handle
->initialized
)
1419 if (g1
->isEmpty() || g2
->isEmpty()) return 0;
1420 return geos::operation::distance::DistanceOp::nearestPoints(g1
, g2
);
1422 catch (const std::exception
&e
)
1424 handle
->ERROR_MESSAGE("%s", e
.what());
1428 handle
->ERROR_MESSAGE("Unknown exception thrown");
1436 GEOSGeomFromWKT_r(GEOSContextHandle_t extHandle
, const char *wkt
)
1438 if ( 0 == extHandle
)
1443 GEOSContextHandleInternal_t
*handle
= 0;
1444 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1445 if ( 0 == handle
->initialized
)
1452 const std::string
wktstring(wkt
);
1453 WKTReader
r(static_cast<GeometryFactory
const*>(handle
->geomFactory
));
1455 Geometry
*g
= r
.read(wktstring
);
1458 catch (const std::exception
&e
)
1460 handle
->ERROR_MESSAGE("%s", e
.what());
1464 handle
->ERROR_MESSAGE("Unknown exception thrown");
1471 GEOSGeomToWKT_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1473 if ( 0 == extHandle
)
1478 GEOSContextHandleInternal_t
*handle
= 0;
1479 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1480 if ( 0 == handle
->initialized
)
1488 char *result
= gstrdup(g1
->toString());
1491 catch (const std::exception
&e
)
1493 handle
->ERROR_MESSAGE("%s", e
.what());
1497 handle
->ERROR_MESSAGE("Unknown exception thrown");
1502 // Remember to free the result!
1504 GEOSGeomToWKB_buf_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, size_t *size
)
1508 if ( 0 == extHandle
)
1513 GEOSContextHandleInternal_t
*handle
= 0;
1514 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1515 if ( 0 == handle
->initialized
)
1520 using geos::io::WKBWriter
;
1523 int byteOrder
= handle
->WKBByteOrder
;
1524 WKBWriter
w(handle
->WKBOutputDims
, byteOrder
);
1525 std::ostringstream
os(std::ios_base::binary
);
1527 std::string
wkbstring(os
.str());
1528 const std::size_t len
= wkbstring
.length();
1530 unsigned char* result
= 0;
1531 result
= static_cast<unsigned char*>(malloc(len
));
1534 std::memcpy(result
, wkbstring
.c_str(), len
);
1539 catch (const std::exception
&e
)
1541 handle
->ERROR_MESSAGE("%s", e
.what());
1545 handle
->ERROR_MESSAGE("Unknown exception thrown");
1552 GEOSGeomFromWKB_buf_r(GEOSContextHandle_t extHandle
, const unsigned char *wkb
, size_t size
)
1554 if ( 0 == extHandle
)
1559 GEOSContextHandleInternal_t
*handle
= 0;
1560 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1561 if ( 0 == handle
->initialized
)
1566 using geos::io::WKBReader
;
1569 std::string
wkbstring(reinterpret_cast<const char*>(wkb
), size
); // make it binary !
1570 WKBReader
r(*(static_cast<GeometryFactory
const*>(handle
->geomFactory
)));
1571 std::istringstream
is(std::ios_base::binary
);
1573 is
.seekg(0, std::ios::beg
); // rewind reader pointer
1574 Geometry
*g
= r
.read(is
);
1577 catch (const std::exception
&e
)
1579 handle
->ERROR_MESSAGE("%s", e
.what());
1583 handle
->ERROR_MESSAGE("Unknown exception thrown");
1589 /* Read/write wkb hex values. Returned geometries are
1590 owned by the caller.*/
1592 GEOSGeomToHEX_buf_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, size_t *size
)
1594 if ( 0 == extHandle
)
1599 GEOSContextHandleInternal_t
*handle
= 0;
1600 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1601 if ( 0 == handle
->initialized
)
1606 using geos::io::WKBWriter
;
1609 int byteOrder
= handle
->WKBByteOrder
;
1610 WKBWriter
w(handle
->WKBOutputDims
, byteOrder
);
1611 std::ostringstream
os(std::ios_base::binary
);
1613 std::string
hexstring(os
.str());
1615 char *result
= gstrdup(hexstring
);
1618 *size
= hexstring
.length();
1621 return reinterpret_cast<unsigned char*>(result
);
1623 catch (const std::exception
&e
)
1625 handle
->ERROR_MESSAGE("%s", e
.what());
1629 handle
->ERROR_MESSAGE("Unknown exception thrown");
1636 GEOSGeomFromHEX_buf_r(GEOSContextHandle_t extHandle
, const unsigned char *hex
, size_t size
)
1638 if ( 0 == extHandle
)
1643 GEOSContextHandleInternal_t
*handle
= 0;
1644 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1645 if ( 0 == handle
->initialized
)
1650 using geos::io::WKBReader
;
1653 std::string
hexstring(reinterpret_cast<const char*>(hex
), size
);
1654 WKBReader
r(*(static_cast<GeometryFactory
const*>(handle
->geomFactory
)));
1655 std::istringstream
is(std::ios_base::binary
);
1657 is
.seekg(0, std::ios::beg
); // rewind reader pointer
1659 Geometry
*g
= r
.readHEX(is
);
1662 catch (const std::exception
&e
)
1664 handle
->ERROR_MESSAGE("%s", e
.what());
1668 handle
->ERROR_MESSAGE("Unknown exception thrown");
1675 GEOSisEmpty_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1677 if ( 0 == extHandle
)
1682 GEOSContextHandleInternal_t
*handle
= 0;
1683 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1684 if ( 0 == handle
->initialized
)
1691 return g1
->isEmpty();
1693 catch (const std::exception
&e
)
1695 handle
->ERROR_MESSAGE("%s", e
.what());
1699 handle
->ERROR_MESSAGE("Unknown exception thrown");
1706 GEOSisSimple_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
->isSimple();
1724 catch (const std::exception
&e
)
1726 handle
->ERROR_MESSAGE("%s", e
.what());
1732 handle
->ERROR_MESSAGE("Unknown exception thrown");
1738 GEOSisRing_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
1740 if ( 0 == extHandle
)
1745 GEOSContextHandleInternal_t
*handle
= 0;
1746 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1747 if ( 0 == handle
->initialized
)
1754 const LineString
*ls
= dynamic_cast<const LineString
*>(g
);
1756 return (ls
->isRing());
1761 catch (const std::exception
&e
)
1763 handle
->ERROR_MESSAGE("%s", e
.what());
1769 handle
->ERROR_MESSAGE("Unknown exception thrown");
1776 //free the result of this
1778 GEOSGeomType_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1780 if ( 0 == extHandle
)
1785 GEOSContextHandleInternal_t
*handle
= 0;
1786 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1787 if ( 0 == handle
->initialized
)
1794 std::string s
= g1
->getGeometryType();
1796 char *result
= gstrdup(s
);
1799 catch (const std::exception
&e
)
1801 handle
->ERROR_MESSAGE("%s", e
.what());
1805 handle
->ERROR_MESSAGE("Unknown exception thrown");
1811 // Return postgis geometry type index
1813 GEOSGeomTypeId_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1815 if ( 0 == extHandle
)
1820 GEOSContextHandleInternal_t
*handle
= 0;
1821 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1822 if ( 0 == handle
->initialized
)
1829 return g1
->getGeometryTypeId();
1831 catch (const std::exception
&e
)
1833 handle
->ERROR_MESSAGE("%s", e
.what());
1837 handle
->ERROR_MESSAGE("Unknown exception thrown");
1843 //-------------------------------------------------------------------
1844 // GEOS functions that return geometries
1845 //-------------------------------------------------------------------
1848 GEOSEnvelope_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1850 if ( 0 == extHandle
)
1855 GEOSContextHandleInternal_t
*handle
= 0;
1856 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1857 if ( 0 == handle
->initialized
)
1864 Geometry
*g3
= g1
->getEnvelope();
1867 catch (const std::exception
&e
)
1869 handle
->ERROR_MESSAGE("%s", e
.what());
1873 handle
->ERROR_MESSAGE("Unknown exception thrown");
1880 GEOSIntersection_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1882 if ( 0 == extHandle
)
1887 GEOSContextHandleInternal_t
*handle
= 0;
1888 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1889 if ( 0 == handle
->initialized
)
1896 return g1
->intersection(g2
);
1898 catch (const std::exception
&e
)
1900 handle
->ERROR_MESSAGE("%s", e
.what());
1904 handle
->ERROR_MESSAGE("Unknown exception thrown");
1911 GEOSBuffer_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadrantsegments
)
1913 if ( 0 == extHandle
)
1918 GEOSContextHandleInternal_t
*handle
= 0;
1919 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1920 if ( 0 == handle
->initialized
)
1927 Geometry
*g3
= g1
->buffer(width
, quadrantsegments
);
1930 catch (const std::exception
&e
)
1932 handle
->ERROR_MESSAGE("%s", e
.what());
1936 handle
->ERROR_MESSAGE("Unknown exception thrown");
1943 GEOSBufferWithStyle_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int endCapStyle
, int joinStyle
, double mitreLimit
)
1945 using geos::operation::buffer::BufferParameters
;
1946 using geos::operation::buffer::BufferOp
;
1947 using geos::util::IllegalArgumentException
;
1949 if ( 0 == extHandle
)
1954 GEOSContextHandleInternal_t
*handle
= 0;
1955 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1956 if ( 0 == handle
->initialized
)
1963 BufferParameters bp
;
1964 bp
.setQuadrantSegments(quadsegs
);
1966 if ( endCapStyle
> BufferParameters::CAP_SQUARE
)
1968 throw IllegalArgumentException("Invalid buffer endCap style");
1971 static_cast<BufferParameters::EndCapStyle
>(endCapStyle
)
1974 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1976 throw IllegalArgumentException("Invalid buffer join style");
1979 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1981 bp
.setMitreLimit(mitreLimit
);
1982 BufferOp
op(g1
, bp
);
1983 Geometry
*g3
= op
.getResultGeometry(width
);
1986 catch (const std::exception
&e
)
1988 handle
->ERROR_MESSAGE("%s", e
.what());
1992 handle
->ERROR_MESSAGE("Unknown exception thrown");
1999 GEOSOffsetCurve_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int joinStyle
, double mitreLimit
)
2001 if ( 0 == extHandle
) return NULL
;
2003 GEOSContextHandleInternal_t
*handle
= 0;
2004 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2005 if ( 0 == handle
->initialized
) return NULL
;
2009 BufferParameters bp
;
2010 bp
.setEndCapStyle( BufferParameters::CAP_FLAT
);
2011 bp
.setQuadrantSegments(quadsegs
);
2013 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
2015 throw IllegalArgumentException("Invalid buffer join style");
2018 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
2020 bp
.setMitreLimit(mitreLimit
);
2022 bool isLeftSide
= true;
2027 BufferBuilder
bufBuilder (bp
);
2028 Geometry
*g3
= bufBuilder
.bufferLineSingleSided(g1
, width
, isLeftSide
);
2032 catch (const std::exception
&e
)
2034 handle
->ERROR_MESSAGE("%s", e
.what());
2038 handle
->ERROR_MESSAGE("Unknown exception thrown");
2044 /* @deprecated in 3.3.0 */
2046 GEOSSingleSidedBuffer_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int joinStyle
, double mitreLimit
, int leftSide
)
2048 if ( 0 == extHandle
) return NULL
;
2050 GEOSContextHandleInternal_t
*handle
= 0;
2051 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2052 if ( 0 == handle
->initialized
) return NULL
;
2056 BufferParameters bp
;
2057 bp
.setEndCapStyle( BufferParameters::CAP_FLAT
);
2058 bp
.setQuadrantSegments(quadsegs
);
2060 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
2062 throw IllegalArgumentException("Invalid buffer join style");
2065 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
2067 bp
.setMitreLimit(mitreLimit
);
2069 bool isLeftSide
= leftSide
== 0 ? false : true;
2070 BufferBuilder
bufBuilder (bp
);
2071 Geometry
*g3
= bufBuilder
.bufferLineSingleSided(g1
, width
, isLeftSide
);
2075 catch (const std::exception
&e
)
2077 handle
->ERROR_MESSAGE("%s", e
.what());
2081 handle
->ERROR_MESSAGE("Unknown exception thrown");
2088 GEOSConvexHull_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2090 if ( 0 == extHandle
)
2095 GEOSContextHandleInternal_t
*handle
= 0;
2096 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2097 if ( 0 == handle
->initialized
)
2104 Geometry
*g3
= g1
->convexHull();
2107 catch (const std::exception
&e
)
2109 handle
->ERROR_MESSAGE("%s", e
.what());
2113 handle
->ERROR_MESSAGE("Unknown exception thrown");
2121 GEOSMinimumRotatedRectangle_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2123 if ( 0 == extHandle
)
2128 GEOSContextHandleInternal_t
*handle
= 0;
2129 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2130 if ( 0 == handle
->initialized
)
2137 geos::algorithm::MinimumDiameter
m(g
);
2139 Geometry
*g3
= m
.getMinimumRectangle();
2142 catch (const std::exception
&e
)
2144 handle
->ERROR_MESSAGE("%s", e
.what());
2148 handle
->ERROR_MESSAGE("Unknown exception thrown");
2155 GEOSMinimumWidth_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2157 if ( 0 == extHandle
)
2162 GEOSContextHandleInternal_t
*handle
= 0;
2163 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2164 if ( 0 == handle
->initialized
)
2171 geos::algorithm::MinimumDiameter
m(g
);
2173 Geometry
*g3
= m
.getDiameter();
2176 catch (const std::exception
&e
)
2178 handle
->ERROR_MESSAGE("%s", e
.what());
2182 handle
->ERROR_MESSAGE("Unknown exception thrown");
2189 GEOSMinimumClearanceLine_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2191 if ( 0 == extHandle
)
2196 GEOSContextHandleInternal_t
*handle
= 0;
2197 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2198 if ( 0 == handle
->initialized
)
2205 geos::precision::MinimumClearance
mc(g
);
2206 return mc
.getLine().release();
2208 catch (const std::exception
&e
)
2210 handle
->ERROR_MESSAGE("%s", e
.what());
2214 handle
->ERROR_MESSAGE("Unknown exception thrown");
2221 GEOSMinimumClearance_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double *d
)
2223 if ( 0 == extHandle
)
2228 GEOSContextHandleInternal_t
*handle
= 0;
2229 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2230 if ( 0 == handle
->initialized
)
2237 geos::precision::MinimumClearance
mc(g
);
2238 double res
= mc
.getDistance();
2242 catch (const std::exception
&e
)
2244 handle
->ERROR_MESSAGE("%s", e
.what());
2248 handle
->ERROR_MESSAGE("Unknown exception thrown");
2256 GEOSDifference_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
2258 if ( 0 == extHandle
)
2263 GEOSContextHandleInternal_t
*handle
= 0;
2264 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2265 if ( 0 == handle
->initialized
)
2272 return g1
->difference(g2
);
2274 catch (const std::exception
&e
)
2276 handle
->ERROR_MESSAGE("%s", e
.what());
2280 handle
->ERROR_MESSAGE("Unknown exception thrown");
2287 GEOSBoundary_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2289 if ( 0 == extHandle
)
2294 GEOSContextHandleInternal_t
*handle
= 0;
2295 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2296 if ( 0 == handle
->initialized
)
2303 Geometry
*g3
= g1
->getBoundary();
2306 catch (const std::exception
&e
)
2308 handle
->ERROR_MESSAGE("%s", e
.what());
2312 handle
->ERROR_MESSAGE("Unknown exception thrown");
2319 GEOSSymDifference_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
2321 if ( 0 == extHandle
)
2326 GEOSContextHandleInternal_t
*handle
= 0;
2327 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2328 if ( 0 == handle
->initialized
)
2335 return g1
->symDifference(g2
);
2337 catch (const std::exception
&e
)
2339 handle
->ERROR_MESSAGE("%s", e
.what());
2345 handle
->ERROR_MESSAGE("Unknown exception thrown");
2351 GEOSUnion_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
2353 if ( 0 == extHandle
)
2358 GEOSContextHandleInternal_t
*handle
= 0;
2359 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2360 if ( 0 == handle
->initialized
)
2367 return g1
->Union(g2
);
2369 catch (const std::exception
&e
)
2371 #if VERBOSE_EXCEPTIONS
2372 std::ostringstream s
;
2373 s
<< "Exception on GEOSUnion with following inputs:" << std::endl
;
2374 s
<< "A: "<<g1
->toString() << std::endl
;
2375 s
<< "B: "<<g2
->toString() << std::endl
;
2376 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
2377 #endif // VERBOSE_EXCEPTIONS
2378 handle
->ERROR_MESSAGE("%s", e
.what());
2382 handle
->ERROR_MESSAGE("Unknown exception thrown");
2389 GEOSUnaryUnion_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2391 if ( 0 == extHandle
)
2396 GEOSContextHandleInternal_t
*handle
= 0;
2397 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2398 if ( 0 == handle
->initialized
)
2405 GeomAutoPtr
g3 ( g
->Union() );
2406 return g3
.release();
2408 catch (const std::exception
&e
)
2410 #if VERBOSE_EXCEPTIONS
2411 std::ostringstream s
;
2412 s
<< "Exception on GEOSUnaryUnion with following inputs:" << std::endl
;
2413 s
<< "A: "<<g1
->toString() << std::endl
;
2414 s
<< "B: "<<g2
->toString() << std::endl
;
2415 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
2416 #endif // VERBOSE_EXCEPTIONS
2417 handle
->ERROR_MESSAGE("%s", e
.what());
2421 handle
->ERROR_MESSAGE("Unknown exception thrown");
2428 GEOSNode_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2430 if ( 0 == extHandle
)
2435 GEOSContextHandleInternal_t
*handle
= 0;
2436 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2437 if ( 0 == handle
->initialized
)
2444 std::auto_ptr
<Geometry
> g3
= geos::noding::GeometryNoder::node(*g
);
2445 return g3
.release();
2447 catch (const std::exception
&e
)
2449 #if VERBOSE_EXCEPTIONS
2450 std::ostringstream s
;
2451 s
<< "Exception on GEOSUnaryUnion with following inputs:" << std::endl
;
2452 s
<< "A: "<<g1
->toString() << std::endl
;
2453 s
<< "B: "<<g2
->toString() << std::endl
;
2454 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
2455 #endif // VERBOSE_EXCEPTIONS
2456 handle
->ERROR_MESSAGE("%s", e
.what());
2460 handle
->ERROR_MESSAGE("Unknown exception thrown");
2467 GEOSUnionCascaded_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2469 if ( 0 == extHandle
)
2474 GEOSContextHandleInternal_t
*handle
= 0;
2475 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2476 if ( 0 == handle
->initialized
)
2483 const geos::geom::MultiPolygon
*p
= dynamic_cast<const geos::geom::MultiPolygon
*>(g1
);
2486 handle
->ERROR_MESSAGE("Invalid argument (must be a MultiPolygon)");
2490 using geos::operation::geounion::CascadedPolygonUnion
;
2491 return CascadedPolygonUnion::Union(p
);
2493 catch (const std::exception
&e
)
2495 handle
->ERROR_MESSAGE("%s", e
.what());
2499 handle
->ERROR_MESSAGE("Unknown exception thrown");
2506 GEOSPointOnSurface_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2508 if ( 0 == extHandle
)
2513 GEOSContextHandleInternal_t
*handle
= 0;
2514 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2515 if ( 0 == handle
->initialized
)
2522 Geometry
*ret
= g1
->getInteriorPoint();
2525 const GeometryFactory
* gf
= handle
->geomFactory
;
2526 // return an empty point
2527 return gf
->createPoint();
2531 catch (const std::exception
&e
)
2533 handle
->ERROR_MESSAGE("%s", e
.what());
2537 handle
->ERROR_MESSAGE("Unknown exception thrown");
2544 GEOSClipByRect_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double xmin
, double ymin
, double xmax
, double ymax
)
2546 if ( 0 == extHandle
)
2551 GEOSContextHandleInternal_t
*handle
= 0;
2552 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2553 if ( 0 == handle
->initialized
)
2560 using geos::operation::intersection::Rectangle
;
2561 using geos::operation::intersection::RectangleIntersection
;
2562 Rectangle
rect(xmin
, ymin
, xmax
, ymax
);
2563 std::auto_ptr
<Geometry
> g3
= RectangleIntersection::clip(*g
, rect
);
2564 return g3
.release();
2566 catch (const std::exception
&e
)
2568 #if VERBOSE_EXCEPTIONS
2569 std::ostringstream s
;
2570 s
<< "Exception on GEOSClipByRect with following inputs:" << std::endl
;
2571 s
<< "A: "<<g1
->toString() << std::endl
;
2572 s
<< "B: "<<g2
->toString() << std::endl
;
2573 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
2574 #endif // VERBOSE_EXCEPTIONS
2575 handle
->ERROR_MESSAGE("%s", e
.what());
2579 handle
->ERROR_MESSAGE("Unknown exception thrown");
2585 //-------------------------------------------------------------------
2586 // memory management functions
2587 //------------------------------------------------------------------
2590 GEOSGeom_destroy_r(GEOSContextHandle_t extHandle
, Geometry
*a
)
2592 GEOSContextHandleInternal_t
*handle
= 0;
2594 // FIXME: mloskot: Does this try-catch around delete means that
2595 // destructors in GEOS may throw? If it does, this is a serious
2596 // violation of "never throw an exception from a destructor" principle
2602 catch (const std::exception
&e
)
2604 if ( 0 == extHandle
)
2609 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2610 if ( 0 == handle
->initialized
)
2615 handle
->ERROR_MESSAGE("%s", e
.what());
2619 if ( 0 == extHandle
)
2624 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2625 if ( 0 == handle
->initialized
)
2630 handle
->ERROR_MESSAGE("Unknown exception thrown");
2635 GEOSGeom_setUserData_r(GEOSContextHandle_t extHandle
, Geometry
*g
, void* userData
)
2639 if ( 0 == extHandle
)
2644 GEOSContextHandleInternal_t
*handle
= 0;
2645 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2646 if ( 0 == handle
->initialized
)
2651 g
->setUserData(userData
);
2655 GEOSSetSRID_r(GEOSContextHandle_t extHandle
, Geometry
*g
, int srid
)
2659 if ( 0 == extHandle
)
2664 GEOSContextHandleInternal_t
*handle
= 0;
2665 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2666 if ( 0 == handle
->initialized
)
2676 GEOSGetNumCoordinates_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2680 if ( 0 == extHandle
)
2685 GEOSContextHandleInternal_t
*handle
= 0;
2686 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2687 if ( 0 == handle
->initialized
)
2694 return static_cast<int>(g
->getNumPoints());
2696 catch (const std::exception
&e
)
2698 handle
->ERROR_MESSAGE("%s", e
.what());
2702 handle
->ERROR_MESSAGE("Unknown exception thrown");
2709 * Return -1 on exception, 0 otherwise.
2710 * Converts Geometry to normal form (or canonical form).
2713 GEOSNormalize_r(GEOSContextHandle_t extHandle
, Geometry
*g
)
2717 if ( 0 == extHandle
)
2722 GEOSContextHandleInternal_t
*handle
= 0;
2723 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2724 if ( 0 == handle
->initialized
)
2732 return 0; // SUCCESS
2734 catch (const std::exception
&e
)
2736 handle
->ERROR_MESSAGE("%s", e
.what());
2740 handle
->ERROR_MESSAGE("Unknown exception thrown");
2747 GEOSGetNumInteriorRings_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2749 if ( 0 == extHandle
)
2754 GEOSContextHandleInternal_t
*handle
= 0;
2755 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2756 if ( 0 == handle
->initialized
)
2763 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
2766 handle
->ERROR_MESSAGE("Argument is not a Polygon");
2769 return static_cast<int>(p
->getNumInteriorRing());
2771 catch (const std::exception
&e
)
2773 handle
->ERROR_MESSAGE("%s", e
.what());
2777 handle
->ERROR_MESSAGE("Unknown exception thrown");
2784 // returns -1 on error and 1 for non-multi geometries
2786 GEOSGetNumGeometries_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2788 if ( 0 == extHandle
)
2793 GEOSContextHandleInternal_t
*handle
= 0;
2794 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2795 if ( 0 == handle
->initialized
)
2802 return static_cast<int>(g1
->getNumGeometries());
2804 catch (const std::exception
&e
)
2806 handle
->ERROR_MESSAGE("%s", e
.what());
2810 handle
->ERROR_MESSAGE("Unknown exception thrown");
2818 * Call only on GEOMETRYCOLLECTION or MULTI*.
2819 * Return a pointer to the internal Geometry.
2822 GEOSGetGeometryN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2824 if ( 0 == extHandle
)
2829 GEOSContextHandleInternal_t
*handle
= 0;
2830 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2831 if ( 0 == handle
->initialized
)
2838 return g1
->getGeometryN(n
);
2840 catch (const std::exception
&e
)
2842 handle
->ERROR_MESSAGE("%s", e
.what());
2846 handle
->ERROR_MESSAGE("Unknown exception thrown");
2853 * Call only on LINESTRING
2854 * Returns NULL on exception
2857 GEOSGeomGetPointN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2859 if ( 0 == extHandle
)
2864 GEOSContextHandleInternal_t
*handle
= 0;
2865 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2866 if ( 0 == handle
->initialized
)
2873 using geos::geom::LineString
;
2874 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2877 handle
->ERROR_MESSAGE("Argument is not a LineString");
2880 return ls
->getPointN(n
);
2882 catch (const std::exception
&e
)
2884 handle
->ERROR_MESSAGE("%s", e
.what());
2888 handle
->ERROR_MESSAGE("Unknown exception thrown");
2895 * Call only on LINESTRING
2898 GEOSGeomGetStartPoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2900 if ( 0 == extHandle
)
2905 GEOSContextHandleInternal_t
*handle
= 0;
2906 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2907 if ( 0 == handle
->initialized
)
2914 using geos::geom::LineString
;
2915 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2918 handle
->ERROR_MESSAGE("Argument is not a LineString");
2921 return ls
->getStartPoint();
2923 catch (const std::exception
&e
)
2925 handle
->ERROR_MESSAGE("%s", e
.what());
2929 handle
->ERROR_MESSAGE("Unknown exception thrown");
2936 * Call only on LINESTRING
2939 GEOSGeomGetEndPoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2941 if ( 0 == extHandle
)
2946 GEOSContextHandleInternal_t
*handle
= 0;
2947 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2948 if ( 0 == handle
->initialized
)
2955 using geos::geom::LineString
;
2956 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2959 handle
->ERROR_MESSAGE("Argument is not a LineString");
2962 return ls
->getEndPoint();
2964 catch (const std::exception
&e
)
2966 handle
->ERROR_MESSAGE("%s", e
.what());
2970 handle
->ERROR_MESSAGE("Unknown exception thrown");
2977 * Call only on LINESTRING or MULTILINESTRING
2978 * return 2 on exception, 1 on true, 0 on false
2981 GEOSisClosed_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2983 if ( 0 == extHandle
)
2988 GEOSContextHandleInternal_t
*handle
= 0;
2989 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2990 if ( 0 == handle
->initialized
)
2997 using geos::geom::LineString
;
2998 using geos::geom::MultiLineString
;
3000 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
3002 return ls
->isClosed();
3005 const MultiLineString
*mls
= dynamic_cast<const MultiLineString
*>(g1
);
3007 return mls
->isClosed();
3010 handle
->ERROR_MESSAGE("Argument is not a LineString or MultiLineString");
3013 catch (const std::exception
&e
)
3015 handle
->ERROR_MESSAGE("%s", e
.what());
3019 handle
->ERROR_MESSAGE("Unknown exception thrown");
3026 * Call only on LINESTRING
3027 * return 0 on exception, otherwise 1
3030 GEOSGeomGetLength_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *length
)
3032 if ( 0 == extHandle
)
3037 GEOSContextHandleInternal_t
*handle
= 0;
3038 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3039 if ( 0 == handle
->initialized
)
3046 using geos::geom::LineString
;
3047 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
3050 handle
->ERROR_MESSAGE("Argument is not a LineString");
3053 *length
= ls
->getLength();
3056 catch (const std::exception
&e
)
3058 handle
->ERROR_MESSAGE("%s", e
.what());
3062 handle
->ERROR_MESSAGE("Unknown exception thrown");
3069 * Call only on LINESTRING
3072 GEOSGeomGetNumPoints_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
3074 if ( 0 == extHandle
)
3079 GEOSContextHandleInternal_t
*handle
= 0;
3080 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3081 if ( 0 == handle
->initialized
)
3088 using geos::geom::LineString
;
3089 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
3092 handle
->ERROR_MESSAGE("Argument is not a LineString");
3095 return static_cast<int>(ls
->getNumPoints());
3097 catch (const std::exception
&e
)
3099 handle
->ERROR_MESSAGE("%s", e
.what());
3103 handle
->ERROR_MESSAGE("Unknown exception thrown");
3111 * returns 0 on exception, otherwise 1
3114 GEOSGeomGetX_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *x
)
3116 if ( 0 == extHandle
)
3121 GEOSContextHandleInternal_t
*handle
= 0;
3122 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3123 if ( 0 == handle
->initialized
)
3130 using geos::geom::Point
;
3131 const Point
*po
= dynamic_cast<const Point
*>(g1
);
3134 handle
->ERROR_MESSAGE("Argument is not a Point");
3140 catch (const std::exception
&e
)
3142 handle
->ERROR_MESSAGE("%s", e
.what());
3146 handle
->ERROR_MESSAGE("Unknown exception thrown");
3154 * returns 0 on exception, otherwise 1
3157 GEOSGeomGetY_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *y
)
3159 if ( 0 == extHandle
)
3164 GEOSContextHandleInternal_t
*handle
= 0;
3165 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3166 if ( 0 == handle
->initialized
)
3173 using geos::geom::Point
;
3174 const Point
*po
= dynamic_cast<const Point
*>(g1
);
3177 handle
->ERROR_MESSAGE("Argument is not a Point");
3183 catch (const std::exception
&e
)
3185 handle
->ERROR_MESSAGE("%s", e
.what());
3189 handle
->ERROR_MESSAGE("Unknown exception thrown");
3196 * Call only on polygon
3197 * Return a copy of the internal Geometry.
3200 GEOSGetExteriorRing_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
3202 if ( 0 == extHandle
)
3207 GEOSContextHandleInternal_t
*handle
= 0;
3208 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3209 if ( 0 == handle
->initialized
)
3216 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
3219 handle
->ERROR_MESSAGE("Invalid argument (must be a Polygon)");
3222 return p
->getExteriorRing();
3224 catch (const std::exception
&e
)
3226 handle
->ERROR_MESSAGE("%s", e
.what());
3230 handle
->ERROR_MESSAGE("Unknown exception thrown");
3237 * Call only on polygon
3238 * Return a pointer to internal storage, do not destroy it.
3241 GEOSGetInteriorRingN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
3243 if ( 0 == extHandle
)
3248 GEOSContextHandleInternal_t
*handle
= 0;
3249 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3250 if ( 0 == handle
->initialized
)
3257 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
3260 handle
->ERROR_MESSAGE("Invalid argument (must be a Polygon)");
3263 return p
->getInteriorRingN(n
);
3265 catch (const std::exception
&e
)
3267 handle
->ERROR_MESSAGE("%s", e
.what());
3271 handle
->ERROR_MESSAGE("Unknown exception thrown");
3278 GEOSGetCentroid_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3280 if ( 0 == extHandle
)
3285 GEOSContextHandleInternal_t
*handle
= 0;
3286 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3287 if ( 0 == handle
->initialized
)
3294 Geometry
*ret
= g
->getCentroid();
3297 const GeometryFactory
*gf
= handle
->geomFactory
;
3298 return gf
->createPoint();
3302 catch (const std::exception
&e
)
3304 handle
->ERROR_MESSAGE("%s", e
.what());
3308 handle
->ERROR_MESSAGE("Unknown exception thrown");
3315 GEOSGeom_createEmptyCollection_r(GEOSContextHandle_t extHandle
, int type
)
3317 if ( 0 == extHandle
)
3322 GEOSContextHandleInternal_t
*handle
= 0;
3323 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3324 if ( 0 == handle
->initialized
)
3331 sprintf(buf
, "createCollection: requested type %d", type
);
3332 handle
->NOTICE_MESSAGE("%s", buf
);// TODO: Can handle->NOTICE_MESSAGE format that directly?
3337 const GeometryFactory
* gf
= handle
->geomFactory
;
3342 case GEOS_GEOMETRYCOLLECTION
:
3343 g
= gf
->createGeometryCollection();
3345 case GEOS_MULTIPOINT
:
3346 g
= gf
->createMultiPoint();
3348 case GEOS_MULTILINESTRING
:
3349 g
= gf
->createMultiLineString();
3351 case GEOS_MULTIPOLYGON
:
3352 g
= gf
->createMultiPolygon();
3355 handle
->ERROR_MESSAGE("Unsupported type request for GEOSGeom_createEmptyCollection_r");
3362 catch (const std::exception
&e
)
3364 handle
->ERROR_MESSAGE("%s", e
.what());
3368 handle
->ERROR_MESSAGE("Unknown exception thrown");
3375 GEOSGeom_createCollection_r(GEOSContextHandle_t extHandle
, int type
, Geometry
**geoms
, unsigned int ngeoms
)
3377 if ( 0 == extHandle
)
3382 GEOSContextHandleInternal_t
*handle
= 0;
3383 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3384 if ( 0 == handle
->initialized
)
3391 sprintf(buf
, "PostGIS2GEOS_collection: requested type %d, ngeoms: %d",
3393 handle
->NOTICE_MESSAGE("%s", buf
);// TODO: Can handle->NOTICE_MESSAGE format that directly?
3398 const GeometryFactory
* gf
= handle
->geomFactory
;
3399 std::vector
<Geometry
*>* vgeoms
= new std::vector
<Geometry
*>(geoms
, geoms
+ ngeoms
);
3404 case GEOS_GEOMETRYCOLLECTION
:
3405 g
= gf
->createGeometryCollection(vgeoms
);
3407 case GEOS_MULTIPOINT
:
3408 g
= gf
->createMultiPoint(vgeoms
);
3410 case GEOS_MULTILINESTRING
:
3411 g
= gf
->createMultiLineString(vgeoms
);
3413 case GEOS_MULTIPOLYGON
:
3414 g
= gf
->createMultiPolygon(vgeoms
);
3417 handle
->ERROR_MESSAGE("Unsupported type request for PostGIS2GEOS_collection");
3425 catch (const std::exception
&e
)
3427 handle
->ERROR_MESSAGE("%s", e
.what());
3431 handle
->ERROR_MESSAGE("Unknown exception thrown");
3438 GEOSPolygonize_r(GEOSContextHandle_t extHandle
, const Geometry
* const * g
, unsigned int ngeoms
)
3440 if ( 0 == extHandle
)
3445 GEOSContextHandleInternal_t
*handle
= 0;
3446 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3447 if ( 0 == handle
->initialized
)
3457 using geos::operation::polygonize::Polygonizer
;
3459 for (std::size_t i
= 0; i
< ngeoms
; ++i
)
3465 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
3468 std::vector
<Polygon
*> *polys
= plgnzr
.getPolygons();
3472 handle
->NOTICE_MESSAGE("output polygons got");
3475 // We need a vector of Geometry pointers, not Polygon pointers.
3476 // STL vector doesn't allow transparent upcast of this
3477 // nature, so we explicitly convert.
3478 // (it's just a waste of processor and memory, btw)
3480 // XXX mloskot: Why not to extent GeometryFactory to accept
3481 // vector of polygons or extend Polygonizer to return list of Geometry*
3482 // or add a wrapper which semantic is similar to:
3483 // std::vector<as_polygon<Geometry*> >
3484 std::vector
<Geometry
*> *polyvec
= new std::vector
<Geometry
*>(polys
->size());
3486 for (std::size_t i
= 0; i
< polys
->size(); ++i
)
3488 (*polyvec
)[i
] = (*polys
)[i
];
3493 const GeometryFactory
*gf
= handle
->geomFactory
;
3495 // The below takes ownership of the passed vector,
3496 // so we must *not* delete it
3497 out
= gf
->createGeometryCollection(polyvec
);
3499 catch (const std::exception
&e
)
3501 handle
->ERROR_MESSAGE("%s", e
.what());
3505 handle
->ERROR_MESSAGE("Unknown exception thrown");
3512 GEOSPolygonizer_getCutEdges_r(GEOSContextHandle_t extHandle
, const Geometry
* const * g
, unsigned int ngeoms
)
3514 if ( 0 == extHandle
)
3519 GEOSContextHandleInternal_t
*handle
= 0;
3520 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3521 if ( 0 == handle
->initialized
)
3531 using geos::operation::polygonize::Polygonizer
;
3533 for (std::size_t i
= 0; i
< ngeoms
; ++i
)
3539 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
3542 const std::vector
<const LineString
*>& lines
= plgnzr
.getCutEdges();
3545 handle
->NOTICE_MESSAGE("output polygons got");
3548 // We need a vector of Geometry pointers, not Polygon pointers.
3549 // STL vector doesn't allow transparent upcast of this
3550 // nature, so we explicitly convert.
3551 // (it's just a waste of processor and memory, btw)
3552 // XXX mloskot: See comment for GEOSPolygonize_r
3553 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3555 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3557 (*linevec
)[i
] = lines
[i
]->clone();
3560 const GeometryFactory
*gf
= handle
->geomFactory
;
3562 // The below takes ownership of the passed vector,
3563 // so we must *not* delete it
3564 out
= gf
->createGeometryCollection(linevec
);
3566 catch (const std::exception
&e
)
3568 handle
->ERROR_MESSAGE("%s", e
.what());
3572 handle
->ERROR_MESSAGE("Unknown exception thrown");
3579 GEOSPolygonize_full_r(GEOSContextHandle_t extHandle
, const Geometry
* g
,
3580 Geometry
** cuts
, Geometry
** dangles
, Geometry
** invalid
)
3582 if ( 0 == extHandle
)
3587 GEOSContextHandleInternal_t
*handle
= 0;
3588 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3589 if ( 0 == handle
->initialized
)
3597 using geos::operation::polygonize::Polygonizer
;
3599 for (std::size_t i
= 0; i
<g
->getNumGeometries(); ++i
)
3601 plgnzr
.add(g
->getGeometryN(i
));
3605 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
3607 const GeometryFactory
*gf
= handle
->geomFactory
;
3611 const std::vector
<const LineString
*>& lines
= plgnzr
.getCutEdges();
3612 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3613 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3615 (*linevec
)[i
] = lines
[i
]->clone();
3618 // The below takes ownership of the passed vector,
3619 // so we must *not* delete it
3620 *cuts
= gf
->createGeometryCollection(linevec
);
3625 const std::vector
<const LineString
*>& lines
= plgnzr
.getDangles();
3626 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3627 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3629 (*linevec
)[i
] = lines
[i
]->clone();
3632 // The below takes ownership of the passed vector,
3633 // so we must *not* delete it
3634 *dangles
= gf
->createGeometryCollection(linevec
);
3639 const std::vector
<LineString
*>& lines
= plgnzr
.getInvalidRingLines();
3640 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3641 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3643 (*linevec
)[i
] = lines
[i
]->clone();
3646 // The below takes ownership of the passed vector,
3647 // so we must *not* delete it
3648 *invalid
= gf
->createGeometryCollection(linevec
);
3651 std::vector
<Polygon
*> *polys
= plgnzr
.getPolygons();
3652 std::vector
<Geometry
*> *polyvec
= new std::vector
<Geometry
*>(polys
->size());
3653 for (std::size_t i
= 0; i
< polys
->size(); ++i
)
3655 (*polyvec
)[i
] = (*polys
)[i
];
3659 return gf
->createGeometryCollection(polyvec
);
3662 catch (const std::exception
&e
)
3664 handle
->ERROR_MESSAGE("%s", e
.what());
3669 handle
->ERROR_MESSAGE("Unknown exception thrown");
3675 GEOSLineMerge_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3677 if ( 0 == extHandle
)
3682 GEOSContextHandleInternal_t
*handle
= 0;
3683 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3684 if ( 0 == handle
->initialized
)
3693 using geos::operation::linemerge::LineMerger
;
3697 std::vector
<LineString
*>* lines
= lmrgr
.getMergedLineStrings();
3701 handle
->NOTICE_MESSAGE("output lines got");
3704 std::vector
<Geometry
*>*geoms
= new std::vector
<Geometry
*>(lines
->size());
3705 for (std::vector
<Geometry
*>::size_type i
= 0; i
< lines
->size(); ++i
)
3707 (*geoms
)[i
] = (*lines
)[i
];
3712 const GeometryFactory
*gf
= handle
->geomFactory
;
3713 out
= gf
->buildGeometry(geoms
);
3716 //out = gf->createGeometryCollection(geoms);
3718 catch (const std::exception
&e
)
3720 handle
->ERROR_MESSAGE("%s", e
.what());
3724 handle
->ERROR_MESSAGE("Unknown exception thrown");
3731 GEOSGeom_getUserData_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3735 if ( 0 == extHandle
)
3740 GEOSContextHandleInternal_t
*handle
= 0;
3741 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3742 if ( 0 == handle
->initialized
)
3749 return g
->getUserData();
3751 catch (const std::exception
&e
)
3753 handle
->ERROR_MESSAGE("%s", e
.what());
3757 handle
->ERROR_MESSAGE("Unknown exception thrown");
3764 GEOSGetSRID_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3768 if ( 0 == extHandle
)
3773 GEOSContextHandleInternal_t
*handle
= 0;
3774 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3775 if ( 0 == handle
->initialized
)
3782 return g
->getSRID();
3784 catch (const std::exception
&e
)
3786 handle
->ERROR_MESSAGE("%s", e
.what());
3790 handle
->ERROR_MESSAGE("Unknown exception thrown");
3796 const char* GEOSversion()
3798 static char version
[256];
3799 sprintf(version
, "%s " GEOS_REVISION
, GEOS_CAPI_VERSION
);
3803 const char* GEOSjtsport()
3805 return GEOS_JTS_PORT
;
3809 GEOSHasZ_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3813 if ( 0 == extHandle
)
3818 GEOSContextHandleInternal_t
*handle
= 0;
3819 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3820 if ( 0 == handle
->initialized
)
3829 assert(0 != g
->getCoordinate());
3831 double az
= g
->getCoordinate()->z
;
3832 //handle->ERROR_MESSAGE("ZCoord: %g", az);
3834 return static_cast<char>(FINITE(az
));
3838 GEOS_getWKBOutputDims_r(GEOSContextHandle_t extHandle
)
3840 if ( 0 == extHandle
)
3845 GEOSContextHandleInternal_t
*handle
= 0;
3846 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3847 if ( 0 == handle
->initialized
)
3852 return handle
->WKBOutputDims
;
3856 GEOS_setWKBOutputDims_r(GEOSContextHandle_t extHandle
, int newdims
)
3858 if ( 0 == extHandle
)
3863 GEOSContextHandleInternal_t
*handle
= 0;
3864 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3865 if ( 0 == handle
->initialized
)
3870 if ( newdims
< 2 || newdims
> 3 )
3872 handle
->ERROR_MESSAGE("WKB output dimensions out of range 2..3");
3875 const int olddims
= handle
->WKBOutputDims
;
3876 handle
->WKBOutputDims
= newdims
;
3882 GEOS_getWKBByteOrder_r(GEOSContextHandle_t extHandle
)
3884 if ( 0 == extHandle
)
3889 GEOSContextHandleInternal_t
*handle
= 0;
3890 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3891 if ( 0 == handle
->initialized
)
3896 return handle
->WKBByteOrder
;
3900 GEOS_setWKBByteOrder_r(GEOSContextHandle_t extHandle
, int byteOrder
)
3902 if ( 0 == extHandle
)
3907 GEOSContextHandleInternal_t
*handle
= 0;
3908 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3909 if ( 0 == handle
->initialized
)
3914 const int oldByteOrder
= handle
->WKBByteOrder
;
3915 handle
->WKBByteOrder
= byteOrder
;
3917 return oldByteOrder
;
3921 CoordinateSequence
*
3922 GEOSCoordSeq_create_r(GEOSContextHandle_t extHandle
, unsigned int size
, unsigned int dims
)
3924 if ( 0 == extHandle
)
3929 GEOSContextHandleInternal_t
*handle
= 0;
3930 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3931 if ( 0 == handle
->initialized
)
3938 const GeometryFactory
*gf
= handle
->geomFactory
;
3939 return gf
->getCoordinateSequenceFactory()->create(size
, dims
);
3941 catch (const std::exception
&e
)
3943 handle
->ERROR_MESSAGE("%s", e
.what());
3947 handle
->ERROR_MESSAGE("Unknown exception thrown");
3954 GEOSCoordSeq_setOrdinate_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
,
3955 unsigned int idx
, unsigned int dim
, double val
)
3958 if ( 0 == extHandle
)
3963 GEOSContextHandleInternal_t
*handle
= 0;
3964 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3965 if ( 0 == handle
->initialized
)
3972 cs
->setOrdinate(idx
, dim
, val
);
3975 catch (const std::exception
&e
)
3977 handle
->ERROR_MESSAGE("%s", e
.what());
3981 handle
->ERROR_MESSAGE("Unknown exception thrown");
3988 GEOSCoordSeq_setX_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3990 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 0, val
);
3994 GEOSCoordSeq_setY_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3996 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 1, val
);
4000 GEOSCoordSeq_setZ_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
4002 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 2, val
);
4005 CoordinateSequence
*
4006 GEOSCoordSeq_clone_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
)
4010 if ( 0 == extHandle
)
4015 GEOSContextHandleInternal_t
*handle
= 0;
4016 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4017 if ( 0 == handle
->initialized
)
4026 catch (const std::exception
&e
)
4028 handle
->ERROR_MESSAGE("%s", e
.what());
4032 handle
->ERROR_MESSAGE("Unknown exception thrown");
4039 GEOSCoordSeq_getOrdinate_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
,
4040 unsigned int idx
, unsigned int dim
, double *val
)
4045 if ( 0 == extHandle
)
4050 GEOSContextHandleInternal_t
*handle
= 0;
4051 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4052 if ( 0 == handle
->initialized
)
4059 double d
= cs
->getOrdinate(idx
, dim
);
4064 catch (const std::exception
&e
)
4066 handle
->ERROR_MESSAGE("%s", e
.what());
4070 handle
->ERROR_MESSAGE("Unknown exception thrown");
4077 GEOSCoordSeq_getX_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
4079 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 0, val
);
4083 GEOSCoordSeq_getY_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
4085 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 1, val
);
4089 GEOSCoordSeq_getZ_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
4091 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 2, val
);
4095 GEOSCoordSeq_getSize_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
, unsigned int *size
)
4100 if ( 0 == extHandle
)
4105 GEOSContextHandleInternal_t
*handle
= 0;
4106 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4107 if ( 0 == handle
->initialized
)
4114 const std::size_t sz
= cs
->getSize();
4115 *size
= static_cast<unsigned int>(sz
);
4118 catch (const std::exception
&e
)
4120 handle
->ERROR_MESSAGE("%s", e
.what());
4124 handle
->ERROR_MESSAGE("Unknown exception thrown");
4131 GEOSCoordSeq_getDimensions_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
, unsigned int *dims
)
4136 if ( 0 == extHandle
)
4141 GEOSContextHandleInternal_t
*handle
= 0;
4142 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4143 if ( 0 == handle
->initialized
)
4150 const std::size_t dim
= cs
->getDimension();
4151 *dims
= static_cast<unsigned int>(dim
);
4155 catch (const std::exception
&e
)
4157 handle
->ERROR_MESSAGE("%s", e
.what());
4162 handle
->ERROR_MESSAGE("Unknown exception thrown");
4169 GEOSCoordSeq_destroy_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
)
4171 GEOSContextHandleInternal_t
*handle
= 0;
4177 catch (const std::exception
&e
)
4179 if ( 0 == extHandle
)
4184 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4185 if ( 0 == handle
->initialized
)
4190 handle
->ERROR_MESSAGE("%s", e
.what());
4194 if ( 0 == extHandle
)
4199 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4200 if ( 0 == handle
->initialized
)
4205 handle
->ERROR_MESSAGE("Unknown exception thrown");
4209 const CoordinateSequence
*
4210 GEOSGeom_getCoordSeq_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
4212 if ( 0 == extHandle
)
4217 GEOSContextHandleInternal_t
*handle
= 0;
4218 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4219 if ( 0 == handle
->initialized
)
4226 using geos::geom::Point
;
4228 const LineString
*ls
= dynamic_cast<const LineString
*>(g
);
4231 return ls
->getCoordinatesRO();
4234 const Point
*p
= dynamic_cast<const Point
*>(g
);
4237 return p
->getCoordinatesRO();
4240 handle
->ERROR_MESSAGE("Geometry must be a Point or LineString");
4243 catch (const std::exception
&e
)
4245 handle
->ERROR_MESSAGE("%s", e
.what());
4249 handle
->ERROR_MESSAGE("Unknown exception thrown");
4256 GEOSGeom_createEmptyPoint_r(GEOSContextHandle_t extHandle
)
4258 if ( 0 == extHandle
)
4263 GEOSContextHandleInternal_t
*handle
= 0;
4264 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4265 if ( 0 == handle
->initialized
)
4272 const GeometryFactory
*gf
= handle
->geomFactory
;
4273 return gf
->createPoint();
4275 catch (const std::exception
&e
)
4277 handle
->ERROR_MESSAGE("%s", e
.what());
4281 handle
->ERROR_MESSAGE("Unknown exception thrown");
4288 GEOSGeom_createPoint_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
4290 if ( 0 == extHandle
)
4295 GEOSContextHandleInternal_t
*handle
= 0;
4296 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4297 if ( 0 == handle
->initialized
)
4304 const GeometryFactory
*gf
= handle
->geomFactory
;
4305 return gf
->createPoint(cs
);
4307 catch (const std::exception
&e
)
4309 handle
->ERROR_MESSAGE("%s", e
.what());
4313 handle
->ERROR_MESSAGE("Unknown exception thrown");
4320 GEOSGeom_createLinearRing_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
4322 if ( 0 == extHandle
)
4327 GEOSContextHandleInternal_t
*handle
= 0;
4328 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4329 if ( 0 == handle
->initialized
)
4336 const GeometryFactory
*gf
= handle
->geomFactory
;
4338 return gf
->createLinearRing(cs
);
4340 catch (const std::exception
&e
)
4342 handle
->ERROR_MESSAGE("%s", e
.what());
4346 handle
->ERROR_MESSAGE("Unknown exception thrown");
4353 GEOSGeom_createEmptyLineString_r(GEOSContextHandle_t extHandle
)
4355 if ( 0 == extHandle
)
4360 GEOSContextHandleInternal_t
*handle
= 0;
4361 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4362 if ( 0 == handle
->initialized
)
4369 const GeometryFactory
*gf
= handle
->geomFactory
;
4371 return gf
->createLineString();
4373 catch (const std::exception
&e
)
4375 handle
->ERROR_MESSAGE("%s", e
.what());
4379 handle
->ERROR_MESSAGE("Unknown exception thrown");
4386 GEOSGeom_createLineString_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
4388 if ( 0 == extHandle
)
4393 GEOSContextHandleInternal_t
*handle
= 0;
4394 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4395 if ( 0 == handle
->initialized
)
4402 const GeometryFactory
*gf
= handle
->geomFactory
;
4404 return gf
->createLineString(cs
);
4406 catch (const std::exception
&e
)
4408 handle
->ERROR_MESSAGE("%s", e
.what());
4412 handle
->ERROR_MESSAGE("Unknown exception thrown");
4419 GEOSGeom_createEmptyPolygon_r(GEOSContextHandle_t extHandle
)
4421 if ( 0 == extHandle
)
4426 GEOSContextHandleInternal_t
*handle
= 0;
4427 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4428 if ( 0 == handle
->initialized
)
4435 const GeometryFactory
*gf
= handle
->geomFactory
;
4436 return gf
->createPolygon();
4438 catch (const std::exception
&e
)
4440 handle
->ERROR_MESSAGE("%s", e
.what());
4444 handle
->ERROR_MESSAGE("Unknown exception thrown");
4451 GEOSGeom_createPolygon_r(GEOSContextHandle_t extHandle
, Geometry
*shell
, Geometry
**holes
, unsigned int nholes
)
4453 // FIXME: holes must be non-nullptr or may be nullptr?
4454 //assert(0 != holes);
4456 if ( 0 == extHandle
)
4461 GEOSContextHandleInternal_t
*handle
= 0;
4462 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4463 if ( 0 == handle
->initialized
)
4470 using geos::geom::LinearRing
;
4472 std::vector
<Geometry
*> *vholes
= new std::vector
<Geometry
*>(holes
, holes
+ nholes
);
4474 LinearRing
*nshell
= dynamic_cast<LinearRing
*>(shell
);
4477 handle
->ERROR_MESSAGE("Shell is not a LinearRing");
4481 const GeometryFactory
*gf
= handle
->geomFactory
;
4483 return gf
->createPolygon(nshell
, vholes
);
4485 catch (const std::exception
&e
)
4487 handle
->ERROR_MESSAGE("%s", e
.what());
4491 handle
->ERROR_MESSAGE("Unknown exception thrown");
4498 GEOSGeom_clone_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
4502 if ( 0 == extHandle
)
4507 GEOSContextHandleInternal_t
*handle
= 0;
4508 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4509 if ( 0 == handle
->initialized
)
4518 catch (const std::exception
&e
)
4520 handle
->ERROR_MESSAGE("%s", e
.what());
4524 handle
->ERROR_MESSAGE("Unknown exception thrown");
4531 GEOSGeom_setPrecision_r(GEOSContextHandle_t extHandle
, const GEOSGeometry
*g
,
4532 double gridSize
, int flags
)
4534 using namespace geos::geom
;
4538 if ( 0 == extHandle
)
4543 GEOSContextHandleInternal_t
*handle
= 0;
4544 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4545 if ( 0 == handle
->initialized
)
4552 const PrecisionModel
*pm
= g
->getPrecisionModel();
4553 double cursize
= pm
->isFloating() ? 0 : 1.0/pm
->getScale();
4554 std::auto_ptr
<PrecisionModel
> newpm
;
4555 if ( gridSize
) newpm
.reset( new PrecisionModel(1.0/gridSize
) );
4556 else newpm
.reset( new PrecisionModel() );
4557 GeometryFactory::unique_ptr gf
=
4558 GeometryFactory::create( newpm
.get(), g
->getSRID() );
4560 if ( gridSize
&& cursize
!= gridSize
)
4562 // We need to snap the geometry
4563 GeometryPrecisionReducer
reducer( *gf
);
4564 reducer
.setPointwise( flags
& GEOS_PREC_NO_TOPO
);
4565 reducer
.setRemoveCollapsedComponents( ! (flags
& GEOS_PREC_KEEP_COLLAPSED
) );
4566 ret
= reducer
.reduce( *g
).release();
4570 // No need or willing to snap, just change the factory
4571 ret
= gf
->createGeometry(g
);
4575 catch (const std::exception
&e
)
4577 handle
->ERROR_MESSAGE("%s", e
.what());
4581 handle
->ERROR_MESSAGE("Unknown exception thrown");
4588 GEOSGeom_getPrecision_r(GEOSContextHandle_t extHandle
, const GEOSGeometry
*g
)
4590 using namespace geos::geom
;
4594 if ( 0 == extHandle
)
4599 GEOSContextHandleInternal_t
*handle
= 0;
4600 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4601 if ( 0 == handle
->initialized
)
4608 const PrecisionModel
*pm
= g
->getPrecisionModel();
4609 double cursize
= pm
->isFloating() ? 0 : 1.0/pm
->getScale();
4612 catch (const std::exception
&e
)
4614 handle
->ERROR_MESSAGE("%s", e
.what());
4618 handle
->ERROR_MESSAGE("Unknown exception thrown");
4625 GEOSGeom_getDimensions_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
4627 if ( 0 == extHandle
)
4632 GEOSContextHandleInternal_t
*handle
= 0;
4633 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4634 if ( 0 == handle
->initialized
)
4641 return (int) g
->getDimension();
4643 catch (const std::exception
&e
)
4645 handle
->ERROR_MESSAGE("%s", e
.what());
4649 handle
->ERROR_MESSAGE("Unknown exception thrown");
4656 GEOSGeom_getCoordinateDimension_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
4658 if ( 0 == extHandle
)
4663 GEOSContextHandleInternal_t
*handle
= 0;
4664 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4665 if ( 0 == handle
->initialized
)
4672 return g
->getCoordinateDimension();
4674 catch (const std::exception
&e
)
4676 handle
->ERROR_MESSAGE("%s", e
.what());
4680 handle
->ERROR_MESSAGE("Unknown exception thrown");
4687 GEOSSimplify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double tolerance
)
4689 if ( 0 == extHandle
)
4694 GEOSContextHandleInternal_t
*handle
= 0;
4695 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4696 if ( 0 == handle
->initialized
)
4703 using namespace geos::simplify
;
4704 Geometry::AutoPtr
g(DouglasPeuckerSimplifier::simplify(g1
, tolerance
));
4707 catch (const std::exception
&e
)
4709 handle
->ERROR_MESSAGE("%s", e
.what());
4713 handle
->ERROR_MESSAGE("Unknown exception thrown");
4720 GEOSTopologyPreserveSimplify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double tolerance
)
4722 if ( 0 == extHandle
)
4727 GEOSContextHandleInternal_t
*handle
= 0;
4728 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4729 if ( 0 == handle
->initialized
)
4736 using namespace geos::simplify
;
4737 Geometry::AutoPtr
g(TopologyPreservingSimplifier::simplify(g1
, tolerance
));
4740 catch (const std::exception
&e
)
4742 handle
->ERROR_MESSAGE("%s", e
.what());
4746 handle
->ERROR_MESSAGE("Unknown exception thrown");
4755 GEOSWKTReader_create_r(GEOSContextHandle_t extHandle
)
4757 if ( 0 == extHandle
)
4762 GEOSContextHandleInternal_t
*handle
= 0;
4763 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4764 if ( 0 == handle
->initialized
)
4771 using geos::io::WKTReader
;
4772 return new WKTReader((GeometryFactory
*)handle
->geomFactory
);
4774 catch (const std::exception
&e
)
4776 handle
->ERROR_MESSAGE("%s", e
.what());
4780 handle
->ERROR_MESSAGE("Unknown exception thrown");
4787 GEOSWKTReader_destroy_r(GEOSContextHandle_t extHandle
, WKTReader
*reader
)
4789 GEOSContextHandleInternal_t
*handle
= 0;
4795 catch (const std::exception
&e
)
4797 if ( 0 == extHandle
)
4802 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4803 if ( 0 == handle
->initialized
)
4808 handle
->ERROR_MESSAGE("%s", e
.what());
4812 if ( 0 == extHandle
)
4817 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4818 if ( 0 == handle
->initialized
)
4823 handle
->ERROR_MESSAGE("Unknown exception thrown");
4829 GEOSWKTReader_read_r(GEOSContextHandle_t extHandle
, WKTReader
*reader
, const char *wkt
)
4831 assert(0 != reader
);
4833 if ( 0 == extHandle
)
4838 GEOSContextHandleInternal_t
*handle
= 0;
4839 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4840 if ( 0 == handle
->initialized
)
4847 const std::string
wktstring(wkt
);
4848 Geometry
*g
= reader
->read(wktstring
);
4851 catch (const std::exception
&e
)
4853 handle
->ERROR_MESSAGE("%s", e
.what());
4857 handle
->ERROR_MESSAGE("Unknown exception thrown");
4865 GEOSWKTWriter_create_r(GEOSContextHandle_t extHandle
)
4867 if ( 0 == extHandle
)
4872 GEOSContextHandleInternal_t
*handle
= 0;
4873 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4874 if ( 0 == handle
->initialized
)
4881 using geos::io::WKTWriter
;
4882 return new WKTWriter();
4884 catch (const std::exception
&e
)
4886 handle
->ERROR_MESSAGE("%s", e
.what());
4890 handle
->ERROR_MESSAGE("Unknown exception thrown");
4897 GEOSWKTWriter_destroy_r(GEOSContextHandle_t extHandle
, WKTWriter
*Writer
)
4900 GEOSContextHandleInternal_t
*handle
= 0;
4906 catch (const std::exception
&e
)
4908 if ( 0 == extHandle
)
4913 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4914 if ( 0 == handle
->initialized
)
4919 handle
->ERROR_MESSAGE("%s", e
.what());
4923 if ( 0 == extHandle
)
4928 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4929 if ( 0 == handle
->initialized
)
4934 handle
->ERROR_MESSAGE("Unknown exception thrown");
4940 GEOSWKTWriter_write_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, const Geometry
*geom
)
4942 assert(0 != writer
);
4944 if ( 0 == extHandle
)
4949 GEOSContextHandleInternal_t
*handle
= 0;
4950 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4951 if ( 0 == handle
->initialized
)
4958 std::string
sgeom(writer
->write(geom
));
4959 char *result
= gstrdup(sgeom
);
4962 catch (const std::exception
&e
)
4964 handle
->ERROR_MESSAGE("%s", e
.what());
4968 handle
->ERROR_MESSAGE("Unknown exception thrown");
4975 GEOSWKTWriter_setTrim_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, char trim
)
4977 assert(0 != writer
);
4979 if ( 0 == extHandle
)
4984 GEOSContextHandleInternal_t
*handle
= 0;
4985 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4986 if ( 0 == handle
->initialized
)
4991 writer
->setTrim(0 != trim
);
4995 GEOSWKTWriter_setRoundingPrecision_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int precision
)
4997 assert(0 != writer
);
4999 if ( 0 == extHandle
)
5004 GEOSContextHandleInternal_t
*handle
= 0;
5005 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5006 if ( 0 == handle
->initialized
)
5011 writer
->setRoundingPrecision(precision
);
5015 GEOSWKTWriter_setOutputDimension_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int dim
)
5017 assert(0 != writer
);
5019 if ( 0 == extHandle
)
5024 GEOSContextHandleInternal_t
*handle
= 0;
5025 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5026 if ( 0 == handle
->initialized
)
5033 writer
->setOutputDimension(dim
);
5035 catch (const std::exception
&e
)
5037 handle
->ERROR_MESSAGE("%s", e
.what());
5041 handle
->ERROR_MESSAGE("Unknown exception thrown");
5046 GEOSWKTWriter_getOutputDimension_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
)
5048 assert(0 != writer
);
5050 if ( 0 == extHandle
)
5055 GEOSContextHandleInternal_t
*handle
= 0;
5056 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5057 if ( 0 == handle
->initialized
)
5066 dim
= writer
->getOutputDimension();
5068 catch (const std::exception
&e
)
5070 handle
->ERROR_MESSAGE("%s", e
.what());
5074 handle
->ERROR_MESSAGE("Unknown exception thrown");
5081 GEOSWKTWriter_setOld3D_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int useOld3D
)
5083 assert(0 != writer
);
5085 if ( 0 == extHandle
)
5090 GEOSContextHandleInternal_t
*handle
= 0;
5091 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5092 if ( 0 == handle
->initialized
)
5097 writer
->setOld3D(0 != useOld3D
);
5102 GEOSWKBReader_create_r(GEOSContextHandle_t extHandle
)
5104 if ( 0 == extHandle
)
5109 GEOSContextHandleInternal_t
*handle
= 0;
5110 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5111 if ( 0 == handle
->initialized
)
5116 using geos::io::WKBReader
;
5119 return new WKBReader(*(GeometryFactory
*)handle
->geomFactory
);
5121 catch (const std::exception
&e
)
5123 handle
->ERROR_MESSAGE("%s", e
.what());
5127 handle
->ERROR_MESSAGE("Unknown exception thrown");
5134 GEOSWKBReader_destroy_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
)
5136 GEOSContextHandleInternal_t
*handle
= 0;
5142 catch (const std::exception
&e
)
5144 if ( 0 == extHandle
)
5149 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5150 if ( 0 == handle
->initialized
)
5155 handle
->ERROR_MESSAGE("%s", e
.what());
5159 if ( 0 == extHandle
)
5164 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5165 if ( 0 == handle
->initialized
)
5170 handle
->ERROR_MESSAGE("Unknown exception thrown");
5174 struct membuf
: public std::streambuf
5176 membuf(char* s
, std::size_t n
)
5183 GEOSWKBReader_read_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
, const unsigned char *wkb
, size_t size
)
5185 assert(0 != reader
);
5188 if ( 0 == extHandle
)
5193 GEOSContextHandleInternal_t
*handle
= 0;
5194 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5195 if ( 0 == handle
->initialized
)
5202 //std::string wkbstring(reinterpret_cast<const char*>(wkb), size); // make it binary !
5203 //std::istringstream is(std::ios_base::binary);
5204 //is.str(wkbstring);
5205 //is.seekg(0, std::ios::beg); // rewind reader pointer
5207 // http://stackoverflow.com/questions/2079912/simpler-way-to-create-a-c-memorystream-from-char-size-t-without-copying-t
5208 membuf
mb((char*)wkb
, size
);
5211 Geometry
*g
= reader
->read(is
);
5214 catch (const std::exception
&e
)
5216 handle
->ERROR_MESSAGE("%s", e
.what());
5220 handle
->ERROR_MESSAGE("Unknown exception thrown");
5227 GEOSWKBReader_readHEX_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
, const unsigned char *hex
, size_t size
)
5229 assert(0 != reader
);
5232 if ( 0 == extHandle
)
5237 GEOSContextHandleInternal_t
*handle
= 0;
5238 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5239 if ( 0 == handle
->initialized
)
5246 std::string
hexstring(reinterpret_cast<const char*>(hex
), size
);
5247 std::istringstream
is(std::ios_base::binary
);
5249 is
.seekg(0, std::ios::beg
); // rewind reader pointer
5251 Geometry
*g
= reader
->readHEX(is
);
5254 catch (const std::exception
&e
)
5256 handle
->ERROR_MESSAGE("%s", e
.what());
5260 handle
->ERROR_MESSAGE("Unknown exception thrown");
5268 GEOSWKBWriter_create_r(GEOSContextHandle_t extHandle
)
5270 if ( 0 == extHandle
)
5275 GEOSContextHandleInternal_t
*handle
= 0;
5276 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5277 if ( 0 == handle
->initialized
)
5284 using geos::io::WKBWriter
;
5285 return new WKBWriter();
5287 catch (const std::exception
&e
)
5289 handle
->ERROR_MESSAGE("%s", e
.what());
5293 handle
->ERROR_MESSAGE("Unknown exception thrown");
5300 GEOSWKBWriter_destroy_r(GEOSContextHandle_t extHandle
, WKBWriter
*Writer
)
5302 GEOSContextHandleInternal_t
*handle
= 0;
5308 catch (const std::exception
&e
)
5310 if ( 0 == extHandle
)
5315 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5316 if ( 0 == handle
->initialized
)
5321 handle
->ERROR_MESSAGE("%s", e
.what());
5325 if ( 0 == extHandle
)
5330 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5331 if ( 0 == handle
->initialized
)
5336 handle
->ERROR_MESSAGE("Unknown exception thrown");
5341 /* The caller owns the result */
5343 GEOSWKBWriter_write_r(GEOSContextHandle_t extHandle
, WKBWriter
*writer
, const Geometry
*geom
, size_t *size
)
5345 assert(0 != writer
);
5349 if ( 0 == extHandle
)
5354 GEOSContextHandleInternal_t
*handle
= 0;
5355 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5356 if ( 0 == handle
->initialized
)
5363 std::ostringstream
os(std::ios_base::binary
);
5364 writer
->write(*geom
, os
);
5366 const std::string
& wkbstring
= os
.str();
5367 const std::size_t len
= wkbstring
.length();
5369 unsigned char *result
= NULL
;
5370 result
= (unsigned char*) malloc(len
);
5371 std::memcpy(result
, wkbstring
.c_str(), len
);
5375 catch (const std::exception
&e
)
5377 handle
->ERROR_MESSAGE("%s", e
.what());
5381 handle
->ERROR_MESSAGE("Unknown exception thrown");
5386 /* The caller owns the result */
5388 GEOSWKBWriter_writeHEX_r(GEOSContextHandle_t extHandle
, WKBWriter
*writer
, const Geometry
*geom
, size_t *size
)
5390 assert(0 != writer
);
5394 if ( 0 == extHandle
)
5399 GEOSContextHandleInternal_t
*handle
= 0;
5400 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5401 if ( 0 == handle
->initialized
)
5408 std::ostringstream
os(std::ios_base::binary
);
5409 writer
->writeHEX(*geom
, os
);
5410 std::string
wkbstring(os
.str());
5411 const std::size_t len
= wkbstring
.length();
5413 unsigned char *result
= NULL
;
5414 result
= (unsigned char*) malloc(len
);
5415 std::memcpy(result
, wkbstring
.c_str(), len
);
5419 catch (const std::exception
&e
)
5421 handle
->ERROR_MESSAGE("%s", e
.what());
5425 handle
->ERROR_MESSAGE("Unknown exception thrown");
5432 GEOSWKBWriter_getOutputDimension_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
5434 assert(0 != writer
);
5436 if ( 0 == extHandle
)
5443 GEOSContextHandleInternal_t
*handle
= 0;
5444 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5445 if ( 0 != handle
->initialized
)
5449 ret
= writer
->getOutputDimension();
5453 handle
->ERROR_MESSAGE("Unknown exception thrown");
5461 GEOSWKBWriter_setOutputDimension_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, int newDimension
)
5463 assert(0 != writer
);
5465 if ( 0 == extHandle
)
5470 GEOSContextHandleInternal_t
*handle
= 0;
5471 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5472 if ( 0 != handle
->initialized
)
5476 writer
->setOutputDimension(newDimension
);
5478 catch (const std::exception
&e
)
5480 handle
->ERROR_MESSAGE("%s", e
.what());
5484 handle
->ERROR_MESSAGE("Unknown exception thrown");
5490 GEOSWKBWriter_getByteOrder_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
5492 assert(0 != writer
);
5494 if ( 0 == extHandle
)
5501 GEOSContextHandleInternal_t
*handle
= 0;
5502 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5503 if ( 0 != handle
->initialized
)
5507 ret
= writer
->getByteOrder();
5512 handle
->ERROR_MESSAGE("Unknown exception thrown");
5520 GEOSWKBWriter_setByteOrder_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, int newByteOrder
)
5522 assert(0 != writer
);
5524 if ( 0 == extHandle
)
5529 GEOSContextHandleInternal_t
*handle
= 0;
5530 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5531 if ( 0 != handle
->initialized
)
5535 writer
->setByteOrder(newByteOrder
);
5537 catch (const std::exception
&e
)
5539 handle
->ERROR_MESSAGE("%s", e
.what());
5543 handle
->ERROR_MESSAGE("Unknown exception thrown");
5549 GEOSWKBWriter_getIncludeSRID_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
5551 assert(0 != writer
);
5553 if ( 0 == extHandle
)
5560 GEOSContextHandleInternal_t
*handle
= 0;
5561 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5562 if ( 0 != handle
->initialized
)
5566 int srid
= writer
->getIncludeSRID();
5571 handle
->ERROR_MESSAGE("Unknown exception thrown");
5575 return static_cast<char>(ret
);
5579 GEOSWKBWriter_setIncludeSRID_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, const char newIncludeSRID
)
5581 assert(0 != writer
);
5583 if ( 0 == extHandle
)
5588 GEOSContextHandleInternal_t
*handle
= 0;
5589 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5590 if ( 0 != handle
->initialized
)
5594 writer
->setIncludeSRID(newIncludeSRID
);
5598 handle
->ERROR_MESSAGE("Unknown exception thrown");
5604 //-----------------------------------------------------------------
5605 // Prepared Geometry
5606 //-----------------------------------------------------------------
5608 const geos::geom::prep::PreparedGeometry
*
5609 GEOSPrepare_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
5611 if ( 0 == extHandle
)
5616 GEOSContextHandleInternal_t
*handle
= 0;
5617 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5618 if ( 0 == handle
->initialized
)
5623 const geos::geom::prep::PreparedGeometry
* prep
= 0;
5627 prep
= geos::geom::prep::PreparedGeometryFactory::prepare(g
);
5629 catch (const std::exception
&e
)
5631 handle
->ERROR_MESSAGE("%s", e
.what());
5635 handle
->ERROR_MESSAGE("Unknown exception thrown");
5642 GEOSPreparedGeom_destroy_r(GEOSContextHandle_t extHandle
, const geos::geom::prep::PreparedGeometry
*a
)
5644 GEOSContextHandleInternal_t
*handle
= 0;
5650 catch (const std::exception
&e
)
5652 if ( 0 == extHandle
)
5657 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5658 if ( 0 == handle
->initialized
)
5663 handle
->ERROR_MESSAGE("%s", e
.what());
5667 if ( 0 == extHandle
)
5672 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5673 if ( 0 == handle
->initialized
)
5678 handle
->ERROR_MESSAGE("Unknown exception thrown");
5683 GEOSPreparedContains_r(GEOSContextHandle_t extHandle
,
5684 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5689 if ( 0 == extHandle
)
5694 GEOSContextHandleInternal_t
*handle
= 0;
5695 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5696 if ( 0 == handle
->initialized
)
5703 bool result
= pg
->contains(g
);
5706 catch (const std::exception
&e
)
5708 handle
->ERROR_MESSAGE("%s", e
.what());
5712 handle
->ERROR_MESSAGE("Unknown exception thrown");
5719 GEOSPreparedContainsProperly_r(GEOSContextHandle_t extHandle
,
5720 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5725 if ( 0 == extHandle
)
5730 GEOSContextHandleInternal_t
*handle
= 0;
5731 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5732 if ( 0 == handle
->initialized
)
5739 bool result
= pg
->containsProperly(g
);
5742 catch (const std::exception
&e
)
5744 handle
->ERROR_MESSAGE("%s", e
.what());
5748 handle
->ERROR_MESSAGE("Unknown exception thrown");
5755 GEOSPreparedCoveredBy_r(GEOSContextHandle_t extHandle
,
5756 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5761 if ( 0 == extHandle
)
5766 GEOSContextHandleInternal_t
*handle
= 0;
5767 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5768 if ( 0 == handle
->initialized
)
5775 bool result
= pg
->coveredBy(g
);
5778 catch (const std::exception
&e
)
5780 handle
->ERROR_MESSAGE("%s", e
.what());
5784 handle
->ERROR_MESSAGE("Unknown exception thrown");
5791 GEOSPreparedCovers_r(GEOSContextHandle_t extHandle
,
5792 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5797 if ( 0 == extHandle
)
5802 GEOSContextHandleInternal_t
*handle
= 0;
5803 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5804 if ( 0 == handle
->initialized
)
5811 bool result
= pg
->covers(g
);
5814 catch (const std::exception
&e
)
5816 handle
->ERROR_MESSAGE("%s", e
.what());
5820 handle
->ERROR_MESSAGE("Unknown exception thrown");
5827 GEOSPreparedCrosses_r(GEOSContextHandle_t extHandle
,
5828 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5833 if ( 0 == extHandle
)
5838 GEOSContextHandleInternal_t
*handle
= 0;
5839 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5840 if ( 0 == handle
->initialized
)
5847 bool result
= pg
->crosses(g
);
5850 catch (const std::exception
&e
)
5852 handle
->ERROR_MESSAGE("%s", e
.what());
5856 handle
->ERROR_MESSAGE("Unknown exception thrown");
5863 GEOSPreparedDisjoint_r(GEOSContextHandle_t extHandle
,
5864 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5869 if ( 0 == extHandle
)
5874 GEOSContextHandleInternal_t
*handle
= 0;
5875 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5876 if ( 0 == handle
->initialized
)
5883 bool result
= pg
->disjoint(g
);
5886 catch (const std::exception
&e
)
5888 handle
->ERROR_MESSAGE("%s", e
.what());
5892 handle
->ERROR_MESSAGE("Unknown exception thrown");
5899 GEOSPreparedIntersects_r(GEOSContextHandle_t extHandle
,
5900 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5905 if ( 0 == extHandle
)
5910 GEOSContextHandleInternal_t
*handle
= 0;
5911 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5912 if ( 0 == handle
->initialized
)
5919 bool result
= pg
->intersects(g
);
5922 catch (const std::exception
&e
)
5924 handle
->ERROR_MESSAGE("%s", e
.what());
5928 handle
->ERROR_MESSAGE("Unknown exception thrown");
5935 GEOSPreparedOverlaps_r(GEOSContextHandle_t extHandle
,
5936 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5941 if ( 0 == extHandle
)
5946 GEOSContextHandleInternal_t
*handle
= 0;
5947 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5948 if ( 0 == handle
->initialized
)
5955 bool result
= pg
->overlaps(g
);
5958 catch (const std::exception
&e
)
5960 handle
->ERROR_MESSAGE("%s", e
.what());
5964 handle
->ERROR_MESSAGE("Unknown exception thrown");
5971 GEOSPreparedTouches_r(GEOSContextHandle_t extHandle
,
5972 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5977 if ( 0 == extHandle
)
5982 GEOSContextHandleInternal_t
*handle
= 0;
5983 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5984 if ( 0 == handle
->initialized
)
5991 bool result
= pg
->touches(g
);
5994 catch (const std::exception
&e
)
5996 handle
->ERROR_MESSAGE("%s", e
.what());
6000 handle
->ERROR_MESSAGE("Unknown exception thrown");
6007 GEOSPreparedWithin_r(GEOSContextHandle_t extHandle
,
6008 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
6013 if ( 0 == extHandle
)
6018 GEOSContextHandleInternal_t
*handle
= 0;
6019 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6020 if ( 0 == handle
->initialized
)
6027 bool result
= pg
->within(g
);
6030 catch (const std::exception
&e
)
6032 handle
->ERROR_MESSAGE("%s", e
.what());
6036 handle
->ERROR_MESSAGE("Unknown exception thrown");
6042 //-----------------------------------------------------------------
6044 //-----------------------------------------------------------------
6046 geos::index::strtree::STRtree
*
6047 GEOSSTRtree_create_r(GEOSContextHandle_t extHandle
,
6048 size_t nodeCapacity
)
6050 if ( 0 == extHandle
)
6055 GEOSContextHandleInternal_t
*handle
= 0;
6056 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6057 if ( 0 == handle
->initialized
)
6062 geos::index::strtree::STRtree
*tree
= 0;
6066 tree
= new geos::index::strtree::STRtree(nodeCapacity
);
6068 catch (const std::exception
&e
)
6070 handle
->ERROR_MESSAGE("%s", e
.what());
6074 handle
->ERROR_MESSAGE("Unknown exception thrown");
6081 GEOSSTRtree_insert_r(GEOSContextHandle_t extHandle
,
6082 geos::index::strtree::STRtree
*tree
,
6083 const geos::geom::Geometry
*g
,
6086 GEOSContextHandleInternal_t
*handle
= 0;
6092 tree
->insert(g
->getEnvelopeInternal(), item
);
6094 catch (const std::exception
&e
)
6096 if ( 0 == extHandle
)
6101 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6102 if ( 0 == handle
->initialized
)
6107 handle
->ERROR_MESSAGE("%s", e
.what());
6111 if ( 0 == extHandle
)
6116 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6117 if ( 0 == handle
->initialized
)
6122 handle
->ERROR_MESSAGE("Unknown exception thrown");
6127 GEOSSTRtree_query_r(GEOSContextHandle_t extHandle
,
6128 geos::index::strtree::STRtree
*tree
,
6129 const geos::geom::Geometry
*g
,
6130 GEOSQueryCallback callback
,
6133 GEOSContextHandleInternal_t
*handle
= 0;
6136 assert(callback
!= 0);
6140 CAPI_ItemVisitor
visitor(callback
, userdata
);
6141 tree
->query(g
->getEnvelopeInternal(), visitor
);
6143 catch (const std::exception
&e
)
6145 if ( 0 == extHandle
)
6150 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6151 if ( 0 == handle
->initialized
)
6156 handle
->ERROR_MESSAGE("%s", e
.what());
6160 if ( 0 == extHandle
)
6165 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6166 if ( 0 == handle
->initialized
)
6171 handle
->ERROR_MESSAGE("Unknown exception thrown");
6175 const GEOSGeometry
*
6176 GEOSSTRtree_nearest_r(GEOSContextHandle_t extHandle
,
6177 geos::index::strtree::STRtree
*tree
,
6178 const geos::geom::Geometry
* geom
)
6180 return (const GEOSGeometry
*) GEOSSTRtree_nearest_generic_r( extHandle
, tree
, geom
, geom
->getEnvelope(), NULL
, NULL
);
6184 GEOSSTRtree_nearest_generic_r(GEOSContextHandle_t extHandle
,
6185 geos::index::strtree::STRtree
*tree
,
6187 const geos::geom::Geometry
* itemEnvelope
,
6188 GEOSDistanceCallback distancefn
,
6191 using namespace geos::index::strtree
;
6193 GEOSContextHandleInternal_t
*handle
= 0;
6195 struct CustomItemDistance
: public ItemDistance
{
6196 CustomItemDistance(GEOSDistanceCallback p_distancefn
, void* p_userdata
)
6197 : m_distancefn(p_distancefn
), m_userdata(p_userdata
) {}
6199 GEOSDistanceCallback m_distancefn
;
6202 double distance(const ItemBoundable
* item1
, const ItemBoundable
* item2
) {
6203 const void* a
= item1
->getItem();
6204 const void* b
= item2
->getItem();
6207 if (!m_distancefn(a
, b
, &d
, m_userdata
)) {
6208 throw std::runtime_error(std::string("Failed to compute distance."));
6218 CustomItemDistance
itemDistance(distancefn
, userdata
);
6219 return tree
->nearestNeighbour(itemEnvelope
->getEnvelopeInternal(), item
, &itemDistance
);
6221 GeometryItemDistance itemDistance
= GeometryItemDistance();
6222 return tree
->nearestNeighbour(itemEnvelope
->getEnvelopeInternal(), item
, &itemDistance
);
6225 catch (const std::exception
&e
)
6227 if ( 0 == extHandle
)
6232 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6233 if ( 0 == handle
->initialized
)
6238 handle
->ERROR_MESSAGE("%s", e
.what());
6242 if ( 0 == extHandle
)
6247 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6248 if ( 0 == handle
->initialized
)
6253 handle
->ERROR_MESSAGE("Unknown exception thrown");
6260 GEOSSTRtree_iterate_r(GEOSContextHandle_t extHandle
,
6261 geos::index::strtree::STRtree
*tree
,
6262 GEOSQueryCallback callback
,
6265 GEOSContextHandleInternal_t
*handle
= 0;
6267 assert(callback
!= 0);
6271 CAPI_ItemVisitor
visitor(callback
, userdata
);
6272 tree
->iterate(visitor
);
6274 catch (const std::exception
&e
)
6276 if ( 0 == extHandle
)
6281 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6282 if ( 0 == handle
->initialized
)
6287 handle
->ERROR_MESSAGE("%s", e
.what());
6291 if ( 0 == extHandle
)
6296 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6297 if ( 0 == handle
->initialized
)
6302 handle
->ERROR_MESSAGE("Unknown exception thrown");
6307 GEOSSTRtree_remove_r(GEOSContextHandle_t extHandle
,
6308 geos::index::strtree::STRtree
*tree
,
6309 const geos::geom::Geometry
*g
,
6315 if ( 0 == extHandle
)
6320 GEOSContextHandleInternal_t
*handle
= 0;
6321 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6322 if ( 0 == handle
->initialized
)
6329 bool result
= tree
->remove(g
->getEnvelopeInternal(), item
);
6332 catch (const std::exception
&e
)
6334 handle
->ERROR_MESSAGE("%s", e
.what());
6338 handle
->ERROR_MESSAGE("Unknown exception thrown");
6345 GEOSSTRtree_destroy_r(GEOSContextHandle_t extHandle
,
6346 geos::index::strtree::STRtree
*tree
)
6348 GEOSContextHandleInternal_t
*handle
= 0;
6354 catch (const std::exception
&e
)
6356 if ( 0 == extHandle
)
6361 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6362 if ( 0 == handle
->initialized
)
6367 handle
->ERROR_MESSAGE("%s", e
.what());
6371 if ( 0 == extHandle
)
6376 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6377 if ( 0 == handle
->initialized
)
6382 handle
->ERROR_MESSAGE("Unknown exception thrown");
6387 GEOSProject_r(GEOSContextHandle_t extHandle
,
6391 if ( 0 == extHandle
) return -1.0;
6392 GEOSContextHandleInternal_t
*handle
=
6393 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6394 if ( handle
->initialized
== 0 ) return -1.0;
6396 const geos::geom::Point
* point
= dynamic_cast<const geos::geom::Point
*>(p
);
6398 handle
->ERROR_MESSAGE("third argument of GEOSProject_r must be Point*");
6402 const geos::geom::Coordinate
* inputPt
= p
->getCoordinate();
6405 return geos::linearref::LengthIndexedLine(g
).project(*inputPt
);
6406 } catch (const std::exception
&e
) {
6407 handle
->ERROR_MESSAGE("%s", e
.what());
6410 handle
->ERROR_MESSAGE("Unknown exception thrown");
6417 GEOSInterpolate_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double d
)
6419 if ( 0 == extHandle
) return 0;
6420 GEOSContextHandleInternal_t
*handle
=
6421 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6422 if ( handle
->initialized
== 0 ) return 0;
6425 geos::linearref::LengthIndexedLine
lil(g
);
6426 geos::geom::Coordinate coord
= lil
.extractPoint(d
);
6427 const GeometryFactory
*gf
= handle
->geomFactory
;
6428 Geometry
* point
= gf
->createPoint(coord
);
6430 } catch (const std::exception
&e
) {
6431 handle
->ERROR_MESSAGE("%s", e
.what());
6434 handle
->ERROR_MESSAGE("Unknown exception thrown");
6441 GEOSProjectNormalized_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
6446 GEOSLength_r(extHandle
, g
, &length
);
6447 return GEOSProject_r(extHandle
, g
, p
) / length
;
6452 GEOSInterpolateNormalized_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
6456 GEOSLength_r(extHandle
, g
, &length
);
6457 return GEOSInterpolate_r(extHandle
, g
, d
* length
);
6461 GEOSGeom_extractUniquePoints_r(GEOSContextHandle_t extHandle
,
6462 const GEOSGeometry
* g
)
6464 if ( 0 == extHandle
) return 0;
6465 GEOSContextHandleInternal_t
*handle
= 0;
6466 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6467 if ( handle
->initialized
== 0 ) return 0;
6469 using namespace geos::geom
;
6470 using namespace geos::util
;
6475 /* 1: extract points */
6476 std::vector
<const Coordinate
*> coords
;
6477 UniqueCoordinateArrayFilter
filter(coords
);
6478 g
->apply_ro(&filter
);
6480 /* 2: for each point, create a geometry and put into a vector */
6481 std::vector
<Geometry
*>* points
= new std::vector
<Geometry
*>();
6482 points
->reserve(coords
.size());
6483 const GeometryFactory
* factory
= g
->getFactory();
6484 for (std::vector
<const Coordinate
*>::iterator it
=coords
.begin(),
6488 Geometry
* point
= factory
->createPoint(*(*it
));
6489 points
->push_back(point
);
6492 /* 3: create a multipoint */
6493 return factory
->createMultiPoint(points
);
6496 catch (const std::exception
&e
)
6498 handle
->ERROR_MESSAGE("%s", e
.what());
6503 handle
->ERROR_MESSAGE("Unknown exception thrown");
6508 int GEOSOrientationIndex_r(GEOSContextHandle_t extHandle
,
6509 double Ax
, double Ay
, double Bx
, double By
, double Px
, double Py
)
6511 GEOSContextHandleInternal_t
*handle
= 0;
6513 using geos::geom::Coordinate
;
6514 using geos::algorithm::CGAlgorithms
;
6516 if ( 0 == extHandle
)
6521 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6522 if ( 0 == handle
->initialized
)
6529 Coordinate
A(Ax
, Ay
);
6530 Coordinate
B(Bx
, By
);
6531 Coordinate
P(Px
, Py
);
6532 return CGAlgorithms::orientationIndex(A
, B
, P
);
6534 catch (const std::exception
&e
)
6536 handle
->ERROR_MESSAGE("%s", e
.what());
6541 handle
->ERROR_MESSAGE("Unknown exception thrown");
6547 GEOSSharedPaths_r(GEOSContextHandle_t extHandle
, const GEOSGeometry
* g1
, const GEOSGeometry
* g2
)
6549 using namespace geos::operation::sharedpaths
;
6551 if ( 0 == extHandle
) return 0;
6552 GEOSContextHandleInternal_t
*handle
=
6553 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6554 if ( handle
->initialized
== 0 ) return 0;
6556 SharedPathsOp::PathList forw
, back
;
6558 SharedPathsOp::sharedPathsOp(*g1
, *g2
, forw
, back
);
6560 catch (const std::exception
&e
)
6562 SharedPathsOp::clearEdges(forw
);
6563 SharedPathsOp::clearEdges(back
);
6564 handle
->ERROR_MESSAGE("%s", e
.what());
6569 SharedPathsOp::clearEdges(forw
);
6570 SharedPathsOp::clearEdges(back
);
6571 handle
->ERROR_MESSAGE("Unknown exception thrown");
6575 // Now forw and back have the geoms we want to use to construct
6576 // our output GeometryCollections...
6578 const GeometryFactory
* factory
= g1
->getFactory();
6581 std::auto_ptr
< std::vector
<Geometry
*> > out1(
6582 new std::vector
<Geometry
*>()
6584 count
= forw
.size();
6585 out1
->reserve(count
);
6586 for (size_t i
=0; i
<count
; ++i
) {
6587 out1
->push_back(forw
[i
]);
6589 std::auto_ptr
<Geometry
> out1g (
6590 factory
->createMultiLineString(out1
.release())
6593 std::auto_ptr
< std::vector
<Geometry
*> > out2(
6594 new std::vector
<Geometry
*>()
6596 count
= back
.size();
6597 out2
->reserve(count
);
6598 for (size_t i
=0; i
<count
; ++i
) {
6599 out2
->push_back(back
[i
]);
6601 std::auto_ptr
<Geometry
> out2g (
6602 factory
->createMultiLineString(out2
.release())
6605 std::auto_ptr
< std::vector
<Geometry
*> > out(
6606 new std::vector
<Geometry
*>()
6609 out
->push_back(out1g
.release());
6610 out
->push_back(out2g
.release());
6612 std::auto_ptr
<Geometry
> outg (
6613 factory
->createGeometryCollection(out
.release())
6616 return outg
.release();
6621 GEOSSnap_r(GEOSContextHandle_t extHandle
, const GEOSGeometry
* g1
,
6622 const GEOSGeometry
* g2
, double tolerance
)
6624 using namespace geos::operation::overlay::snap
;
6626 if ( 0 == extHandle
) return 0;
6627 GEOSContextHandleInternal_t
*handle
=
6628 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6629 if ( handle
->initialized
== 0 ) return 0;
6632 GeometrySnapper
snapper( *g1
);
6633 std::auto_ptr
<Geometry
> ret
= snapper
.snapTo(*g2
, tolerance
);
6634 return ret
.release();
6636 catch (const std::exception
&e
)
6638 handle
->ERROR_MESSAGE("%s", e
.what());
6643 handle
->ERROR_MESSAGE("Unknown exception thrown");
6649 GEOSBufferParams_create_r(GEOSContextHandle_t extHandle
)
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
;
6659 BufferParameters
*p
= new BufferParameters();
6662 catch (const std::exception
&e
)
6664 handle
->ERROR_MESSAGE("%s", e
.what());
6668 handle
->ERROR_MESSAGE("Unknown exception thrown");
6675 GEOSBufferParams_destroy_r(GEOSContextHandle_t extHandle
, BufferParameters
* p
)
6682 GEOSBufferParams_setEndCapStyle_r(GEOSContextHandle_t extHandle
,
6683 GEOSBufferParams
* p
, int style
)
6685 if ( 0 == extHandle
) return 0;
6687 GEOSContextHandleInternal_t
*handle
= 0;
6688 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6689 if ( 0 == handle
->initialized
) return 0;
6693 if ( style
> BufferParameters::CAP_SQUARE
)
6695 throw IllegalArgumentException("Invalid buffer endCap style");
6697 p
->setEndCapStyle(static_cast<BufferParameters::EndCapStyle
>(style
));
6700 catch (const std::exception
&e
)
6702 handle
->ERROR_MESSAGE("%s", e
.what());
6706 handle
->ERROR_MESSAGE("Unknown exception thrown");
6713 GEOSBufferParams_setJoinStyle_r(GEOSContextHandle_t extHandle
,
6714 GEOSBufferParams
* p
, int style
)
6716 if ( 0 == extHandle
) return 0;
6718 GEOSContextHandleInternal_t
*handle
= 0;
6719 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6720 if ( 0 == handle
->initialized
) return 0;
6724 if ( style
> BufferParameters::JOIN_BEVEL
) {
6725 throw IllegalArgumentException("Invalid buffer join style");
6727 p
->setJoinStyle(static_cast<BufferParameters::JoinStyle
>(style
));
6730 catch (const std::exception
&e
)
6732 handle
->ERROR_MESSAGE("%s", e
.what());
6736 handle
->ERROR_MESSAGE("Unknown exception thrown");
6743 GEOSBufferParams_setMitreLimit_r(GEOSContextHandle_t extHandle
,
6744 GEOSBufferParams
* p
, double limit
)
6746 if ( 0 == extHandle
) return 0;
6748 GEOSContextHandleInternal_t
*handle
= 0;
6749 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6750 if ( 0 == handle
->initialized
) return 0;
6754 p
->setMitreLimit(limit
);
6757 catch (const std::exception
&e
)
6759 handle
->ERROR_MESSAGE("%s", e
.what());
6763 handle
->ERROR_MESSAGE("Unknown exception thrown");
6770 GEOSBufferParams_setQuadrantSegments_r(GEOSContextHandle_t extHandle
,
6771 GEOSBufferParams
* p
, int segs
)
6773 if ( 0 == extHandle
) return 0;
6775 GEOSContextHandleInternal_t
*handle
= 0;
6776 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6777 if ( 0 == handle
->initialized
) return 0;
6781 p
->setQuadrantSegments(segs
);
6784 catch (const std::exception
&e
)
6786 handle
->ERROR_MESSAGE("%s", e
.what());
6790 handle
->ERROR_MESSAGE("Unknown exception thrown");
6797 GEOSBufferParams_setSingleSided_r(GEOSContextHandle_t extHandle
,
6798 GEOSBufferParams
* p
, int ss
)
6800 if ( 0 == extHandle
) return 0;
6802 GEOSContextHandleInternal_t
*handle
= 0;
6803 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6804 if ( 0 == handle
->initialized
) return 0;
6808 p
->setSingleSided( (ss
!= 0) );
6811 catch (const std::exception
&e
)
6813 handle
->ERROR_MESSAGE("%s", e
.what());
6817 handle
->ERROR_MESSAGE("Unknown exception thrown");
6824 GEOSBufferWithParams_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const BufferParameters
* bp
, double width
)
6826 using geos::operation::buffer::BufferOp
;
6828 if ( 0 == extHandle
) return NULL
;
6830 GEOSContextHandleInternal_t
*handle
= 0;
6831 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6832 if ( 0 == handle
->initialized
) return NULL
;
6836 BufferOp
op(g1
, *bp
);
6837 Geometry
*g3
= op
.getResultGeometry(width
);
6840 catch (const std::exception
&e
)
6842 handle
->ERROR_MESSAGE("%s", e
.what());
6846 handle
->ERROR_MESSAGE("Unknown exception thrown");
6853 GEOSDelaunayTriangulation_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double tolerance
, int onlyEdges
)
6855 if ( 0 == extHandle
) return NULL
;
6857 GEOSContextHandleInternal_t
*handle
= 0;
6858 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6859 if ( 0 == handle
->initialized
) return NULL
;
6861 using geos::triangulate::DelaunayTriangulationBuilder
;
6865 DelaunayTriangulationBuilder builder
;
6866 builder
.setTolerance(tolerance
);
6867 builder
.setSites(*g1
);
6869 if ( onlyEdges
) return builder
.getEdges( *g1
->getFactory() ).release();
6870 else return builder
.getTriangles( *g1
->getFactory() ).release();
6873 catch (const std::exception
&e
)
6875 handle
->ERROR_MESSAGE("%s", e
.what());
6879 handle
->ERROR_MESSAGE("Unknown exception thrown");
6885 GEOSVoronoiDiagram_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*env
, double tolerance
,int onlyEdges
)
6887 if ( 0 == extHandle
) return NULL
;
6889 GEOSContextHandleInternal_t
*handle
= 0;
6890 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6891 if ( 0 == handle
->initialized
) return NULL
;
6893 using geos::triangulate::VoronoiDiagramBuilder
;
6897 VoronoiDiagramBuilder builder
;
6898 builder
.setSites(*g1
);
6899 builder
.setTolerance(tolerance
);
6900 if(env
) builder
.setClipEnvelope(env
->getEnvelopeInternal());
6901 if(onlyEdges
) return builder
.getDiagramEdges(*g1
->getFactory()).release();
6902 else return builder
.getDiagram(*g1
->getFactory()).release();
6904 catch(const std::exception
&e
)
6906 handle
->ERROR_MESSAGE("%s", e
.what());
6910 handle
->ERROR_MESSAGE("Unknow exception thrown");