1 /************************************************************************
4 * C-Wrapper for GEOS library
6 * Copyright (C) 2010 2011 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/operation/valid/IsValidOp.h>
49 #include <geos/operation/polygonize/Polygonizer.h>
50 #include <geos/operation/linemerge/LineMerger.h>
51 #include <geos/operation/overlay/OverlayOp.h>
52 #include <geos/operation/union/CascadedPolygonUnion.h>
53 #include <geos/operation/buffer/BufferOp.h>
54 #include <geos/operation/buffer/BufferParameters.h>
55 #include <geos/operation/buffer/BufferBuilder.h>
56 #include <geos/operation/relate/RelateOp.h>
57 #include <geos/operation/sharedpaths/SharedPathsOp.h>
58 #include <geos/linearref/LengthIndexedLine.h>
59 #include <geos/geom/BinaryOp.h>
60 #include <geos/util/IllegalArgumentException.h>
61 #include <geos/util/UniqueCoordinateArrayFilter.h>
62 #include <geos/util/Machine.h>
63 #include <geos/version.h>
65 // This should go away
66 #include <cmath> // finite
78 #pragma warning(disable : 4099)
81 // Some extra magic to make type declarations in geos_c.h work -
82 // for cross-checking of types in header.
83 #define GEOSGeometry geos::geom::Geometry
84 #define GEOSPreparedGeometry geos::geom::prep::PreparedGeometry
85 #define GEOSCoordSequence geos::geom::CoordinateSequence
86 #define GEOSBufferParams geos::operation::buffer::BufferParameters
87 #define GEOSSTRtree geos::index::strtree::STRtree
88 #define GEOSWKTReader_t geos::io::WKTReader
89 #define GEOSWKTWriter_t geos::io::WKTWriter
90 #define GEOSWKBReader_t geos::io::WKBReader
91 #define GEOSWKBWriter_t geos::io::WKBWriter
95 // Intentional, to allow non-standard C elements like C99 functions to be
96 // imported through C++ headers of C library, like <cmath>.
99 /// Define this if you want operations triggering Exceptions to
101 /// (will use the NOTIFY channel - only implemented for GEOSUnion so far)
103 #undef VERBOSE_EXCEPTIONS
105 #include <geos/export.h>
108 // import the most frequently used definitions globally
109 using geos::geom::Geometry
;
110 using geos::geom::LineString
;
111 using geos::geom::Polygon
;
112 using geos::geom::CoordinateSequence
;
113 using geos::geom::GeometryFactory
;
115 using geos::io::WKTReader
;
116 using geos::io::WKTWriter
;
117 using geos::io::WKBReader
;
118 using geos::io::WKBWriter
;
120 using geos::operation::overlay::OverlayOp
;
121 using geos::operation::overlay::overlayOp
;
122 using geos::operation::geounion::CascadedPolygonUnion
;
123 using geos::operation::buffer::BufferParameters
;
124 using geos::operation::buffer::BufferBuilder
;
125 using geos::util::IllegalArgumentException
;
126 using geos::algorithm::distance::DiscreteHausdorffDistance
;
128 typedef std::auto_ptr
<Geometry
> GeomAutoPtr
;
130 typedef struct GEOSContextHandleInternal
132 const GeometryFactory
*geomFactory
;
133 GEOSMessageHandler NOTICE_MESSAGE
;
134 GEOSMessageHandler ERROR_MESSAGE
;
138 } GEOSContextHandleInternal_t
;
140 // CAPI_ItemVisitor is used internally by the CAPI STRtree
141 // wrappers. It's defined here just to keep it out of the
143 class CAPI_ItemVisitor
: public geos::index::ItemVisitor
{
144 GEOSQueryCallback callback
;
147 CAPI_ItemVisitor (GEOSQueryCallback cb
, void *ud
)
148 : ItemVisitor(), callback(cb
), userdata(ud
) {}
149 void visitItem (void *item
) { callback(item
, userdata
); }
153 //## PROTOTYPES #############################################
155 extern "C" const char GEOS_DLL
*GEOSjtsport();
156 extern "C" char GEOS_DLL
*GEOSasText(Geometry
*g1
);
158 namespace { // anonymous
160 char* gstrdup_s(const char* str
, const std::size_t size
)
162 char* out
= static_cast<char*>(std::malloc(size
+ 1));
165 // as no strlen call necessary, memcpy may be faster than strcpy
166 std::memcpy(out
, str
, size
+ 1);
171 // we haven't been checking allocation before ticket #371
174 throw(std::runtime_error("Failed to allocate memory for duplicate string"));
180 char* gstrdup(std::string
const& str
)
182 return gstrdup_s(str
.c_str(), str
.size());
185 } // namespace anonymous
190 initGEOS_r(GEOSMessageHandler nf
, GEOSMessageHandler ef
)
192 GEOSContextHandleInternal_t
*handle
= 0;
195 extHandle
= std::malloc(sizeof(GEOSContextHandleInternal_t
));
198 handle
= static_cast<GEOSContextHandleInternal_t
*>(extHandle
);
199 handle
->NOTICE_MESSAGE
= nf
;
200 handle
->ERROR_MESSAGE
= ef
;
201 handle
->geomFactory
= GeometryFactory::getDefaultInstance();
202 handle
->WKBOutputDims
= 2;
203 handle
->WKBByteOrder
= getMachineByteOrder();
204 handle
->initialized
= 1;
207 return static_cast<GEOSContextHandle_t
>(extHandle
);
211 GEOSContext_setNoticeHandler_r(GEOSContextHandle_t extHandle
, GEOSMessageHandler nf
)
213 GEOSMessageHandler f
;
214 GEOSContextHandleInternal_t
*handle
= 0;
215 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
216 if ( 0 == handle
->initialized
)
221 f
= handle
->NOTICE_MESSAGE
;
222 handle
->NOTICE_MESSAGE
= nf
;
228 GEOSContext_setErrorHandler_r(GEOSContextHandle_t extHandle
, GEOSMessageHandler nf
)
230 GEOSMessageHandler f
;
231 GEOSContextHandleInternal_t
*handle
= 0;
232 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
233 if ( 0 == handle
->initialized
)
238 f
= handle
->ERROR_MESSAGE
;
239 handle
->ERROR_MESSAGE
= nf
;
245 finishGEOS_r(GEOSContextHandle_t extHandle
)
247 // Fix up freeing handle w.r.t. malloc above
248 std::free(extHandle
);
253 GEOSFree_r (GEOSContextHandle_t extHandle
, void* buffer
)
255 assert(0 != extHandle
);
260 //-----------------------------------------------------------
261 // relate()-related functions
262 // return 0 = false, 1 = true, 2 = error occured
263 //-----------------------------------------------------------
266 GEOSDisjoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
268 if ( 0 == extHandle
)
273 GEOSContextHandleInternal_t
*handle
= 0;
274 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
275 if ( handle
->initialized
== 0 )
282 bool result
= g1
->disjoint(g2
);
286 // TODO: mloskot is going to replace these double-catch block
287 // with a macro to remove redundant code in this and
288 // following functions.
289 catch (const std::exception
&e
)
291 handle
->ERROR_MESSAGE("%s", e
.what());
295 handle
->ERROR_MESSAGE("Unknown exception thrown");
302 GEOSTouches_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
304 if ( 0 == extHandle
)
309 GEOSContextHandleInternal_t
*handle
= 0;
310 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
311 if ( 0 == handle
->initialized
)
318 bool result
= g1
->touches(g2
);
321 catch (const std::exception
&e
)
323 handle
->ERROR_MESSAGE("%s", e
.what());
327 handle
->ERROR_MESSAGE("Unknown exception thrown");
334 GEOSIntersects_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
336 if ( 0 == extHandle
)
341 GEOSContextHandleInternal_t
*handle
= 0;
342 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
343 if ( 0 == handle
->initialized
)
350 bool result
= g1
->intersects(g2
);
353 catch (const std::exception
&e
)
355 handle
->ERROR_MESSAGE("%s", e
.what());
359 handle
->ERROR_MESSAGE("Unknown exception thrown");
366 GEOSCrosses_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
368 if ( 0 == extHandle
)
373 GEOSContextHandleInternal_t
*handle
= 0;
374 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
375 if ( 0 == handle
->initialized
)
382 bool result
= g1
->crosses(g2
);
385 catch (const std::exception
&e
)
387 handle
->ERROR_MESSAGE("%s", e
.what());
391 handle
->ERROR_MESSAGE("Unknown exception thrown");
398 GEOSWithin_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
400 if ( 0 == extHandle
)
405 GEOSContextHandleInternal_t
*handle
= 0;
406 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
407 if ( 0 == handle
->initialized
)
414 bool result
= g1
->within(g2
);
417 catch (const std::exception
&e
)
419 handle
->ERROR_MESSAGE("%s", e
.what());
423 handle
->ERROR_MESSAGE("Unknown exception thrown");
429 // call g1->contains(g2)
432 // 2 = error was trapped
434 GEOSContains_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
436 if ( 0 == extHandle
)
441 GEOSContextHandleInternal_t
*handle
= 0;
442 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
443 if ( 0 == handle
->initialized
)
450 bool result
= g1
->contains(g2
);
453 catch (const std::exception
&e
)
455 handle
->ERROR_MESSAGE("%s", e
.what());
459 handle
->ERROR_MESSAGE("Unknown exception thrown");
466 GEOSOverlaps_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
468 if ( 0 == extHandle
)
473 GEOSContextHandleInternal_t
*handle
= 0;
474 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
475 if ( 0 == handle
->initialized
)
482 bool result
= g1
->overlaps(g2
);
485 catch (const std::exception
&e
)
487 handle
->ERROR_MESSAGE("%s", e
.what());
491 handle
->ERROR_MESSAGE("Unknown exception thrown");
498 GEOSCovers_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
500 if ( 0 == extHandle
)
505 GEOSContextHandleInternal_t
*handle
= 0;
506 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
507 if ( 0 == handle
->initialized
)
514 bool result
= g1
->covers(g2
);
517 catch (const std::exception
&e
)
519 handle
->ERROR_MESSAGE("%s", e
.what());
523 handle
->ERROR_MESSAGE("Unknown exception thrown");
530 GEOSCoveredBy_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
532 if ( 0 == extHandle
)
537 GEOSContextHandleInternal_t
*handle
= 0;
538 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
539 if ( 0 == handle
->initialized
)
546 bool result
= g1
->coveredBy(g2
);
549 catch (const std::exception
&e
)
551 handle
->ERROR_MESSAGE("%s", e
.what());
555 handle
->ERROR_MESSAGE("Unknown exception thrown");
562 //-------------------------------------------------------------------
563 // low-level relate functions
564 //------------------------------------------------------------------
567 GEOSRelatePattern_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, const char *pat
)
569 if ( 0 == extHandle
)
574 GEOSContextHandleInternal_t
*handle
= 0;
575 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
576 if ( 0 == handle
->initialized
)
584 bool result
= g1
->relate(g2
, s
);
587 catch (const std::exception
&e
)
589 handle
->ERROR_MESSAGE("%s", e
.what());
593 handle
->ERROR_MESSAGE("Unknown exception thrown");
600 GEOSRelatePatternMatch_r(GEOSContextHandle_t extHandle
, const char *mat
,
603 if ( 0 == extHandle
)
608 GEOSContextHandleInternal_t
*handle
= 0;
609 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
610 if ( 0 == handle
->initialized
)
617 using geos::geom::IntersectionMatrix
;
621 IntersectionMatrix
im(m
);
623 bool result
= im
.matches(p
);
626 catch (const std::exception
&e
)
628 handle
->ERROR_MESSAGE("%s", e
.what());
632 handle
->ERROR_MESSAGE("Unknown exception thrown");
639 GEOSRelate_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
641 if ( 0 == extHandle
)
646 GEOSContextHandleInternal_t
*handle
= 0;
647 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
648 if ( 0 == handle
->initialized
)
655 using geos::geom::IntersectionMatrix
;
657 IntersectionMatrix
* im
= g1
->relate(g2
);
663 char *result
= gstrdup(im
->toString());
670 catch (const std::exception
&e
)
672 handle
->ERROR_MESSAGE("%s", e
.what());
676 handle
->ERROR_MESSAGE("Unknown exception thrown");
683 GEOSRelateBoundaryNodeRule_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, int bnr
)
685 if ( 0 == extHandle
)
690 GEOSContextHandleInternal_t
*handle
= 0;
691 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
692 if ( 0 == handle
->initialized
)
699 using geos::operation::relate::RelateOp
;
700 using geos::geom::IntersectionMatrix
;
701 using geos::algorithm::BoundaryNodeRule
;
703 IntersectionMatrix
* im
;
705 case GEOSRELATE_BNR_MOD2
: /* same as OGC */
706 im
= RelateOp::relate(g1
, g2
,
707 BoundaryNodeRule::MOD2_BOUNDARY_RULE
);
709 case GEOSRELATE_BNR_ENDPOINT
:
710 im
= RelateOp::relate(g1
, g2
,
711 BoundaryNodeRule::ENDPOINT_BOUNDARY_RULE
);
713 case GEOSRELATE_BNR_MULTIVALENT_ENDPOINT
:
714 im
= RelateOp::relate(g1
, g2
,
715 BoundaryNodeRule::MULTIVALENT_ENDPOINT_BOUNDARY_RULE
);
717 case GEOSRELATE_BNR_MONOVALENT_ENDPOINT
:
718 im
= RelateOp::relate(g1
, g2
,
719 BoundaryNodeRule::MONOVALENT_ENDPOINT_BOUNDARY_RULE
);
722 handle
->ERROR_MESSAGE("Invalid boundary node rule %d", bnr
);
727 if (0 == im
) return 0;
729 char *result
= gstrdup(im
->toString());
736 catch (const std::exception
&e
)
738 handle
->ERROR_MESSAGE("%s", e
.what());
742 handle
->ERROR_MESSAGE("Unknown exception thrown");
750 //-----------------------------------------------------------------
752 //-----------------------------------------------------------------
756 GEOSisValid_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
758 if ( 0 == extHandle
)
763 GEOSContextHandleInternal_t
*handle
= 0;
764 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
765 if ( 0 == handle
->initialized
)
772 using geos::operation::valid::IsValidOp
;
773 using geos::operation::valid::TopologyValidationError
;
776 TopologyValidationError
*err
= ivo
.getValidationError();
779 handle
->NOTICE_MESSAGE("%s", err
->toString().c_str());
787 catch (const std::exception
&e
)
789 handle
->ERROR_MESSAGE("%s", e
.what());
793 handle
->ERROR_MESSAGE("Unknown exception thrown");
800 GEOSisValidReason_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
802 if ( 0 == extHandle
)
807 GEOSContextHandleInternal_t
*handle
= 0;
808 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
809 if ( 0 == handle
->initialized
)
816 using geos::operation::valid::IsValidOp
;
817 using geos::operation::valid::TopologyValidationError
;
820 char const* const validstr
= "Valid Geometry";
823 TopologyValidationError
*err
= ivo
.getValidationError();
826 std::ostringstream ss
;
828 ss
<< err
->getCoordinate();
829 const std::string errloc
= ss
.str();
830 std::string
errmsg(err
->getMessage());
831 errmsg
+= "[" + errloc
+ "]";
832 result
= gstrdup(errmsg
);
836 result
= gstrdup(std::string(validstr
));
841 catch (const std::exception
&e
)
843 handle
->ERROR_MESSAGE("%s", e
.what());
847 handle
->ERROR_MESSAGE("Unknown exception thrown");
854 GEOSisValidDetail_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
855 int flags
, char** reason
, Geometry
** location
)
857 if ( 0 == extHandle
)
862 GEOSContextHandleInternal_t
*handle
= 0;
863 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
864 if ( 0 == handle
->initialized
)
871 using geos::operation::valid::IsValidOp
;
872 using geos::operation::valid::TopologyValidationError
;
875 if ( flags
& GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE
) {
876 ivo
.setSelfTouchingRingFormingHoleValid(true);
878 TopologyValidationError
*err
= ivo
.getValidationError();
882 *location
= handle
->geomFactory
->createPoint(err
->getCoordinate());
885 std::string
errmsg(err
->getMessage());
886 *reason
= gstrdup(errmsg
);
891 if ( location
) *location
= 0;
892 if ( reason
) *reason
= 0;
893 return 1; /* valid */
896 catch (const std::exception
&e
)
898 handle
->ERROR_MESSAGE("%s", e
.what());
902 handle
->ERROR_MESSAGE("Unknown exception thrown");
905 return 2; /* exception */
908 //-----------------------------------------------------------------
910 //-----------------------------------------------------------------
913 GEOSEquals_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
915 if ( 0 == extHandle
)
920 GEOSContextHandleInternal_t
*handle
= 0;
921 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
922 if ( 0 == handle
->initialized
)
929 bool result
= g1
->equals(g2
);
932 catch (const std::exception
&e
)
934 handle
->ERROR_MESSAGE("%s", e
.what());
938 handle
->ERROR_MESSAGE("Unknown exception thrown");
945 GEOSEqualsExact_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double tolerance
)
947 if ( 0 == extHandle
)
952 GEOSContextHandleInternal_t
*handle
= 0;
953 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
954 if ( 0 == handle
->initialized
)
961 bool result
= g1
->equalsExact(g2
, tolerance
);
964 catch (const std::exception
&e
)
966 handle
->ERROR_MESSAGE("%s", e
.what());
970 handle
->ERROR_MESSAGE("Unknown exception thrown");
977 GEOSDistance_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double *dist
)
981 if ( 0 == extHandle
)
986 GEOSContextHandleInternal_t
*handle
= 0;
987 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
988 if ( 0 == handle
->initialized
)
995 *dist
= g1
->distance(g2
);
998 catch (const std::exception
&e
)
1000 handle
->ERROR_MESSAGE("%s", e
.what());
1004 handle
->ERROR_MESSAGE("Unknown exception thrown");
1011 GEOSHausdorffDistance_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double *dist
)
1015 if ( 0 == extHandle
)
1020 GEOSContextHandleInternal_t
*handle
= 0;
1021 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1022 if ( 0 == handle
->initialized
)
1029 *dist
= DiscreteHausdorffDistance::distance(*g1
, *g2
);
1032 catch (const std::exception
&e
)
1034 handle
->ERROR_MESSAGE("%s", e
.what());
1038 handle
->ERROR_MESSAGE("Unknown exception thrown");
1045 GEOSHausdorffDistanceDensify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double densifyFrac
, double *dist
)
1049 if ( 0 == extHandle
)
1054 GEOSContextHandleInternal_t
*handle
= 0;
1055 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1056 if ( 0 == handle
->initialized
)
1063 *dist
= DiscreteHausdorffDistance::distance(*g1
, *g2
, densifyFrac
);
1066 catch (const std::exception
&e
)
1068 handle
->ERROR_MESSAGE("%s", e
.what());
1072 handle
->ERROR_MESSAGE("Unknown exception thrown");
1079 GEOSArea_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double *area
)
1083 if ( 0 == extHandle
)
1088 GEOSContextHandleInternal_t
*handle
= 0;
1089 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1090 if ( 0 == handle
->initialized
)
1097 *area
= g
->getArea();
1100 catch (const std::exception
&e
)
1102 handle
->ERROR_MESSAGE("%s", e
.what());
1106 handle
->ERROR_MESSAGE("Unknown exception thrown");
1113 GEOSLength_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double *length
)
1115 assert(0 != length
);
1117 if ( 0 == extHandle
)
1122 GEOSContextHandleInternal_t
*handle
= 0;
1123 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1124 if ( 0 == handle
->initialized
)
1131 *length
= g
->getLength();
1134 catch (const std::exception
&e
)
1136 handle
->ERROR_MESSAGE("%s", e
.what());
1140 handle
->ERROR_MESSAGE("Unknown exception thrown");
1147 GEOSGeomFromWKT_r(GEOSContextHandle_t extHandle
, const char *wkt
)
1149 if ( 0 == extHandle
)
1154 GEOSContextHandleInternal_t
*handle
= 0;
1155 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1156 if ( 0 == handle
->initialized
)
1163 const std::string
wktstring(wkt
);
1164 WKTReader
r(static_cast<GeometryFactory
const*>(handle
->geomFactory
));
1166 Geometry
*g
= r
.read(wktstring
);
1169 catch (const std::exception
&e
)
1171 handle
->ERROR_MESSAGE("%s", e
.what());
1175 handle
->ERROR_MESSAGE("Unknown exception thrown");
1182 GEOSGeomToWKT_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1184 if ( 0 == extHandle
)
1189 GEOSContextHandleInternal_t
*handle
= 0;
1190 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1191 if ( 0 == handle
->initialized
)
1199 char *result
= gstrdup(g1
->toString());
1202 catch (const std::exception
&e
)
1204 handle
->ERROR_MESSAGE("%s", e
.what());
1208 handle
->ERROR_MESSAGE("Unknown exception thrown");
1213 // Remember to free the result!
1215 GEOSGeomToWKB_buf_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, size_t *size
)
1219 if ( 0 == extHandle
)
1224 GEOSContextHandleInternal_t
*handle
= 0;
1225 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1226 if ( 0 == handle
->initialized
)
1231 using geos::io::WKBWriter
;
1234 int byteOrder
= handle
->WKBByteOrder
;
1235 WKBWriter
w(handle
->WKBOutputDims
, byteOrder
);
1236 std::ostringstream
os(std::ios_base::binary
);
1238 std::string
wkbstring(os
.str());
1239 const std::size_t len
= wkbstring
.length();
1241 unsigned char* result
= 0;
1242 result
= static_cast<unsigned char*>(std::malloc(len
));
1245 std::memcpy(result
, wkbstring
.c_str(), len
);
1250 catch (const std::exception
&e
)
1252 handle
->ERROR_MESSAGE("%s", e
.what());
1256 handle
->ERROR_MESSAGE("Unknown exception thrown");
1263 GEOSGeomFromWKB_buf_r(GEOSContextHandle_t extHandle
, const unsigned char *wkb
, size_t size
)
1265 if ( 0 == extHandle
)
1270 GEOSContextHandleInternal_t
*handle
= 0;
1271 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1272 if ( 0 == handle
->initialized
)
1277 using geos::io::WKBReader
;
1280 std::string
wkbstring(reinterpret_cast<const char*>(wkb
), size
); // make it binary !
1281 WKBReader
r(*(static_cast<GeometryFactory
const*>(handle
->geomFactory
)));
1282 std::istringstream
is(std::ios_base::binary
);
1284 is
.seekg(0, std::ios::beg
); // rewind reader pointer
1285 Geometry
*g
= r
.read(is
);
1288 catch (const std::exception
&e
)
1290 handle
->ERROR_MESSAGE("%s", e
.what());
1294 handle
->ERROR_MESSAGE("Unknown exception thrown");
1300 /* Read/write wkb hex values. Returned geometries are
1301 owned by the caller.*/
1303 GEOSGeomToHEX_buf_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, size_t *size
)
1305 if ( 0 == extHandle
)
1310 GEOSContextHandleInternal_t
*handle
= 0;
1311 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1312 if ( 0 == handle
->initialized
)
1317 using geos::io::WKBWriter
;
1320 int byteOrder
= handle
->WKBByteOrder
;
1321 WKBWriter
w(handle
->WKBOutputDims
, byteOrder
);
1322 std::ostringstream
os(std::ios_base::binary
);
1324 std::string
hexstring(os
.str());
1326 char *result
= gstrdup(hexstring
);
1329 *size
= hexstring
.length();
1332 return reinterpret_cast<unsigned char*>(result
);
1334 catch (const std::exception
&e
)
1336 handle
->ERROR_MESSAGE("%s", e
.what());
1340 handle
->ERROR_MESSAGE("Unknown exception thrown");
1347 GEOSGeomFromHEX_buf_r(GEOSContextHandle_t extHandle
, const unsigned char *hex
, size_t size
)
1349 if ( 0 == extHandle
)
1354 GEOSContextHandleInternal_t
*handle
= 0;
1355 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1356 if ( 0 == handle
->initialized
)
1361 using geos::io::WKBReader
;
1364 std::string
hexstring(reinterpret_cast<const char*>(hex
), size
);
1365 WKBReader
r(*(static_cast<GeometryFactory
const*>(handle
->geomFactory
)));
1366 std::istringstream
is(std::ios_base::binary
);
1368 is
.seekg(0, std::ios::beg
); // rewind reader pointer
1370 Geometry
*g
= r
.readHEX(is
);
1373 catch (const std::exception
&e
)
1375 handle
->ERROR_MESSAGE("%s", e
.what());
1379 handle
->ERROR_MESSAGE("Unknown exception thrown");
1386 GEOSisEmpty_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1388 if ( 0 == extHandle
)
1393 GEOSContextHandleInternal_t
*handle
= 0;
1394 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1395 if ( 0 == handle
->initialized
)
1402 return g1
->isEmpty();
1404 catch (const std::exception
&e
)
1406 handle
->ERROR_MESSAGE("%s", e
.what());
1410 handle
->ERROR_MESSAGE("Unknown exception thrown");
1417 GEOSisSimple_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1419 if ( 0 == extHandle
)
1424 GEOSContextHandleInternal_t
*handle
= 0;
1425 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1426 if ( 0 == handle
->initialized
)
1433 return g1
->isSimple();
1435 catch (const std::exception
&e
)
1437 handle
->ERROR_MESSAGE("%s", e
.what());
1443 handle
->ERROR_MESSAGE("Unknown exception thrown");
1449 GEOSisRing_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
1451 if ( 0 == extHandle
)
1456 GEOSContextHandleInternal_t
*handle
= 0;
1457 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1458 if ( 0 == handle
->initialized
)
1465 const LineString
*ls
= dynamic_cast<const LineString
*>(g
);
1467 return (ls
->isRing());
1472 catch (const std::exception
&e
)
1474 handle
->ERROR_MESSAGE("%s", e
.what());
1480 handle
->ERROR_MESSAGE("Unknown exception thrown");
1487 //free the result of this
1489 GEOSGeomType_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1491 if ( 0 == extHandle
)
1496 GEOSContextHandleInternal_t
*handle
= 0;
1497 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1498 if ( 0 == handle
->initialized
)
1505 std::string s
= g1
->getGeometryType();
1507 char *result
= gstrdup(s
);
1510 catch (const std::exception
&e
)
1512 handle
->ERROR_MESSAGE("%s", e
.what());
1516 handle
->ERROR_MESSAGE("Unknown exception thrown");
1522 // Return postgis geometry type index
1524 GEOSGeomTypeId_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1526 if ( 0 == extHandle
)
1531 GEOSContextHandleInternal_t
*handle
= 0;
1532 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1533 if ( 0 == handle
->initialized
)
1540 return g1
->getGeometryTypeId();
1542 catch (const std::exception
&e
)
1544 handle
->ERROR_MESSAGE("%s", e
.what());
1548 handle
->ERROR_MESSAGE("Unknown exception thrown");
1554 //-------------------------------------------------------------------
1555 // GEOS functions that return geometries
1556 //-------------------------------------------------------------------
1559 GEOSEnvelope_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1561 if ( 0 == extHandle
)
1566 GEOSContextHandleInternal_t
*handle
= 0;
1567 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1568 if ( 0 == handle
->initialized
)
1575 Geometry
*g3
= g1
->getEnvelope();
1578 catch (const std::exception
&e
)
1580 handle
->ERROR_MESSAGE("%s", e
.what());
1584 handle
->ERROR_MESSAGE("Unknown exception thrown");
1591 GEOSIntersection_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1593 if ( 0 == extHandle
)
1598 GEOSContextHandleInternal_t
*handle
= 0;
1599 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1600 if ( 0 == handle
->initialized
)
1607 GeomAutoPtr
g3(BinaryOp(g1
, g2
, overlayOp(OverlayOp::opINTERSECTION
)));
1608 return g3
.release();
1611 //Geometry *g3 = g1->intersection(g2);
1614 catch (const std::exception
&e
)
1616 handle
->ERROR_MESSAGE("%s", e
.what());
1620 handle
->ERROR_MESSAGE("Unknown exception thrown");
1627 GEOSBuffer_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadrantsegments
)
1629 if ( 0 == extHandle
)
1634 GEOSContextHandleInternal_t
*handle
= 0;
1635 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1636 if ( 0 == handle
->initialized
)
1643 Geometry
*g3
= g1
->buffer(width
, quadrantsegments
);
1646 catch (const std::exception
&e
)
1648 handle
->ERROR_MESSAGE("%s", e
.what());
1652 handle
->ERROR_MESSAGE("Unknown exception thrown");
1659 GEOSBufferWithStyle_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int endCapStyle
, int joinStyle
, double mitreLimit
)
1661 using geos::operation::buffer::BufferParameters
;
1662 using geos::operation::buffer::BufferOp
;
1663 using geos::util::IllegalArgumentException
;
1665 if ( 0 == extHandle
)
1670 GEOSContextHandleInternal_t
*handle
= 0;
1671 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1672 if ( 0 == handle
->initialized
)
1679 BufferParameters bp
;
1680 bp
.setQuadrantSegments(quadsegs
);
1682 if ( endCapStyle
> BufferParameters::CAP_SQUARE
)
1684 throw IllegalArgumentException("Invalid buffer endCap style");
1687 static_cast<BufferParameters::EndCapStyle
>(endCapStyle
)
1690 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1692 throw IllegalArgumentException("Invalid buffer join style");
1695 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1697 bp
.setMitreLimit(mitreLimit
);
1698 BufferOp
op(g1
, bp
);
1699 Geometry
*g3
= op
.getResultGeometry(width
);
1702 catch (const std::exception
&e
)
1704 handle
->ERROR_MESSAGE("%s", e
.what());
1708 handle
->ERROR_MESSAGE("Unknown exception thrown");
1715 GEOSOffsetCurve_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int joinStyle
, double mitreLimit
)
1717 if ( 0 == extHandle
) return NULL
;
1719 GEOSContextHandleInternal_t
*handle
= 0;
1720 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1721 if ( 0 == handle
->initialized
) return NULL
;
1725 BufferParameters bp
;
1726 bp
.setEndCapStyle( BufferParameters::CAP_FLAT
);
1727 bp
.setQuadrantSegments(quadsegs
);
1729 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1731 throw IllegalArgumentException("Invalid buffer join style");
1734 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1736 bp
.setMitreLimit(mitreLimit
);
1738 bool isLeftSide
= true;
1743 BufferBuilder
bufBuilder (bp
);
1744 Geometry
*g3
= bufBuilder
.bufferLineSingleSided(g1
, width
, isLeftSide
);
1748 catch (const std::exception
&e
)
1750 handle
->ERROR_MESSAGE("%s", e
.what());
1754 handle
->ERROR_MESSAGE("Unknown exception thrown");
1760 /* @deprecated in 3.3.0 */
1762 GEOSSingleSidedBuffer_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int joinStyle
, double mitreLimit
, int leftSide
)
1764 if ( 0 == extHandle
) return NULL
;
1766 GEOSContextHandleInternal_t
*handle
= 0;
1767 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1768 if ( 0 == handle
->initialized
) return NULL
;
1772 BufferParameters bp
;
1773 bp
.setEndCapStyle( BufferParameters::CAP_FLAT
);
1774 bp
.setQuadrantSegments(quadsegs
);
1776 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1778 throw IllegalArgumentException("Invalid buffer join style");
1781 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1783 bp
.setMitreLimit(mitreLimit
);
1785 bool isLeftSide
= leftSide
== 0 ? false : true;
1786 BufferBuilder
bufBuilder (bp
);
1787 Geometry
*g3
= bufBuilder
.bufferLineSingleSided(g1
, width
, isLeftSide
);
1791 catch (const std::exception
&e
)
1793 handle
->ERROR_MESSAGE("%s", e
.what());
1797 handle
->ERROR_MESSAGE("Unknown exception thrown");
1804 GEOSConvexHull_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1806 if ( 0 == extHandle
)
1811 GEOSContextHandleInternal_t
*handle
= 0;
1812 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1813 if ( 0 == handle
->initialized
)
1820 Geometry
*g3
= g1
->convexHull();
1823 catch (const std::exception
&e
)
1825 handle
->ERROR_MESSAGE("%s", e
.what());
1829 handle
->ERROR_MESSAGE("Unknown exception thrown");
1836 GEOSDifference_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1838 if ( 0 == extHandle
)
1843 GEOSContextHandleInternal_t
*handle
= 0;
1844 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1845 if ( 0 == handle
->initialized
)
1852 GeomAutoPtr
g3(BinaryOp(g1
, g2
, overlayOp(OverlayOp::opDIFFERENCE
)));
1853 return g3
.release();
1856 //Geometry *g3 = g1->difference(g2);
1859 catch (const std::exception
&e
)
1861 handle
->ERROR_MESSAGE("%s", e
.what());
1865 handle
->ERROR_MESSAGE("Unknown exception thrown");
1872 GEOSBoundary_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1874 if ( 0 == extHandle
)
1879 GEOSContextHandleInternal_t
*handle
= 0;
1880 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1881 if ( 0 == handle
->initialized
)
1888 Geometry
*g3
= g1
->getBoundary();
1891 catch (const std::exception
&e
)
1893 handle
->ERROR_MESSAGE("%s", e
.what());
1897 handle
->ERROR_MESSAGE("Unknown exception thrown");
1904 GEOSSymDifference_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1906 if ( 0 == extHandle
)
1911 GEOSContextHandleInternal_t
*handle
= 0;
1912 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1913 if ( 0 == handle
->initialized
)
1920 GeomAutoPtr g3
= BinaryOp(g1
, g2
, overlayOp(OverlayOp::opSYMDIFFERENCE
));
1921 return g3
.release();
1922 //Geometry *g3 = g1->symDifference(g2);
1925 catch (const std::exception
&e
)
1927 handle
->ERROR_MESSAGE("%s", e
.what());
1933 handle
->ERROR_MESSAGE("Unknown exception thrown");
1939 GEOSUnion_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1941 if ( 0 == extHandle
)
1946 GEOSContextHandleInternal_t
*handle
= 0;
1947 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1948 if ( 0 == handle
->initialized
)
1955 GeomAutoPtr g3
= BinaryOp(g1
, g2
, overlayOp(OverlayOp::opUNION
));
1956 return g3
.release();
1959 //Geometry *g3 = g1->Union(g2);
1962 catch (const std::exception
&e
)
1964 #if VERBOSE_EXCEPTIONS
1965 std::ostringstream s
;
1966 s
<< "Exception on GEOSUnion with following inputs:" << std::endl
;
1967 s
<< "A: "<<g1
->toString() << std::endl
;
1968 s
<< "B: "<<g2
->toString() << std::endl
;
1969 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
1970 #endif // VERBOSE_EXCEPTIONS
1971 handle
->ERROR_MESSAGE("%s", e
.what());
1975 handle
->ERROR_MESSAGE("Unknown exception thrown");
1982 GEOSUnaryUnion_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
1984 if ( 0 == extHandle
)
1989 GEOSContextHandleInternal_t
*handle
= 0;
1990 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1991 if ( 0 == handle
->initialized
)
1998 GeomAutoPtr
g3 ( g
->Union() );
1999 return g3
.release();
2001 catch (const std::exception
&e
)
2003 #if VERBOSE_EXCEPTIONS
2004 std::ostringstream s
;
2005 s
<< "Exception on GEOSUnaryUnion with following inputs:" << std::endl
;
2006 s
<< "A: "<<g1
->toString() << std::endl
;
2007 s
<< "B: "<<g2
->toString() << std::endl
;
2008 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
2009 #endif // VERBOSE_EXCEPTIONS
2010 handle
->ERROR_MESSAGE("%s", e
.what());
2014 handle
->ERROR_MESSAGE("Unknown exception thrown");
2021 GEOSUnionCascaded_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2023 if ( 0 == extHandle
)
2028 GEOSContextHandleInternal_t
*handle
= 0;
2029 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2030 if ( 0 == handle
->initialized
)
2037 const geos::geom::MultiPolygon
*p
= dynamic_cast<const geos::geom::MultiPolygon
*>(g1
);
2040 handle
->ERROR_MESSAGE("Invalid argument (must be a MultiPolygon)");
2044 using geos::operation::geounion::CascadedPolygonUnion
;
2045 return CascadedPolygonUnion::Union(p
);
2047 catch (const std::exception
&e
)
2049 handle
->ERROR_MESSAGE("%s", e
.what());
2053 handle
->ERROR_MESSAGE("Unknown exception thrown");
2060 GEOSPointOnSurface_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2062 if ( 0 == extHandle
)
2067 GEOSContextHandleInternal_t
*handle
= 0;
2068 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2069 if ( 0 == handle
->initialized
)
2076 Geometry
*ret
= g1
->getInteriorPoint();
2079 const GeometryFactory
* gf
= handle
->geomFactory
;
2080 // return an empty collection
2081 return gf
->createGeometryCollection();
2085 catch (const std::exception
&e
)
2087 handle
->ERROR_MESSAGE("%s", e
.what());
2091 handle
->ERROR_MESSAGE("Unknown exception thrown");
2097 //-------------------------------------------------------------------
2098 // memory management functions
2099 //------------------------------------------------------------------
2102 GEOSGeom_destroy_r(GEOSContextHandle_t extHandle
, Geometry
*a
)
2104 GEOSContextHandleInternal_t
*handle
= 0;
2106 // FIXME: mloskot: Does this try-catch around delete means that
2107 // destructors in GEOS may throw? If it does, this is a serious
2108 // violation of "never throw an exception from a destructor" principle
2114 catch (const std::exception
&e
)
2116 if ( 0 == extHandle
)
2121 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2122 if ( 0 == handle
->initialized
)
2127 handle
->ERROR_MESSAGE("%s", e
.what());
2131 if ( 0 == extHandle
)
2136 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2137 if ( 0 == handle
->initialized
)
2142 handle
->ERROR_MESSAGE("Unknown exception thrown");
2147 GEOSSetSRID_r(GEOSContextHandle_t extHandle
, Geometry
*g
, int srid
)
2151 if ( 0 == extHandle
)
2156 GEOSContextHandleInternal_t
*handle
= 0;
2157 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2158 if ( 0 == handle
->initialized
)
2168 GEOSGetNumCoordinates_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2172 if ( 0 == extHandle
)
2177 GEOSContextHandleInternal_t
*handle
= 0;
2178 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2179 if ( 0 == handle
->initialized
)
2186 return static_cast<int>(g
->getNumPoints());
2188 catch (const std::exception
&e
)
2190 handle
->ERROR_MESSAGE("%s", e
.what());
2194 handle
->ERROR_MESSAGE("Unknown exception thrown");
2201 * Return -1 on exception, 0 otherwise.
2202 * Converts Geometry to normal form (or canonical form).
2205 GEOSNormalize_r(GEOSContextHandle_t extHandle
, Geometry
*g
)
2209 if ( 0 == extHandle
)
2214 GEOSContextHandleInternal_t
*handle
= 0;
2215 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2216 if ( 0 == handle
->initialized
)
2224 return 0; // SUCCESS
2226 catch (const std::exception
&e
)
2228 handle
->ERROR_MESSAGE("%s", e
.what());
2232 handle
->ERROR_MESSAGE("Unknown exception thrown");
2239 GEOSGetNumInteriorRings_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2241 if ( 0 == extHandle
)
2246 GEOSContextHandleInternal_t
*handle
= 0;
2247 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2248 if ( 0 == handle
->initialized
)
2255 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
2258 handle
->ERROR_MESSAGE("Argument is not a Polygon");
2261 return static_cast<int>(p
->getNumInteriorRing());
2263 catch (const std::exception
&e
)
2265 handle
->ERROR_MESSAGE("%s", e
.what());
2269 handle
->ERROR_MESSAGE("Unknown exception thrown");
2276 // returns -1 on error and 1 for non-multi geometries
2278 GEOSGetNumGeometries_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2280 if ( 0 == extHandle
)
2285 GEOSContextHandleInternal_t
*handle
= 0;
2286 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2287 if ( 0 == handle
->initialized
)
2294 return static_cast<int>(g1
->getNumGeometries());
2296 catch (const std::exception
&e
)
2298 handle
->ERROR_MESSAGE("%s", e
.what());
2302 handle
->ERROR_MESSAGE("Unknown exception thrown");
2310 * Call only on GEOMETRYCOLLECTION or MULTI*.
2311 * Return a pointer to the internal Geometry.
2314 GEOSGetGeometryN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2316 if ( 0 == extHandle
)
2321 GEOSContextHandleInternal_t
*handle
= 0;
2322 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2323 if ( 0 == handle
->initialized
)
2330 return g1
->getGeometryN(n
);
2332 catch (const std::exception
&e
)
2334 handle
->ERROR_MESSAGE("%s", e
.what());
2338 handle
->ERROR_MESSAGE("Unknown exception thrown");
2345 * Call only on LINESTRING
2346 * Returns NULL on exception
2349 GEOSGeomGetPointN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2351 if ( 0 == extHandle
)
2356 GEOSContextHandleInternal_t
*handle
= 0;
2357 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2358 if ( 0 == handle
->initialized
)
2365 using geos::geom::LineString
;
2366 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2369 handle
->ERROR_MESSAGE("Argument is not a LineString");
2372 return ls
->getPointN(n
);
2374 catch (const std::exception
&e
)
2376 handle
->ERROR_MESSAGE("%s", e
.what());
2380 handle
->ERROR_MESSAGE("Unknown exception thrown");
2387 * Call only on LINESTRING
2390 GEOSGeomGetStartPoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2392 if ( 0 == extHandle
)
2397 GEOSContextHandleInternal_t
*handle
= 0;
2398 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2399 if ( 0 == handle
->initialized
)
2406 using geos::geom::LineString
;
2407 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2410 handle
->ERROR_MESSAGE("Argument is not a LineString");
2413 return ls
->getStartPoint();
2415 catch (const std::exception
&e
)
2417 handle
->ERROR_MESSAGE("%s", e
.what());
2421 handle
->ERROR_MESSAGE("Unknown exception thrown");
2428 * Call only on LINESTRING
2431 GEOSGeomGetEndPoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2433 if ( 0 == extHandle
)
2438 GEOSContextHandleInternal_t
*handle
= 0;
2439 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2440 if ( 0 == handle
->initialized
)
2447 using geos::geom::LineString
;
2448 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2451 handle
->ERROR_MESSAGE("Argument is not a LineString");
2454 return ls
->getEndPoint();
2456 catch (const std::exception
&e
)
2458 handle
->ERROR_MESSAGE("%s", e
.what());
2462 handle
->ERROR_MESSAGE("Unknown exception thrown");
2469 * Call only on LINESTRING
2470 * return 2 on exception, 1 on true, 0 on false
2473 GEOSisClosed_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2475 if ( 0 == extHandle
)
2480 GEOSContextHandleInternal_t
*handle
= 0;
2481 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2482 if ( 0 == handle
->initialized
)
2489 using geos::geom::LineString
;
2490 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2493 handle
->ERROR_MESSAGE("Argument is not a LineString");
2496 return ls
->isClosed();
2498 catch (const std::exception
&e
)
2500 handle
->ERROR_MESSAGE("%s", e
.what());
2504 handle
->ERROR_MESSAGE("Unknown exception thrown");
2511 * Call only on LINESTRING
2512 * return 0 on exception, otherwise 1
2515 GEOSGeomGetLength_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *length
)
2517 if ( 0 == extHandle
)
2522 GEOSContextHandleInternal_t
*handle
= 0;
2523 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2524 if ( 0 == handle
->initialized
)
2531 using geos::geom::LineString
;
2532 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2535 handle
->ERROR_MESSAGE("Argument is not a LineString");
2538 *length
= ls
->getLength();
2541 catch (const std::exception
&e
)
2543 handle
->ERROR_MESSAGE("%s", e
.what());
2547 handle
->ERROR_MESSAGE("Unknown exception thrown");
2554 * Call only on LINESTRING
2557 GEOSGeomGetNumPoints_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2559 if ( 0 == extHandle
)
2564 GEOSContextHandleInternal_t
*handle
= 0;
2565 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2566 if ( 0 == handle
->initialized
)
2573 using geos::geom::LineString
;
2574 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2577 handle
->ERROR_MESSAGE("Argument is not a LineString");
2580 return static_cast<int>(ls
->getNumPoints());
2582 catch (const std::exception
&e
)
2584 handle
->ERROR_MESSAGE("%s", e
.what());
2588 handle
->ERROR_MESSAGE("Unknown exception thrown");
2596 * returns 0 on exception, otherwise 1
2599 GEOSGeomGetX_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *x
)
2601 if ( 0 == extHandle
)
2606 GEOSContextHandleInternal_t
*handle
= 0;
2607 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2608 if ( 0 == handle
->initialized
)
2615 using geos::geom::Point
;
2616 const Point
*po
= dynamic_cast<const Point
*>(g1
);
2619 handle
->ERROR_MESSAGE("Argument is not a Point");
2625 catch (const std::exception
&e
)
2627 handle
->ERROR_MESSAGE("%s", e
.what());
2631 handle
->ERROR_MESSAGE("Unknown exception thrown");
2639 * returns 0 on exception, otherwise 1
2642 GEOSGeomGetY_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *y
)
2644 if ( 0 == extHandle
)
2649 GEOSContextHandleInternal_t
*handle
= 0;
2650 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2651 if ( 0 == handle
->initialized
)
2658 using geos::geom::Point
;
2659 const Point
*po
= dynamic_cast<const Point
*>(g1
);
2662 handle
->ERROR_MESSAGE("Argument is not a Point");
2668 catch (const std::exception
&e
)
2670 handle
->ERROR_MESSAGE("%s", e
.what());
2674 handle
->ERROR_MESSAGE("Unknown exception thrown");
2681 * Call only on polygon
2682 * Return a copy of the internal Geometry.
2685 GEOSGetExteriorRing_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2687 if ( 0 == extHandle
)
2692 GEOSContextHandleInternal_t
*handle
= 0;
2693 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2694 if ( 0 == handle
->initialized
)
2701 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
2704 handle
->ERROR_MESSAGE("Invalid argument (must be a Polygon)");
2707 return p
->getExteriorRing();
2709 catch (const std::exception
&e
)
2711 handle
->ERROR_MESSAGE("%s", e
.what());
2715 handle
->ERROR_MESSAGE("Unknown exception thrown");
2722 * Call only on polygon
2723 * Return a pointer to internal storage, do not destroy it.
2726 GEOSGetInteriorRingN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2728 if ( 0 == extHandle
)
2733 GEOSContextHandleInternal_t
*handle
= 0;
2734 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2735 if ( 0 == handle
->initialized
)
2742 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
2745 handle
->ERROR_MESSAGE("Invalid argument (must be a Polygon)");
2748 return p
->getInteriorRingN(n
);
2750 catch (const std::exception
&e
)
2752 handle
->ERROR_MESSAGE("%s", e
.what());
2756 handle
->ERROR_MESSAGE("Unknown exception thrown");
2763 GEOSGetCentroid_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2765 if ( 0 == extHandle
)
2770 GEOSContextHandleInternal_t
*handle
= 0;
2771 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2772 if ( 0 == handle
->initialized
)
2779 Geometry
*ret
= g
->getCentroid();
2782 const GeometryFactory
*gf
= handle
->geomFactory
;
2783 return gf
->createGeometryCollection();
2787 catch (const std::exception
&e
)
2789 handle
->ERROR_MESSAGE("%s", e
.what());
2793 handle
->ERROR_MESSAGE("Unknown exception thrown");
2800 GEOSGeom_createEmptyCollection_r(GEOSContextHandle_t extHandle
, int type
)
2802 if ( 0 == extHandle
)
2807 GEOSContextHandleInternal_t
*handle
= 0;
2808 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2809 if ( 0 == handle
->initialized
)
2816 sprintf(buf
, "createCollection: requested type %d, ngeoms: %d",
2818 handle
->NOTICE_MESSAGE("%s", buf
);// TODO: Can handle->NOTICE_MESSAGE format that directly?
2823 const GeometryFactory
* gf
= handle
->geomFactory
;
2828 case GEOS_GEOMETRYCOLLECTION
:
2829 g
= gf
->createGeometryCollection();
2831 case GEOS_MULTIPOINT
:
2832 g
= gf
->createMultiPoint();
2834 case GEOS_MULTILINESTRING
:
2835 g
= gf
->createMultiLineString();
2837 case GEOS_MULTIPOLYGON
:
2838 g
= gf
->createMultiPolygon();
2841 handle
->ERROR_MESSAGE("Unsupported type request for GEOSGeom_createEmptyCollection_r");
2848 catch (const std::exception
&e
)
2850 handle
->ERROR_MESSAGE("%s", e
.what());
2854 handle
->ERROR_MESSAGE("Unknown exception thrown");
2861 GEOSGeom_createCollection_r(GEOSContextHandle_t extHandle
, int type
, Geometry
**geoms
, unsigned int ngeoms
)
2863 if ( 0 == extHandle
)
2868 GEOSContextHandleInternal_t
*handle
= 0;
2869 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2870 if ( 0 == handle
->initialized
)
2877 sprintf(buf
, "PostGIS2GEOS_collection: requested type %d, ngeoms: %d",
2879 handle
->NOTICE_MESSAGE("%s", buf
);// TODO: Can handle->NOTICE_MESSAGE format that directly?
2884 const GeometryFactory
* gf
= handle
->geomFactory
;
2885 std::vector
<Geometry
*>* vgeoms
= new std::vector
<Geometry
*>(geoms
, geoms
+ ngeoms
);
2890 case GEOS_GEOMETRYCOLLECTION
:
2891 g
= gf
->createGeometryCollection(vgeoms
);
2893 case GEOS_MULTIPOINT
:
2894 g
= gf
->createMultiPoint(vgeoms
);
2896 case GEOS_MULTILINESTRING
:
2897 g
= gf
->createMultiLineString(vgeoms
);
2899 case GEOS_MULTIPOLYGON
:
2900 g
= gf
->createMultiPolygon(vgeoms
);
2903 handle
->ERROR_MESSAGE("Unsupported type request for PostGIS2GEOS_collection");
2910 catch (const std::exception
&e
)
2912 handle
->ERROR_MESSAGE("%s", e
.what());
2916 handle
->ERROR_MESSAGE("Unknown exception thrown");
2923 GEOSPolygonize_r(GEOSContextHandle_t extHandle
, const Geometry
* const * g
, unsigned int ngeoms
)
2925 if ( 0 == extHandle
)
2930 GEOSContextHandleInternal_t
*handle
= 0;
2931 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2932 if ( 0 == handle
->initialized
)
2942 using geos::operation::polygonize::Polygonizer
;
2944 for (std::size_t i
= 0; i
< ngeoms
; ++i
)
2950 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
2953 std::vector
<Polygon
*> *polys
= plgnzr
.getPolygons();
2957 handle
->NOTICE_MESSAGE("output polygons got");
2960 // We need a vector of Geometry pointers, not Polygon pointers.
2961 // STL vector doesn't allow transparent upcast of this
2962 // nature, so we explicitly convert.
2963 // (it's just a waste of processor and memory, btw)
2965 // XXX mloskot: Why not to extent GeometryFactory to accept
2966 // vector of polygons or extend Polygonizer to return list of Geometry*
2967 // or add a wrapper which semantic is similar to:
2968 // std::vector<as_polygon<Geometry*> >
2969 std::vector
<Geometry
*> *polyvec
= new std::vector
<Geometry
*>(polys
->size());
2971 for (std::size_t i
= 0; i
< polys
->size(); ++i
)
2973 (*polyvec
)[i
] = (*polys
)[i
];
2978 const GeometryFactory
*gf
= handle
->geomFactory
;
2980 // The below takes ownership of the passed vector,
2981 // so we must *not* delete it
2982 out
= gf
->createGeometryCollection(polyvec
);
2984 catch (const std::exception
&e
)
2986 handle
->ERROR_MESSAGE("%s", e
.what());
2990 handle
->ERROR_MESSAGE("Unknown exception thrown");
2997 GEOSPolygonizer_getCutEdges_r(GEOSContextHandle_t extHandle
, const Geometry
* const * g
, unsigned int ngeoms
)
2999 if ( 0 == extHandle
)
3004 GEOSContextHandleInternal_t
*handle
= 0;
3005 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3006 if ( 0 == handle
->initialized
)
3016 using geos::operation::polygonize::Polygonizer
;
3018 for (std::size_t i
= 0; i
< ngeoms
; ++i
)
3024 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
3027 const std::vector
<const LineString
*>& lines
= plgnzr
.getCutEdges();
3030 handle
->NOTICE_MESSAGE("output polygons got");
3033 // We need a vector of Geometry pointers, not Polygon pointers.
3034 // STL vector doesn't allow transparent upcast of this
3035 // nature, so we explicitly convert.
3036 // (it's just a waste of processor and memory, btw)
3037 // XXX mloskot: See comment for GEOSPolygonize_r
3038 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3040 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3042 (*linevec
)[i
] = lines
[i
]->clone();
3045 const GeometryFactory
*gf
= handle
->geomFactory
;
3047 // The below takes ownership of the passed vector,
3048 // so we must *not* delete it
3049 out
= gf
->createGeometryCollection(linevec
);
3051 catch (const std::exception
&e
)
3053 handle
->ERROR_MESSAGE("%s", e
.what());
3057 handle
->ERROR_MESSAGE("Unknown exception thrown");
3064 GEOSPolygonize_full_r(GEOSContextHandle_t extHandle
, const Geometry
* g
,
3065 Geometry
** cuts
, Geometry
** dangles
, Geometry
** invalid
)
3067 if ( 0 == extHandle
)
3072 GEOSContextHandleInternal_t
*handle
= 0;
3073 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3074 if ( 0 == handle
->initialized
)
3082 using geos::operation::polygonize::Polygonizer
;
3084 for (std::size_t i
= 0; i
<g
->getNumGeometries(); ++i
)
3086 plgnzr
.add(g
->getGeometryN(i
));
3090 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
3092 const GeometryFactory
*gf
= handle
->geomFactory
;
3096 const std::vector
<const LineString
*>& lines
= plgnzr
.getCutEdges();
3097 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3098 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3100 (*linevec
)[i
] = lines
[i
]->clone();
3103 // The below takes ownership of the passed vector,
3104 // so we must *not* delete it
3105 *cuts
= gf
->createGeometryCollection(linevec
);
3110 const std::vector
<const LineString
*>& lines
= plgnzr
.getDangles();
3111 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3112 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3114 (*linevec
)[i
] = lines
[i
]->clone();
3117 // The below takes ownership of the passed vector,
3118 // so we must *not* delete it
3119 *dangles
= gf
->createGeometryCollection(linevec
);
3124 const std::vector
<LineString
*>& lines
= plgnzr
.getInvalidRingLines();
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 *invalid
= gf
->createGeometryCollection(linevec
);
3136 std::vector
<Polygon
*> *polys
= plgnzr
.getPolygons();
3137 std::vector
<Geometry
*> *polyvec
= new std::vector
<Geometry
*>(polys
->size());
3138 for (std::size_t i
= 0; i
< polys
->size(); ++i
)
3140 (*polyvec
)[i
] = (*polys
)[i
];
3144 return gf
->createGeometryCollection(polyvec
);
3147 catch (const std::exception
&e
)
3149 handle
->ERROR_MESSAGE("%s", e
.what());
3154 handle
->ERROR_MESSAGE("Unknown exception thrown");
3160 GEOSLineMerge_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3162 if ( 0 == extHandle
)
3167 GEOSContextHandleInternal_t
*handle
= 0;
3168 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3169 if ( 0 == handle
->initialized
)
3178 using geos::operation::linemerge::LineMerger
;
3182 std::vector
<LineString
*>* lines
= lmrgr
.getMergedLineStrings();
3186 handle
->NOTICE_MESSAGE("output lines got");
3189 std::vector
<Geometry
*>*geoms
= new std::vector
<Geometry
*>(lines
->size());
3190 for (std::vector
<Geometry
*>::size_type i
= 0; i
< lines
->size(); ++i
)
3192 (*geoms
)[i
] = (*lines
)[i
];
3197 const GeometryFactory
*gf
= handle
->geomFactory
;
3198 out
= gf
->buildGeometry(geoms
);
3201 //out = gf->createGeometryCollection(geoms);
3203 catch (const std::exception
&e
)
3205 handle
->ERROR_MESSAGE("%s", e
.what());
3209 handle
->ERROR_MESSAGE("Unknown exception thrown");
3216 GEOSGetSRID_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3220 if ( 0 == extHandle
)
3225 GEOSContextHandleInternal_t
*handle
= 0;
3226 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3227 if ( 0 == handle
->initialized
)
3234 return g
->getSRID();
3236 catch (const std::exception
&e
)
3238 handle
->ERROR_MESSAGE("%s", e
.what());
3242 handle
->ERROR_MESSAGE("Unknown exception thrown");
3248 const char* GEOSversion()
3250 return GEOS_CAPI_VERSION
;
3253 const char* GEOSjtsport()
3255 return GEOS_JTS_PORT
;
3259 GEOSHasZ_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3263 if ( 0 == extHandle
)
3268 GEOSContextHandleInternal_t
*handle
= 0;
3269 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3270 if ( 0 == handle
->initialized
)
3279 assert(0 != g
->getCoordinate());
3281 double az
= g
->getCoordinate()->z
;
3282 //handle->ERROR_MESSAGE("ZCoord: %g", az);
3284 return static_cast<char>(FINITE(az
));
3288 GEOS_getWKBOutputDims_r(GEOSContextHandle_t extHandle
)
3290 if ( 0 == extHandle
)
3295 GEOSContextHandleInternal_t
*handle
= 0;
3296 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3297 if ( 0 == handle
->initialized
)
3302 return handle
->WKBOutputDims
;
3306 GEOS_setWKBOutputDims_r(GEOSContextHandle_t extHandle
, int newdims
)
3308 if ( 0 == extHandle
)
3313 GEOSContextHandleInternal_t
*handle
= 0;
3314 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3315 if ( 0 == handle
->initialized
)
3320 if ( newdims
< 2 || newdims
> 3 )
3322 handle
->ERROR_MESSAGE("WKB output dimensions out of range 2..3");
3325 const int olddims
= handle
->WKBOutputDims
;
3326 handle
->WKBOutputDims
= newdims
;
3332 GEOS_getWKBByteOrder_r(GEOSContextHandle_t extHandle
)
3334 if ( 0 == extHandle
)
3339 GEOSContextHandleInternal_t
*handle
= 0;
3340 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3341 if ( 0 == handle
->initialized
)
3346 return handle
->WKBByteOrder
;
3350 GEOS_setWKBByteOrder_r(GEOSContextHandle_t extHandle
, int byteOrder
)
3352 if ( 0 == extHandle
)
3357 GEOSContextHandleInternal_t
*handle
= 0;
3358 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3359 if ( 0 == handle
->initialized
)
3364 const int oldByteOrder
= handle
->WKBByteOrder
;
3365 handle
->WKBByteOrder
= byteOrder
;
3367 return oldByteOrder
;
3371 CoordinateSequence
*
3372 GEOSCoordSeq_create_r(GEOSContextHandle_t extHandle
, unsigned int size
, unsigned int dims
)
3374 if ( 0 == extHandle
)
3379 GEOSContextHandleInternal_t
*handle
= 0;
3380 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3381 if ( 0 == handle
->initialized
)
3388 const GeometryFactory
*gf
= handle
->geomFactory
;
3389 return gf
->getCoordinateSequenceFactory()->create(size
, dims
);
3391 catch (const std::exception
&e
)
3393 handle
->ERROR_MESSAGE("%s", e
.what());
3397 handle
->ERROR_MESSAGE("Unknown exception thrown");
3404 GEOSCoordSeq_setOrdinate_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
,
3405 unsigned int idx
, unsigned int dim
, double val
)
3408 if ( 0 == extHandle
)
3413 GEOSContextHandleInternal_t
*handle
= 0;
3414 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3415 if ( 0 == handle
->initialized
)
3422 cs
->setOrdinate(idx
, dim
, val
);
3425 catch (const std::exception
&e
)
3427 handle
->ERROR_MESSAGE("%s", e
.what());
3431 handle
->ERROR_MESSAGE("Unknown exception thrown");
3438 GEOSCoordSeq_setX_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3440 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 0, val
);
3444 GEOSCoordSeq_setY_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3446 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 1, val
);
3450 GEOSCoordSeq_setZ_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3452 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 2, val
);
3455 CoordinateSequence
*
3456 GEOSCoordSeq_clone_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
)
3460 if ( 0 == extHandle
)
3465 GEOSContextHandleInternal_t
*handle
= 0;
3466 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3467 if ( 0 == handle
->initialized
)
3476 catch (const std::exception
&e
)
3478 handle
->ERROR_MESSAGE("%s", e
.what());
3482 handle
->ERROR_MESSAGE("Unknown exception thrown");
3489 GEOSCoordSeq_getOrdinate_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
,
3490 unsigned int idx
, unsigned int dim
, double *val
)
3495 if ( 0 == extHandle
)
3500 GEOSContextHandleInternal_t
*handle
= 0;
3501 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3502 if ( 0 == handle
->initialized
)
3509 double d
= cs
->getOrdinate(idx
, dim
);
3514 catch (const std::exception
&e
)
3516 handle
->ERROR_MESSAGE("%s", e
.what());
3520 handle
->ERROR_MESSAGE("Unknown exception thrown");
3527 GEOSCoordSeq_getX_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
3529 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 0, val
);
3533 GEOSCoordSeq_getY_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
3535 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 1, val
);
3539 GEOSCoordSeq_getZ_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
3541 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 2, val
);
3545 GEOSCoordSeq_getSize_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
, unsigned int *size
)
3550 if ( 0 == extHandle
)
3555 GEOSContextHandleInternal_t
*handle
= 0;
3556 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3557 if ( 0 == handle
->initialized
)
3564 const std::size_t sz
= cs
->getSize();
3565 *size
= static_cast<unsigned int>(sz
);
3568 catch (const std::exception
&e
)
3570 handle
->ERROR_MESSAGE("%s", e
.what());
3574 handle
->ERROR_MESSAGE("Unknown exception thrown");
3581 GEOSCoordSeq_getDimensions_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
, unsigned int *dims
)
3586 if ( 0 == extHandle
)
3591 GEOSContextHandleInternal_t
*handle
= 0;
3592 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3593 if ( 0 == handle
->initialized
)
3600 const std::size_t dim
= cs
->getDimension();
3601 *dims
= static_cast<unsigned int>(dim
);
3605 catch (const std::exception
&e
)
3607 handle
->ERROR_MESSAGE("%s", e
.what());
3612 handle
->ERROR_MESSAGE("Unknown exception thrown");
3619 GEOSCoordSeq_destroy_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
)
3621 GEOSContextHandleInternal_t
*handle
= 0;
3627 catch (const std::exception
&e
)
3629 if ( 0 == extHandle
)
3634 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3635 if ( 0 == handle
->initialized
)
3640 handle
->ERROR_MESSAGE("%s", e
.what());
3644 if ( 0 == extHandle
)
3649 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3650 if ( 0 == handle
->initialized
)
3655 handle
->ERROR_MESSAGE("Unknown exception thrown");
3659 const CoordinateSequence
*
3660 GEOSGeom_getCoordSeq_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3662 if ( 0 == extHandle
)
3667 GEOSContextHandleInternal_t
*handle
= 0;
3668 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3669 if ( 0 == handle
->initialized
)
3676 using geos::geom::Point
;
3678 const LineString
*ls
= dynamic_cast<const LineString
*>(g
);
3681 return ls
->getCoordinatesRO();
3684 const Point
*p
= dynamic_cast<const Point
*>(g
);
3687 return p
->getCoordinatesRO();
3690 handle
->ERROR_MESSAGE("Geometry must be a Point or LineString");
3693 catch (const std::exception
&e
)
3695 handle
->ERROR_MESSAGE("%s", e
.what());
3699 handle
->ERROR_MESSAGE("Unknown exception thrown");
3706 GEOSGeom_createEmptyPoint_r(GEOSContextHandle_t extHandle
)
3708 if ( 0 == extHandle
)
3713 GEOSContextHandleInternal_t
*handle
= 0;
3714 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3715 if ( 0 == handle
->initialized
)
3722 const GeometryFactory
*gf
= handle
->geomFactory
;
3723 return gf
->createPoint();
3725 catch (const std::exception
&e
)
3727 handle
->ERROR_MESSAGE("%s", e
.what());
3731 handle
->ERROR_MESSAGE("Unknown exception thrown");
3738 GEOSGeom_createPoint_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
3740 if ( 0 == extHandle
)
3745 GEOSContextHandleInternal_t
*handle
= 0;
3746 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3747 if ( 0 == handle
->initialized
)
3754 const GeometryFactory
*gf
= handle
->geomFactory
;
3755 return gf
->createPoint(cs
);
3757 catch (const std::exception
&e
)
3759 handle
->ERROR_MESSAGE("%s", e
.what());
3763 handle
->ERROR_MESSAGE("Unknown exception thrown");
3770 GEOSGeom_createLinearRing_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
3772 if ( 0 == extHandle
)
3777 GEOSContextHandleInternal_t
*handle
= 0;
3778 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3779 if ( 0 == handle
->initialized
)
3786 const GeometryFactory
*gf
= handle
->geomFactory
;
3788 return gf
->createLinearRing(cs
);
3790 catch (const std::exception
&e
)
3792 handle
->ERROR_MESSAGE("%s", e
.what());
3796 handle
->ERROR_MESSAGE("Unknown exception thrown");
3803 GEOSGeom_createEmptyLineString_r(GEOSContextHandle_t extHandle
)
3805 if ( 0 == extHandle
)
3810 GEOSContextHandleInternal_t
*handle
= 0;
3811 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3812 if ( 0 == handle
->initialized
)
3819 const GeometryFactory
*gf
= handle
->geomFactory
;
3821 return gf
->createLineString();
3823 catch (const std::exception
&e
)
3825 handle
->ERROR_MESSAGE("%s", e
.what());
3829 handle
->ERROR_MESSAGE("Unknown exception thrown");
3836 GEOSGeom_createLineString_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
3838 if ( 0 == extHandle
)
3843 GEOSContextHandleInternal_t
*handle
= 0;
3844 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3845 if ( 0 == handle
->initialized
)
3852 const GeometryFactory
*gf
= handle
->geomFactory
;
3854 return gf
->createLineString(cs
);
3856 catch (const std::exception
&e
)
3858 handle
->ERROR_MESSAGE("%s", e
.what());
3862 handle
->ERROR_MESSAGE("Unknown exception thrown");
3869 GEOSGeom_createEmptyPolygon_r(GEOSContextHandle_t extHandle
)
3871 if ( 0 == extHandle
)
3876 GEOSContextHandleInternal_t
*handle
= 0;
3877 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3878 if ( 0 == handle
->initialized
)
3885 const GeometryFactory
*gf
= handle
->geomFactory
;
3886 return gf
->createPolygon();
3888 catch (const std::exception
&e
)
3890 handle
->ERROR_MESSAGE("%s", e
.what());
3894 handle
->ERROR_MESSAGE("Unknown exception thrown");
3901 GEOSGeom_createPolygon_r(GEOSContextHandle_t extHandle
, Geometry
*shell
, Geometry
**holes
, unsigned int nholes
)
3903 // FIXME: holes must be non-nullptr or may be nullptr?
3904 //assert(0 != holes);
3906 if ( 0 == extHandle
)
3911 GEOSContextHandleInternal_t
*handle
= 0;
3912 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3913 if ( 0 == handle
->initialized
)
3920 using geos::geom::LinearRing
;
3922 std::vector
<Geometry
*> *vholes
= new std::vector
<Geometry
*>(holes
, holes
+ nholes
);
3924 LinearRing
*nshell
= dynamic_cast<LinearRing
*>(shell
);
3927 handle
->ERROR_MESSAGE("Shell is not a LinearRing");
3930 const GeometryFactory
*gf
= handle
->geomFactory
;
3932 return gf
->createPolygon(nshell
, vholes
);
3934 catch (const std::exception
&e
)
3936 handle
->ERROR_MESSAGE("%s", e
.what());
3940 handle
->ERROR_MESSAGE("Unknown exception thrown");
3947 GEOSGeom_clone_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3951 if ( 0 == extHandle
)
3956 GEOSContextHandleInternal_t
*handle
= 0;
3957 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3958 if ( 0 == handle
->initialized
)
3967 catch (const std::exception
&e
)
3969 handle
->ERROR_MESSAGE("%s", e
.what());
3973 handle
->ERROR_MESSAGE("Unknown exception thrown");
3980 GEOSGeom_getDimensions_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3982 if ( 0 == extHandle
)
3987 GEOSContextHandleInternal_t
*handle
= 0;
3988 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3989 if ( 0 == handle
->initialized
)
3996 return (int) g
->getDimension();
3998 catch (const std::exception
&e
)
4000 handle
->ERROR_MESSAGE("%s", e
.what());
4004 handle
->ERROR_MESSAGE("Unknown exception thrown");
4011 GEOSGeom_getCoordinateDimension_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
4013 if ( 0 == extHandle
)
4018 GEOSContextHandleInternal_t
*handle
= 0;
4019 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4020 if ( 0 == handle
->initialized
)
4027 return g
->getCoordinateDimension();
4029 catch (const std::exception
&e
)
4031 handle
->ERROR_MESSAGE("%s", e
.what());
4035 handle
->ERROR_MESSAGE("Unknown exception thrown");
4042 GEOSSimplify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double tolerance
)
4044 if ( 0 == extHandle
)
4049 GEOSContextHandleInternal_t
*handle
= 0;
4050 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4051 if ( 0 == handle
->initialized
)
4058 using namespace geos::simplify
;
4059 Geometry::AutoPtr
g(DouglasPeuckerSimplifier::simplify(g1
, tolerance
));
4062 catch (const std::exception
&e
)
4064 handle
->ERROR_MESSAGE("%s", e
.what());
4068 handle
->ERROR_MESSAGE("Unknown exception thrown");
4075 GEOSTopologyPreserveSimplify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double tolerance
)
4077 if ( 0 == extHandle
)
4082 GEOSContextHandleInternal_t
*handle
= 0;
4083 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4084 if ( 0 == handle
->initialized
)
4091 using namespace geos::simplify
;
4092 Geometry::AutoPtr
g(TopologyPreservingSimplifier::simplify(g1
, tolerance
));
4095 catch (const std::exception
&e
)
4097 handle
->ERROR_MESSAGE("%s", e
.what());
4101 handle
->ERROR_MESSAGE("Unknown exception thrown");
4110 GEOSWKTReader_create_r(GEOSContextHandle_t extHandle
)
4112 if ( 0 == extHandle
)
4117 GEOSContextHandleInternal_t
*handle
= 0;
4118 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4119 if ( 0 == handle
->initialized
)
4126 using geos::io::WKTReader
;
4127 return new WKTReader((GeometryFactory
*)handle
->geomFactory
);
4129 catch (const std::exception
&e
)
4131 handle
->ERROR_MESSAGE("%s", e
.what());
4135 handle
->ERROR_MESSAGE("Unknown exception thrown");
4142 GEOSWKTReader_destroy_r(GEOSContextHandle_t extHandle
, WKTReader
*reader
)
4144 GEOSContextHandleInternal_t
*handle
= 0;
4150 catch (const std::exception
&e
)
4152 if ( 0 == extHandle
)
4157 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4158 if ( 0 == handle
->initialized
)
4163 handle
->ERROR_MESSAGE("%s", e
.what());
4167 if ( 0 == extHandle
)
4172 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4173 if ( 0 == handle
->initialized
)
4178 handle
->ERROR_MESSAGE("Unknown exception thrown");
4184 GEOSWKTReader_read_r(GEOSContextHandle_t extHandle
, WKTReader
*reader
, const char *wkt
)
4186 assert(0 != reader
);
4188 if ( 0 == extHandle
)
4193 GEOSContextHandleInternal_t
*handle
= 0;
4194 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4195 if ( 0 == handle
->initialized
)
4202 const std::string
wktstring(wkt
);
4203 Geometry
*g
= reader
->read(wktstring
);
4206 catch (const std::exception
&e
)
4208 handle
->ERROR_MESSAGE("%s", e
.what());
4212 handle
->ERROR_MESSAGE("Unknown exception thrown");
4220 GEOSWKTWriter_create_r(GEOSContextHandle_t extHandle
)
4222 if ( 0 == extHandle
)
4227 GEOSContextHandleInternal_t
*handle
= 0;
4228 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4229 if ( 0 == handle
->initialized
)
4236 using geos::io::WKTWriter
;
4237 return new WKTWriter();
4239 catch (const std::exception
&e
)
4241 handle
->ERROR_MESSAGE("%s", e
.what());
4245 handle
->ERROR_MESSAGE("Unknown exception thrown");
4252 GEOSWKTWriter_destroy_r(GEOSContextHandle_t extHandle
, WKTWriter
*Writer
)
4255 GEOSContextHandleInternal_t
*handle
= 0;
4261 catch (const std::exception
&e
)
4263 if ( 0 == extHandle
)
4268 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4269 if ( 0 == handle
->initialized
)
4274 handle
->ERROR_MESSAGE("%s", e
.what());
4278 if ( 0 == extHandle
)
4283 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4284 if ( 0 == handle
->initialized
)
4289 handle
->ERROR_MESSAGE("Unknown exception thrown");
4295 GEOSWKTWriter_write_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, const Geometry
*geom
)
4297 assert(0 != writer
);
4299 if ( 0 == extHandle
)
4304 GEOSContextHandleInternal_t
*handle
= 0;
4305 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4306 if ( 0 == handle
->initialized
)
4313 std::string
sgeom(writer
->write(geom
));
4314 char *result
= gstrdup(sgeom
);
4317 catch (const std::exception
&e
)
4319 handle
->ERROR_MESSAGE("%s", e
.what());
4323 handle
->ERROR_MESSAGE("Unknown exception thrown");
4330 GEOSWKTWriter_setTrim_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, char trim
)
4332 assert(0 != writer
);
4334 if ( 0 == extHandle
)
4339 GEOSContextHandleInternal_t
*handle
= 0;
4340 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4341 if ( 0 == handle
->initialized
)
4346 writer
->setTrim(0 != trim
);
4350 GEOSWKTWriter_setRoundingPrecision_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int precision
)
4352 assert(0 != writer
);
4354 if ( 0 == extHandle
)
4359 GEOSContextHandleInternal_t
*handle
= 0;
4360 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4361 if ( 0 == handle
->initialized
)
4366 writer
->setRoundingPrecision(precision
);
4370 GEOSWKTWriter_setOutputDimension_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int dim
)
4372 assert(0 != writer
);
4374 if ( 0 == extHandle
)
4379 GEOSContextHandleInternal_t
*handle
= 0;
4380 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4381 if ( 0 == handle
->initialized
)
4388 writer
->setOutputDimension(dim
);
4390 catch (const std::exception
&e
)
4392 handle
->ERROR_MESSAGE("%s", e
.what());
4396 handle
->ERROR_MESSAGE("Unknown exception thrown");
4401 GEOSWKTWriter_getOutputDimension_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
)
4403 assert(0 != writer
);
4405 if ( 0 == extHandle
)
4410 GEOSContextHandleInternal_t
*handle
= 0;
4411 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4412 if ( 0 == handle
->initialized
)
4421 dim
= writer
->getOutputDimension();
4423 catch (const std::exception
&e
)
4425 handle
->ERROR_MESSAGE("%s", e
.what());
4429 handle
->ERROR_MESSAGE("Unknown exception thrown");
4436 GEOSWKTWriter_setOld3D_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int useOld3D
)
4438 assert(0 != writer
);
4440 if ( 0 == extHandle
)
4445 GEOSContextHandleInternal_t
*handle
= 0;
4446 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4447 if ( 0 == handle
->initialized
)
4452 writer
->setOld3D(0 != useOld3D
);
4457 GEOSWKBReader_create_r(GEOSContextHandle_t extHandle
)
4459 if ( 0 == extHandle
)
4464 GEOSContextHandleInternal_t
*handle
= 0;
4465 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4466 if ( 0 == handle
->initialized
)
4471 using geos::io::WKBReader
;
4474 return new WKBReader(*(GeometryFactory
*)handle
->geomFactory
);
4476 catch (const std::exception
&e
)
4478 handle
->ERROR_MESSAGE("%s", e
.what());
4482 handle
->ERROR_MESSAGE("Unknown exception thrown");
4489 GEOSWKBReader_destroy_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
)
4491 GEOSContextHandleInternal_t
*handle
= 0;
4497 catch (const std::exception
&e
)
4499 if ( 0 == extHandle
)
4504 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4505 if ( 0 == handle
->initialized
)
4510 handle
->ERROR_MESSAGE("%s", e
.what());
4514 if ( 0 == extHandle
)
4519 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4520 if ( 0 == handle
->initialized
)
4525 handle
->ERROR_MESSAGE("Unknown exception thrown");
4531 GEOSWKBReader_read_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
, const unsigned char *wkb
, size_t size
)
4533 assert(0 != reader
);
4536 if ( 0 == extHandle
)
4541 GEOSContextHandleInternal_t
*handle
= 0;
4542 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4543 if ( 0 == handle
->initialized
)
4550 std::string
wkbstring(reinterpret_cast<const char*>(wkb
), size
); // make it binary !
4551 std::istringstream
is(std::ios_base::binary
);
4553 is
.seekg(0, std::ios::beg
); // rewind reader pointer
4555 Geometry
*g
= reader
->read(is
);
4558 catch (const std::exception
&e
)
4560 handle
->ERROR_MESSAGE("%s", e
.what());
4564 handle
->ERROR_MESSAGE("Unknown exception thrown");
4571 GEOSWKBReader_readHEX_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
, const unsigned char *hex
, size_t size
)
4573 assert(0 != reader
);
4576 if ( 0 == extHandle
)
4581 GEOSContextHandleInternal_t
*handle
= 0;
4582 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4583 if ( 0 == handle
->initialized
)
4590 std::string
hexstring(reinterpret_cast<const char*>(hex
), size
);
4591 std::istringstream
is(std::ios_base::binary
);
4593 is
.seekg(0, std::ios::beg
); // rewind reader pointer
4595 Geometry
*g
= reader
->readHEX(is
);
4598 catch (const std::exception
&e
)
4600 handle
->ERROR_MESSAGE("%s", e
.what());
4604 handle
->ERROR_MESSAGE("Unknown exception thrown");
4612 GEOSWKBWriter_create_r(GEOSContextHandle_t extHandle
)
4614 if ( 0 == extHandle
)
4619 GEOSContextHandleInternal_t
*handle
= 0;
4620 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4621 if ( 0 == handle
->initialized
)
4628 using geos::io::WKBWriter
;
4629 return new WKBWriter();
4631 catch (const std::exception
&e
)
4633 handle
->ERROR_MESSAGE("%s", e
.what());
4637 handle
->ERROR_MESSAGE("Unknown exception thrown");
4644 GEOSWKBWriter_destroy_r(GEOSContextHandle_t extHandle
, WKBWriter
*Writer
)
4646 GEOSContextHandleInternal_t
*handle
= 0;
4652 catch (const std::exception
&e
)
4654 if ( 0 == extHandle
)
4659 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4660 if ( 0 == handle
->initialized
)
4665 handle
->ERROR_MESSAGE("%s", e
.what());
4669 if ( 0 == extHandle
)
4674 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4675 if ( 0 == handle
->initialized
)
4680 handle
->ERROR_MESSAGE("Unknown exception thrown");
4685 /* The caller owns the result */
4687 GEOSWKBWriter_write_r(GEOSContextHandle_t extHandle
, WKBWriter
*writer
, const Geometry
*geom
, size_t *size
)
4689 assert(0 != writer
);
4693 if ( 0 == extHandle
)
4698 GEOSContextHandleInternal_t
*handle
= 0;
4699 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4700 if ( 0 == handle
->initialized
)
4707 std::ostringstream
os(std::ios_base::binary
);
4708 writer
->write(*geom
, os
);
4709 std::string
wkbstring(os
.str());
4710 const std::size_t len
= wkbstring
.length();
4712 unsigned char *result
= NULL
;
4713 result
= (unsigned char*) std::malloc(len
);
4714 std::memcpy(result
, wkbstring
.c_str(), len
);
4718 catch (const std::exception
&e
)
4720 handle
->ERROR_MESSAGE("%s", e
.what());
4724 handle
->ERROR_MESSAGE("Unknown exception thrown");
4729 /* The caller owns the result */
4731 GEOSWKBWriter_writeHEX_r(GEOSContextHandle_t extHandle
, WKBWriter
*writer
, const Geometry
*geom
, size_t *size
)
4733 assert(0 != writer
);
4737 if ( 0 == extHandle
)
4742 GEOSContextHandleInternal_t
*handle
= 0;
4743 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4744 if ( 0 == handle
->initialized
)
4751 std::ostringstream
os(std::ios_base::binary
);
4752 writer
->writeHEX(*geom
, os
);
4753 std::string
wkbstring(os
.str());
4754 const std::size_t len
= wkbstring
.length();
4756 unsigned char *result
= NULL
;
4757 result
= (unsigned char*) std::malloc(len
);
4758 std::memcpy(result
, wkbstring
.c_str(), len
);
4762 catch (const std::exception
&e
)
4764 handle
->ERROR_MESSAGE("%s", e
.what());
4768 handle
->ERROR_MESSAGE("Unknown exception thrown");
4775 GEOSWKBWriter_getOutputDimension_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
4777 assert(0 != writer
);
4779 if ( 0 == extHandle
)
4786 GEOSContextHandleInternal_t
*handle
= 0;
4787 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4788 if ( 0 != handle
->initialized
)
4792 ret
= writer
->getOutputDimension();
4796 handle
->ERROR_MESSAGE("Unknown exception thrown");
4804 GEOSWKBWriter_setOutputDimension_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, int newDimension
)
4806 assert(0 != writer
);
4808 if ( 0 == extHandle
)
4813 GEOSContextHandleInternal_t
*handle
= 0;
4814 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4815 if ( 0 != handle
->initialized
)
4819 writer
->setOutputDimension(newDimension
);
4821 catch (const std::exception
&e
)
4823 handle
->ERROR_MESSAGE("%s", e
.what());
4827 handle
->ERROR_MESSAGE("Unknown exception thrown");
4833 GEOSWKBWriter_getByteOrder_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
4835 assert(0 != writer
);
4837 if ( 0 == extHandle
)
4844 GEOSContextHandleInternal_t
*handle
= 0;
4845 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4846 if ( 0 != handle
->initialized
)
4850 ret
= writer
->getByteOrder();
4855 handle
->ERROR_MESSAGE("Unknown exception thrown");
4863 GEOSWKBWriter_setByteOrder_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, int newByteOrder
)
4865 assert(0 != writer
);
4867 if ( 0 == extHandle
)
4872 GEOSContextHandleInternal_t
*handle
= 0;
4873 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4874 if ( 0 != handle
->initialized
)
4878 writer
->setByteOrder(newByteOrder
);
4880 catch (const std::exception
&e
)
4882 handle
->ERROR_MESSAGE("%s", e
.what());
4886 handle
->ERROR_MESSAGE("Unknown exception thrown");
4892 GEOSWKBWriter_getIncludeSRID_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
4894 assert(0 != writer
);
4896 if ( 0 == extHandle
)
4903 GEOSContextHandleInternal_t
*handle
= 0;
4904 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4905 if ( 0 != handle
->initialized
)
4909 int srid
= writer
->getIncludeSRID();
4914 handle
->ERROR_MESSAGE("Unknown exception thrown");
4918 return static_cast<char>(ret
);
4922 GEOSWKBWriter_setIncludeSRID_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, const char newIncludeSRID
)
4924 assert(0 != writer
);
4926 if ( 0 == extHandle
)
4931 GEOSContextHandleInternal_t
*handle
= 0;
4932 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4933 if ( 0 != handle
->initialized
)
4937 writer
->setIncludeSRID(newIncludeSRID
);
4941 handle
->ERROR_MESSAGE("Unknown exception thrown");
4947 //-----------------------------------------------------------------
4948 // Prepared Geometry
4949 //-----------------------------------------------------------------
4951 const geos::geom::prep::PreparedGeometry
*
4952 GEOSPrepare_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
4954 if ( 0 == extHandle
)
4959 GEOSContextHandleInternal_t
*handle
= 0;
4960 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4961 if ( 0 == handle
->initialized
)
4966 const geos::geom::prep::PreparedGeometry
* prep
= 0;
4970 prep
= geos::geom::prep::PreparedGeometryFactory::prepare(g
);
4972 catch (const std::exception
&e
)
4974 handle
->ERROR_MESSAGE("%s", e
.what());
4978 handle
->ERROR_MESSAGE("Unknown exception thrown");
4985 GEOSPreparedGeom_destroy_r(GEOSContextHandle_t extHandle
, const geos::geom::prep::PreparedGeometry
*a
)
4987 GEOSContextHandleInternal_t
*handle
= 0;
4993 catch (const std::exception
&e
)
4995 if ( 0 == extHandle
)
5000 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5001 if ( 0 == handle
->initialized
)
5006 handle
->ERROR_MESSAGE("%s", e
.what());
5010 if ( 0 == extHandle
)
5015 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5016 if ( 0 == handle
->initialized
)
5021 handle
->ERROR_MESSAGE("Unknown exception thrown");
5026 GEOSPreparedContains_r(GEOSContextHandle_t extHandle
,
5027 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5032 if ( 0 == extHandle
)
5037 GEOSContextHandleInternal_t
*handle
= 0;
5038 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5039 if ( 0 == handle
->initialized
)
5046 bool result
= pg
->contains(g
);
5049 catch (const std::exception
&e
)
5051 handle
->ERROR_MESSAGE("%s", e
.what());
5055 handle
->ERROR_MESSAGE("Unknown exception thrown");
5062 GEOSPreparedContainsProperly_r(GEOSContextHandle_t extHandle
,
5063 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5068 if ( 0 == extHandle
)
5073 GEOSContextHandleInternal_t
*handle
= 0;
5074 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5075 if ( 0 == handle
->initialized
)
5082 bool result
= pg
->containsProperly(g
);
5085 catch (const std::exception
&e
)
5087 handle
->ERROR_MESSAGE("%s", e
.what());
5091 handle
->ERROR_MESSAGE("Unknown exception thrown");
5098 GEOSPreparedCoveredBy_r(GEOSContextHandle_t extHandle
,
5099 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5104 if ( 0 == extHandle
)
5109 GEOSContextHandleInternal_t
*handle
= 0;
5110 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5111 if ( 0 == handle
->initialized
)
5118 bool result
= pg
->coveredBy(g
);
5121 catch (const std::exception
&e
)
5123 handle
->ERROR_MESSAGE("%s", e
.what());
5127 handle
->ERROR_MESSAGE("Unknown exception thrown");
5134 GEOSPreparedCovers_r(GEOSContextHandle_t extHandle
,
5135 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5140 if ( 0 == extHandle
)
5145 GEOSContextHandleInternal_t
*handle
= 0;
5146 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5147 if ( 0 == handle
->initialized
)
5154 bool result
= pg
->covers(g
);
5157 catch (const std::exception
&e
)
5159 handle
->ERROR_MESSAGE("%s", e
.what());
5163 handle
->ERROR_MESSAGE("Unknown exception thrown");
5170 GEOSPreparedCrosses_r(GEOSContextHandle_t extHandle
,
5171 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5176 if ( 0 == extHandle
)
5181 GEOSContextHandleInternal_t
*handle
= 0;
5182 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5183 if ( 0 == handle
->initialized
)
5190 bool result
= pg
->crosses(g
);
5193 catch (const std::exception
&e
)
5195 handle
->ERROR_MESSAGE("%s", e
.what());
5199 handle
->ERROR_MESSAGE("Unknown exception thrown");
5206 GEOSPreparedDisjoint_r(GEOSContextHandle_t extHandle
,
5207 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5212 if ( 0 == extHandle
)
5217 GEOSContextHandleInternal_t
*handle
= 0;
5218 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5219 if ( 0 == handle
->initialized
)
5226 bool result
= pg
->disjoint(g
);
5229 catch (const std::exception
&e
)
5231 handle
->ERROR_MESSAGE("%s", e
.what());
5235 handle
->ERROR_MESSAGE("Unknown exception thrown");
5242 GEOSPreparedIntersects_r(GEOSContextHandle_t extHandle
,
5243 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5248 if ( 0 == extHandle
)
5253 GEOSContextHandleInternal_t
*handle
= 0;
5254 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5255 if ( 0 == handle
->initialized
)
5262 bool result
= pg
->intersects(g
);
5265 catch (const std::exception
&e
)
5267 handle
->ERROR_MESSAGE("%s", e
.what());
5271 handle
->ERROR_MESSAGE("Unknown exception thrown");
5278 GEOSPreparedOverlaps_r(GEOSContextHandle_t extHandle
,
5279 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5284 if ( 0 == extHandle
)
5289 GEOSContextHandleInternal_t
*handle
= 0;
5290 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5291 if ( 0 == handle
->initialized
)
5298 bool result
= pg
->overlaps(g
);
5301 catch (const std::exception
&e
)
5303 handle
->ERROR_MESSAGE("%s", e
.what());
5307 handle
->ERROR_MESSAGE("Unknown exception thrown");
5314 GEOSPreparedTouches_r(GEOSContextHandle_t extHandle
,
5315 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5320 if ( 0 == extHandle
)
5325 GEOSContextHandleInternal_t
*handle
= 0;
5326 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5327 if ( 0 == handle
->initialized
)
5334 bool result
= pg
->touches(g
);
5337 catch (const std::exception
&e
)
5339 handle
->ERROR_MESSAGE("%s", e
.what());
5343 handle
->ERROR_MESSAGE("Unknown exception thrown");
5350 GEOSPreparedWithin_r(GEOSContextHandle_t extHandle
,
5351 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5356 if ( 0 == extHandle
)
5361 GEOSContextHandleInternal_t
*handle
= 0;
5362 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5363 if ( 0 == handle
->initialized
)
5370 bool result
= pg
->within(g
);
5373 catch (const std::exception
&e
)
5375 handle
->ERROR_MESSAGE("%s", e
.what());
5379 handle
->ERROR_MESSAGE("Unknown exception thrown");
5385 //-----------------------------------------------------------------
5387 //-----------------------------------------------------------------
5389 geos::index::strtree::STRtree
*
5390 GEOSSTRtree_create_r(GEOSContextHandle_t extHandle
,
5391 size_t nodeCapacity
)
5393 if ( 0 == extHandle
)
5398 GEOSContextHandleInternal_t
*handle
= 0;
5399 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5400 if ( 0 == handle
->initialized
)
5405 geos::index::strtree::STRtree
*tree
= 0;
5409 tree
= new geos::index::strtree::STRtree(nodeCapacity
);
5411 catch (const std::exception
&e
)
5413 handle
->ERROR_MESSAGE("%s", e
.what());
5417 handle
->ERROR_MESSAGE("Unknown exception thrown");
5424 GEOSSTRtree_insert_r(GEOSContextHandle_t extHandle
,
5425 geos::index::strtree::STRtree
*tree
,
5426 const geos::geom::Geometry
*g
,
5429 GEOSContextHandleInternal_t
*handle
= 0;
5435 tree
->insert(g
->getEnvelopeInternal(), item
);
5437 catch (const std::exception
&e
)
5439 if ( 0 == extHandle
)
5444 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5445 if ( 0 == handle
->initialized
)
5450 handle
->ERROR_MESSAGE("%s", e
.what());
5454 if ( 0 == extHandle
)
5459 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5460 if ( 0 == handle
->initialized
)
5465 handle
->ERROR_MESSAGE("Unknown exception thrown");
5470 GEOSSTRtree_query_r(GEOSContextHandle_t extHandle
,
5471 geos::index::strtree::STRtree
*tree
,
5472 const geos::geom::Geometry
*g
,
5473 GEOSQueryCallback callback
,
5476 GEOSContextHandleInternal_t
*handle
= 0;
5479 assert(callback
!= 0);
5483 CAPI_ItemVisitor
visitor(callback
, userdata
);
5484 tree
->query(g
->getEnvelopeInternal(), visitor
);
5486 catch (const std::exception
&e
)
5488 if ( 0 == extHandle
)
5493 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5494 if ( 0 == handle
->initialized
)
5499 handle
->ERROR_MESSAGE("%s", e
.what());
5503 if ( 0 == extHandle
)
5508 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5509 if ( 0 == handle
->initialized
)
5514 handle
->ERROR_MESSAGE("Unknown exception thrown");
5519 GEOSSTRtree_iterate_r(GEOSContextHandle_t extHandle
,
5520 geos::index::strtree::STRtree
*tree
,
5521 GEOSQueryCallback callback
,
5524 GEOSContextHandleInternal_t
*handle
= 0;
5526 assert(callback
!= 0);
5530 CAPI_ItemVisitor
visitor(callback
, userdata
);
5531 tree
->iterate(visitor
);
5533 catch (const std::exception
&e
)
5535 if ( 0 == extHandle
)
5540 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5541 if ( 0 == handle
->initialized
)
5546 handle
->ERROR_MESSAGE("%s", e
.what());
5550 if ( 0 == extHandle
)
5555 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5556 if ( 0 == handle
->initialized
)
5561 handle
->ERROR_MESSAGE("Unknown exception thrown");
5566 GEOSSTRtree_remove_r(GEOSContextHandle_t extHandle
,
5567 geos::index::strtree::STRtree
*tree
,
5568 const geos::geom::Geometry
*g
,
5574 if ( 0 == extHandle
)
5579 GEOSContextHandleInternal_t
*handle
= 0;
5580 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5581 if ( 0 == handle
->initialized
)
5588 bool result
= tree
->remove(g
->getEnvelopeInternal(), item
);
5591 catch (const std::exception
&e
)
5593 handle
->ERROR_MESSAGE("%s", e
.what());
5597 handle
->ERROR_MESSAGE("Unknown exception thrown");
5604 GEOSSTRtree_destroy_r(GEOSContextHandle_t extHandle
,
5605 geos::index::strtree::STRtree
*tree
)
5607 GEOSContextHandleInternal_t
*handle
= 0;
5613 catch (const std::exception
&e
)
5615 if ( 0 == extHandle
)
5620 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5621 if ( 0 == handle
->initialized
)
5626 handle
->ERROR_MESSAGE("%s", e
.what());
5630 if ( 0 == extHandle
)
5635 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5636 if ( 0 == handle
->initialized
)
5641 handle
->ERROR_MESSAGE("Unknown exception thrown");
5646 GEOSProject_r(GEOSContextHandle_t extHandle
,
5650 if ( 0 == extHandle
) return -1.0;
5651 GEOSContextHandleInternal_t
*handle
=
5652 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5653 if ( handle
->initialized
== 0 ) return -1.0;
5655 const geos::geom::Point
* point
= dynamic_cast<const geos::geom::Point
*>(p
);
5657 handle
->ERROR_MESSAGE("third argument of GEOSProject_r must be Point*");
5661 const geos::geom::Coordinate
* inputPt
= p
->getCoordinate();
5664 return geos::linearref::LengthIndexedLine(g
).project(*inputPt
);
5665 } catch (const std::exception
&e
) {
5666 handle
->ERROR_MESSAGE("%s", e
.what());
5669 handle
->ERROR_MESSAGE("Unknown exception thrown");
5676 GEOSInterpolate_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double d
)
5678 if ( 0 == extHandle
) return 0;
5679 GEOSContextHandleInternal_t
*handle
=
5680 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5681 if ( handle
->initialized
== 0 ) return 0;
5684 geos::linearref::LengthIndexedLine
lil(g
);
5685 geos::geom::Coordinate coord
= lil
.extractPoint(d
);
5686 const GeometryFactory
*gf
= handle
->geomFactory
;
5687 Geometry
* point
= gf
->createPoint(coord
);
5689 } catch (const std::exception
&e
) {
5690 handle
->ERROR_MESSAGE("%s", e
.what());
5693 handle
->ERROR_MESSAGE("Unknown exception thrown");
5700 GEOSProjectNormalized_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
5705 GEOSLength_r(extHandle
, g
, &length
);
5706 return GEOSProject_r(extHandle
, g
, p
) / length
;
5711 GEOSInterpolateNormalized_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
5715 GEOSLength_r(extHandle
, g
, &length
);
5716 return GEOSInterpolate_r(extHandle
, g
, d
* length
);
5720 GEOSGeom_extractUniquePoints_r(GEOSContextHandle_t extHandle
,
5721 const GEOSGeometry
* g
)
5723 if ( 0 == extHandle
) return 0;
5724 GEOSContextHandleInternal_t
*handle
= 0;
5725 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5726 if ( handle
->initialized
== 0 ) return 0;
5728 using namespace geos::geom
;
5729 using namespace geos::util
;
5734 /* 1: extract points */
5735 std::vector
<const Coordinate
*> coords
;
5736 UniqueCoordinateArrayFilter
filter(coords
);
5737 g
->apply_ro(&filter
);
5739 /* 2: for each point, create a geometry and put into a vector */
5740 std::vector
<Geometry
*>* points
= new std::vector
<Geometry
*>();
5741 points
->reserve(coords
.size());
5742 const GeometryFactory
* factory
= g
->getFactory();
5743 for (std::vector
<const Coordinate
*>::iterator it
=coords
.begin(),
5747 Geometry
* point
= factory
->createPoint(*(*it
));
5748 points
->push_back(point
);
5751 /* 3: create a multipoint */
5752 return factory
->createMultiPoint(points
);
5755 catch (const std::exception
&e
)
5757 handle
->ERROR_MESSAGE("%s", e
.what());
5762 handle
->ERROR_MESSAGE("Unknown exception thrown");
5767 int GEOSOrientationIndex_r(GEOSContextHandle_t extHandle
,
5768 double Ax
, double Ay
, double Bx
, double By
, double Px
, double Py
)
5770 GEOSContextHandleInternal_t
*handle
= 0;
5772 using geos::geom::Coordinate
;
5773 using geos::algorithm::CGAlgorithms
;
5775 if ( 0 == extHandle
)
5780 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5781 if ( 0 == handle
->initialized
)
5788 Coordinate
A(Ax
, Ay
);
5789 Coordinate
B(Bx
, By
);
5790 Coordinate
P(Px
, Py
);
5791 return CGAlgorithms::orientationIndex(A
, B
, P
);
5793 catch (const std::exception
&e
)
5795 handle
->ERROR_MESSAGE("%s", e
.what());
5800 handle
->ERROR_MESSAGE("Unknown exception thrown");
5806 GEOSSharedPaths_r(GEOSContextHandle_t extHandle
, const GEOSGeometry
* g1
, const GEOSGeometry
* g2
)
5808 using namespace geos::operation::sharedpaths
;
5810 if ( 0 == extHandle
) return 0;
5811 GEOSContextHandleInternal_t
*handle
=
5812 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5813 if ( handle
->initialized
== 0 ) return 0;
5815 SharedPathsOp::PathList forw
, back
;
5817 SharedPathsOp::sharedPathsOp(*g1
, *g2
, forw
, back
);
5819 catch (const std::exception
&e
)
5821 SharedPathsOp::clearEdges(forw
);
5822 SharedPathsOp::clearEdges(back
);
5823 handle
->ERROR_MESSAGE("%s", e
.what());
5828 SharedPathsOp::clearEdges(forw
);
5829 SharedPathsOp::clearEdges(back
);
5830 handle
->ERROR_MESSAGE("Unknown exception thrown");
5834 // Now forw and back have the geoms we want to use to construct
5835 // our output GeometryCollections...
5837 const GeometryFactory
* factory
= g1
->getFactory();
5840 std::auto_ptr
< std::vector
<Geometry
*> > out1(
5841 new std::vector
<Geometry
*>()
5843 count
= forw
.size();
5844 out1
->reserve(count
);
5845 for (size_t i
=0; i
<count
; ++i
) {
5846 out1
->push_back(forw
[i
]);
5848 std::auto_ptr
<Geometry
> out1g (
5849 factory
->createMultiLineString(out1
.release())
5852 std::auto_ptr
< std::vector
<Geometry
*> > out2(
5853 new std::vector
<Geometry
*>()
5855 count
= back
.size();
5856 out2
->reserve(count
);
5857 for (size_t i
=0; i
<count
; ++i
) {
5858 out2
->push_back(back
[i
]);
5860 std::auto_ptr
<Geometry
> out2g (
5861 factory
->createMultiLineString(out2
.release())
5864 std::auto_ptr
< std::vector
<Geometry
*> > out(
5865 new std::vector
<Geometry
*>()
5868 out
->push_back(out1g
.release());
5869 out
->push_back(out2g
.release());
5871 std::auto_ptr
<Geometry
> outg (
5872 factory
->createGeometryCollection(out
.release())
5875 return outg
.release();
5880 GEOSSnap_r(GEOSContextHandle_t extHandle
, const GEOSGeometry
* g1
,
5881 const GEOSGeometry
* g2
, double tolerance
)
5883 using namespace geos::operation::overlay::snap
;
5885 if ( 0 == extHandle
) return 0;
5886 GEOSContextHandleInternal_t
*handle
=
5887 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5888 if ( handle
->initialized
== 0 ) return 0;
5891 GeometrySnapper
snapper( *g1
);
5892 std::auto_ptr
<Geometry
> ret
= snapper
.snapTo(*g2
, tolerance
);
5893 return ret
.release();
5895 catch (const std::exception
&e
)
5897 handle
->ERROR_MESSAGE("%s", e
.what());
5902 handle
->ERROR_MESSAGE("Unknown exception thrown");
5908 GEOSBufferParams_create_r(GEOSContextHandle_t extHandle
)
5910 if ( 0 == extHandle
) return NULL
;
5912 GEOSContextHandleInternal_t
*handle
= 0;
5913 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5914 if ( 0 == handle
->initialized
) return NULL
;
5918 BufferParameters
*p
= new BufferParameters();
5921 catch (const std::exception
&e
)
5923 handle
->ERROR_MESSAGE("%s", e
.what());
5927 handle
->ERROR_MESSAGE("Unknown exception thrown");
5934 GEOSBufferParams_destroy_r(GEOSContextHandle_t extHandle
, BufferParameters
* p
)
5941 GEOSBufferParams_setEndCapStyle_r(GEOSContextHandle_t extHandle
,
5942 GEOSBufferParams
* p
, int style
)
5944 if ( 0 == extHandle
) return 0;
5946 GEOSContextHandleInternal_t
*handle
= 0;
5947 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5948 if ( 0 == handle
->initialized
) return 0;
5952 if ( style
> BufferParameters::CAP_SQUARE
)
5954 throw IllegalArgumentException("Invalid buffer endCap style");
5956 p
->setEndCapStyle(static_cast<BufferParameters::EndCapStyle
>(style
));
5959 catch (const std::exception
&e
)
5961 handle
->ERROR_MESSAGE("%s", e
.what());
5965 handle
->ERROR_MESSAGE("Unknown exception thrown");
5972 GEOSBufferParams_setJoinStyle_r(GEOSContextHandle_t extHandle
,
5973 GEOSBufferParams
* p
, int style
)
5975 if ( 0 == extHandle
) return 0;
5977 GEOSContextHandleInternal_t
*handle
= 0;
5978 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5979 if ( 0 == handle
->initialized
) return 0;
5983 if ( style
> BufferParameters::JOIN_BEVEL
) {
5984 throw IllegalArgumentException("Invalid buffer join style");
5986 p
->setJoinStyle(static_cast<BufferParameters::JoinStyle
>(style
));
5989 catch (const std::exception
&e
)
5991 handle
->ERROR_MESSAGE("%s", e
.what());
5995 handle
->ERROR_MESSAGE("Unknown exception thrown");
6002 GEOSBufferParams_setMitreLimit_r(GEOSContextHandle_t extHandle
,
6003 GEOSBufferParams
* p
, double limit
)
6005 if ( 0 == extHandle
) return 0;
6007 GEOSContextHandleInternal_t
*handle
= 0;
6008 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6009 if ( 0 == handle
->initialized
) return 0;
6013 p
->setMitreLimit(limit
);
6016 catch (const std::exception
&e
)
6018 handle
->ERROR_MESSAGE("%s", e
.what());
6022 handle
->ERROR_MESSAGE("Unknown exception thrown");
6029 GEOSBufferParams_setQuadrantSegments_r(GEOSContextHandle_t extHandle
,
6030 GEOSBufferParams
* p
, int segs
)
6032 if ( 0 == extHandle
) return 0;
6034 GEOSContextHandleInternal_t
*handle
= 0;
6035 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6036 if ( 0 == handle
->initialized
) return 0;
6040 p
->setQuadrantSegments(segs
);
6043 catch (const std::exception
&e
)
6045 handle
->ERROR_MESSAGE("%s", e
.what());
6049 handle
->ERROR_MESSAGE("Unknown exception thrown");
6056 GEOSBufferParams_setSingleSided_r(GEOSContextHandle_t extHandle
,
6057 GEOSBufferParams
* p
, int ss
)
6059 if ( 0 == extHandle
) return 0;
6061 GEOSContextHandleInternal_t
*handle
= 0;
6062 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6063 if ( 0 == handle
->initialized
) return 0;
6067 p
->setSingleSided( (ss
!= 0) );
6070 catch (const std::exception
&e
)
6072 handle
->ERROR_MESSAGE("%s", e
.what());
6076 handle
->ERROR_MESSAGE("Unknown exception thrown");
6083 GEOSBufferWithParams_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const BufferParameters
* bp
, double width
)
6085 using geos::operation::buffer::BufferOp
;
6087 if ( 0 == extHandle
) return NULL
;
6089 GEOSContextHandleInternal_t
*handle
= 0;
6090 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6091 if ( 0 == handle
->initialized
) return NULL
;
6095 BufferOp
op(g1
, *bp
);
6096 Geometry
*g3
= op
.getResultGeometry(width
);
6099 catch (const std::exception
&e
)
6101 handle
->ERROR_MESSAGE("%s", e
.what());
6105 handle
->ERROR_MESSAGE("Unknown exception thrown");