1 /************************************************************************
4 * C-Wrapper for GEOS library
6 * Copyright (C) 2010-2012 Sandro Santilli <strk@keybit.net>
7 * Copyright (C) 2005-2006 Refractions Research Inc.
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
14 * Author: Sandro Santilli <strk@keybit.net>
15 * Thread Safety modifications: Chuck Thibert <charles.thibert@ingres.com>
17 ***********************************************************************/
19 #include <geos/platform.h> // for FINITE
20 #include <geos/geom/Geometry.h>
21 #include <geos/geom/prep/PreparedGeometry.h>
22 #include <geos/geom/prep/PreparedGeometryFactory.h>
23 #include <geos/geom/GeometryCollection.h>
24 #include <geos/geom/Polygon.h>
25 #include <geos/geom/Point.h>
26 #include <geos/geom/MultiPoint.h>
27 #include <geos/geom/MultiLineString.h>
28 #include <geos/geom/MultiPolygon.h>
29 #include <geos/geom/LinearRing.h>
30 #include <geos/geom/LineString.h>
31 #include <geos/geom/PrecisionModel.h>
32 #include <geos/geom/GeometryFactory.h>
33 #include <geos/geom/CoordinateSequenceFactory.h>
34 #include <geos/geom/Coordinate.h>
35 #include <geos/geom/IntersectionMatrix.h>
36 #include <geos/geom/Envelope.h>
37 #include <geos/index/strtree/STRtree.h>
38 #include <geos/index/ItemVisitor.h>
39 #include <geos/io/WKTReader.h>
40 #include <geos/io/WKBReader.h>
41 #include <geos/io/WKTWriter.h>
42 #include <geos/io/WKBWriter.h>
43 #include <geos/algorithm/distance/DiscreteHausdorffDistance.h>
44 #include <geos/algorithm/CGAlgorithms.h>
45 #include <geos/algorithm/BoundaryNodeRule.h>
46 #include <geos/simplify/DouglasPeuckerSimplifier.h>
47 #include <geos/simplify/TopologyPreservingSimplifier.h>
48 #include <geos/noding/GeometryNoder.h>
49 #include <geos/operation/valid/IsValidOp.h>
50 #include <geos/operation/polygonize/Polygonizer.h>
51 #include <geos/operation/linemerge/LineMerger.h>
52 #include <geos/operation/overlay/OverlayOp.h>
53 #include <geos/operation/overlay/snap/GeometrySnapper.h>
54 #include <geos/operation/union/CascadedPolygonUnion.h>
55 #include <geos/operation/buffer/BufferOp.h>
56 #include <geos/operation/buffer/BufferParameters.h>
57 #include <geos/operation/buffer/BufferBuilder.h>
58 #include <geos/operation/relate/RelateOp.h>
59 #include <geos/operation/sharedpaths/SharedPathsOp.h>
60 #include <geos/linearref/LengthIndexedLine.h>
61 #include <geos/triangulate/DelaunayTriangulationBuilder.h>
62 #include <geos/util/IllegalArgumentException.h>
63 #include <geos/util/Interrupt.h>
64 #include <geos/util/UniqueCoordinateArrayFilter.h>
65 #include <geos/util/Machine.h>
66 #include <geos/version.h>
68 // This should go away
69 #include <cmath> // finite
81 #pragma warning(disable : 4099)
84 // Some extra magic to make type declarations in geos_c.h work -
85 // for cross-checking of types in header.
86 #define GEOSGeometry geos::geom::Geometry
87 #define GEOSPreparedGeometry geos::geom::prep::PreparedGeometry
88 #define GEOSCoordSequence geos::geom::CoordinateSequence
89 #define GEOSBufferParams geos::operation::buffer::BufferParameters
90 #define GEOSSTRtree geos::index::strtree::STRtree
91 #define GEOSWKTReader_t geos::io::WKTReader
92 #define GEOSWKTWriter_t geos::io::WKTWriter
93 #define GEOSWKBReader_t geos::io::WKBReader
94 #define GEOSWKBWriter_t geos::io::WKBWriter
97 #include "../geos_svn_revision.h"
99 // Intentional, to allow non-standard C elements like C99 functions to be
100 // imported through C++ headers of C library, like <cmath>.
103 /// Define this if you want operations triggering Exceptions to
105 /// (will use the NOTIFY channel - only implemented for GEOSUnion so far)
107 #undef VERBOSE_EXCEPTIONS
109 #include <geos/export.h>
112 // import the most frequently used definitions globally
113 using geos::geom::Geometry
;
114 using geos::geom::LineString
;
115 using geos::geom::Polygon
;
116 using geos::geom::CoordinateSequence
;
117 using geos::geom::GeometryFactory
;
119 using geos::io::WKTReader
;
120 using geos::io::WKTWriter
;
121 using geos::io::WKBReader
;
122 using geos::io::WKBWriter
;
124 using geos::operation::overlay::OverlayOp
;
125 using geos::operation::overlay::overlayOp
;
126 using geos::operation::geounion::CascadedPolygonUnion
;
127 using geos::operation::buffer::BufferParameters
;
128 using geos::operation::buffer::BufferBuilder
;
129 using geos::util::IllegalArgumentException
;
130 using geos::algorithm::distance::DiscreteHausdorffDistance
;
132 typedef std::auto_ptr
<Geometry
> GeomAutoPtr
;
134 typedef struct GEOSContextHandleInternal
136 const GeometryFactory
*geomFactory
;
137 GEOSMessageHandler NOTICE_MESSAGE
;
138 GEOSMessageHandler ERROR_MESSAGE
;
142 } GEOSContextHandleInternal_t
;
144 // CAPI_ItemVisitor is used internally by the CAPI STRtree
145 // wrappers. It's defined here just to keep it out of the
147 class CAPI_ItemVisitor
: public geos::index::ItemVisitor
{
148 GEOSQueryCallback callback
;
151 CAPI_ItemVisitor (GEOSQueryCallback cb
, void *ud
)
152 : ItemVisitor(), callback(cb
), userdata(ud
) {}
153 void visitItem (void *item
) { callback(item
, userdata
); }
157 //## PROTOTYPES #############################################
159 extern "C" const char GEOS_DLL
*GEOSjtsport();
160 extern "C" char GEOS_DLL
*GEOSasText(Geometry
*g1
);
163 namespace { // anonymous
165 char* gstrdup_s(const char* str
, const std::size_t size
)
167 char* out
= static_cast<char*>(malloc(size
+ 1));
170 // as no strlen call necessary, memcpy may be faster than strcpy
171 std::memcpy(out
, str
, size
+ 1);
176 // we haven't been checking allocation before ticket #371
179 throw(std::runtime_error("Failed to allocate memory for duplicate string"));
185 char* gstrdup(std::string
const& str
)
187 return gstrdup_s(str
.c_str(), str
.size());
190 } // namespace anonymous
195 initGEOS_r(GEOSMessageHandler nf
, GEOSMessageHandler ef
)
197 GEOSContextHandleInternal_t
*handle
= 0;
200 extHandle
= malloc(sizeof(GEOSContextHandleInternal_t
));
203 handle
= static_cast<GEOSContextHandleInternal_t
*>(extHandle
);
204 handle
->NOTICE_MESSAGE
= nf
;
205 handle
->ERROR_MESSAGE
= ef
;
206 handle
->geomFactory
= GeometryFactory::getDefaultInstance();
207 handle
->WKBOutputDims
= 2;
208 handle
->WKBByteOrder
= getMachineByteOrder();
209 handle
->initialized
= 1;
212 geos::util::Interrupt::cancel();
214 return static_cast<GEOSContextHandle_t
>(extHandle
);
218 GEOSContext_setNoticeHandler_r(GEOSContextHandle_t extHandle
, GEOSMessageHandler nf
)
220 GEOSMessageHandler f
;
221 GEOSContextHandleInternal_t
*handle
= 0;
222 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
223 if ( 0 == handle
->initialized
)
228 f
= handle
->NOTICE_MESSAGE
;
229 handle
->NOTICE_MESSAGE
= nf
;
235 GEOSContext_setErrorHandler_r(GEOSContextHandle_t extHandle
, GEOSMessageHandler nf
)
237 GEOSMessageHandler f
;
238 GEOSContextHandleInternal_t
*handle
= 0;
239 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
240 if ( 0 == handle
->initialized
)
245 f
= handle
->ERROR_MESSAGE
;
246 handle
->ERROR_MESSAGE
= nf
;
252 finishGEOS_r(GEOSContextHandle_t extHandle
)
254 // Fix up freeing handle w.r.t. malloc above
260 GEOSFree_r (GEOSContextHandle_t extHandle
, void* buffer
)
262 assert(0 != extHandle
);
267 //-----------------------------------------------------------
268 // relate()-related functions
269 // return 0 = false, 1 = true, 2 = error occured
270 //-----------------------------------------------------------
273 GEOSDisjoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
275 if ( 0 == extHandle
)
280 GEOSContextHandleInternal_t
*handle
= 0;
281 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
282 if ( handle
->initialized
== 0 )
289 bool result
= g1
->disjoint(g2
);
293 // TODO: mloskot is going to replace these double-catch block
294 // with a macro to remove redundant code in this and
295 // following functions.
296 catch (const std::exception
&e
)
298 handle
->ERROR_MESSAGE("%s", e
.what());
302 handle
->ERROR_MESSAGE("Unknown exception thrown");
309 GEOSTouches_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
311 if ( 0 == extHandle
)
316 GEOSContextHandleInternal_t
*handle
= 0;
317 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
318 if ( 0 == handle
->initialized
)
325 bool result
= g1
->touches(g2
);
328 catch (const std::exception
&e
)
330 handle
->ERROR_MESSAGE("%s", e
.what());
334 handle
->ERROR_MESSAGE("Unknown exception thrown");
341 GEOSIntersects_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
343 if ( 0 == extHandle
)
348 GEOSContextHandleInternal_t
*handle
= 0;
349 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
350 if ( 0 == handle
->initialized
)
357 bool result
= g1
->intersects(g2
);
360 catch (const std::exception
&e
)
362 handle
->ERROR_MESSAGE("%s", e
.what());
366 handle
->ERROR_MESSAGE("Unknown exception thrown");
373 GEOSCrosses_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
375 if ( 0 == extHandle
)
380 GEOSContextHandleInternal_t
*handle
= 0;
381 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
382 if ( 0 == handle
->initialized
)
389 bool result
= g1
->crosses(g2
);
392 catch (const std::exception
&e
)
394 handle
->ERROR_MESSAGE("%s", e
.what());
398 handle
->ERROR_MESSAGE("Unknown exception thrown");
405 GEOSWithin_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
407 if ( 0 == extHandle
)
412 GEOSContextHandleInternal_t
*handle
= 0;
413 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
414 if ( 0 == handle
->initialized
)
421 bool result
= g1
->within(g2
);
424 catch (const std::exception
&e
)
426 handle
->ERROR_MESSAGE("%s", e
.what());
430 handle
->ERROR_MESSAGE("Unknown exception thrown");
436 // call g1->contains(g2)
439 // 2 = error was trapped
441 GEOSContains_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
443 if ( 0 == extHandle
)
448 GEOSContextHandleInternal_t
*handle
= 0;
449 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
450 if ( 0 == handle
->initialized
)
457 bool result
= g1
->contains(g2
);
460 catch (const std::exception
&e
)
462 handle
->ERROR_MESSAGE("%s", e
.what());
466 handle
->ERROR_MESSAGE("Unknown exception thrown");
473 GEOSOverlaps_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
475 if ( 0 == extHandle
)
480 GEOSContextHandleInternal_t
*handle
= 0;
481 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
482 if ( 0 == handle
->initialized
)
489 bool result
= g1
->overlaps(g2
);
492 catch (const std::exception
&e
)
494 handle
->ERROR_MESSAGE("%s", e
.what());
498 handle
->ERROR_MESSAGE("Unknown exception thrown");
505 GEOSCovers_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
507 if ( 0 == extHandle
)
512 GEOSContextHandleInternal_t
*handle
= 0;
513 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
514 if ( 0 == handle
->initialized
)
521 bool result
= g1
->covers(g2
);
524 catch (const std::exception
&e
)
526 handle
->ERROR_MESSAGE("%s", e
.what());
530 handle
->ERROR_MESSAGE("Unknown exception thrown");
537 GEOSCoveredBy_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
539 if ( 0 == extHandle
)
544 GEOSContextHandleInternal_t
*handle
= 0;
545 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
546 if ( 0 == handle
->initialized
)
553 bool result
= g1
->coveredBy(g2
);
556 catch (const std::exception
&e
)
558 handle
->ERROR_MESSAGE("%s", e
.what());
562 handle
->ERROR_MESSAGE("Unknown exception thrown");
569 //-------------------------------------------------------------------
570 // low-level relate functions
571 //------------------------------------------------------------------
574 GEOSRelatePattern_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, const char *pat
)
576 if ( 0 == extHandle
)
581 GEOSContextHandleInternal_t
*handle
= 0;
582 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
583 if ( 0 == handle
->initialized
)
591 bool result
= g1
->relate(g2
, s
);
594 catch (const std::exception
&e
)
596 handle
->ERROR_MESSAGE("%s", e
.what());
600 handle
->ERROR_MESSAGE("Unknown exception thrown");
607 GEOSRelatePatternMatch_r(GEOSContextHandle_t extHandle
, const char *mat
,
610 if ( 0 == extHandle
)
615 GEOSContextHandleInternal_t
*handle
= 0;
616 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
617 if ( 0 == handle
->initialized
)
624 using geos::geom::IntersectionMatrix
;
628 IntersectionMatrix
im(m
);
630 bool result
= im
.matches(p
);
633 catch (const std::exception
&e
)
635 handle
->ERROR_MESSAGE("%s", e
.what());
639 handle
->ERROR_MESSAGE("Unknown exception thrown");
646 GEOSRelate_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
648 if ( 0 == extHandle
)
653 GEOSContextHandleInternal_t
*handle
= 0;
654 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
655 if ( 0 == handle
->initialized
)
662 using geos::geom::IntersectionMatrix
;
664 IntersectionMatrix
* im
= g1
->relate(g2
);
670 char *result
= gstrdup(im
->toString());
677 catch (const std::exception
&e
)
679 handle
->ERROR_MESSAGE("%s", e
.what());
683 handle
->ERROR_MESSAGE("Unknown exception thrown");
690 GEOSRelateBoundaryNodeRule_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, int bnr
)
692 if ( 0 == extHandle
)
697 GEOSContextHandleInternal_t
*handle
= 0;
698 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
699 if ( 0 == handle
->initialized
)
706 using geos::operation::relate::RelateOp
;
707 using geos::geom::IntersectionMatrix
;
708 using geos::algorithm::BoundaryNodeRule
;
710 IntersectionMatrix
* im
;
712 case GEOSRELATE_BNR_MOD2
: /* same as OGC */
713 im
= RelateOp::relate(g1
, g2
,
714 BoundaryNodeRule::getBoundaryRuleMod2());
716 case GEOSRELATE_BNR_ENDPOINT
:
717 im
= RelateOp::relate(g1
, g2
,
718 BoundaryNodeRule::getBoundaryEndPoint());
720 case GEOSRELATE_BNR_MULTIVALENT_ENDPOINT
:
721 im
= RelateOp::relate(g1
, g2
,
722 BoundaryNodeRule::getBoundaryMultivalentEndPoint());
724 case GEOSRELATE_BNR_MONOVALENT_ENDPOINT
:
725 im
= RelateOp::relate(g1
, g2
,
726 BoundaryNodeRule::getBoundaryMonovalentEndPoint());
729 handle
->ERROR_MESSAGE("Invalid boundary node rule %d", bnr
);
734 if (0 == im
) return 0;
736 char *result
= gstrdup(im
->toString());
743 catch (const std::exception
&e
)
745 handle
->ERROR_MESSAGE("%s", e
.what());
749 handle
->ERROR_MESSAGE("Unknown exception thrown");
757 //-----------------------------------------------------------------
759 //-----------------------------------------------------------------
763 GEOSisValid_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
765 if ( 0 == extHandle
)
770 GEOSContextHandleInternal_t
*handle
= 0;
771 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
772 if ( 0 == handle
->initialized
)
779 using geos::operation::valid::IsValidOp
;
780 using geos::operation::valid::TopologyValidationError
;
783 TopologyValidationError
*err
= ivo
.getValidationError();
786 handle
->NOTICE_MESSAGE("%s", err
->toString().c_str());
794 catch (const std::exception
&e
)
796 handle
->ERROR_MESSAGE("%s", e
.what());
800 handle
->ERROR_MESSAGE("Unknown exception thrown");
807 GEOSisValidReason_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
809 if ( 0 == extHandle
)
814 GEOSContextHandleInternal_t
*handle
= 0;
815 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
816 if ( 0 == handle
->initialized
)
823 using geos::operation::valid::IsValidOp
;
824 using geos::operation::valid::TopologyValidationError
;
827 char const* const validstr
= "Valid Geometry";
830 TopologyValidationError
*err
= ivo
.getValidationError();
833 std::ostringstream ss
;
835 ss
<< err
->getCoordinate();
836 const std::string errloc
= ss
.str();
837 std::string
errmsg(err
->getMessage());
838 errmsg
+= "[" + errloc
+ "]";
839 result
= gstrdup(errmsg
);
843 result
= gstrdup(std::string(validstr
));
848 catch (const std::exception
&e
)
850 handle
->ERROR_MESSAGE("%s", e
.what());
854 handle
->ERROR_MESSAGE("Unknown exception thrown");
861 GEOSisValidDetail_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
862 int flags
, char** reason
, Geometry
** location
)
864 if ( 0 == extHandle
)
869 GEOSContextHandleInternal_t
*handle
= 0;
870 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
871 if ( 0 == handle
->initialized
)
878 using geos::operation::valid::IsValidOp
;
879 using geos::operation::valid::TopologyValidationError
;
882 if ( flags
& GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE
) {
883 ivo
.setSelfTouchingRingFormingHoleValid(true);
885 TopologyValidationError
*err
= ivo
.getValidationError();
889 *location
= handle
->geomFactory
->createPoint(err
->getCoordinate());
892 std::string
errmsg(err
->getMessage());
893 *reason
= gstrdup(errmsg
);
898 if ( location
) *location
= 0;
899 if ( reason
) *reason
= 0;
900 return 1; /* valid */
903 catch (const std::exception
&e
)
905 handle
->ERROR_MESSAGE("%s", e
.what());
909 handle
->ERROR_MESSAGE("Unknown exception thrown");
912 return 2; /* exception */
915 //-----------------------------------------------------------------
917 //-----------------------------------------------------------------
920 GEOSEquals_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
922 if ( 0 == extHandle
)
927 GEOSContextHandleInternal_t
*handle
= 0;
928 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
929 if ( 0 == handle
->initialized
)
936 bool result
= g1
->equals(g2
);
939 catch (const std::exception
&e
)
941 handle
->ERROR_MESSAGE("%s", e
.what());
945 handle
->ERROR_MESSAGE("Unknown exception thrown");
952 GEOSEqualsExact_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double tolerance
)
954 if ( 0 == extHandle
)
959 GEOSContextHandleInternal_t
*handle
= 0;
960 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
961 if ( 0 == handle
->initialized
)
968 bool result
= g1
->equalsExact(g2
, tolerance
);
971 catch (const std::exception
&e
)
973 handle
->ERROR_MESSAGE("%s", e
.what());
977 handle
->ERROR_MESSAGE("Unknown exception thrown");
984 GEOSDistance_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double *dist
)
988 if ( 0 == extHandle
)
993 GEOSContextHandleInternal_t
*handle
= 0;
994 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
995 if ( 0 == handle
->initialized
)
1002 *dist
= g1
->distance(g2
);
1005 catch (const std::exception
&e
)
1007 handle
->ERROR_MESSAGE("%s", e
.what());
1011 handle
->ERROR_MESSAGE("Unknown exception thrown");
1018 GEOSHausdorffDistance_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double *dist
)
1022 if ( 0 == extHandle
)
1027 GEOSContextHandleInternal_t
*handle
= 0;
1028 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1029 if ( 0 == handle
->initialized
)
1036 *dist
= DiscreteHausdorffDistance::distance(*g1
, *g2
);
1039 catch (const std::exception
&e
)
1041 handle
->ERROR_MESSAGE("%s", e
.what());
1045 handle
->ERROR_MESSAGE("Unknown exception thrown");
1052 GEOSHausdorffDistanceDensify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double densifyFrac
, double *dist
)
1056 if ( 0 == extHandle
)
1061 GEOSContextHandleInternal_t
*handle
= 0;
1062 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1063 if ( 0 == handle
->initialized
)
1070 *dist
= DiscreteHausdorffDistance::distance(*g1
, *g2
, densifyFrac
);
1073 catch (const std::exception
&e
)
1075 handle
->ERROR_MESSAGE("%s", e
.what());
1079 handle
->ERROR_MESSAGE("Unknown exception thrown");
1086 GEOSArea_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double *area
)
1090 if ( 0 == extHandle
)
1095 GEOSContextHandleInternal_t
*handle
= 0;
1096 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1097 if ( 0 == handle
->initialized
)
1104 *area
= g
->getArea();
1107 catch (const std::exception
&e
)
1109 handle
->ERROR_MESSAGE("%s", e
.what());
1113 handle
->ERROR_MESSAGE("Unknown exception thrown");
1120 GEOSLength_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double *length
)
1122 assert(0 != length
);
1124 if ( 0 == extHandle
)
1129 GEOSContextHandleInternal_t
*handle
= 0;
1130 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1131 if ( 0 == handle
->initialized
)
1138 *length
= g
->getLength();
1141 catch (const std::exception
&e
)
1143 handle
->ERROR_MESSAGE("%s", e
.what());
1147 handle
->ERROR_MESSAGE("Unknown exception thrown");
1154 GEOSGeomFromWKT_r(GEOSContextHandle_t extHandle
, const char *wkt
)
1156 if ( 0 == extHandle
)
1161 GEOSContextHandleInternal_t
*handle
= 0;
1162 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1163 if ( 0 == handle
->initialized
)
1170 const std::string
wktstring(wkt
);
1171 WKTReader
r(static_cast<GeometryFactory
const*>(handle
->geomFactory
));
1173 Geometry
*g
= r
.read(wktstring
);
1176 catch (const std::exception
&e
)
1178 handle
->ERROR_MESSAGE("%s", e
.what());
1182 handle
->ERROR_MESSAGE("Unknown exception thrown");
1189 GEOSGeomToWKT_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1191 if ( 0 == extHandle
)
1196 GEOSContextHandleInternal_t
*handle
= 0;
1197 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1198 if ( 0 == handle
->initialized
)
1206 char *result
= gstrdup(g1
->toString());
1209 catch (const std::exception
&e
)
1211 handle
->ERROR_MESSAGE("%s", e
.what());
1215 handle
->ERROR_MESSAGE("Unknown exception thrown");
1220 // Remember to free the result!
1222 GEOSGeomToWKB_buf_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, size_t *size
)
1226 if ( 0 == extHandle
)
1231 GEOSContextHandleInternal_t
*handle
= 0;
1232 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1233 if ( 0 == handle
->initialized
)
1238 using geos::io::WKBWriter
;
1241 int byteOrder
= handle
->WKBByteOrder
;
1242 WKBWriter
w(handle
->WKBOutputDims
, byteOrder
);
1243 std::ostringstream
os(std::ios_base::binary
);
1245 std::string
wkbstring(os
.str());
1246 const std::size_t len
= wkbstring
.length();
1248 unsigned char* result
= 0;
1249 result
= static_cast<unsigned char*>(malloc(len
));
1252 std::memcpy(result
, wkbstring
.c_str(), len
);
1257 catch (const std::exception
&e
)
1259 handle
->ERROR_MESSAGE("%s", e
.what());
1263 handle
->ERROR_MESSAGE("Unknown exception thrown");
1270 GEOSGeomFromWKB_buf_r(GEOSContextHandle_t extHandle
, const unsigned char *wkb
, size_t size
)
1272 if ( 0 == extHandle
)
1277 GEOSContextHandleInternal_t
*handle
= 0;
1278 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1279 if ( 0 == handle
->initialized
)
1284 using geos::io::WKBReader
;
1287 std::string
wkbstring(reinterpret_cast<const char*>(wkb
), size
); // make it binary !
1288 WKBReader
r(*(static_cast<GeometryFactory
const*>(handle
->geomFactory
)));
1289 std::istringstream
is(std::ios_base::binary
);
1291 is
.seekg(0, std::ios::beg
); // rewind reader pointer
1292 Geometry
*g
= r
.read(is
);
1295 catch (const std::exception
&e
)
1297 handle
->ERROR_MESSAGE("%s", e
.what());
1301 handle
->ERROR_MESSAGE("Unknown exception thrown");
1307 /* Read/write wkb hex values. Returned geometries are
1308 owned by the caller.*/
1310 GEOSGeomToHEX_buf_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, size_t *size
)
1312 if ( 0 == extHandle
)
1317 GEOSContextHandleInternal_t
*handle
= 0;
1318 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1319 if ( 0 == handle
->initialized
)
1324 using geos::io::WKBWriter
;
1327 int byteOrder
= handle
->WKBByteOrder
;
1328 WKBWriter
w(handle
->WKBOutputDims
, byteOrder
);
1329 std::ostringstream
os(std::ios_base::binary
);
1331 std::string
hexstring(os
.str());
1333 char *result
= gstrdup(hexstring
);
1336 *size
= hexstring
.length();
1339 return reinterpret_cast<unsigned char*>(result
);
1341 catch (const std::exception
&e
)
1343 handle
->ERROR_MESSAGE("%s", e
.what());
1347 handle
->ERROR_MESSAGE("Unknown exception thrown");
1354 GEOSGeomFromHEX_buf_r(GEOSContextHandle_t extHandle
, const unsigned char *hex
, size_t size
)
1356 if ( 0 == extHandle
)
1361 GEOSContextHandleInternal_t
*handle
= 0;
1362 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1363 if ( 0 == handle
->initialized
)
1368 using geos::io::WKBReader
;
1371 std::string
hexstring(reinterpret_cast<const char*>(hex
), size
);
1372 WKBReader
r(*(static_cast<GeometryFactory
const*>(handle
->geomFactory
)));
1373 std::istringstream
is(std::ios_base::binary
);
1375 is
.seekg(0, std::ios::beg
); // rewind reader pointer
1377 Geometry
*g
= r
.readHEX(is
);
1380 catch (const std::exception
&e
)
1382 handle
->ERROR_MESSAGE("%s", e
.what());
1386 handle
->ERROR_MESSAGE("Unknown exception thrown");
1393 GEOSisEmpty_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1395 if ( 0 == extHandle
)
1400 GEOSContextHandleInternal_t
*handle
= 0;
1401 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1402 if ( 0 == handle
->initialized
)
1409 return g1
->isEmpty();
1411 catch (const std::exception
&e
)
1413 handle
->ERROR_MESSAGE("%s", e
.what());
1417 handle
->ERROR_MESSAGE("Unknown exception thrown");
1424 GEOSisSimple_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1426 if ( 0 == extHandle
)
1431 GEOSContextHandleInternal_t
*handle
= 0;
1432 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1433 if ( 0 == handle
->initialized
)
1440 return g1
->isSimple();
1442 catch (const std::exception
&e
)
1444 handle
->ERROR_MESSAGE("%s", e
.what());
1450 handle
->ERROR_MESSAGE("Unknown exception thrown");
1456 GEOSisRing_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
1458 if ( 0 == extHandle
)
1463 GEOSContextHandleInternal_t
*handle
= 0;
1464 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1465 if ( 0 == handle
->initialized
)
1472 const LineString
*ls
= dynamic_cast<const LineString
*>(g
);
1474 return (ls
->isRing());
1479 catch (const std::exception
&e
)
1481 handle
->ERROR_MESSAGE("%s", e
.what());
1487 handle
->ERROR_MESSAGE("Unknown exception thrown");
1494 //free the result of this
1496 GEOSGeomType_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1498 if ( 0 == extHandle
)
1503 GEOSContextHandleInternal_t
*handle
= 0;
1504 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1505 if ( 0 == handle
->initialized
)
1512 std::string s
= g1
->getGeometryType();
1514 char *result
= gstrdup(s
);
1517 catch (const std::exception
&e
)
1519 handle
->ERROR_MESSAGE("%s", e
.what());
1523 handle
->ERROR_MESSAGE("Unknown exception thrown");
1529 // Return postgis geometry type index
1531 GEOSGeomTypeId_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1533 if ( 0 == extHandle
)
1538 GEOSContextHandleInternal_t
*handle
= 0;
1539 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1540 if ( 0 == handle
->initialized
)
1547 return g1
->getGeometryTypeId();
1549 catch (const std::exception
&e
)
1551 handle
->ERROR_MESSAGE("%s", e
.what());
1555 handle
->ERROR_MESSAGE("Unknown exception thrown");
1561 //-------------------------------------------------------------------
1562 // GEOS functions that return geometries
1563 //-------------------------------------------------------------------
1566 GEOSEnvelope_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1568 if ( 0 == extHandle
)
1573 GEOSContextHandleInternal_t
*handle
= 0;
1574 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1575 if ( 0 == handle
->initialized
)
1582 Geometry
*g3
= g1
->getEnvelope();
1585 catch (const std::exception
&e
)
1587 handle
->ERROR_MESSAGE("%s", e
.what());
1591 handle
->ERROR_MESSAGE("Unknown exception thrown");
1598 GEOSIntersection_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1600 if ( 0 == extHandle
)
1605 GEOSContextHandleInternal_t
*handle
= 0;
1606 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1607 if ( 0 == handle
->initialized
)
1614 return g1
->intersection(g2
);
1616 catch (const std::exception
&e
)
1618 handle
->ERROR_MESSAGE("%s", e
.what());
1622 handle
->ERROR_MESSAGE("Unknown exception thrown");
1629 GEOSBuffer_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadrantsegments
)
1631 if ( 0 == extHandle
)
1636 GEOSContextHandleInternal_t
*handle
= 0;
1637 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1638 if ( 0 == handle
->initialized
)
1645 Geometry
*g3
= g1
->buffer(width
, quadrantsegments
);
1648 catch (const std::exception
&e
)
1650 handle
->ERROR_MESSAGE("%s", e
.what());
1654 handle
->ERROR_MESSAGE("Unknown exception thrown");
1661 GEOSBufferWithStyle_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int endCapStyle
, int joinStyle
, double mitreLimit
)
1663 using geos::operation::buffer::BufferParameters
;
1664 using geos::operation::buffer::BufferOp
;
1665 using geos::util::IllegalArgumentException
;
1667 if ( 0 == extHandle
)
1672 GEOSContextHandleInternal_t
*handle
= 0;
1673 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1674 if ( 0 == handle
->initialized
)
1681 BufferParameters bp
;
1682 bp
.setQuadrantSegments(quadsegs
);
1684 if ( endCapStyle
> BufferParameters::CAP_SQUARE
)
1686 throw IllegalArgumentException("Invalid buffer endCap style");
1689 static_cast<BufferParameters::EndCapStyle
>(endCapStyle
)
1692 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1694 throw IllegalArgumentException("Invalid buffer join style");
1697 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1699 bp
.setMitreLimit(mitreLimit
);
1700 BufferOp
op(g1
, bp
);
1701 Geometry
*g3
= op
.getResultGeometry(width
);
1704 catch (const std::exception
&e
)
1706 handle
->ERROR_MESSAGE("%s", e
.what());
1710 handle
->ERROR_MESSAGE("Unknown exception thrown");
1717 GEOSOffsetCurve_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int joinStyle
, double mitreLimit
)
1719 if ( 0 == extHandle
) return NULL
;
1721 GEOSContextHandleInternal_t
*handle
= 0;
1722 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1723 if ( 0 == handle
->initialized
) return NULL
;
1727 BufferParameters bp
;
1728 bp
.setEndCapStyle( BufferParameters::CAP_FLAT
);
1729 bp
.setQuadrantSegments(quadsegs
);
1731 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1733 throw IllegalArgumentException("Invalid buffer join style");
1736 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1738 bp
.setMitreLimit(mitreLimit
);
1740 bool isLeftSide
= true;
1745 BufferBuilder
bufBuilder (bp
);
1746 Geometry
*g3
= bufBuilder
.bufferLineSingleSided(g1
, width
, isLeftSide
);
1750 catch (const std::exception
&e
)
1752 handle
->ERROR_MESSAGE("%s", e
.what());
1756 handle
->ERROR_MESSAGE("Unknown exception thrown");
1762 /* @deprecated in 3.3.0 */
1764 GEOSSingleSidedBuffer_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int joinStyle
, double mitreLimit
, int leftSide
)
1766 if ( 0 == extHandle
) return NULL
;
1768 GEOSContextHandleInternal_t
*handle
= 0;
1769 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1770 if ( 0 == handle
->initialized
) return NULL
;
1774 BufferParameters bp
;
1775 bp
.setEndCapStyle( BufferParameters::CAP_FLAT
);
1776 bp
.setQuadrantSegments(quadsegs
);
1778 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1780 throw IllegalArgumentException("Invalid buffer join style");
1783 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1785 bp
.setMitreLimit(mitreLimit
);
1787 bool isLeftSide
= leftSide
== 0 ? false : true;
1788 BufferBuilder
bufBuilder (bp
);
1789 Geometry
*g3
= bufBuilder
.bufferLineSingleSided(g1
, width
, isLeftSide
);
1793 catch (const std::exception
&e
)
1795 handle
->ERROR_MESSAGE("%s", e
.what());
1799 handle
->ERROR_MESSAGE("Unknown exception thrown");
1806 GEOSConvexHull_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1808 if ( 0 == extHandle
)
1813 GEOSContextHandleInternal_t
*handle
= 0;
1814 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1815 if ( 0 == handle
->initialized
)
1822 Geometry
*g3
= g1
->convexHull();
1825 catch (const std::exception
&e
)
1827 handle
->ERROR_MESSAGE("%s", e
.what());
1831 handle
->ERROR_MESSAGE("Unknown exception thrown");
1838 GEOSDifference_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1840 if ( 0 == extHandle
)
1845 GEOSContextHandleInternal_t
*handle
= 0;
1846 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1847 if ( 0 == handle
->initialized
)
1854 return g1
->difference(g2
);
1856 catch (const std::exception
&e
)
1858 handle
->ERROR_MESSAGE("%s", e
.what());
1862 handle
->ERROR_MESSAGE("Unknown exception thrown");
1869 GEOSBoundary_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1871 if ( 0 == extHandle
)
1876 GEOSContextHandleInternal_t
*handle
= 0;
1877 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1878 if ( 0 == handle
->initialized
)
1885 Geometry
*g3
= g1
->getBoundary();
1888 catch (const std::exception
&e
)
1890 handle
->ERROR_MESSAGE("%s", e
.what());
1894 handle
->ERROR_MESSAGE("Unknown exception thrown");
1901 GEOSSymDifference_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1903 if ( 0 == extHandle
)
1908 GEOSContextHandleInternal_t
*handle
= 0;
1909 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1910 if ( 0 == handle
->initialized
)
1917 return g1
->symDifference(g2
);
1919 catch (const std::exception
&e
)
1921 handle
->ERROR_MESSAGE("%s", e
.what());
1927 handle
->ERROR_MESSAGE("Unknown exception thrown");
1933 GEOSUnion_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1935 if ( 0 == extHandle
)
1940 GEOSContextHandleInternal_t
*handle
= 0;
1941 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1942 if ( 0 == handle
->initialized
)
1949 return g1
->Union(g2
);
1951 catch (const std::exception
&e
)
1953 #if VERBOSE_EXCEPTIONS
1954 std::ostringstream s
;
1955 s
<< "Exception on GEOSUnion with following inputs:" << std::endl
;
1956 s
<< "A: "<<g1
->toString() << std::endl
;
1957 s
<< "B: "<<g2
->toString() << std::endl
;
1958 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
1959 #endif // VERBOSE_EXCEPTIONS
1960 handle
->ERROR_MESSAGE("%s", e
.what());
1964 handle
->ERROR_MESSAGE("Unknown exception thrown");
1971 GEOSUnaryUnion_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
1973 if ( 0 == extHandle
)
1978 GEOSContextHandleInternal_t
*handle
= 0;
1979 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1980 if ( 0 == handle
->initialized
)
1987 GeomAutoPtr
g3 ( g
->Union() );
1988 return g3
.release();
1990 catch (const std::exception
&e
)
1992 #if VERBOSE_EXCEPTIONS
1993 std::ostringstream s
;
1994 s
<< "Exception on GEOSUnaryUnion with following inputs:" << std::endl
;
1995 s
<< "A: "<<g1
->toString() << std::endl
;
1996 s
<< "B: "<<g2
->toString() << std::endl
;
1997 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
1998 #endif // VERBOSE_EXCEPTIONS
1999 handle
->ERROR_MESSAGE("%s", e
.what());
2003 handle
->ERROR_MESSAGE("Unknown exception thrown");
2010 GEOSNode_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2012 if ( 0 == extHandle
)
2017 GEOSContextHandleInternal_t
*handle
= 0;
2018 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2019 if ( 0 == handle
->initialized
)
2026 std::auto_ptr
<Geometry
> g3
= geos::noding::GeometryNoder::node(*g
);
2027 return g3
.release();
2029 catch (const std::exception
&e
)
2031 #if VERBOSE_EXCEPTIONS
2032 std::ostringstream s
;
2033 s
<< "Exception on GEOSUnaryUnion with following inputs:" << std::endl
;
2034 s
<< "A: "<<g1
->toString() << std::endl
;
2035 s
<< "B: "<<g2
->toString() << std::endl
;
2036 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
2037 #endif // VERBOSE_EXCEPTIONS
2038 handle
->ERROR_MESSAGE("%s", e
.what());
2042 handle
->ERROR_MESSAGE("Unknown exception thrown");
2049 GEOSUnionCascaded_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2051 if ( 0 == extHandle
)
2056 GEOSContextHandleInternal_t
*handle
= 0;
2057 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2058 if ( 0 == handle
->initialized
)
2065 const geos::geom::MultiPolygon
*p
= dynamic_cast<const geos::geom::MultiPolygon
*>(g1
);
2068 handle
->ERROR_MESSAGE("Invalid argument (must be a MultiPolygon)");
2072 using geos::operation::geounion::CascadedPolygonUnion
;
2073 return CascadedPolygonUnion::Union(p
);
2075 catch (const std::exception
&e
)
2077 handle
->ERROR_MESSAGE("%s", e
.what());
2081 handle
->ERROR_MESSAGE("Unknown exception thrown");
2088 GEOSPointOnSurface_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
*ret
= g1
->getInteriorPoint();
2107 const GeometryFactory
* gf
= handle
->geomFactory
;
2108 // return an empty point
2109 return gf
->createPoint();
2113 catch (const std::exception
&e
)
2115 handle
->ERROR_MESSAGE("%s", e
.what());
2119 handle
->ERROR_MESSAGE("Unknown exception thrown");
2125 //-------------------------------------------------------------------
2126 // memory management functions
2127 //------------------------------------------------------------------
2130 GEOSGeom_destroy_r(GEOSContextHandle_t extHandle
, Geometry
*a
)
2132 GEOSContextHandleInternal_t
*handle
= 0;
2134 // FIXME: mloskot: Does this try-catch around delete means that
2135 // destructors in GEOS may throw? If it does, this is a serious
2136 // violation of "never throw an exception from a destructor" principle
2142 catch (const std::exception
&e
)
2144 if ( 0 == extHandle
)
2149 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2150 if ( 0 == handle
->initialized
)
2155 handle
->ERROR_MESSAGE("%s", e
.what());
2159 if ( 0 == extHandle
)
2164 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2165 if ( 0 == handle
->initialized
)
2170 handle
->ERROR_MESSAGE("Unknown exception thrown");
2175 GEOSSetSRID_r(GEOSContextHandle_t extHandle
, Geometry
*g
, int srid
)
2179 if ( 0 == extHandle
)
2184 GEOSContextHandleInternal_t
*handle
= 0;
2185 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2186 if ( 0 == handle
->initialized
)
2196 GEOSGetNumCoordinates_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2200 if ( 0 == extHandle
)
2205 GEOSContextHandleInternal_t
*handle
= 0;
2206 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2207 if ( 0 == handle
->initialized
)
2214 return static_cast<int>(g
->getNumPoints());
2216 catch (const std::exception
&e
)
2218 handle
->ERROR_MESSAGE("%s", e
.what());
2222 handle
->ERROR_MESSAGE("Unknown exception thrown");
2229 * Return -1 on exception, 0 otherwise.
2230 * Converts Geometry to normal form (or canonical form).
2233 GEOSNormalize_r(GEOSContextHandle_t extHandle
, Geometry
*g
)
2237 if ( 0 == extHandle
)
2242 GEOSContextHandleInternal_t
*handle
= 0;
2243 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2244 if ( 0 == handle
->initialized
)
2252 return 0; // SUCCESS
2254 catch (const std::exception
&e
)
2256 handle
->ERROR_MESSAGE("%s", e
.what());
2260 handle
->ERROR_MESSAGE("Unknown exception thrown");
2267 GEOSGetNumInteriorRings_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2269 if ( 0 == extHandle
)
2274 GEOSContextHandleInternal_t
*handle
= 0;
2275 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2276 if ( 0 == handle
->initialized
)
2283 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
2286 handle
->ERROR_MESSAGE("Argument is not a Polygon");
2289 return static_cast<int>(p
->getNumInteriorRing());
2291 catch (const std::exception
&e
)
2293 handle
->ERROR_MESSAGE("%s", e
.what());
2297 handle
->ERROR_MESSAGE("Unknown exception thrown");
2304 // returns -1 on error and 1 for non-multi geometries
2306 GEOSGetNumGeometries_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2308 if ( 0 == extHandle
)
2313 GEOSContextHandleInternal_t
*handle
= 0;
2314 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2315 if ( 0 == handle
->initialized
)
2322 return static_cast<int>(g1
->getNumGeometries());
2324 catch (const std::exception
&e
)
2326 handle
->ERROR_MESSAGE("%s", e
.what());
2330 handle
->ERROR_MESSAGE("Unknown exception thrown");
2338 * Call only on GEOMETRYCOLLECTION or MULTI*.
2339 * Return a pointer to the internal Geometry.
2342 GEOSGetGeometryN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2344 if ( 0 == extHandle
)
2349 GEOSContextHandleInternal_t
*handle
= 0;
2350 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2351 if ( 0 == handle
->initialized
)
2358 return g1
->getGeometryN(n
);
2360 catch (const std::exception
&e
)
2362 handle
->ERROR_MESSAGE("%s", e
.what());
2366 handle
->ERROR_MESSAGE("Unknown exception thrown");
2373 * Call only on LINESTRING
2374 * Returns NULL on exception
2377 GEOSGeomGetPointN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2379 if ( 0 == extHandle
)
2384 GEOSContextHandleInternal_t
*handle
= 0;
2385 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2386 if ( 0 == handle
->initialized
)
2393 using geos::geom::LineString
;
2394 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2397 handle
->ERROR_MESSAGE("Argument is not a LineString");
2400 return ls
->getPointN(n
);
2402 catch (const std::exception
&e
)
2404 handle
->ERROR_MESSAGE("%s", e
.what());
2408 handle
->ERROR_MESSAGE("Unknown exception thrown");
2415 * Call only on LINESTRING
2418 GEOSGeomGetStartPoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2420 if ( 0 == extHandle
)
2425 GEOSContextHandleInternal_t
*handle
= 0;
2426 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2427 if ( 0 == handle
->initialized
)
2434 using geos::geom::LineString
;
2435 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2438 handle
->ERROR_MESSAGE("Argument is not a LineString");
2441 return ls
->getStartPoint();
2443 catch (const std::exception
&e
)
2445 handle
->ERROR_MESSAGE("%s", e
.what());
2449 handle
->ERROR_MESSAGE("Unknown exception thrown");
2456 * Call only on LINESTRING
2459 GEOSGeomGetEndPoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2461 if ( 0 == extHandle
)
2466 GEOSContextHandleInternal_t
*handle
= 0;
2467 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2468 if ( 0 == handle
->initialized
)
2475 using geos::geom::LineString
;
2476 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2479 handle
->ERROR_MESSAGE("Argument is not a LineString");
2482 return ls
->getEndPoint();
2484 catch (const std::exception
&e
)
2486 handle
->ERROR_MESSAGE("%s", e
.what());
2490 handle
->ERROR_MESSAGE("Unknown exception thrown");
2497 * Call only on LINESTRING
2498 * return 2 on exception, 1 on true, 0 on false
2501 GEOSisClosed_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2503 if ( 0 == extHandle
)
2508 GEOSContextHandleInternal_t
*handle
= 0;
2509 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2510 if ( 0 == handle
->initialized
)
2517 using geos::geom::LineString
;
2518 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2521 handle
->ERROR_MESSAGE("Argument is not a LineString");
2524 return ls
->isClosed();
2526 catch (const std::exception
&e
)
2528 handle
->ERROR_MESSAGE("%s", e
.what());
2532 handle
->ERROR_MESSAGE("Unknown exception thrown");
2539 * Call only on LINESTRING
2540 * return 0 on exception, otherwise 1
2543 GEOSGeomGetLength_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *length
)
2545 if ( 0 == extHandle
)
2550 GEOSContextHandleInternal_t
*handle
= 0;
2551 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2552 if ( 0 == handle
->initialized
)
2559 using geos::geom::LineString
;
2560 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2563 handle
->ERROR_MESSAGE("Argument is not a LineString");
2566 *length
= ls
->getLength();
2569 catch (const std::exception
&e
)
2571 handle
->ERROR_MESSAGE("%s", e
.what());
2575 handle
->ERROR_MESSAGE("Unknown exception thrown");
2582 * Call only on LINESTRING
2585 GEOSGeomGetNumPoints_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2587 if ( 0 == extHandle
)
2592 GEOSContextHandleInternal_t
*handle
= 0;
2593 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2594 if ( 0 == handle
->initialized
)
2601 using geos::geom::LineString
;
2602 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2605 handle
->ERROR_MESSAGE("Argument is not a LineString");
2608 return static_cast<int>(ls
->getNumPoints());
2610 catch (const std::exception
&e
)
2612 handle
->ERROR_MESSAGE("%s", e
.what());
2616 handle
->ERROR_MESSAGE("Unknown exception thrown");
2624 * returns 0 on exception, otherwise 1
2627 GEOSGeomGetX_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *x
)
2629 if ( 0 == extHandle
)
2634 GEOSContextHandleInternal_t
*handle
= 0;
2635 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2636 if ( 0 == handle
->initialized
)
2643 using geos::geom::Point
;
2644 const Point
*po
= dynamic_cast<const Point
*>(g1
);
2647 handle
->ERROR_MESSAGE("Argument is not a Point");
2653 catch (const std::exception
&e
)
2655 handle
->ERROR_MESSAGE("%s", e
.what());
2659 handle
->ERROR_MESSAGE("Unknown exception thrown");
2667 * returns 0 on exception, otherwise 1
2670 GEOSGeomGetY_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *y
)
2672 if ( 0 == extHandle
)
2677 GEOSContextHandleInternal_t
*handle
= 0;
2678 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2679 if ( 0 == handle
->initialized
)
2686 using geos::geom::Point
;
2687 const Point
*po
= dynamic_cast<const Point
*>(g1
);
2690 handle
->ERROR_MESSAGE("Argument is not a Point");
2696 catch (const std::exception
&e
)
2698 handle
->ERROR_MESSAGE("%s", e
.what());
2702 handle
->ERROR_MESSAGE("Unknown exception thrown");
2709 * Call only on polygon
2710 * Return a copy of the internal Geometry.
2713 GEOSGetExteriorRing_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2715 if ( 0 == extHandle
)
2720 GEOSContextHandleInternal_t
*handle
= 0;
2721 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2722 if ( 0 == handle
->initialized
)
2729 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
2732 handle
->ERROR_MESSAGE("Invalid argument (must be a Polygon)");
2735 return p
->getExteriorRing();
2737 catch (const std::exception
&e
)
2739 handle
->ERROR_MESSAGE("%s", e
.what());
2743 handle
->ERROR_MESSAGE("Unknown exception thrown");
2750 * Call only on polygon
2751 * Return a pointer to internal storage, do not destroy it.
2754 GEOSGetInteriorRingN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2756 if ( 0 == extHandle
)
2761 GEOSContextHandleInternal_t
*handle
= 0;
2762 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2763 if ( 0 == handle
->initialized
)
2770 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
2773 handle
->ERROR_MESSAGE("Invalid argument (must be a Polygon)");
2776 return p
->getInteriorRingN(n
);
2778 catch (const std::exception
&e
)
2780 handle
->ERROR_MESSAGE("%s", e
.what());
2784 handle
->ERROR_MESSAGE("Unknown exception thrown");
2791 GEOSGetCentroid_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2793 if ( 0 == extHandle
)
2798 GEOSContextHandleInternal_t
*handle
= 0;
2799 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2800 if ( 0 == handle
->initialized
)
2807 Geometry
*ret
= g
->getCentroid();
2810 const GeometryFactory
*gf
= handle
->geomFactory
;
2811 return gf
->createPoint();
2815 catch (const std::exception
&e
)
2817 handle
->ERROR_MESSAGE("%s", e
.what());
2821 handle
->ERROR_MESSAGE("Unknown exception thrown");
2828 GEOSGeom_createEmptyCollection_r(GEOSContextHandle_t extHandle
, int type
)
2830 if ( 0 == extHandle
)
2835 GEOSContextHandleInternal_t
*handle
= 0;
2836 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2837 if ( 0 == handle
->initialized
)
2844 sprintf(buf
, "createCollection: requested type %d, ngeoms: %d",
2846 handle
->NOTICE_MESSAGE("%s", buf
);// TODO: Can handle->NOTICE_MESSAGE format that directly?
2851 const GeometryFactory
* gf
= handle
->geomFactory
;
2856 case GEOS_GEOMETRYCOLLECTION
:
2857 g
= gf
->createGeometryCollection();
2859 case GEOS_MULTIPOINT
:
2860 g
= gf
->createMultiPoint();
2862 case GEOS_MULTILINESTRING
:
2863 g
= gf
->createMultiLineString();
2865 case GEOS_MULTIPOLYGON
:
2866 g
= gf
->createMultiPolygon();
2869 handle
->ERROR_MESSAGE("Unsupported type request for GEOSGeom_createEmptyCollection_r");
2876 catch (const std::exception
&e
)
2878 handle
->ERROR_MESSAGE("%s", e
.what());
2882 handle
->ERROR_MESSAGE("Unknown exception thrown");
2889 GEOSGeom_createCollection_r(GEOSContextHandle_t extHandle
, int type
, Geometry
**geoms
, unsigned int ngeoms
)
2891 if ( 0 == extHandle
)
2896 GEOSContextHandleInternal_t
*handle
= 0;
2897 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2898 if ( 0 == handle
->initialized
)
2905 sprintf(buf
, "PostGIS2GEOS_collection: requested type %d, ngeoms: %d",
2907 handle
->NOTICE_MESSAGE("%s", buf
);// TODO: Can handle->NOTICE_MESSAGE format that directly?
2912 const GeometryFactory
* gf
= handle
->geomFactory
;
2913 std::vector
<Geometry
*>* vgeoms
= new std::vector
<Geometry
*>(geoms
, geoms
+ ngeoms
);
2918 case GEOS_GEOMETRYCOLLECTION
:
2919 g
= gf
->createGeometryCollection(vgeoms
);
2921 case GEOS_MULTIPOINT
:
2922 g
= gf
->createMultiPoint(vgeoms
);
2924 case GEOS_MULTILINESTRING
:
2925 g
= gf
->createMultiLineString(vgeoms
);
2927 case GEOS_MULTIPOLYGON
:
2928 g
= gf
->createMultiPolygon(vgeoms
);
2931 handle
->ERROR_MESSAGE("Unsupported type request for PostGIS2GEOS_collection");
2938 catch (const std::exception
&e
)
2940 handle
->ERROR_MESSAGE("%s", e
.what());
2944 handle
->ERROR_MESSAGE("Unknown exception thrown");
2951 GEOSPolygonize_r(GEOSContextHandle_t extHandle
, const Geometry
* const * g
, unsigned int ngeoms
)
2953 if ( 0 == extHandle
)
2958 GEOSContextHandleInternal_t
*handle
= 0;
2959 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2960 if ( 0 == handle
->initialized
)
2970 using geos::operation::polygonize::Polygonizer
;
2972 for (std::size_t i
= 0; i
< ngeoms
; ++i
)
2978 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
2981 std::vector
<Polygon
*> *polys
= plgnzr
.getPolygons();
2985 handle
->NOTICE_MESSAGE("output polygons got");
2988 // We need a vector of Geometry pointers, not Polygon pointers.
2989 // STL vector doesn't allow transparent upcast of this
2990 // nature, so we explicitly convert.
2991 // (it's just a waste of processor and memory, btw)
2993 // XXX mloskot: Why not to extent GeometryFactory to accept
2994 // vector of polygons or extend Polygonizer to return list of Geometry*
2995 // or add a wrapper which semantic is similar to:
2996 // std::vector<as_polygon<Geometry*> >
2997 std::vector
<Geometry
*> *polyvec
= new std::vector
<Geometry
*>(polys
->size());
2999 for (std::size_t i
= 0; i
< polys
->size(); ++i
)
3001 (*polyvec
)[i
] = (*polys
)[i
];
3006 const GeometryFactory
*gf
= handle
->geomFactory
;
3008 // The below takes ownership of the passed vector,
3009 // so we must *not* delete it
3010 out
= gf
->createGeometryCollection(polyvec
);
3012 catch (const std::exception
&e
)
3014 handle
->ERROR_MESSAGE("%s", e
.what());
3018 handle
->ERROR_MESSAGE("Unknown exception thrown");
3025 GEOSPolygonizer_getCutEdges_r(GEOSContextHandle_t extHandle
, const Geometry
* const * g
, unsigned int ngeoms
)
3027 if ( 0 == extHandle
)
3032 GEOSContextHandleInternal_t
*handle
= 0;
3033 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3034 if ( 0 == handle
->initialized
)
3044 using geos::operation::polygonize::Polygonizer
;
3046 for (std::size_t i
= 0; i
< ngeoms
; ++i
)
3052 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
3055 const std::vector
<const LineString
*>& lines
= plgnzr
.getCutEdges();
3058 handle
->NOTICE_MESSAGE("output polygons got");
3061 // We need a vector of Geometry pointers, not Polygon pointers.
3062 // STL vector doesn't allow transparent upcast of this
3063 // nature, so we explicitly convert.
3064 // (it's just a waste of processor and memory, btw)
3065 // XXX mloskot: See comment for GEOSPolygonize_r
3066 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3068 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3070 (*linevec
)[i
] = lines
[i
]->clone();
3073 const GeometryFactory
*gf
= handle
->geomFactory
;
3075 // The below takes ownership of the passed vector,
3076 // so we must *not* delete it
3077 out
= gf
->createGeometryCollection(linevec
);
3079 catch (const std::exception
&e
)
3081 handle
->ERROR_MESSAGE("%s", e
.what());
3085 handle
->ERROR_MESSAGE("Unknown exception thrown");
3092 GEOSPolygonize_full_r(GEOSContextHandle_t extHandle
, const Geometry
* g
,
3093 Geometry
** cuts
, Geometry
** dangles
, Geometry
** invalid
)
3095 if ( 0 == extHandle
)
3100 GEOSContextHandleInternal_t
*handle
= 0;
3101 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3102 if ( 0 == handle
->initialized
)
3110 using geos::operation::polygonize::Polygonizer
;
3112 for (std::size_t i
= 0; i
<g
->getNumGeometries(); ++i
)
3114 plgnzr
.add(g
->getGeometryN(i
));
3118 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
3120 const GeometryFactory
*gf
= handle
->geomFactory
;
3124 const std::vector
<const LineString
*>& lines
= plgnzr
.getCutEdges();
3125 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3126 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3128 (*linevec
)[i
] = lines
[i
]->clone();
3131 // The below takes ownership of the passed vector,
3132 // so we must *not* delete it
3133 *cuts
= gf
->createGeometryCollection(linevec
);
3138 const std::vector
<const LineString
*>& lines
= plgnzr
.getDangles();
3139 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3140 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3142 (*linevec
)[i
] = lines
[i
]->clone();
3145 // The below takes ownership of the passed vector,
3146 // so we must *not* delete it
3147 *dangles
= gf
->createGeometryCollection(linevec
);
3152 const std::vector
<LineString
*>& lines
= plgnzr
.getInvalidRingLines();
3153 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3154 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3156 (*linevec
)[i
] = lines
[i
]->clone();
3159 // The below takes ownership of the passed vector,
3160 // so we must *not* delete it
3161 *invalid
= gf
->createGeometryCollection(linevec
);
3164 std::vector
<Polygon
*> *polys
= plgnzr
.getPolygons();
3165 std::vector
<Geometry
*> *polyvec
= new std::vector
<Geometry
*>(polys
->size());
3166 for (std::size_t i
= 0; i
< polys
->size(); ++i
)
3168 (*polyvec
)[i
] = (*polys
)[i
];
3172 return gf
->createGeometryCollection(polyvec
);
3175 catch (const std::exception
&e
)
3177 handle
->ERROR_MESSAGE("%s", e
.what());
3182 handle
->ERROR_MESSAGE("Unknown exception thrown");
3188 GEOSLineMerge_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3190 if ( 0 == extHandle
)
3195 GEOSContextHandleInternal_t
*handle
= 0;
3196 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3197 if ( 0 == handle
->initialized
)
3206 using geos::operation::linemerge::LineMerger
;
3210 std::vector
<LineString
*>* lines
= lmrgr
.getMergedLineStrings();
3214 handle
->NOTICE_MESSAGE("output lines got");
3217 std::vector
<Geometry
*>*geoms
= new std::vector
<Geometry
*>(lines
->size());
3218 for (std::vector
<Geometry
*>::size_type i
= 0; i
< lines
->size(); ++i
)
3220 (*geoms
)[i
] = (*lines
)[i
];
3225 const GeometryFactory
*gf
= handle
->geomFactory
;
3226 out
= gf
->buildGeometry(geoms
);
3229 //out = gf->createGeometryCollection(geoms);
3231 catch (const std::exception
&e
)
3233 handle
->ERROR_MESSAGE("%s", e
.what());
3237 handle
->ERROR_MESSAGE("Unknown exception thrown");
3244 GEOSGetSRID_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3248 if ( 0 == extHandle
)
3253 GEOSContextHandleInternal_t
*handle
= 0;
3254 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3255 if ( 0 == handle
->initialized
)
3262 return g
->getSRID();
3264 catch (const std::exception
&e
)
3266 handle
->ERROR_MESSAGE("%s", e
.what());
3270 handle
->ERROR_MESSAGE("Unknown exception thrown");
3276 const char* GEOSversion()
3278 static char version
[256];
3279 sprintf(version
, "%s r%d", GEOS_CAPI_VERSION
, GEOS_SVN_REVISION
);
3283 const char* GEOSjtsport()
3285 return GEOS_JTS_PORT
;
3289 GEOSHasZ_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3293 if ( 0 == extHandle
)
3298 GEOSContextHandleInternal_t
*handle
= 0;
3299 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3300 if ( 0 == handle
->initialized
)
3309 assert(0 != g
->getCoordinate());
3311 double az
= g
->getCoordinate()->z
;
3312 //handle->ERROR_MESSAGE("ZCoord: %g", az);
3314 return static_cast<char>(FINITE(az
));
3318 GEOS_getWKBOutputDims_r(GEOSContextHandle_t extHandle
)
3320 if ( 0 == extHandle
)
3325 GEOSContextHandleInternal_t
*handle
= 0;
3326 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3327 if ( 0 == handle
->initialized
)
3332 return handle
->WKBOutputDims
;
3336 GEOS_setWKBOutputDims_r(GEOSContextHandle_t extHandle
, int newdims
)
3338 if ( 0 == extHandle
)
3343 GEOSContextHandleInternal_t
*handle
= 0;
3344 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3345 if ( 0 == handle
->initialized
)
3350 if ( newdims
< 2 || newdims
> 3 )
3352 handle
->ERROR_MESSAGE("WKB output dimensions out of range 2..3");
3355 const int olddims
= handle
->WKBOutputDims
;
3356 handle
->WKBOutputDims
= newdims
;
3362 GEOS_getWKBByteOrder_r(GEOSContextHandle_t extHandle
)
3364 if ( 0 == extHandle
)
3369 GEOSContextHandleInternal_t
*handle
= 0;
3370 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3371 if ( 0 == handle
->initialized
)
3376 return handle
->WKBByteOrder
;
3380 GEOS_setWKBByteOrder_r(GEOSContextHandle_t extHandle
, int byteOrder
)
3382 if ( 0 == extHandle
)
3387 GEOSContextHandleInternal_t
*handle
= 0;
3388 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3389 if ( 0 == handle
->initialized
)
3394 const int oldByteOrder
= handle
->WKBByteOrder
;
3395 handle
->WKBByteOrder
= byteOrder
;
3397 return oldByteOrder
;
3401 CoordinateSequence
*
3402 GEOSCoordSeq_create_r(GEOSContextHandle_t extHandle
, unsigned int size
, unsigned int dims
)
3404 if ( 0 == extHandle
)
3409 GEOSContextHandleInternal_t
*handle
= 0;
3410 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3411 if ( 0 == handle
->initialized
)
3418 const GeometryFactory
*gf
= handle
->geomFactory
;
3419 return gf
->getCoordinateSequenceFactory()->create(size
, dims
);
3421 catch (const std::exception
&e
)
3423 handle
->ERROR_MESSAGE("%s", e
.what());
3427 handle
->ERROR_MESSAGE("Unknown exception thrown");
3434 GEOSCoordSeq_setOrdinate_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
,
3435 unsigned int idx
, unsigned int dim
, double val
)
3438 if ( 0 == extHandle
)
3443 GEOSContextHandleInternal_t
*handle
= 0;
3444 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3445 if ( 0 == handle
->initialized
)
3452 cs
->setOrdinate(idx
, dim
, val
);
3455 catch (const std::exception
&e
)
3457 handle
->ERROR_MESSAGE("%s", e
.what());
3461 handle
->ERROR_MESSAGE("Unknown exception thrown");
3468 GEOSCoordSeq_setX_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3470 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 0, val
);
3474 GEOSCoordSeq_setY_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3476 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 1, val
);
3480 GEOSCoordSeq_setZ_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3482 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 2, val
);
3485 CoordinateSequence
*
3486 GEOSCoordSeq_clone_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
)
3490 if ( 0 == extHandle
)
3495 GEOSContextHandleInternal_t
*handle
= 0;
3496 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3497 if ( 0 == handle
->initialized
)
3506 catch (const std::exception
&e
)
3508 handle
->ERROR_MESSAGE("%s", e
.what());
3512 handle
->ERROR_MESSAGE("Unknown exception thrown");
3519 GEOSCoordSeq_getOrdinate_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
,
3520 unsigned int idx
, unsigned int dim
, double *val
)
3525 if ( 0 == extHandle
)
3530 GEOSContextHandleInternal_t
*handle
= 0;
3531 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3532 if ( 0 == handle
->initialized
)
3539 double d
= cs
->getOrdinate(idx
, dim
);
3544 catch (const std::exception
&e
)
3546 handle
->ERROR_MESSAGE("%s", e
.what());
3550 handle
->ERROR_MESSAGE("Unknown exception thrown");
3557 GEOSCoordSeq_getX_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
3559 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 0, val
);
3563 GEOSCoordSeq_getY_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
3565 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 1, val
);
3569 GEOSCoordSeq_getZ_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
3571 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 2, val
);
3575 GEOSCoordSeq_getSize_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
, unsigned int *size
)
3580 if ( 0 == extHandle
)
3585 GEOSContextHandleInternal_t
*handle
= 0;
3586 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3587 if ( 0 == handle
->initialized
)
3594 const std::size_t sz
= cs
->getSize();
3595 *size
= static_cast<unsigned int>(sz
);
3598 catch (const std::exception
&e
)
3600 handle
->ERROR_MESSAGE("%s", e
.what());
3604 handle
->ERROR_MESSAGE("Unknown exception thrown");
3611 GEOSCoordSeq_getDimensions_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
, unsigned int *dims
)
3616 if ( 0 == extHandle
)
3621 GEOSContextHandleInternal_t
*handle
= 0;
3622 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3623 if ( 0 == handle
->initialized
)
3630 const std::size_t dim
= cs
->getDimension();
3631 *dims
= static_cast<unsigned int>(dim
);
3635 catch (const std::exception
&e
)
3637 handle
->ERROR_MESSAGE("%s", e
.what());
3642 handle
->ERROR_MESSAGE("Unknown exception thrown");
3649 GEOSCoordSeq_destroy_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
)
3651 GEOSContextHandleInternal_t
*handle
= 0;
3657 catch (const std::exception
&e
)
3659 if ( 0 == extHandle
)
3664 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3665 if ( 0 == handle
->initialized
)
3670 handle
->ERROR_MESSAGE("%s", e
.what());
3674 if ( 0 == extHandle
)
3679 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3680 if ( 0 == handle
->initialized
)
3685 handle
->ERROR_MESSAGE("Unknown exception thrown");
3689 const CoordinateSequence
*
3690 GEOSGeom_getCoordSeq_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3692 if ( 0 == extHandle
)
3697 GEOSContextHandleInternal_t
*handle
= 0;
3698 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3699 if ( 0 == handle
->initialized
)
3706 using geos::geom::Point
;
3708 const LineString
*ls
= dynamic_cast<const LineString
*>(g
);
3711 return ls
->getCoordinatesRO();
3714 const Point
*p
= dynamic_cast<const Point
*>(g
);
3717 return p
->getCoordinatesRO();
3720 handle
->ERROR_MESSAGE("Geometry must be a Point or LineString");
3723 catch (const std::exception
&e
)
3725 handle
->ERROR_MESSAGE("%s", e
.what());
3729 handle
->ERROR_MESSAGE("Unknown exception thrown");
3736 GEOSGeom_createEmptyPoint_r(GEOSContextHandle_t extHandle
)
3738 if ( 0 == extHandle
)
3743 GEOSContextHandleInternal_t
*handle
= 0;
3744 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3745 if ( 0 == handle
->initialized
)
3752 const GeometryFactory
*gf
= handle
->geomFactory
;
3753 return gf
->createPoint();
3755 catch (const std::exception
&e
)
3757 handle
->ERROR_MESSAGE("%s", e
.what());
3761 handle
->ERROR_MESSAGE("Unknown exception thrown");
3768 GEOSGeom_createPoint_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
3770 if ( 0 == extHandle
)
3775 GEOSContextHandleInternal_t
*handle
= 0;
3776 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3777 if ( 0 == handle
->initialized
)
3784 const GeometryFactory
*gf
= handle
->geomFactory
;
3785 return gf
->createPoint(cs
);
3787 catch (const std::exception
&e
)
3789 handle
->ERROR_MESSAGE("%s", e
.what());
3793 handle
->ERROR_MESSAGE("Unknown exception thrown");
3800 GEOSGeom_createLinearRing_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
3802 if ( 0 == extHandle
)
3807 GEOSContextHandleInternal_t
*handle
= 0;
3808 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3809 if ( 0 == handle
->initialized
)
3816 const GeometryFactory
*gf
= handle
->geomFactory
;
3818 return gf
->createLinearRing(cs
);
3820 catch (const std::exception
&e
)
3822 handle
->ERROR_MESSAGE("%s", e
.what());
3826 handle
->ERROR_MESSAGE("Unknown exception thrown");
3833 GEOSGeom_createEmptyLineString_r(GEOSContextHandle_t extHandle
)
3835 if ( 0 == extHandle
)
3840 GEOSContextHandleInternal_t
*handle
= 0;
3841 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3842 if ( 0 == handle
->initialized
)
3849 const GeometryFactory
*gf
= handle
->geomFactory
;
3851 return gf
->createLineString();
3853 catch (const std::exception
&e
)
3855 handle
->ERROR_MESSAGE("%s", e
.what());
3859 handle
->ERROR_MESSAGE("Unknown exception thrown");
3866 GEOSGeom_createLineString_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
3868 if ( 0 == extHandle
)
3873 GEOSContextHandleInternal_t
*handle
= 0;
3874 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3875 if ( 0 == handle
->initialized
)
3882 const GeometryFactory
*gf
= handle
->geomFactory
;
3884 return gf
->createLineString(cs
);
3886 catch (const std::exception
&e
)
3888 handle
->ERROR_MESSAGE("%s", e
.what());
3892 handle
->ERROR_MESSAGE("Unknown exception thrown");
3899 GEOSGeom_createEmptyPolygon_r(GEOSContextHandle_t extHandle
)
3901 if ( 0 == extHandle
)
3906 GEOSContextHandleInternal_t
*handle
= 0;
3907 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3908 if ( 0 == handle
->initialized
)
3915 const GeometryFactory
*gf
= handle
->geomFactory
;
3916 return gf
->createPolygon();
3918 catch (const std::exception
&e
)
3920 handle
->ERROR_MESSAGE("%s", e
.what());
3924 handle
->ERROR_MESSAGE("Unknown exception thrown");
3931 GEOSGeom_createPolygon_r(GEOSContextHandle_t extHandle
, Geometry
*shell
, Geometry
**holes
, unsigned int nholes
)
3933 // FIXME: holes must be non-nullptr or may be nullptr?
3934 //assert(0 != holes);
3936 if ( 0 == extHandle
)
3941 GEOSContextHandleInternal_t
*handle
= 0;
3942 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3943 if ( 0 == handle
->initialized
)
3950 using geos::geom::LinearRing
;
3952 std::vector
<Geometry
*> *vholes
= new std::vector
<Geometry
*>(holes
, holes
+ nholes
);
3954 LinearRing
*nshell
= dynamic_cast<LinearRing
*>(shell
);
3957 handle
->ERROR_MESSAGE("Shell is not a LinearRing");
3960 const GeometryFactory
*gf
= handle
->geomFactory
;
3962 return gf
->createPolygon(nshell
, vholes
);
3964 catch (const std::exception
&e
)
3966 handle
->ERROR_MESSAGE("%s", e
.what());
3970 handle
->ERROR_MESSAGE("Unknown exception thrown");
3977 GEOSGeom_clone_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3981 if ( 0 == extHandle
)
3986 GEOSContextHandleInternal_t
*handle
= 0;
3987 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3988 if ( 0 == handle
->initialized
)
3997 catch (const std::exception
&e
)
3999 handle
->ERROR_MESSAGE("%s", e
.what());
4003 handle
->ERROR_MESSAGE("Unknown exception thrown");
4010 GEOSGeom_getDimensions_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
4012 if ( 0 == extHandle
)
4017 GEOSContextHandleInternal_t
*handle
= 0;
4018 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4019 if ( 0 == handle
->initialized
)
4026 return (int) g
->getDimension();
4028 catch (const std::exception
&e
)
4030 handle
->ERROR_MESSAGE("%s", e
.what());
4034 handle
->ERROR_MESSAGE("Unknown exception thrown");
4041 GEOSGeom_getCoordinateDimension_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
4043 if ( 0 == extHandle
)
4048 GEOSContextHandleInternal_t
*handle
= 0;
4049 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4050 if ( 0 == handle
->initialized
)
4057 return g
->getCoordinateDimension();
4059 catch (const std::exception
&e
)
4061 handle
->ERROR_MESSAGE("%s", e
.what());
4065 handle
->ERROR_MESSAGE("Unknown exception thrown");
4072 GEOSSimplify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double tolerance
)
4074 if ( 0 == extHandle
)
4079 GEOSContextHandleInternal_t
*handle
= 0;
4080 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4081 if ( 0 == handle
->initialized
)
4088 using namespace geos::simplify
;
4089 Geometry::AutoPtr
g(DouglasPeuckerSimplifier::simplify(g1
, tolerance
));
4092 catch (const std::exception
&e
)
4094 handle
->ERROR_MESSAGE("%s", e
.what());
4098 handle
->ERROR_MESSAGE("Unknown exception thrown");
4105 GEOSTopologyPreserveSimplify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double tolerance
)
4107 if ( 0 == extHandle
)
4112 GEOSContextHandleInternal_t
*handle
= 0;
4113 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4114 if ( 0 == handle
->initialized
)
4121 using namespace geos::simplify
;
4122 Geometry::AutoPtr
g(TopologyPreservingSimplifier::simplify(g1
, tolerance
));
4125 catch (const std::exception
&e
)
4127 handle
->ERROR_MESSAGE("%s", e
.what());
4131 handle
->ERROR_MESSAGE("Unknown exception thrown");
4140 GEOSWKTReader_create_r(GEOSContextHandle_t extHandle
)
4142 if ( 0 == extHandle
)
4147 GEOSContextHandleInternal_t
*handle
= 0;
4148 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4149 if ( 0 == handle
->initialized
)
4156 using geos::io::WKTReader
;
4157 return new WKTReader((GeometryFactory
*)handle
->geomFactory
);
4159 catch (const std::exception
&e
)
4161 handle
->ERROR_MESSAGE("%s", e
.what());
4165 handle
->ERROR_MESSAGE("Unknown exception thrown");
4172 GEOSWKTReader_destroy_r(GEOSContextHandle_t extHandle
, WKTReader
*reader
)
4174 GEOSContextHandleInternal_t
*handle
= 0;
4180 catch (const std::exception
&e
)
4182 if ( 0 == extHandle
)
4187 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4188 if ( 0 == handle
->initialized
)
4193 handle
->ERROR_MESSAGE("%s", e
.what());
4197 if ( 0 == extHandle
)
4202 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4203 if ( 0 == handle
->initialized
)
4208 handle
->ERROR_MESSAGE("Unknown exception thrown");
4214 GEOSWKTReader_read_r(GEOSContextHandle_t extHandle
, WKTReader
*reader
, const char *wkt
)
4216 assert(0 != reader
);
4218 if ( 0 == extHandle
)
4223 GEOSContextHandleInternal_t
*handle
= 0;
4224 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4225 if ( 0 == handle
->initialized
)
4232 const std::string
wktstring(wkt
);
4233 Geometry
*g
= reader
->read(wktstring
);
4236 catch (const std::exception
&e
)
4238 handle
->ERROR_MESSAGE("%s", e
.what());
4242 handle
->ERROR_MESSAGE("Unknown exception thrown");
4250 GEOSWKTWriter_create_r(GEOSContextHandle_t extHandle
)
4252 if ( 0 == extHandle
)
4257 GEOSContextHandleInternal_t
*handle
= 0;
4258 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4259 if ( 0 == handle
->initialized
)
4266 using geos::io::WKTWriter
;
4267 return new WKTWriter();
4269 catch (const std::exception
&e
)
4271 handle
->ERROR_MESSAGE("%s", e
.what());
4275 handle
->ERROR_MESSAGE("Unknown exception thrown");
4282 GEOSWKTWriter_destroy_r(GEOSContextHandle_t extHandle
, WKTWriter
*Writer
)
4285 GEOSContextHandleInternal_t
*handle
= 0;
4291 catch (const std::exception
&e
)
4293 if ( 0 == extHandle
)
4298 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4299 if ( 0 == handle
->initialized
)
4304 handle
->ERROR_MESSAGE("%s", e
.what());
4308 if ( 0 == extHandle
)
4313 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4314 if ( 0 == handle
->initialized
)
4319 handle
->ERROR_MESSAGE("Unknown exception thrown");
4325 GEOSWKTWriter_write_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, const Geometry
*geom
)
4327 assert(0 != writer
);
4329 if ( 0 == extHandle
)
4334 GEOSContextHandleInternal_t
*handle
= 0;
4335 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4336 if ( 0 == handle
->initialized
)
4343 std::string
sgeom(writer
->write(geom
));
4344 char *result
= gstrdup(sgeom
);
4347 catch (const std::exception
&e
)
4349 handle
->ERROR_MESSAGE("%s", e
.what());
4353 handle
->ERROR_MESSAGE("Unknown exception thrown");
4360 GEOSWKTWriter_setTrim_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, char trim
)
4362 assert(0 != writer
);
4364 if ( 0 == extHandle
)
4369 GEOSContextHandleInternal_t
*handle
= 0;
4370 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4371 if ( 0 == handle
->initialized
)
4376 writer
->setTrim(0 != trim
);
4380 GEOSWKTWriter_setRoundingPrecision_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int precision
)
4382 assert(0 != writer
);
4384 if ( 0 == extHandle
)
4389 GEOSContextHandleInternal_t
*handle
= 0;
4390 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4391 if ( 0 == handle
->initialized
)
4396 writer
->setRoundingPrecision(precision
);
4400 GEOSWKTWriter_setOutputDimension_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int dim
)
4402 assert(0 != writer
);
4404 if ( 0 == extHandle
)
4409 GEOSContextHandleInternal_t
*handle
= 0;
4410 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4411 if ( 0 == handle
->initialized
)
4418 writer
->setOutputDimension(dim
);
4420 catch (const std::exception
&e
)
4422 handle
->ERROR_MESSAGE("%s", e
.what());
4426 handle
->ERROR_MESSAGE("Unknown exception thrown");
4431 GEOSWKTWriter_getOutputDimension_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
)
4433 assert(0 != writer
);
4435 if ( 0 == extHandle
)
4440 GEOSContextHandleInternal_t
*handle
= 0;
4441 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4442 if ( 0 == handle
->initialized
)
4451 dim
= writer
->getOutputDimension();
4453 catch (const std::exception
&e
)
4455 handle
->ERROR_MESSAGE("%s", e
.what());
4459 handle
->ERROR_MESSAGE("Unknown exception thrown");
4466 GEOSWKTWriter_setOld3D_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int useOld3D
)
4468 assert(0 != writer
);
4470 if ( 0 == extHandle
)
4475 GEOSContextHandleInternal_t
*handle
= 0;
4476 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4477 if ( 0 == handle
->initialized
)
4482 writer
->setOld3D(0 != useOld3D
);
4487 GEOSWKBReader_create_r(GEOSContextHandle_t extHandle
)
4489 if ( 0 == extHandle
)
4494 GEOSContextHandleInternal_t
*handle
= 0;
4495 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4496 if ( 0 == handle
->initialized
)
4501 using geos::io::WKBReader
;
4504 return new WKBReader(*(GeometryFactory
*)handle
->geomFactory
);
4506 catch (const std::exception
&e
)
4508 handle
->ERROR_MESSAGE("%s", e
.what());
4512 handle
->ERROR_MESSAGE("Unknown exception thrown");
4519 GEOSWKBReader_destroy_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
)
4521 GEOSContextHandleInternal_t
*handle
= 0;
4527 catch (const std::exception
&e
)
4529 if ( 0 == extHandle
)
4534 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4535 if ( 0 == handle
->initialized
)
4540 handle
->ERROR_MESSAGE("%s", e
.what());
4544 if ( 0 == extHandle
)
4549 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4550 if ( 0 == handle
->initialized
)
4555 handle
->ERROR_MESSAGE("Unknown exception thrown");
4559 struct membuf
: public std::streambuf
4561 membuf(char* s
, std::size_t n
)
4568 GEOSWKBReader_read_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
, const unsigned char *wkb
, size_t size
)
4570 assert(0 != reader
);
4573 if ( 0 == extHandle
)
4578 GEOSContextHandleInternal_t
*handle
= 0;
4579 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4580 if ( 0 == handle
->initialized
)
4587 //std::string wkbstring(reinterpret_cast<const char*>(wkb), size); // make it binary !
4588 //std::istringstream is(std::ios_base::binary);
4589 //is.str(wkbstring);
4590 //is.seekg(0, std::ios::beg); // rewind reader pointer
4592 // http://stackoverflow.com/questions/2079912/simpler-way-to-create-a-c-memorystream-from-char-size-t-without-copying-t
4593 membuf
mb((char*)wkb
, size
);
4596 Geometry
*g
= reader
->read(is
);
4599 catch (const std::exception
&e
)
4601 handle
->ERROR_MESSAGE("%s", e
.what());
4605 handle
->ERROR_MESSAGE("Unknown exception thrown");
4612 GEOSWKBReader_readHEX_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
, const unsigned char *hex
, size_t size
)
4614 assert(0 != reader
);
4617 if ( 0 == extHandle
)
4622 GEOSContextHandleInternal_t
*handle
= 0;
4623 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4624 if ( 0 == handle
->initialized
)
4631 std::string
hexstring(reinterpret_cast<const char*>(hex
), size
);
4632 std::istringstream
is(std::ios_base::binary
);
4634 is
.seekg(0, std::ios::beg
); // rewind reader pointer
4636 Geometry
*g
= reader
->readHEX(is
);
4639 catch (const std::exception
&e
)
4641 handle
->ERROR_MESSAGE("%s", e
.what());
4645 handle
->ERROR_MESSAGE("Unknown exception thrown");
4653 GEOSWKBWriter_create_r(GEOSContextHandle_t extHandle
)
4655 if ( 0 == extHandle
)
4660 GEOSContextHandleInternal_t
*handle
= 0;
4661 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4662 if ( 0 == handle
->initialized
)
4669 using geos::io::WKBWriter
;
4670 return new WKBWriter();
4672 catch (const std::exception
&e
)
4674 handle
->ERROR_MESSAGE("%s", e
.what());
4678 handle
->ERROR_MESSAGE("Unknown exception thrown");
4685 GEOSWKBWriter_destroy_r(GEOSContextHandle_t extHandle
, WKBWriter
*Writer
)
4687 GEOSContextHandleInternal_t
*handle
= 0;
4693 catch (const std::exception
&e
)
4695 if ( 0 == extHandle
)
4700 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4701 if ( 0 == handle
->initialized
)
4706 handle
->ERROR_MESSAGE("%s", e
.what());
4710 if ( 0 == extHandle
)
4715 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4716 if ( 0 == handle
->initialized
)
4721 handle
->ERROR_MESSAGE("Unknown exception thrown");
4726 /* The caller owns the result */
4728 GEOSWKBWriter_write_r(GEOSContextHandle_t extHandle
, WKBWriter
*writer
, const Geometry
*geom
, size_t *size
)
4730 assert(0 != writer
);
4734 if ( 0 == extHandle
)
4739 GEOSContextHandleInternal_t
*handle
= 0;
4740 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4741 if ( 0 == handle
->initialized
)
4748 std::ostringstream
os(std::ios_base::binary
);
4749 writer
->write(*geom
, os
);
4751 const std::string
& wkbstring
= os
.str();
4752 const std::size_t len
= wkbstring
.length();
4754 unsigned char *result
= NULL
;
4755 result
= (unsigned char*) malloc(len
);
4756 std::memcpy(result
, wkbstring
.c_str(), len
);
4760 catch (const std::exception
&e
)
4762 handle
->ERROR_MESSAGE("%s", e
.what());
4766 handle
->ERROR_MESSAGE("Unknown exception thrown");
4771 /* The caller owns the result */
4773 GEOSWKBWriter_writeHEX_r(GEOSContextHandle_t extHandle
, WKBWriter
*writer
, const Geometry
*geom
, size_t *size
)
4775 assert(0 != writer
);
4779 if ( 0 == extHandle
)
4784 GEOSContextHandleInternal_t
*handle
= 0;
4785 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4786 if ( 0 == handle
->initialized
)
4793 std::ostringstream
os(std::ios_base::binary
);
4794 writer
->writeHEX(*geom
, os
);
4795 std::string
wkbstring(os
.str());
4796 const std::size_t len
= wkbstring
.length();
4798 unsigned char *result
= NULL
;
4799 result
= (unsigned char*) malloc(len
);
4800 std::memcpy(result
, wkbstring
.c_str(), len
);
4804 catch (const std::exception
&e
)
4806 handle
->ERROR_MESSAGE("%s", e
.what());
4810 handle
->ERROR_MESSAGE("Unknown exception thrown");
4817 GEOSWKBWriter_getOutputDimension_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
4819 assert(0 != writer
);
4821 if ( 0 == extHandle
)
4828 GEOSContextHandleInternal_t
*handle
= 0;
4829 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4830 if ( 0 != handle
->initialized
)
4834 ret
= writer
->getOutputDimension();
4838 handle
->ERROR_MESSAGE("Unknown exception thrown");
4846 GEOSWKBWriter_setOutputDimension_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, int newDimension
)
4848 assert(0 != writer
);
4850 if ( 0 == extHandle
)
4855 GEOSContextHandleInternal_t
*handle
= 0;
4856 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4857 if ( 0 != handle
->initialized
)
4861 writer
->setOutputDimension(newDimension
);
4863 catch (const std::exception
&e
)
4865 handle
->ERROR_MESSAGE("%s", e
.what());
4869 handle
->ERROR_MESSAGE("Unknown exception thrown");
4875 GEOSWKBWriter_getByteOrder_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
4877 assert(0 != writer
);
4879 if ( 0 == extHandle
)
4886 GEOSContextHandleInternal_t
*handle
= 0;
4887 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4888 if ( 0 != handle
->initialized
)
4892 ret
= writer
->getByteOrder();
4897 handle
->ERROR_MESSAGE("Unknown exception thrown");
4905 GEOSWKBWriter_setByteOrder_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, int newByteOrder
)
4907 assert(0 != writer
);
4909 if ( 0 == extHandle
)
4914 GEOSContextHandleInternal_t
*handle
= 0;
4915 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4916 if ( 0 != handle
->initialized
)
4920 writer
->setByteOrder(newByteOrder
);
4922 catch (const std::exception
&e
)
4924 handle
->ERROR_MESSAGE("%s", e
.what());
4928 handle
->ERROR_MESSAGE("Unknown exception thrown");
4934 GEOSWKBWriter_getIncludeSRID_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
4936 assert(0 != writer
);
4938 if ( 0 == extHandle
)
4945 GEOSContextHandleInternal_t
*handle
= 0;
4946 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4947 if ( 0 != handle
->initialized
)
4951 int srid
= writer
->getIncludeSRID();
4956 handle
->ERROR_MESSAGE("Unknown exception thrown");
4960 return static_cast<char>(ret
);
4964 GEOSWKBWriter_setIncludeSRID_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, const char newIncludeSRID
)
4966 assert(0 != writer
);
4968 if ( 0 == extHandle
)
4973 GEOSContextHandleInternal_t
*handle
= 0;
4974 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4975 if ( 0 != handle
->initialized
)
4979 writer
->setIncludeSRID(newIncludeSRID
);
4983 handle
->ERROR_MESSAGE("Unknown exception thrown");
4989 //-----------------------------------------------------------------
4990 // Prepared Geometry
4991 //-----------------------------------------------------------------
4993 const geos::geom::prep::PreparedGeometry
*
4994 GEOSPrepare_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
4996 if ( 0 == extHandle
)
5001 GEOSContextHandleInternal_t
*handle
= 0;
5002 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5003 if ( 0 == handle
->initialized
)
5008 const geos::geom::prep::PreparedGeometry
* prep
= 0;
5012 prep
= geos::geom::prep::PreparedGeometryFactory::prepare(g
);
5014 catch (const std::exception
&e
)
5016 handle
->ERROR_MESSAGE("%s", e
.what());
5020 handle
->ERROR_MESSAGE("Unknown exception thrown");
5027 GEOSPreparedGeom_destroy_r(GEOSContextHandle_t extHandle
, const geos::geom::prep::PreparedGeometry
*a
)
5029 GEOSContextHandleInternal_t
*handle
= 0;
5035 catch (const std::exception
&e
)
5037 if ( 0 == extHandle
)
5042 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5043 if ( 0 == handle
->initialized
)
5048 handle
->ERROR_MESSAGE("%s", e
.what());
5052 if ( 0 == extHandle
)
5057 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5058 if ( 0 == handle
->initialized
)
5063 handle
->ERROR_MESSAGE("Unknown exception thrown");
5068 GEOSPreparedContains_r(GEOSContextHandle_t extHandle
,
5069 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5074 if ( 0 == extHandle
)
5079 GEOSContextHandleInternal_t
*handle
= 0;
5080 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5081 if ( 0 == handle
->initialized
)
5088 bool result
= pg
->contains(g
);
5091 catch (const std::exception
&e
)
5093 handle
->ERROR_MESSAGE("%s", e
.what());
5097 handle
->ERROR_MESSAGE("Unknown exception thrown");
5104 GEOSPreparedContainsProperly_r(GEOSContextHandle_t extHandle
,
5105 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5110 if ( 0 == extHandle
)
5115 GEOSContextHandleInternal_t
*handle
= 0;
5116 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5117 if ( 0 == handle
->initialized
)
5124 bool result
= pg
->containsProperly(g
);
5127 catch (const std::exception
&e
)
5129 handle
->ERROR_MESSAGE("%s", e
.what());
5133 handle
->ERROR_MESSAGE("Unknown exception thrown");
5140 GEOSPreparedCoveredBy_r(GEOSContextHandle_t extHandle
,
5141 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5146 if ( 0 == extHandle
)
5151 GEOSContextHandleInternal_t
*handle
= 0;
5152 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5153 if ( 0 == handle
->initialized
)
5160 bool result
= pg
->coveredBy(g
);
5163 catch (const std::exception
&e
)
5165 handle
->ERROR_MESSAGE("%s", e
.what());
5169 handle
->ERROR_MESSAGE("Unknown exception thrown");
5176 GEOSPreparedCovers_r(GEOSContextHandle_t extHandle
,
5177 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5182 if ( 0 == extHandle
)
5187 GEOSContextHandleInternal_t
*handle
= 0;
5188 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5189 if ( 0 == handle
->initialized
)
5196 bool result
= pg
->covers(g
);
5199 catch (const std::exception
&e
)
5201 handle
->ERROR_MESSAGE("%s", e
.what());
5205 handle
->ERROR_MESSAGE("Unknown exception thrown");
5212 GEOSPreparedCrosses_r(GEOSContextHandle_t extHandle
,
5213 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5218 if ( 0 == extHandle
)
5223 GEOSContextHandleInternal_t
*handle
= 0;
5224 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5225 if ( 0 == handle
->initialized
)
5232 bool result
= pg
->crosses(g
);
5235 catch (const std::exception
&e
)
5237 handle
->ERROR_MESSAGE("%s", e
.what());
5241 handle
->ERROR_MESSAGE("Unknown exception thrown");
5248 GEOSPreparedDisjoint_r(GEOSContextHandle_t extHandle
,
5249 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5254 if ( 0 == extHandle
)
5259 GEOSContextHandleInternal_t
*handle
= 0;
5260 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5261 if ( 0 == handle
->initialized
)
5268 bool result
= pg
->disjoint(g
);
5271 catch (const std::exception
&e
)
5273 handle
->ERROR_MESSAGE("%s", e
.what());
5277 handle
->ERROR_MESSAGE("Unknown exception thrown");
5284 GEOSPreparedIntersects_r(GEOSContextHandle_t extHandle
,
5285 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5290 if ( 0 == extHandle
)
5295 GEOSContextHandleInternal_t
*handle
= 0;
5296 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5297 if ( 0 == handle
->initialized
)
5304 bool result
= pg
->intersects(g
);
5307 catch (const std::exception
&e
)
5309 handle
->ERROR_MESSAGE("%s", e
.what());
5313 handle
->ERROR_MESSAGE("Unknown exception thrown");
5320 GEOSPreparedOverlaps_r(GEOSContextHandle_t extHandle
,
5321 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5326 if ( 0 == extHandle
)
5331 GEOSContextHandleInternal_t
*handle
= 0;
5332 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5333 if ( 0 == handle
->initialized
)
5340 bool result
= pg
->overlaps(g
);
5343 catch (const std::exception
&e
)
5345 handle
->ERROR_MESSAGE("%s", e
.what());
5349 handle
->ERROR_MESSAGE("Unknown exception thrown");
5356 GEOSPreparedTouches_r(GEOSContextHandle_t extHandle
,
5357 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5362 if ( 0 == extHandle
)
5367 GEOSContextHandleInternal_t
*handle
= 0;
5368 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5369 if ( 0 == handle
->initialized
)
5376 bool result
= pg
->touches(g
);
5379 catch (const std::exception
&e
)
5381 handle
->ERROR_MESSAGE("%s", e
.what());
5385 handle
->ERROR_MESSAGE("Unknown exception thrown");
5392 GEOSPreparedWithin_r(GEOSContextHandle_t extHandle
,
5393 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5398 if ( 0 == extHandle
)
5403 GEOSContextHandleInternal_t
*handle
= 0;
5404 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5405 if ( 0 == handle
->initialized
)
5412 bool result
= pg
->within(g
);
5415 catch (const std::exception
&e
)
5417 handle
->ERROR_MESSAGE("%s", e
.what());
5421 handle
->ERROR_MESSAGE("Unknown exception thrown");
5427 //-----------------------------------------------------------------
5429 //-----------------------------------------------------------------
5431 geos::index::strtree::STRtree
*
5432 GEOSSTRtree_create_r(GEOSContextHandle_t extHandle
,
5433 size_t nodeCapacity
)
5435 if ( 0 == extHandle
)
5440 GEOSContextHandleInternal_t
*handle
= 0;
5441 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5442 if ( 0 == handle
->initialized
)
5447 geos::index::strtree::STRtree
*tree
= 0;
5451 tree
= new geos::index::strtree::STRtree(nodeCapacity
);
5453 catch (const std::exception
&e
)
5455 handle
->ERROR_MESSAGE("%s", e
.what());
5459 handle
->ERROR_MESSAGE("Unknown exception thrown");
5466 GEOSSTRtree_insert_r(GEOSContextHandle_t extHandle
,
5467 geos::index::strtree::STRtree
*tree
,
5468 const geos::geom::Geometry
*g
,
5471 GEOSContextHandleInternal_t
*handle
= 0;
5477 tree
->insert(g
->getEnvelopeInternal(), item
);
5479 catch (const std::exception
&e
)
5481 if ( 0 == extHandle
)
5486 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5487 if ( 0 == handle
->initialized
)
5492 handle
->ERROR_MESSAGE("%s", e
.what());
5496 if ( 0 == extHandle
)
5501 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5502 if ( 0 == handle
->initialized
)
5507 handle
->ERROR_MESSAGE("Unknown exception thrown");
5512 GEOSSTRtree_query_r(GEOSContextHandle_t extHandle
,
5513 geos::index::strtree::STRtree
*tree
,
5514 const geos::geom::Geometry
*g
,
5515 GEOSQueryCallback callback
,
5518 GEOSContextHandleInternal_t
*handle
= 0;
5521 assert(callback
!= 0);
5525 CAPI_ItemVisitor
visitor(callback
, userdata
);
5526 tree
->query(g
->getEnvelopeInternal(), visitor
);
5528 catch (const std::exception
&e
)
5530 if ( 0 == extHandle
)
5535 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5536 if ( 0 == handle
->initialized
)
5541 handle
->ERROR_MESSAGE("%s", e
.what());
5545 if ( 0 == extHandle
)
5550 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5551 if ( 0 == handle
->initialized
)
5556 handle
->ERROR_MESSAGE("Unknown exception thrown");
5561 GEOSSTRtree_iterate_r(GEOSContextHandle_t extHandle
,
5562 geos::index::strtree::STRtree
*tree
,
5563 GEOSQueryCallback callback
,
5566 GEOSContextHandleInternal_t
*handle
= 0;
5568 assert(callback
!= 0);
5572 CAPI_ItemVisitor
visitor(callback
, userdata
);
5573 tree
->iterate(visitor
);
5575 catch (const std::exception
&e
)
5577 if ( 0 == extHandle
)
5582 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5583 if ( 0 == handle
->initialized
)
5588 handle
->ERROR_MESSAGE("%s", e
.what());
5592 if ( 0 == extHandle
)
5597 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5598 if ( 0 == handle
->initialized
)
5603 handle
->ERROR_MESSAGE("Unknown exception thrown");
5608 GEOSSTRtree_remove_r(GEOSContextHandle_t extHandle
,
5609 geos::index::strtree::STRtree
*tree
,
5610 const geos::geom::Geometry
*g
,
5616 if ( 0 == extHandle
)
5621 GEOSContextHandleInternal_t
*handle
= 0;
5622 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5623 if ( 0 == handle
->initialized
)
5630 bool result
= tree
->remove(g
->getEnvelopeInternal(), item
);
5633 catch (const std::exception
&e
)
5635 handle
->ERROR_MESSAGE("%s", e
.what());
5639 handle
->ERROR_MESSAGE("Unknown exception thrown");
5646 GEOSSTRtree_destroy_r(GEOSContextHandle_t extHandle
,
5647 geos::index::strtree::STRtree
*tree
)
5649 GEOSContextHandleInternal_t
*handle
= 0;
5655 catch (const std::exception
&e
)
5657 if ( 0 == extHandle
)
5662 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5663 if ( 0 == handle
->initialized
)
5668 handle
->ERROR_MESSAGE("%s", e
.what());
5672 if ( 0 == extHandle
)
5677 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5678 if ( 0 == handle
->initialized
)
5683 handle
->ERROR_MESSAGE("Unknown exception thrown");
5688 GEOSProject_r(GEOSContextHandle_t extHandle
,
5692 if ( 0 == extHandle
) return -1.0;
5693 GEOSContextHandleInternal_t
*handle
=
5694 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5695 if ( handle
->initialized
== 0 ) return -1.0;
5697 const geos::geom::Point
* point
= dynamic_cast<const geos::geom::Point
*>(p
);
5699 handle
->ERROR_MESSAGE("third argument of GEOSProject_r must be Point*");
5703 const geos::geom::Coordinate
* inputPt
= p
->getCoordinate();
5706 return geos::linearref::LengthIndexedLine(g
).project(*inputPt
);
5707 } catch (const std::exception
&e
) {
5708 handle
->ERROR_MESSAGE("%s", e
.what());
5711 handle
->ERROR_MESSAGE("Unknown exception thrown");
5718 GEOSInterpolate_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double d
)
5720 if ( 0 == extHandle
) return 0;
5721 GEOSContextHandleInternal_t
*handle
=
5722 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5723 if ( handle
->initialized
== 0 ) return 0;
5726 geos::linearref::LengthIndexedLine
lil(g
);
5727 geos::geom::Coordinate coord
= lil
.extractPoint(d
);
5728 const GeometryFactory
*gf
= handle
->geomFactory
;
5729 Geometry
* point
= gf
->createPoint(coord
);
5731 } catch (const std::exception
&e
) {
5732 handle
->ERROR_MESSAGE("%s", e
.what());
5735 handle
->ERROR_MESSAGE("Unknown exception thrown");
5742 GEOSProjectNormalized_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
5747 GEOSLength_r(extHandle
, g
, &length
);
5748 return GEOSProject_r(extHandle
, g
, p
) / length
;
5753 GEOSInterpolateNormalized_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
5757 GEOSLength_r(extHandle
, g
, &length
);
5758 return GEOSInterpolate_r(extHandle
, g
, d
* length
);
5762 GEOSGeom_extractUniquePoints_r(GEOSContextHandle_t extHandle
,
5763 const GEOSGeometry
* g
)
5765 if ( 0 == extHandle
) return 0;
5766 GEOSContextHandleInternal_t
*handle
= 0;
5767 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5768 if ( handle
->initialized
== 0 ) return 0;
5770 using namespace geos::geom
;
5771 using namespace geos::util
;
5776 /* 1: extract points */
5777 std::vector
<const Coordinate
*> coords
;
5778 UniqueCoordinateArrayFilter
filter(coords
);
5779 g
->apply_ro(&filter
);
5781 /* 2: for each point, create a geometry and put into a vector */
5782 std::vector
<Geometry
*>* points
= new std::vector
<Geometry
*>();
5783 points
->reserve(coords
.size());
5784 const GeometryFactory
* factory
= g
->getFactory();
5785 for (std::vector
<const Coordinate
*>::iterator it
=coords
.begin(),
5789 Geometry
* point
= factory
->createPoint(*(*it
));
5790 points
->push_back(point
);
5793 /* 3: create a multipoint */
5794 return factory
->createMultiPoint(points
);
5797 catch (const std::exception
&e
)
5799 handle
->ERROR_MESSAGE("%s", e
.what());
5804 handle
->ERROR_MESSAGE("Unknown exception thrown");
5809 int GEOSOrientationIndex_r(GEOSContextHandle_t extHandle
,
5810 double Ax
, double Ay
, double Bx
, double By
, double Px
, double Py
)
5812 GEOSContextHandleInternal_t
*handle
= 0;
5814 using geos::geom::Coordinate
;
5815 using geos::algorithm::CGAlgorithms
;
5817 if ( 0 == extHandle
)
5822 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5823 if ( 0 == handle
->initialized
)
5830 Coordinate
A(Ax
, Ay
);
5831 Coordinate
B(Bx
, By
);
5832 Coordinate
P(Px
, Py
);
5833 return CGAlgorithms::orientationIndex(A
, B
, P
);
5835 catch (const std::exception
&e
)
5837 handle
->ERROR_MESSAGE("%s", e
.what());
5842 handle
->ERROR_MESSAGE("Unknown exception thrown");
5848 GEOSSharedPaths_r(GEOSContextHandle_t extHandle
, const GEOSGeometry
* g1
, const GEOSGeometry
* g2
)
5850 using namespace geos::operation::sharedpaths
;
5852 if ( 0 == extHandle
) return 0;
5853 GEOSContextHandleInternal_t
*handle
=
5854 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5855 if ( handle
->initialized
== 0 ) return 0;
5857 SharedPathsOp::PathList forw
, back
;
5859 SharedPathsOp::sharedPathsOp(*g1
, *g2
, forw
, back
);
5861 catch (const std::exception
&e
)
5863 SharedPathsOp::clearEdges(forw
);
5864 SharedPathsOp::clearEdges(back
);
5865 handle
->ERROR_MESSAGE("%s", e
.what());
5870 SharedPathsOp::clearEdges(forw
);
5871 SharedPathsOp::clearEdges(back
);
5872 handle
->ERROR_MESSAGE("Unknown exception thrown");
5876 // Now forw and back have the geoms we want to use to construct
5877 // our output GeometryCollections...
5879 const GeometryFactory
* factory
= g1
->getFactory();
5882 std::auto_ptr
< std::vector
<Geometry
*> > out1(
5883 new std::vector
<Geometry
*>()
5885 count
= forw
.size();
5886 out1
->reserve(count
);
5887 for (size_t i
=0; i
<count
; ++i
) {
5888 out1
->push_back(forw
[i
]);
5890 std::auto_ptr
<Geometry
> out1g (
5891 factory
->createMultiLineString(out1
.release())
5894 std::auto_ptr
< std::vector
<Geometry
*> > out2(
5895 new std::vector
<Geometry
*>()
5897 count
= back
.size();
5898 out2
->reserve(count
);
5899 for (size_t i
=0; i
<count
; ++i
) {
5900 out2
->push_back(back
[i
]);
5902 std::auto_ptr
<Geometry
> out2g (
5903 factory
->createMultiLineString(out2
.release())
5906 std::auto_ptr
< std::vector
<Geometry
*> > out(
5907 new std::vector
<Geometry
*>()
5910 out
->push_back(out1g
.release());
5911 out
->push_back(out2g
.release());
5913 std::auto_ptr
<Geometry
> outg (
5914 factory
->createGeometryCollection(out
.release())
5917 return outg
.release();
5922 GEOSSnap_r(GEOSContextHandle_t extHandle
, const GEOSGeometry
* g1
,
5923 const GEOSGeometry
* g2
, double tolerance
)
5925 using namespace geos::operation::overlay::snap
;
5927 if ( 0 == extHandle
) return 0;
5928 GEOSContextHandleInternal_t
*handle
=
5929 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5930 if ( handle
->initialized
== 0 ) return 0;
5933 GeometrySnapper
snapper( *g1
);
5934 std::auto_ptr
<Geometry
> ret
= snapper
.snapTo(*g2
, tolerance
);
5935 return ret
.release();
5937 catch (const std::exception
&e
)
5939 handle
->ERROR_MESSAGE("%s", e
.what());
5944 handle
->ERROR_MESSAGE("Unknown exception thrown");
5950 GEOSBufferParams_create_r(GEOSContextHandle_t extHandle
)
5952 if ( 0 == extHandle
) return NULL
;
5954 GEOSContextHandleInternal_t
*handle
= 0;
5955 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5956 if ( 0 == handle
->initialized
) return NULL
;
5960 BufferParameters
*p
= new BufferParameters();
5963 catch (const std::exception
&e
)
5965 handle
->ERROR_MESSAGE("%s", e
.what());
5969 handle
->ERROR_MESSAGE("Unknown exception thrown");
5976 GEOSBufferParams_destroy_r(GEOSContextHandle_t extHandle
, BufferParameters
* p
)
5983 GEOSBufferParams_setEndCapStyle_r(GEOSContextHandle_t extHandle
,
5984 GEOSBufferParams
* p
, int style
)
5986 if ( 0 == extHandle
) return 0;
5988 GEOSContextHandleInternal_t
*handle
= 0;
5989 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5990 if ( 0 == handle
->initialized
) return 0;
5994 if ( style
> BufferParameters::CAP_SQUARE
)
5996 throw IllegalArgumentException("Invalid buffer endCap style");
5998 p
->setEndCapStyle(static_cast<BufferParameters::EndCapStyle
>(style
));
6001 catch (const std::exception
&e
)
6003 handle
->ERROR_MESSAGE("%s", e
.what());
6007 handle
->ERROR_MESSAGE("Unknown exception thrown");
6014 GEOSBufferParams_setJoinStyle_r(GEOSContextHandle_t extHandle
,
6015 GEOSBufferParams
* p
, int style
)
6017 if ( 0 == extHandle
) return 0;
6019 GEOSContextHandleInternal_t
*handle
= 0;
6020 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6021 if ( 0 == handle
->initialized
) return 0;
6025 if ( style
> BufferParameters::JOIN_BEVEL
) {
6026 throw IllegalArgumentException("Invalid buffer join style");
6028 p
->setJoinStyle(static_cast<BufferParameters::JoinStyle
>(style
));
6031 catch (const std::exception
&e
)
6033 handle
->ERROR_MESSAGE("%s", e
.what());
6037 handle
->ERROR_MESSAGE("Unknown exception thrown");
6044 GEOSBufferParams_setMitreLimit_r(GEOSContextHandle_t extHandle
,
6045 GEOSBufferParams
* p
, double limit
)
6047 if ( 0 == extHandle
) return 0;
6049 GEOSContextHandleInternal_t
*handle
= 0;
6050 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6051 if ( 0 == handle
->initialized
) return 0;
6055 p
->setMitreLimit(limit
);
6058 catch (const std::exception
&e
)
6060 handle
->ERROR_MESSAGE("%s", e
.what());
6064 handle
->ERROR_MESSAGE("Unknown exception thrown");
6071 GEOSBufferParams_setQuadrantSegments_r(GEOSContextHandle_t extHandle
,
6072 GEOSBufferParams
* p
, int segs
)
6074 if ( 0 == extHandle
) return 0;
6076 GEOSContextHandleInternal_t
*handle
= 0;
6077 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6078 if ( 0 == handle
->initialized
) return 0;
6082 p
->setQuadrantSegments(segs
);
6085 catch (const std::exception
&e
)
6087 handle
->ERROR_MESSAGE("%s", e
.what());
6091 handle
->ERROR_MESSAGE("Unknown exception thrown");
6098 GEOSBufferParams_setSingleSided_r(GEOSContextHandle_t extHandle
,
6099 GEOSBufferParams
* p
, int ss
)
6101 if ( 0 == extHandle
) return 0;
6103 GEOSContextHandleInternal_t
*handle
= 0;
6104 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6105 if ( 0 == handle
->initialized
) return 0;
6109 p
->setSingleSided( (ss
!= 0) );
6112 catch (const std::exception
&e
)
6114 handle
->ERROR_MESSAGE("%s", e
.what());
6118 handle
->ERROR_MESSAGE("Unknown exception thrown");
6125 GEOSBufferWithParams_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const BufferParameters
* bp
, double width
)
6127 using geos::operation::buffer::BufferOp
;
6129 if ( 0 == extHandle
) return NULL
;
6131 GEOSContextHandleInternal_t
*handle
= 0;
6132 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6133 if ( 0 == handle
->initialized
) return NULL
;
6137 BufferOp
op(g1
, *bp
);
6138 Geometry
*g3
= op
.getResultGeometry(width
);
6141 catch (const std::exception
&e
)
6143 handle
->ERROR_MESSAGE("%s", e
.what());
6147 handle
->ERROR_MESSAGE("Unknown exception thrown");
6154 GEOSDelaunayTriangulation_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double tolerance
, int onlyEdges
)
6156 if ( 0 == extHandle
) return NULL
;
6158 GEOSContextHandleInternal_t
*handle
= 0;
6159 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6160 if ( 0 == handle
->initialized
) return NULL
;
6162 using geos::triangulate::DelaunayTriangulationBuilder
;
6166 DelaunayTriangulationBuilder builder
;
6167 builder
.setTolerance(tolerance
);
6168 builder
.setSites(*g1
);
6170 if ( onlyEdges
) return builder
.getEdges( *g1
->getFactory() ).release();
6171 else return builder
.getTriangles( *g1
->getFactory() ).release();
6174 catch (const std::exception
&e
)
6176 handle
->ERROR_MESSAGE("%s", e
.what());
6180 handle
->ERROR_MESSAGE("Unknown exception thrown");