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/noding/GeometryNoder.h>
49 #include <geos/operation/valid/IsValidOp.h>
50 #include <geos/operation/polygonize/Polygonizer.h>
51 #include <geos/operation/linemerge/LineMerger.h>
52 #include <geos/operation/overlay/OverlayOp.h>
53 #include <geos/operation/union/CascadedPolygonUnion.h>
54 #include <geos/operation/buffer/BufferOp.h>
55 #include <geos/operation/buffer/BufferParameters.h>
56 #include <geos/operation/buffer/BufferBuilder.h>
57 #include <geos/operation/relate/RelateOp.h>
58 #include <geos/operation/sharedpaths/SharedPathsOp.h>
59 #include <geos/linearref/LengthIndexedLine.h>
60 #include <geos/geom/BinaryOp.h>
61 #include <geos/util/IllegalArgumentException.h>
62 #include <geos/util/UniqueCoordinateArrayFilter.h>
63 #include <geos/util/Machine.h>
64 #include <geos/version.h>
66 // This should go away
67 #include <cmath> // finite
79 #pragma warning(disable : 4099)
82 // Some extra magic to make type declarations in geos_c.h work -
83 // for cross-checking of types in header.
84 #define GEOSGeometry geos::geom::Geometry
85 #define GEOSPreparedGeometry geos::geom::prep::PreparedGeometry
86 #define GEOSCoordSequence geos::geom::CoordinateSequence
87 #define GEOSBufferParams geos::operation::buffer::BufferParameters
88 #define GEOSSTRtree geos::index::strtree::STRtree
89 #define GEOSWKTReader_t geos::io::WKTReader
90 #define GEOSWKTWriter_t geos::io::WKTWriter
91 #define GEOSWKBReader_t geos::io::WKBReader
92 #define GEOSWKBWriter_t geos::io::WKBWriter
96 // Intentional, to allow non-standard C elements like C99 functions to be
97 // imported through C++ headers of C library, like <cmath>.
100 /// Define this if you want operations triggering Exceptions to
102 /// (will use the NOTIFY channel - only implemented for GEOSUnion so far)
104 #undef VERBOSE_EXCEPTIONS
106 #include <geos/export.h>
109 // import the most frequently used definitions globally
110 using geos::geom::Geometry
;
111 using geos::geom::LineString
;
112 using geos::geom::Polygon
;
113 using geos::geom::CoordinateSequence
;
114 using geos::geom::GeometryFactory
;
116 using geos::io::WKTReader
;
117 using geos::io::WKTWriter
;
118 using geos::io::WKBReader
;
119 using geos::io::WKBWriter
;
121 using geos::operation::overlay::OverlayOp
;
122 using geos::operation::overlay::overlayOp
;
123 using geos::operation::geounion::CascadedPolygonUnion
;
124 using geos::operation::buffer::BufferParameters
;
125 using geos::operation::buffer::BufferBuilder
;
126 using geos::util::IllegalArgumentException
;
127 using geos::algorithm::distance::DiscreteHausdorffDistance
;
129 typedef std::auto_ptr
<Geometry
> GeomAutoPtr
;
131 typedef struct GEOSContextHandleInternal
133 const GeometryFactory
*geomFactory
;
134 GEOSMessageHandler NOTICE_MESSAGE
;
135 GEOSMessageHandler ERROR_MESSAGE
;
139 } GEOSContextHandleInternal_t
;
141 // CAPI_ItemVisitor is used internally by the CAPI STRtree
142 // wrappers. It's defined here just to keep it out of the
144 class CAPI_ItemVisitor
: public geos::index::ItemVisitor
{
145 GEOSQueryCallback callback
;
148 CAPI_ItemVisitor (GEOSQueryCallback cb
, void *ud
)
149 : ItemVisitor(), callback(cb
), userdata(ud
) {}
150 void visitItem (void *item
) { callback(item
, userdata
); }
154 //## PROTOTYPES #############################################
156 extern "C" const char GEOS_DLL
*GEOSjtsport();
157 extern "C" char GEOS_DLL
*GEOSasText(Geometry
*g1
);
159 namespace { // anonymous
161 char* gstrdup_s(const char* str
, const std::size_t size
)
163 char* out
= static_cast<char*>(std::malloc(size
+ 1));
166 // as no strlen call necessary, memcpy may be faster than strcpy
167 std::memcpy(out
, str
, size
+ 1);
172 // we haven't been checking allocation before ticket #371
175 throw(std::runtime_error("Failed to allocate memory for duplicate string"));
181 char* gstrdup(std::string
const& str
)
183 return gstrdup_s(str
.c_str(), str
.size());
186 } // namespace anonymous
191 initGEOS_r(GEOSMessageHandler nf
, GEOSMessageHandler ef
)
193 GEOSContextHandleInternal_t
*handle
= 0;
196 extHandle
= std::malloc(sizeof(GEOSContextHandleInternal_t
));
199 handle
= static_cast<GEOSContextHandleInternal_t
*>(extHandle
);
200 handle
->NOTICE_MESSAGE
= nf
;
201 handle
->ERROR_MESSAGE
= ef
;
202 handle
->geomFactory
= GeometryFactory::getDefaultInstance();
203 handle
->WKBOutputDims
= 2;
204 handle
->WKBByteOrder
= getMachineByteOrder();
205 handle
->initialized
= 1;
208 return static_cast<GEOSContextHandle_t
>(extHandle
);
212 GEOSContext_setNoticeHandler_r(GEOSContextHandle_t extHandle
, GEOSMessageHandler nf
)
214 GEOSMessageHandler f
;
215 GEOSContextHandleInternal_t
*handle
= 0;
216 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
217 if ( 0 == handle
->initialized
)
222 f
= handle
->NOTICE_MESSAGE
;
223 handle
->NOTICE_MESSAGE
= nf
;
229 GEOSContext_setErrorHandler_r(GEOSContextHandle_t extHandle
, GEOSMessageHandler nf
)
231 GEOSMessageHandler f
;
232 GEOSContextHandleInternal_t
*handle
= 0;
233 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
234 if ( 0 == handle
->initialized
)
239 f
= handle
->ERROR_MESSAGE
;
240 handle
->ERROR_MESSAGE
= nf
;
246 finishGEOS_r(GEOSContextHandle_t extHandle
)
248 // Fix up freeing handle w.r.t. malloc above
249 std::free(extHandle
);
254 GEOSFree_r (GEOSContextHandle_t extHandle
, void* buffer
)
256 assert(0 != extHandle
);
261 //-----------------------------------------------------------
262 // relate()-related functions
263 // return 0 = false, 1 = true, 2 = error occured
264 //-----------------------------------------------------------
267 GEOSDisjoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
269 if ( 0 == extHandle
)
274 GEOSContextHandleInternal_t
*handle
= 0;
275 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
276 if ( handle
->initialized
== 0 )
283 bool result
= g1
->disjoint(g2
);
287 // TODO: mloskot is going to replace these double-catch block
288 // with a macro to remove redundant code in this and
289 // following functions.
290 catch (const std::exception
&e
)
292 handle
->ERROR_MESSAGE("%s", e
.what());
296 handle
->ERROR_MESSAGE("Unknown exception thrown");
303 GEOSTouches_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
305 if ( 0 == extHandle
)
310 GEOSContextHandleInternal_t
*handle
= 0;
311 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
312 if ( 0 == handle
->initialized
)
319 bool result
= g1
->touches(g2
);
322 catch (const std::exception
&e
)
324 handle
->ERROR_MESSAGE("%s", e
.what());
328 handle
->ERROR_MESSAGE("Unknown exception thrown");
335 GEOSIntersects_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
337 if ( 0 == extHandle
)
342 GEOSContextHandleInternal_t
*handle
= 0;
343 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
344 if ( 0 == handle
->initialized
)
351 bool result
= g1
->intersects(g2
);
354 catch (const std::exception
&e
)
356 handle
->ERROR_MESSAGE("%s", e
.what());
360 handle
->ERROR_MESSAGE("Unknown exception thrown");
367 GEOSCrosses_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
369 if ( 0 == extHandle
)
374 GEOSContextHandleInternal_t
*handle
= 0;
375 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
376 if ( 0 == handle
->initialized
)
383 bool result
= g1
->crosses(g2
);
386 catch (const std::exception
&e
)
388 handle
->ERROR_MESSAGE("%s", e
.what());
392 handle
->ERROR_MESSAGE("Unknown exception thrown");
399 GEOSWithin_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
401 if ( 0 == extHandle
)
406 GEOSContextHandleInternal_t
*handle
= 0;
407 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
408 if ( 0 == handle
->initialized
)
415 bool result
= g1
->within(g2
);
418 catch (const std::exception
&e
)
420 handle
->ERROR_MESSAGE("%s", e
.what());
424 handle
->ERROR_MESSAGE("Unknown exception thrown");
430 // call g1->contains(g2)
433 // 2 = error was trapped
435 GEOSContains_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
437 if ( 0 == extHandle
)
442 GEOSContextHandleInternal_t
*handle
= 0;
443 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
444 if ( 0 == handle
->initialized
)
451 bool result
= g1
->contains(g2
);
454 catch (const std::exception
&e
)
456 handle
->ERROR_MESSAGE("%s", e
.what());
460 handle
->ERROR_MESSAGE("Unknown exception thrown");
467 GEOSOverlaps_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
469 if ( 0 == extHandle
)
474 GEOSContextHandleInternal_t
*handle
= 0;
475 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
476 if ( 0 == handle
->initialized
)
483 bool result
= g1
->overlaps(g2
);
486 catch (const std::exception
&e
)
488 handle
->ERROR_MESSAGE("%s", e
.what());
492 handle
->ERROR_MESSAGE("Unknown exception thrown");
499 GEOSCovers_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
501 if ( 0 == extHandle
)
506 GEOSContextHandleInternal_t
*handle
= 0;
507 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
508 if ( 0 == handle
->initialized
)
515 bool result
= g1
->covers(g2
);
518 catch (const std::exception
&e
)
520 handle
->ERROR_MESSAGE("%s", e
.what());
524 handle
->ERROR_MESSAGE("Unknown exception thrown");
531 GEOSCoveredBy_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
533 if ( 0 == extHandle
)
538 GEOSContextHandleInternal_t
*handle
= 0;
539 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
540 if ( 0 == handle
->initialized
)
547 bool result
= g1
->coveredBy(g2
);
550 catch (const std::exception
&e
)
552 handle
->ERROR_MESSAGE("%s", e
.what());
556 handle
->ERROR_MESSAGE("Unknown exception thrown");
563 //-------------------------------------------------------------------
564 // low-level relate functions
565 //------------------------------------------------------------------
568 GEOSRelatePattern_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, const char *pat
)
570 if ( 0 == extHandle
)
575 GEOSContextHandleInternal_t
*handle
= 0;
576 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
577 if ( 0 == handle
->initialized
)
585 bool result
= g1
->relate(g2
, s
);
588 catch (const std::exception
&e
)
590 handle
->ERROR_MESSAGE("%s", e
.what());
594 handle
->ERROR_MESSAGE("Unknown exception thrown");
601 GEOSRelatePatternMatch_r(GEOSContextHandle_t extHandle
, const char *mat
,
604 if ( 0 == extHandle
)
609 GEOSContextHandleInternal_t
*handle
= 0;
610 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
611 if ( 0 == handle
->initialized
)
618 using geos::geom::IntersectionMatrix
;
622 IntersectionMatrix
im(m
);
624 bool result
= im
.matches(p
);
627 catch (const std::exception
&e
)
629 handle
->ERROR_MESSAGE("%s", e
.what());
633 handle
->ERROR_MESSAGE("Unknown exception thrown");
640 GEOSRelate_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
642 if ( 0 == extHandle
)
647 GEOSContextHandleInternal_t
*handle
= 0;
648 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
649 if ( 0 == handle
->initialized
)
656 using geos::geom::IntersectionMatrix
;
658 IntersectionMatrix
* im
= g1
->relate(g2
);
664 char *result
= gstrdup(im
->toString());
671 catch (const std::exception
&e
)
673 handle
->ERROR_MESSAGE("%s", e
.what());
677 handle
->ERROR_MESSAGE("Unknown exception thrown");
684 GEOSRelateBoundaryNodeRule_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, int bnr
)
686 if ( 0 == extHandle
)
691 GEOSContextHandleInternal_t
*handle
= 0;
692 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
693 if ( 0 == handle
->initialized
)
700 using geos::operation::relate::RelateOp
;
701 using geos::geom::IntersectionMatrix
;
702 using geos::algorithm::BoundaryNodeRule
;
704 IntersectionMatrix
* im
;
706 case GEOSRELATE_BNR_MOD2
: /* same as OGC */
707 im
= RelateOp::relate(g1
, g2
,
708 BoundaryNodeRule::MOD2_BOUNDARY_RULE
);
710 case GEOSRELATE_BNR_ENDPOINT
:
711 im
= RelateOp::relate(g1
, g2
,
712 BoundaryNodeRule::ENDPOINT_BOUNDARY_RULE
);
714 case GEOSRELATE_BNR_MULTIVALENT_ENDPOINT
:
715 im
= RelateOp::relate(g1
, g2
,
716 BoundaryNodeRule::MULTIVALENT_ENDPOINT_BOUNDARY_RULE
);
718 case GEOSRELATE_BNR_MONOVALENT_ENDPOINT
:
719 im
= RelateOp::relate(g1
, g2
,
720 BoundaryNodeRule::MONOVALENT_ENDPOINT_BOUNDARY_RULE
);
723 handle
->ERROR_MESSAGE("Invalid boundary node rule %d", bnr
);
728 if (0 == im
) return 0;
730 char *result
= gstrdup(im
->toString());
737 catch (const std::exception
&e
)
739 handle
->ERROR_MESSAGE("%s", e
.what());
743 handle
->ERROR_MESSAGE("Unknown exception thrown");
751 //-----------------------------------------------------------------
753 //-----------------------------------------------------------------
757 GEOSisValid_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
759 if ( 0 == extHandle
)
764 GEOSContextHandleInternal_t
*handle
= 0;
765 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
766 if ( 0 == handle
->initialized
)
773 using geos::operation::valid::IsValidOp
;
774 using geos::operation::valid::TopologyValidationError
;
777 TopologyValidationError
*err
= ivo
.getValidationError();
780 handle
->NOTICE_MESSAGE("%s", err
->toString().c_str());
788 catch (const std::exception
&e
)
790 handle
->ERROR_MESSAGE("%s", e
.what());
794 handle
->ERROR_MESSAGE("Unknown exception thrown");
801 GEOSisValidReason_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
803 if ( 0 == extHandle
)
808 GEOSContextHandleInternal_t
*handle
= 0;
809 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
810 if ( 0 == handle
->initialized
)
817 using geos::operation::valid::IsValidOp
;
818 using geos::operation::valid::TopologyValidationError
;
821 char const* const validstr
= "Valid Geometry";
824 TopologyValidationError
*err
= ivo
.getValidationError();
827 std::ostringstream ss
;
829 ss
<< err
->getCoordinate();
830 const std::string errloc
= ss
.str();
831 std::string
errmsg(err
->getMessage());
832 errmsg
+= "[" + errloc
+ "]";
833 result
= gstrdup(errmsg
);
837 result
= gstrdup(std::string(validstr
));
842 catch (const std::exception
&e
)
844 handle
->ERROR_MESSAGE("%s", e
.what());
848 handle
->ERROR_MESSAGE("Unknown exception thrown");
855 GEOSisValidDetail_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
856 int flags
, char** reason
, Geometry
** location
)
858 if ( 0 == extHandle
)
863 GEOSContextHandleInternal_t
*handle
= 0;
864 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
865 if ( 0 == handle
->initialized
)
872 using geos::operation::valid::IsValidOp
;
873 using geos::operation::valid::TopologyValidationError
;
876 if ( flags
& GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE
) {
877 ivo
.setSelfTouchingRingFormingHoleValid(true);
879 TopologyValidationError
*err
= ivo
.getValidationError();
883 *location
= handle
->geomFactory
->createPoint(err
->getCoordinate());
886 std::string
errmsg(err
->getMessage());
887 *reason
= gstrdup(errmsg
);
892 if ( location
) *location
= 0;
893 if ( reason
) *reason
= 0;
894 return 1; /* valid */
897 catch (const std::exception
&e
)
899 handle
->ERROR_MESSAGE("%s", e
.what());
903 handle
->ERROR_MESSAGE("Unknown exception thrown");
906 return 2; /* exception */
909 //-----------------------------------------------------------------
911 //-----------------------------------------------------------------
914 GEOSEquals_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
916 if ( 0 == extHandle
)
921 GEOSContextHandleInternal_t
*handle
= 0;
922 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
923 if ( 0 == handle
->initialized
)
930 bool result
= g1
->equals(g2
);
933 catch (const std::exception
&e
)
935 handle
->ERROR_MESSAGE("%s", e
.what());
939 handle
->ERROR_MESSAGE("Unknown exception thrown");
946 GEOSEqualsExact_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double tolerance
)
948 if ( 0 == extHandle
)
953 GEOSContextHandleInternal_t
*handle
= 0;
954 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
955 if ( 0 == handle
->initialized
)
962 bool result
= g1
->equalsExact(g2
, tolerance
);
965 catch (const std::exception
&e
)
967 handle
->ERROR_MESSAGE("%s", e
.what());
971 handle
->ERROR_MESSAGE("Unknown exception thrown");
978 GEOSDistance_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double *dist
)
982 if ( 0 == extHandle
)
987 GEOSContextHandleInternal_t
*handle
= 0;
988 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
989 if ( 0 == handle
->initialized
)
996 *dist
= g1
->distance(g2
);
999 catch (const std::exception
&e
)
1001 handle
->ERROR_MESSAGE("%s", e
.what());
1005 handle
->ERROR_MESSAGE("Unknown exception thrown");
1012 GEOSHausdorffDistance_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double *dist
)
1016 if ( 0 == extHandle
)
1021 GEOSContextHandleInternal_t
*handle
= 0;
1022 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1023 if ( 0 == handle
->initialized
)
1030 *dist
= DiscreteHausdorffDistance::distance(*g1
, *g2
);
1033 catch (const std::exception
&e
)
1035 handle
->ERROR_MESSAGE("%s", e
.what());
1039 handle
->ERROR_MESSAGE("Unknown exception thrown");
1046 GEOSHausdorffDistanceDensify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double densifyFrac
, double *dist
)
1050 if ( 0 == extHandle
)
1055 GEOSContextHandleInternal_t
*handle
= 0;
1056 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1057 if ( 0 == handle
->initialized
)
1064 *dist
= DiscreteHausdorffDistance::distance(*g1
, *g2
, densifyFrac
);
1067 catch (const std::exception
&e
)
1069 handle
->ERROR_MESSAGE("%s", e
.what());
1073 handle
->ERROR_MESSAGE("Unknown exception thrown");
1080 GEOSArea_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double *area
)
1084 if ( 0 == extHandle
)
1089 GEOSContextHandleInternal_t
*handle
= 0;
1090 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1091 if ( 0 == handle
->initialized
)
1098 *area
= g
->getArea();
1101 catch (const std::exception
&e
)
1103 handle
->ERROR_MESSAGE("%s", e
.what());
1107 handle
->ERROR_MESSAGE("Unknown exception thrown");
1114 GEOSLength_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double *length
)
1116 assert(0 != length
);
1118 if ( 0 == extHandle
)
1123 GEOSContextHandleInternal_t
*handle
= 0;
1124 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1125 if ( 0 == handle
->initialized
)
1132 *length
= g
->getLength();
1135 catch (const std::exception
&e
)
1137 handle
->ERROR_MESSAGE("%s", e
.what());
1141 handle
->ERROR_MESSAGE("Unknown exception thrown");
1148 GEOSGeomFromWKT_r(GEOSContextHandle_t extHandle
, const char *wkt
)
1150 if ( 0 == extHandle
)
1155 GEOSContextHandleInternal_t
*handle
= 0;
1156 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1157 if ( 0 == handle
->initialized
)
1164 const std::string
wktstring(wkt
);
1165 WKTReader
r(static_cast<GeometryFactory
const*>(handle
->geomFactory
));
1167 Geometry
*g
= r
.read(wktstring
);
1170 catch (const std::exception
&e
)
1172 handle
->ERROR_MESSAGE("%s", e
.what());
1176 handle
->ERROR_MESSAGE("Unknown exception thrown");
1183 GEOSGeomToWKT_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1185 if ( 0 == extHandle
)
1190 GEOSContextHandleInternal_t
*handle
= 0;
1191 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1192 if ( 0 == handle
->initialized
)
1200 char *result
= gstrdup(g1
->toString());
1203 catch (const std::exception
&e
)
1205 handle
->ERROR_MESSAGE("%s", e
.what());
1209 handle
->ERROR_MESSAGE("Unknown exception thrown");
1214 // Remember to free the result!
1216 GEOSGeomToWKB_buf_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, size_t *size
)
1220 if ( 0 == extHandle
)
1225 GEOSContextHandleInternal_t
*handle
= 0;
1226 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1227 if ( 0 == handle
->initialized
)
1232 using geos::io::WKBWriter
;
1235 int byteOrder
= handle
->WKBByteOrder
;
1236 WKBWriter
w(handle
->WKBOutputDims
, byteOrder
);
1237 std::ostringstream
os(std::ios_base::binary
);
1239 std::string
wkbstring(os
.str());
1240 const std::size_t len
= wkbstring
.length();
1242 unsigned char* result
= 0;
1243 result
= static_cast<unsigned char*>(std::malloc(len
));
1246 std::memcpy(result
, wkbstring
.c_str(), len
);
1251 catch (const std::exception
&e
)
1253 handle
->ERROR_MESSAGE("%s", e
.what());
1257 handle
->ERROR_MESSAGE("Unknown exception thrown");
1264 GEOSGeomFromWKB_buf_r(GEOSContextHandle_t extHandle
, const unsigned char *wkb
, size_t size
)
1266 if ( 0 == extHandle
)
1271 GEOSContextHandleInternal_t
*handle
= 0;
1272 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1273 if ( 0 == handle
->initialized
)
1278 using geos::io::WKBReader
;
1281 std::string
wkbstring(reinterpret_cast<const char*>(wkb
), size
); // make it binary !
1282 WKBReader
r(*(static_cast<GeometryFactory
const*>(handle
->geomFactory
)));
1283 std::istringstream
is(std::ios_base::binary
);
1285 is
.seekg(0, std::ios::beg
); // rewind reader pointer
1286 Geometry
*g
= r
.read(is
);
1289 catch (const std::exception
&e
)
1291 handle
->ERROR_MESSAGE("%s", e
.what());
1295 handle
->ERROR_MESSAGE("Unknown exception thrown");
1301 /* Read/write wkb hex values. Returned geometries are
1302 owned by the caller.*/
1304 GEOSGeomToHEX_buf_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, size_t *size
)
1306 if ( 0 == extHandle
)
1311 GEOSContextHandleInternal_t
*handle
= 0;
1312 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1313 if ( 0 == handle
->initialized
)
1318 using geos::io::WKBWriter
;
1321 int byteOrder
= handle
->WKBByteOrder
;
1322 WKBWriter
w(handle
->WKBOutputDims
, byteOrder
);
1323 std::ostringstream
os(std::ios_base::binary
);
1325 std::string
hexstring(os
.str());
1327 char *result
= gstrdup(hexstring
);
1330 *size
= hexstring
.length();
1333 return reinterpret_cast<unsigned char*>(result
);
1335 catch (const std::exception
&e
)
1337 handle
->ERROR_MESSAGE("%s", e
.what());
1341 handle
->ERROR_MESSAGE("Unknown exception thrown");
1348 GEOSGeomFromHEX_buf_r(GEOSContextHandle_t extHandle
, const unsigned char *hex
, size_t size
)
1350 if ( 0 == extHandle
)
1355 GEOSContextHandleInternal_t
*handle
= 0;
1356 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1357 if ( 0 == handle
->initialized
)
1362 using geos::io::WKBReader
;
1365 std::string
hexstring(reinterpret_cast<const char*>(hex
), size
);
1366 WKBReader
r(*(static_cast<GeometryFactory
const*>(handle
->geomFactory
)));
1367 std::istringstream
is(std::ios_base::binary
);
1369 is
.seekg(0, std::ios::beg
); // rewind reader pointer
1371 Geometry
*g
= r
.readHEX(is
);
1374 catch (const std::exception
&e
)
1376 handle
->ERROR_MESSAGE("%s", e
.what());
1380 handle
->ERROR_MESSAGE("Unknown exception thrown");
1387 GEOSisEmpty_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1389 if ( 0 == extHandle
)
1394 GEOSContextHandleInternal_t
*handle
= 0;
1395 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1396 if ( 0 == handle
->initialized
)
1403 return g1
->isEmpty();
1405 catch (const std::exception
&e
)
1407 handle
->ERROR_MESSAGE("%s", e
.what());
1411 handle
->ERROR_MESSAGE("Unknown exception thrown");
1418 GEOSisSimple_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1420 if ( 0 == extHandle
)
1425 GEOSContextHandleInternal_t
*handle
= 0;
1426 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1427 if ( 0 == handle
->initialized
)
1434 return g1
->isSimple();
1436 catch (const std::exception
&e
)
1438 handle
->ERROR_MESSAGE("%s", e
.what());
1444 handle
->ERROR_MESSAGE("Unknown exception thrown");
1450 GEOSisRing_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
1452 if ( 0 == extHandle
)
1457 GEOSContextHandleInternal_t
*handle
= 0;
1458 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1459 if ( 0 == handle
->initialized
)
1466 const LineString
*ls
= dynamic_cast<const LineString
*>(g
);
1468 return (ls
->isRing());
1473 catch (const std::exception
&e
)
1475 handle
->ERROR_MESSAGE("%s", e
.what());
1481 handle
->ERROR_MESSAGE("Unknown exception thrown");
1488 //free the result of this
1490 GEOSGeomType_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1492 if ( 0 == extHandle
)
1497 GEOSContextHandleInternal_t
*handle
= 0;
1498 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1499 if ( 0 == handle
->initialized
)
1506 std::string s
= g1
->getGeometryType();
1508 char *result
= gstrdup(s
);
1511 catch (const std::exception
&e
)
1513 handle
->ERROR_MESSAGE("%s", e
.what());
1517 handle
->ERROR_MESSAGE("Unknown exception thrown");
1523 // Return postgis geometry type index
1525 GEOSGeomTypeId_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1527 if ( 0 == extHandle
)
1532 GEOSContextHandleInternal_t
*handle
= 0;
1533 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1534 if ( 0 == handle
->initialized
)
1541 return g1
->getGeometryTypeId();
1543 catch (const std::exception
&e
)
1545 handle
->ERROR_MESSAGE("%s", e
.what());
1549 handle
->ERROR_MESSAGE("Unknown exception thrown");
1555 //-------------------------------------------------------------------
1556 // GEOS functions that return geometries
1557 //-------------------------------------------------------------------
1560 GEOSEnvelope_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1562 if ( 0 == extHandle
)
1567 GEOSContextHandleInternal_t
*handle
= 0;
1568 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1569 if ( 0 == handle
->initialized
)
1576 Geometry
*g3
= g1
->getEnvelope();
1579 catch (const std::exception
&e
)
1581 handle
->ERROR_MESSAGE("%s", e
.what());
1585 handle
->ERROR_MESSAGE("Unknown exception thrown");
1592 GEOSIntersection_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1594 if ( 0 == extHandle
)
1599 GEOSContextHandleInternal_t
*handle
= 0;
1600 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1601 if ( 0 == handle
->initialized
)
1608 GeomAutoPtr
g3(BinaryOp(g1
, g2
, overlayOp(OverlayOp::opINTERSECTION
)));
1609 return g3
.release();
1612 //Geometry *g3 = g1->intersection(g2);
1615 catch (const std::exception
&e
)
1617 handle
->ERROR_MESSAGE("%s", e
.what());
1621 handle
->ERROR_MESSAGE("Unknown exception thrown");
1628 GEOSBuffer_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadrantsegments
)
1630 if ( 0 == extHandle
)
1635 GEOSContextHandleInternal_t
*handle
= 0;
1636 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1637 if ( 0 == handle
->initialized
)
1644 Geometry
*g3
= g1
->buffer(width
, quadrantsegments
);
1647 catch (const std::exception
&e
)
1649 handle
->ERROR_MESSAGE("%s", e
.what());
1653 handle
->ERROR_MESSAGE("Unknown exception thrown");
1660 GEOSBufferWithStyle_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int endCapStyle
, int joinStyle
, double mitreLimit
)
1662 using geos::operation::buffer::BufferParameters
;
1663 using geos::operation::buffer::BufferOp
;
1664 using geos::util::IllegalArgumentException
;
1666 if ( 0 == extHandle
)
1671 GEOSContextHandleInternal_t
*handle
= 0;
1672 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1673 if ( 0 == handle
->initialized
)
1680 BufferParameters bp
;
1681 bp
.setQuadrantSegments(quadsegs
);
1683 if ( endCapStyle
> BufferParameters::CAP_SQUARE
)
1685 throw IllegalArgumentException("Invalid buffer endCap style");
1688 static_cast<BufferParameters::EndCapStyle
>(endCapStyle
)
1691 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1693 throw IllegalArgumentException("Invalid buffer join style");
1696 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1698 bp
.setMitreLimit(mitreLimit
);
1699 BufferOp
op(g1
, bp
);
1700 Geometry
*g3
= op
.getResultGeometry(width
);
1703 catch (const std::exception
&e
)
1705 handle
->ERROR_MESSAGE("%s", e
.what());
1709 handle
->ERROR_MESSAGE("Unknown exception thrown");
1716 GEOSOffsetCurve_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int joinStyle
, double mitreLimit
)
1718 if ( 0 == extHandle
) return NULL
;
1720 GEOSContextHandleInternal_t
*handle
= 0;
1721 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1722 if ( 0 == handle
->initialized
) return NULL
;
1726 BufferParameters bp
;
1727 bp
.setEndCapStyle( BufferParameters::CAP_FLAT
);
1728 bp
.setQuadrantSegments(quadsegs
);
1730 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1732 throw IllegalArgumentException("Invalid buffer join style");
1735 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1737 bp
.setMitreLimit(mitreLimit
);
1739 bool isLeftSide
= true;
1744 BufferBuilder
bufBuilder (bp
);
1745 Geometry
*g3
= bufBuilder
.bufferLineSingleSided(g1
, width
, isLeftSide
);
1749 catch (const std::exception
&e
)
1751 handle
->ERROR_MESSAGE("%s", e
.what());
1755 handle
->ERROR_MESSAGE("Unknown exception thrown");
1761 /* @deprecated in 3.3.0 */
1763 GEOSSingleSidedBuffer_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int joinStyle
, double mitreLimit
, int leftSide
)
1765 if ( 0 == extHandle
) return NULL
;
1767 GEOSContextHandleInternal_t
*handle
= 0;
1768 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1769 if ( 0 == handle
->initialized
) return NULL
;
1773 BufferParameters bp
;
1774 bp
.setEndCapStyle( BufferParameters::CAP_FLAT
);
1775 bp
.setQuadrantSegments(quadsegs
);
1777 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1779 throw IllegalArgumentException("Invalid buffer join style");
1782 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1784 bp
.setMitreLimit(mitreLimit
);
1786 bool isLeftSide
= leftSide
== 0 ? false : true;
1787 BufferBuilder
bufBuilder (bp
);
1788 Geometry
*g3
= bufBuilder
.bufferLineSingleSided(g1
, width
, isLeftSide
);
1792 catch (const std::exception
&e
)
1794 handle
->ERROR_MESSAGE("%s", e
.what());
1798 handle
->ERROR_MESSAGE("Unknown exception thrown");
1805 GEOSConvexHull_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1807 if ( 0 == extHandle
)
1812 GEOSContextHandleInternal_t
*handle
= 0;
1813 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1814 if ( 0 == handle
->initialized
)
1821 Geometry
*g3
= g1
->convexHull();
1824 catch (const std::exception
&e
)
1826 handle
->ERROR_MESSAGE("%s", e
.what());
1830 handle
->ERROR_MESSAGE("Unknown exception thrown");
1837 GEOSDifference_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1839 if ( 0 == extHandle
)
1844 GEOSContextHandleInternal_t
*handle
= 0;
1845 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1846 if ( 0 == handle
->initialized
)
1853 GeomAutoPtr
g3(BinaryOp(g1
, g2
, overlayOp(OverlayOp::opDIFFERENCE
)));
1854 return g3
.release();
1857 //Geometry *g3 = g1->difference(g2);
1860 catch (const std::exception
&e
)
1862 handle
->ERROR_MESSAGE("%s", e
.what());
1866 handle
->ERROR_MESSAGE("Unknown exception thrown");
1873 GEOSBoundary_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1875 if ( 0 == extHandle
)
1880 GEOSContextHandleInternal_t
*handle
= 0;
1881 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1882 if ( 0 == handle
->initialized
)
1889 Geometry
*g3
= g1
->getBoundary();
1892 catch (const std::exception
&e
)
1894 handle
->ERROR_MESSAGE("%s", e
.what());
1898 handle
->ERROR_MESSAGE("Unknown exception thrown");
1905 GEOSSymDifference_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1907 if ( 0 == extHandle
)
1912 GEOSContextHandleInternal_t
*handle
= 0;
1913 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1914 if ( 0 == handle
->initialized
)
1921 GeomAutoPtr g3
= BinaryOp(g1
, g2
, overlayOp(OverlayOp::opSYMDIFFERENCE
));
1922 return g3
.release();
1923 //Geometry *g3 = g1->symDifference(g2);
1926 catch (const std::exception
&e
)
1928 handle
->ERROR_MESSAGE("%s", e
.what());
1934 handle
->ERROR_MESSAGE("Unknown exception thrown");
1940 GEOSUnion_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1942 if ( 0 == extHandle
)
1947 GEOSContextHandleInternal_t
*handle
= 0;
1948 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1949 if ( 0 == handle
->initialized
)
1956 GeomAutoPtr g3
= BinaryOp(g1
, g2
, overlayOp(OverlayOp::opUNION
));
1957 return g3
.release();
1960 //Geometry *g3 = g1->Union(g2);
1963 catch (const std::exception
&e
)
1965 #if VERBOSE_EXCEPTIONS
1966 std::ostringstream s
;
1967 s
<< "Exception on GEOSUnion with following inputs:" << std::endl
;
1968 s
<< "A: "<<g1
->toString() << std::endl
;
1969 s
<< "B: "<<g2
->toString() << std::endl
;
1970 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
1971 #endif // VERBOSE_EXCEPTIONS
1972 handle
->ERROR_MESSAGE("%s", e
.what());
1976 handle
->ERROR_MESSAGE("Unknown exception thrown");
1983 GEOSUnaryUnion_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
1985 if ( 0 == extHandle
)
1990 GEOSContextHandleInternal_t
*handle
= 0;
1991 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1992 if ( 0 == handle
->initialized
)
1999 GeomAutoPtr
g3 ( g
->Union() );
2000 return g3
.release();
2002 catch (const std::exception
&e
)
2004 #if VERBOSE_EXCEPTIONS
2005 std::ostringstream s
;
2006 s
<< "Exception on GEOSUnaryUnion with following inputs:" << std::endl
;
2007 s
<< "A: "<<g1
->toString() << std::endl
;
2008 s
<< "B: "<<g2
->toString() << std::endl
;
2009 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
2010 #endif // VERBOSE_EXCEPTIONS
2011 handle
->ERROR_MESSAGE("%s", e
.what());
2015 handle
->ERROR_MESSAGE("Unknown exception thrown");
2022 GEOSNode_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2024 if ( 0 == extHandle
)
2029 GEOSContextHandleInternal_t
*handle
= 0;
2030 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2031 if ( 0 == handle
->initialized
)
2038 std::auto_ptr
<Geometry
> g3
= geos::noding::GeometryNoder::node(*g
);
2039 return g3
.release();
2041 catch (const std::exception
&e
)
2043 #if VERBOSE_EXCEPTIONS
2044 std::ostringstream s
;
2045 s
<< "Exception on GEOSUnaryUnion with following inputs:" << std::endl
;
2046 s
<< "A: "<<g1
->toString() << std::endl
;
2047 s
<< "B: "<<g2
->toString() << std::endl
;
2048 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
2049 #endif // VERBOSE_EXCEPTIONS
2050 handle
->ERROR_MESSAGE("%s", e
.what());
2054 handle
->ERROR_MESSAGE("Unknown exception thrown");
2061 GEOSUnionCascaded_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2063 if ( 0 == extHandle
)
2068 GEOSContextHandleInternal_t
*handle
= 0;
2069 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2070 if ( 0 == handle
->initialized
)
2077 const geos::geom::MultiPolygon
*p
= dynamic_cast<const geos::geom::MultiPolygon
*>(g1
);
2080 handle
->ERROR_MESSAGE("Invalid argument (must be a MultiPolygon)");
2084 using geos::operation::geounion::CascadedPolygonUnion
;
2085 return CascadedPolygonUnion::Union(p
);
2087 catch (const std::exception
&e
)
2089 handle
->ERROR_MESSAGE("%s", e
.what());
2093 handle
->ERROR_MESSAGE("Unknown exception thrown");
2100 GEOSPointOnSurface_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2102 if ( 0 == extHandle
)
2107 GEOSContextHandleInternal_t
*handle
= 0;
2108 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2109 if ( 0 == handle
->initialized
)
2116 Geometry
*ret
= g1
->getInteriorPoint();
2119 const GeometryFactory
* gf
= handle
->geomFactory
;
2120 // return an empty collection
2121 return gf
->createGeometryCollection();
2125 catch (const std::exception
&e
)
2127 handle
->ERROR_MESSAGE("%s", e
.what());
2131 handle
->ERROR_MESSAGE("Unknown exception thrown");
2137 //-------------------------------------------------------------------
2138 // memory management functions
2139 //------------------------------------------------------------------
2142 GEOSGeom_destroy_r(GEOSContextHandle_t extHandle
, Geometry
*a
)
2144 GEOSContextHandleInternal_t
*handle
= 0;
2146 // FIXME: mloskot: Does this try-catch around delete means that
2147 // destructors in GEOS may throw? If it does, this is a serious
2148 // violation of "never throw an exception from a destructor" principle
2154 catch (const std::exception
&e
)
2156 if ( 0 == extHandle
)
2161 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2162 if ( 0 == handle
->initialized
)
2167 handle
->ERROR_MESSAGE("%s", e
.what());
2171 if ( 0 == extHandle
)
2176 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2177 if ( 0 == handle
->initialized
)
2182 handle
->ERROR_MESSAGE("Unknown exception thrown");
2187 GEOSSetSRID_r(GEOSContextHandle_t extHandle
, Geometry
*g
, int srid
)
2191 if ( 0 == extHandle
)
2196 GEOSContextHandleInternal_t
*handle
= 0;
2197 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2198 if ( 0 == handle
->initialized
)
2208 GEOSGetNumCoordinates_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2212 if ( 0 == extHandle
)
2217 GEOSContextHandleInternal_t
*handle
= 0;
2218 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2219 if ( 0 == handle
->initialized
)
2226 return static_cast<int>(g
->getNumPoints());
2228 catch (const std::exception
&e
)
2230 handle
->ERROR_MESSAGE("%s", e
.what());
2234 handle
->ERROR_MESSAGE("Unknown exception thrown");
2241 * Return -1 on exception, 0 otherwise.
2242 * Converts Geometry to normal form (or canonical form).
2245 GEOSNormalize_r(GEOSContextHandle_t extHandle
, Geometry
*g
)
2249 if ( 0 == extHandle
)
2254 GEOSContextHandleInternal_t
*handle
= 0;
2255 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2256 if ( 0 == handle
->initialized
)
2264 return 0; // SUCCESS
2266 catch (const std::exception
&e
)
2268 handle
->ERROR_MESSAGE("%s", e
.what());
2272 handle
->ERROR_MESSAGE("Unknown exception thrown");
2279 GEOSGetNumInteriorRings_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2281 if ( 0 == extHandle
)
2286 GEOSContextHandleInternal_t
*handle
= 0;
2287 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2288 if ( 0 == handle
->initialized
)
2295 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
2298 handle
->ERROR_MESSAGE("Argument is not a Polygon");
2301 return static_cast<int>(p
->getNumInteriorRing());
2303 catch (const std::exception
&e
)
2305 handle
->ERROR_MESSAGE("%s", e
.what());
2309 handle
->ERROR_MESSAGE("Unknown exception thrown");
2316 // returns -1 on error and 1 for non-multi geometries
2318 GEOSGetNumGeometries_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2320 if ( 0 == extHandle
)
2325 GEOSContextHandleInternal_t
*handle
= 0;
2326 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2327 if ( 0 == handle
->initialized
)
2334 return static_cast<int>(g1
->getNumGeometries());
2336 catch (const std::exception
&e
)
2338 handle
->ERROR_MESSAGE("%s", e
.what());
2342 handle
->ERROR_MESSAGE("Unknown exception thrown");
2350 * Call only on GEOMETRYCOLLECTION or MULTI*.
2351 * Return a pointer to the internal Geometry.
2354 GEOSGetGeometryN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2356 if ( 0 == extHandle
)
2361 GEOSContextHandleInternal_t
*handle
= 0;
2362 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2363 if ( 0 == handle
->initialized
)
2370 return g1
->getGeometryN(n
);
2372 catch (const std::exception
&e
)
2374 handle
->ERROR_MESSAGE("%s", e
.what());
2378 handle
->ERROR_MESSAGE("Unknown exception thrown");
2385 * Call only on LINESTRING
2386 * Returns NULL on exception
2389 GEOSGeomGetPointN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2391 if ( 0 == extHandle
)
2396 GEOSContextHandleInternal_t
*handle
= 0;
2397 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2398 if ( 0 == handle
->initialized
)
2405 using geos::geom::LineString
;
2406 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2409 handle
->ERROR_MESSAGE("Argument is not a LineString");
2412 return ls
->getPointN(n
);
2414 catch (const std::exception
&e
)
2416 handle
->ERROR_MESSAGE("%s", e
.what());
2420 handle
->ERROR_MESSAGE("Unknown exception thrown");
2427 * Call only on LINESTRING
2430 GEOSGeomGetStartPoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2432 if ( 0 == extHandle
)
2437 GEOSContextHandleInternal_t
*handle
= 0;
2438 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2439 if ( 0 == handle
->initialized
)
2446 using geos::geom::LineString
;
2447 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2450 handle
->ERROR_MESSAGE("Argument is not a LineString");
2453 return ls
->getStartPoint();
2455 catch (const std::exception
&e
)
2457 handle
->ERROR_MESSAGE("%s", e
.what());
2461 handle
->ERROR_MESSAGE("Unknown exception thrown");
2468 * Call only on LINESTRING
2471 GEOSGeomGetEndPoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2473 if ( 0 == extHandle
)
2478 GEOSContextHandleInternal_t
*handle
= 0;
2479 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2480 if ( 0 == handle
->initialized
)
2487 using geos::geom::LineString
;
2488 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2491 handle
->ERROR_MESSAGE("Argument is not a LineString");
2494 return ls
->getEndPoint();
2496 catch (const std::exception
&e
)
2498 handle
->ERROR_MESSAGE("%s", e
.what());
2502 handle
->ERROR_MESSAGE("Unknown exception thrown");
2509 * Call only on LINESTRING
2510 * return 2 on exception, 1 on true, 0 on false
2513 GEOSisClosed_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2515 if ( 0 == extHandle
)
2520 GEOSContextHandleInternal_t
*handle
= 0;
2521 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2522 if ( 0 == handle
->initialized
)
2529 using geos::geom::LineString
;
2530 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2533 handle
->ERROR_MESSAGE("Argument is not a LineString");
2536 return ls
->isClosed();
2538 catch (const std::exception
&e
)
2540 handle
->ERROR_MESSAGE("%s", e
.what());
2544 handle
->ERROR_MESSAGE("Unknown exception thrown");
2551 * Call only on LINESTRING
2552 * return 0 on exception, otherwise 1
2555 GEOSGeomGetLength_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *length
)
2557 if ( 0 == extHandle
)
2562 GEOSContextHandleInternal_t
*handle
= 0;
2563 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2564 if ( 0 == handle
->initialized
)
2571 using geos::geom::LineString
;
2572 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2575 handle
->ERROR_MESSAGE("Argument is not a LineString");
2578 *length
= ls
->getLength();
2581 catch (const std::exception
&e
)
2583 handle
->ERROR_MESSAGE("%s", e
.what());
2587 handle
->ERROR_MESSAGE("Unknown exception thrown");
2594 * Call only on LINESTRING
2597 GEOSGeomGetNumPoints_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2599 if ( 0 == extHandle
)
2604 GEOSContextHandleInternal_t
*handle
= 0;
2605 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2606 if ( 0 == handle
->initialized
)
2613 using geos::geom::LineString
;
2614 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2617 handle
->ERROR_MESSAGE("Argument is not a LineString");
2620 return static_cast<int>(ls
->getNumPoints());
2622 catch (const std::exception
&e
)
2624 handle
->ERROR_MESSAGE("%s", e
.what());
2628 handle
->ERROR_MESSAGE("Unknown exception thrown");
2636 * returns 0 on exception, otherwise 1
2639 GEOSGeomGetX_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *x
)
2641 if ( 0 == extHandle
)
2646 GEOSContextHandleInternal_t
*handle
= 0;
2647 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2648 if ( 0 == handle
->initialized
)
2655 using geos::geom::Point
;
2656 const Point
*po
= dynamic_cast<const Point
*>(g1
);
2659 handle
->ERROR_MESSAGE("Argument is not a Point");
2665 catch (const std::exception
&e
)
2667 handle
->ERROR_MESSAGE("%s", e
.what());
2671 handle
->ERROR_MESSAGE("Unknown exception thrown");
2679 * returns 0 on exception, otherwise 1
2682 GEOSGeomGetY_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *y
)
2684 if ( 0 == extHandle
)
2689 GEOSContextHandleInternal_t
*handle
= 0;
2690 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2691 if ( 0 == handle
->initialized
)
2698 using geos::geom::Point
;
2699 const Point
*po
= dynamic_cast<const Point
*>(g1
);
2702 handle
->ERROR_MESSAGE("Argument is not a Point");
2708 catch (const std::exception
&e
)
2710 handle
->ERROR_MESSAGE("%s", e
.what());
2714 handle
->ERROR_MESSAGE("Unknown exception thrown");
2721 * Call only on polygon
2722 * Return a copy of the internal Geometry.
2725 GEOSGetExteriorRing_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2727 if ( 0 == extHandle
)
2732 GEOSContextHandleInternal_t
*handle
= 0;
2733 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2734 if ( 0 == handle
->initialized
)
2741 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
2744 handle
->ERROR_MESSAGE("Invalid argument (must be a Polygon)");
2747 return p
->getExteriorRing();
2749 catch (const std::exception
&e
)
2751 handle
->ERROR_MESSAGE("%s", e
.what());
2755 handle
->ERROR_MESSAGE("Unknown exception thrown");
2762 * Call only on polygon
2763 * Return a pointer to internal storage, do not destroy it.
2766 GEOSGetInteriorRingN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2768 if ( 0 == extHandle
)
2773 GEOSContextHandleInternal_t
*handle
= 0;
2774 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2775 if ( 0 == handle
->initialized
)
2782 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
2785 handle
->ERROR_MESSAGE("Invalid argument (must be a Polygon)");
2788 return p
->getInteriorRingN(n
);
2790 catch (const std::exception
&e
)
2792 handle
->ERROR_MESSAGE("%s", e
.what());
2796 handle
->ERROR_MESSAGE("Unknown exception thrown");
2803 GEOSGetCentroid_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2805 if ( 0 == extHandle
)
2810 GEOSContextHandleInternal_t
*handle
= 0;
2811 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2812 if ( 0 == handle
->initialized
)
2819 Geometry
*ret
= g
->getCentroid();
2822 const GeometryFactory
*gf
= handle
->geomFactory
;
2823 return gf
->createGeometryCollection();
2827 catch (const std::exception
&e
)
2829 handle
->ERROR_MESSAGE("%s", e
.what());
2833 handle
->ERROR_MESSAGE("Unknown exception thrown");
2840 GEOSGeom_createEmptyCollection_r(GEOSContextHandle_t extHandle
, int type
)
2842 if ( 0 == extHandle
)
2847 GEOSContextHandleInternal_t
*handle
= 0;
2848 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2849 if ( 0 == handle
->initialized
)
2856 sprintf(buf
, "createCollection: requested type %d, ngeoms: %d",
2858 handle
->NOTICE_MESSAGE("%s", buf
);// TODO: Can handle->NOTICE_MESSAGE format that directly?
2863 const GeometryFactory
* gf
= handle
->geomFactory
;
2868 case GEOS_GEOMETRYCOLLECTION
:
2869 g
= gf
->createGeometryCollection();
2871 case GEOS_MULTIPOINT
:
2872 g
= gf
->createMultiPoint();
2874 case GEOS_MULTILINESTRING
:
2875 g
= gf
->createMultiLineString();
2877 case GEOS_MULTIPOLYGON
:
2878 g
= gf
->createMultiPolygon();
2881 handle
->ERROR_MESSAGE("Unsupported type request for GEOSGeom_createEmptyCollection_r");
2888 catch (const std::exception
&e
)
2890 handle
->ERROR_MESSAGE("%s", e
.what());
2894 handle
->ERROR_MESSAGE("Unknown exception thrown");
2901 GEOSGeom_createCollection_r(GEOSContextHandle_t extHandle
, int type
, Geometry
**geoms
, unsigned int ngeoms
)
2903 if ( 0 == extHandle
)
2908 GEOSContextHandleInternal_t
*handle
= 0;
2909 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2910 if ( 0 == handle
->initialized
)
2917 sprintf(buf
, "PostGIS2GEOS_collection: requested type %d, ngeoms: %d",
2919 handle
->NOTICE_MESSAGE("%s", buf
);// TODO: Can handle->NOTICE_MESSAGE format that directly?
2924 const GeometryFactory
* gf
= handle
->geomFactory
;
2925 std::vector
<Geometry
*>* vgeoms
= new std::vector
<Geometry
*>(geoms
, geoms
+ ngeoms
);
2930 case GEOS_GEOMETRYCOLLECTION
:
2931 g
= gf
->createGeometryCollection(vgeoms
);
2933 case GEOS_MULTIPOINT
:
2934 g
= gf
->createMultiPoint(vgeoms
);
2936 case GEOS_MULTILINESTRING
:
2937 g
= gf
->createMultiLineString(vgeoms
);
2939 case GEOS_MULTIPOLYGON
:
2940 g
= gf
->createMultiPolygon(vgeoms
);
2943 handle
->ERROR_MESSAGE("Unsupported type request for PostGIS2GEOS_collection");
2950 catch (const std::exception
&e
)
2952 handle
->ERROR_MESSAGE("%s", e
.what());
2956 handle
->ERROR_MESSAGE("Unknown exception thrown");
2963 GEOSPolygonize_r(GEOSContextHandle_t extHandle
, const Geometry
* const * g
, unsigned int ngeoms
)
2965 if ( 0 == extHandle
)
2970 GEOSContextHandleInternal_t
*handle
= 0;
2971 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2972 if ( 0 == handle
->initialized
)
2982 using geos::operation::polygonize::Polygonizer
;
2984 for (std::size_t i
= 0; i
< ngeoms
; ++i
)
2990 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
2993 std::vector
<Polygon
*> *polys
= plgnzr
.getPolygons();
2997 handle
->NOTICE_MESSAGE("output polygons got");
3000 // We need a vector of Geometry pointers, not Polygon pointers.
3001 // STL vector doesn't allow transparent upcast of this
3002 // nature, so we explicitly convert.
3003 // (it's just a waste of processor and memory, btw)
3005 // XXX mloskot: Why not to extent GeometryFactory to accept
3006 // vector of polygons or extend Polygonizer to return list of Geometry*
3007 // or add a wrapper which semantic is similar to:
3008 // std::vector<as_polygon<Geometry*> >
3009 std::vector
<Geometry
*> *polyvec
= new std::vector
<Geometry
*>(polys
->size());
3011 for (std::size_t i
= 0; i
< polys
->size(); ++i
)
3013 (*polyvec
)[i
] = (*polys
)[i
];
3018 const GeometryFactory
*gf
= handle
->geomFactory
;
3020 // The below takes ownership of the passed vector,
3021 // so we must *not* delete it
3022 out
= gf
->createGeometryCollection(polyvec
);
3024 catch (const std::exception
&e
)
3026 handle
->ERROR_MESSAGE("%s", e
.what());
3030 handle
->ERROR_MESSAGE("Unknown exception thrown");
3037 GEOSPolygonizer_getCutEdges_r(GEOSContextHandle_t extHandle
, const Geometry
* const * g
, unsigned int ngeoms
)
3039 if ( 0 == extHandle
)
3044 GEOSContextHandleInternal_t
*handle
= 0;
3045 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3046 if ( 0 == handle
->initialized
)
3056 using geos::operation::polygonize::Polygonizer
;
3058 for (std::size_t i
= 0; i
< ngeoms
; ++i
)
3064 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
3067 const std::vector
<const LineString
*>& lines
= plgnzr
.getCutEdges();
3070 handle
->NOTICE_MESSAGE("output polygons got");
3073 // We need a vector of Geometry pointers, not Polygon pointers.
3074 // STL vector doesn't allow transparent upcast of this
3075 // nature, so we explicitly convert.
3076 // (it's just a waste of processor and memory, btw)
3077 // XXX mloskot: See comment for GEOSPolygonize_r
3078 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3080 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3082 (*linevec
)[i
] = lines
[i
]->clone();
3085 const GeometryFactory
*gf
= handle
->geomFactory
;
3087 // The below takes ownership of the passed vector,
3088 // so we must *not* delete it
3089 out
= gf
->createGeometryCollection(linevec
);
3091 catch (const std::exception
&e
)
3093 handle
->ERROR_MESSAGE("%s", e
.what());
3097 handle
->ERROR_MESSAGE("Unknown exception thrown");
3104 GEOSPolygonize_full_r(GEOSContextHandle_t extHandle
, const Geometry
* g
,
3105 Geometry
** cuts
, Geometry
** dangles
, Geometry
** invalid
)
3107 if ( 0 == extHandle
)
3112 GEOSContextHandleInternal_t
*handle
= 0;
3113 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3114 if ( 0 == handle
->initialized
)
3122 using geos::operation::polygonize::Polygonizer
;
3124 for (std::size_t i
= 0; i
<g
->getNumGeometries(); ++i
)
3126 plgnzr
.add(g
->getGeometryN(i
));
3130 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
3132 const GeometryFactory
*gf
= handle
->geomFactory
;
3136 const std::vector
<const LineString
*>& lines
= plgnzr
.getCutEdges();
3137 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3138 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3140 (*linevec
)[i
] = lines
[i
]->clone();
3143 // The below takes ownership of the passed vector,
3144 // so we must *not* delete it
3145 *cuts
= gf
->createGeometryCollection(linevec
);
3150 const std::vector
<const LineString
*>& lines
= plgnzr
.getDangles();
3151 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3152 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3154 (*linevec
)[i
] = lines
[i
]->clone();
3157 // The below takes ownership of the passed vector,
3158 // so we must *not* delete it
3159 *dangles
= gf
->createGeometryCollection(linevec
);
3164 const std::vector
<LineString
*>& lines
= plgnzr
.getInvalidRingLines();
3165 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3166 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3168 (*linevec
)[i
] = lines
[i
]->clone();
3171 // The below takes ownership of the passed vector,
3172 // so we must *not* delete it
3173 *invalid
= gf
->createGeometryCollection(linevec
);
3176 std::vector
<Polygon
*> *polys
= plgnzr
.getPolygons();
3177 std::vector
<Geometry
*> *polyvec
= new std::vector
<Geometry
*>(polys
->size());
3178 for (std::size_t i
= 0; i
< polys
->size(); ++i
)
3180 (*polyvec
)[i
] = (*polys
)[i
];
3184 return gf
->createGeometryCollection(polyvec
);
3187 catch (const std::exception
&e
)
3189 handle
->ERROR_MESSAGE("%s", e
.what());
3194 handle
->ERROR_MESSAGE("Unknown exception thrown");
3200 GEOSLineMerge_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3202 if ( 0 == extHandle
)
3207 GEOSContextHandleInternal_t
*handle
= 0;
3208 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3209 if ( 0 == handle
->initialized
)
3218 using geos::operation::linemerge::LineMerger
;
3222 std::vector
<LineString
*>* lines
= lmrgr
.getMergedLineStrings();
3226 handle
->NOTICE_MESSAGE("output lines got");
3229 std::vector
<Geometry
*>*geoms
= new std::vector
<Geometry
*>(lines
->size());
3230 for (std::vector
<Geometry
*>::size_type i
= 0; i
< lines
->size(); ++i
)
3232 (*geoms
)[i
] = (*lines
)[i
];
3237 const GeometryFactory
*gf
= handle
->geomFactory
;
3238 out
= gf
->buildGeometry(geoms
);
3241 //out = gf->createGeometryCollection(geoms);
3243 catch (const std::exception
&e
)
3245 handle
->ERROR_MESSAGE("%s", e
.what());
3249 handle
->ERROR_MESSAGE("Unknown exception thrown");
3256 GEOSGetSRID_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3260 if ( 0 == extHandle
)
3265 GEOSContextHandleInternal_t
*handle
= 0;
3266 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3267 if ( 0 == handle
->initialized
)
3274 return g
->getSRID();
3276 catch (const std::exception
&e
)
3278 handle
->ERROR_MESSAGE("%s", e
.what());
3282 handle
->ERROR_MESSAGE("Unknown exception thrown");
3288 const char* GEOSversion()
3290 return GEOS_CAPI_VERSION
;
3293 const char* GEOSjtsport()
3295 return GEOS_JTS_PORT
;
3299 GEOSHasZ_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3303 if ( 0 == extHandle
)
3308 GEOSContextHandleInternal_t
*handle
= 0;
3309 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3310 if ( 0 == handle
->initialized
)
3319 assert(0 != g
->getCoordinate());
3321 double az
= g
->getCoordinate()->z
;
3322 //handle->ERROR_MESSAGE("ZCoord: %g", az);
3324 return static_cast<char>(FINITE(az
));
3328 GEOS_getWKBOutputDims_r(GEOSContextHandle_t extHandle
)
3330 if ( 0 == extHandle
)
3335 GEOSContextHandleInternal_t
*handle
= 0;
3336 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3337 if ( 0 == handle
->initialized
)
3342 return handle
->WKBOutputDims
;
3346 GEOS_setWKBOutputDims_r(GEOSContextHandle_t extHandle
, int newdims
)
3348 if ( 0 == extHandle
)
3353 GEOSContextHandleInternal_t
*handle
= 0;
3354 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3355 if ( 0 == handle
->initialized
)
3360 if ( newdims
< 2 || newdims
> 3 )
3362 handle
->ERROR_MESSAGE("WKB output dimensions out of range 2..3");
3365 const int olddims
= handle
->WKBOutputDims
;
3366 handle
->WKBOutputDims
= newdims
;
3372 GEOS_getWKBByteOrder_r(GEOSContextHandle_t extHandle
)
3374 if ( 0 == extHandle
)
3379 GEOSContextHandleInternal_t
*handle
= 0;
3380 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3381 if ( 0 == handle
->initialized
)
3386 return handle
->WKBByteOrder
;
3390 GEOS_setWKBByteOrder_r(GEOSContextHandle_t extHandle
, int byteOrder
)
3392 if ( 0 == extHandle
)
3397 GEOSContextHandleInternal_t
*handle
= 0;
3398 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3399 if ( 0 == handle
->initialized
)
3404 const int oldByteOrder
= handle
->WKBByteOrder
;
3405 handle
->WKBByteOrder
= byteOrder
;
3407 return oldByteOrder
;
3411 CoordinateSequence
*
3412 GEOSCoordSeq_create_r(GEOSContextHandle_t extHandle
, unsigned int size
, unsigned int dims
)
3414 if ( 0 == extHandle
)
3419 GEOSContextHandleInternal_t
*handle
= 0;
3420 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3421 if ( 0 == handle
->initialized
)
3428 const GeometryFactory
*gf
= handle
->geomFactory
;
3429 return gf
->getCoordinateSequenceFactory()->create(size
, dims
);
3431 catch (const std::exception
&e
)
3433 handle
->ERROR_MESSAGE("%s", e
.what());
3437 handle
->ERROR_MESSAGE("Unknown exception thrown");
3444 GEOSCoordSeq_setOrdinate_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
,
3445 unsigned int idx
, unsigned int dim
, double val
)
3448 if ( 0 == extHandle
)
3453 GEOSContextHandleInternal_t
*handle
= 0;
3454 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3455 if ( 0 == handle
->initialized
)
3462 cs
->setOrdinate(idx
, dim
, val
);
3465 catch (const std::exception
&e
)
3467 handle
->ERROR_MESSAGE("%s", e
.what());
3471 handle
->ERROR_MESSAGE("Unknown exception thrown");
3478 GEOSCoordSeq_setX_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3480 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 0, val
);
3484 GEOSCoordSeq_setY_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3486 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 1, val
);
3490 GEOSCoordSeq_setZ_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3492 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 2, val
);
3495 CoordinateSequence
*
3496 GEOSCoordSeq_clone_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
)
3500 if ( 0 == extHandle
)
3505 GEOSContextHandleInternal_t
*handle
= 0;
3506 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3507 if ( 0 == handle
->initialized
)
3516 catch (const std::exception
&e
)
3518 handle
->ERROR_MESSAGE("%s", e
.what());
3522 handle
->ERROR_MESSAGE("Unknown exception thrown");
3529 GEOSCoordSeq_getOrdinate_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
,
3530 unsigned int idx
, unsigned int dim
, double *val
)
3535 if ( 0 == extHandle
)
3540 GEOSContextHandleInternal_t
*handle
= 0;
3541 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3542 if ( 0 == handle
->initialized
)
3549 double d
= cs
->getOrdinate(idx
, dim
);
3554 catch (const std::exception
&e
)
3556 handle
->ERROR_MESSAGE("%s", e
.what());
3560 handle
->ERROR_MESSAGE("Unknown exception thrown");
3567 GEOSCoordSeq_getX_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
3569 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 0, val
);
3573 GEOSCoordSeq_getY_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
3575 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 1, val
);
3579 GEOSCoordSeq_getZ_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
3581 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 2, val
);
3585 GEOSCoordSeq_getSize_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
, unsigned int *size
)
3590 if ( 0 == extHandle
)
3595 GEOSContextHandleInternal_t
*handle
= 0;
3596 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3597 if ( 0 == handle
->initialized
)
3604 const std::size_t sz
= cs
->getSize();
3605 *size
= static_cast<unsigned int>(sz
);
3608 catch (const std::exception
&e
)
3610 handle
->ERROR_MESSAGE("%s", e
.what());
3614 handle
->ERROR_MESSAGE("Unknown exception thrown");
3621 GEOSCoordSeq_getDimensions_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
, unsigned int *dims
)
3626 if ( 0 == extHandle
)
3631 GEOSContextHandleInternal_t
*handle
= 0;
3632 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3633 if ( 0 == handle
->initialized
)
3640 const std::size_t dim
= cs
->getDimension();
3641 *dims
= static_cast<unsigned int>(dim
);
3645 catch (const std::exception
&e
)
3647 handle
->ERROR_MESSAGE("%s", e
.what());
3652 handle
->ERROR_MESSAGE("Unknown exception thrown");
3659 GEOSCoordSeq_destroy_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
)
3661 GEOSContextHandleInternal_t
*handle
= 0;
3667 catch (const std::exception
&e
)
3669 if ( 0 == extHandle
)
3674 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3675 if ( 0 == handle
->initialized
)
3680 handle
->ERROR_MESSAGE("%s", e
.what());
3684 if ( 0 == extHandle
)
3689 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3690 if ( 0 == handle
->initialized
)
3695 handle
->ERROR_MESSAGE("Unknown exception thrown");
3699 const CoordinateSequence
*
3700 GEOSGeom_getCoordSeq_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3702 if ( 0 == extHandle
)
3707 GEOSContextHandleInternal_t
*handle
= 0;
3708 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3709 if ( 0 == handle
->initialized
)
3716 using geos::geom::Point
;
3718 const LineString
*ls
= dynamic_cast<const LineString
*>(g
);
3721 return ls
->getCoordinatesRO();
3724 const Point
*p
= dynamic_cast<const Point
*>(g
);
3727 return p
->getCoordinatesRO();
3730 handle
->ERROR_MESSAGE("Geometry must be a Point or LineString");
3733 catch (const std::exception
&e
)
3735 handle
->ERROR_MESSAGE("%s", e
.what());
3739 handle
->ERROR_MESSAGE("Unknown exception thrown");
3746 GEOSGeom_createEmptyPoint_r(GEOSContextHandle_t extHandle
)
3748 if ( 0 == extHandle
)
3753 GEOSContextHandleInternal_t
*handle
= 0;
3754 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3755 if ( 0 == handle
->initialized
)
3762 const GeometryFactory
*gf
= handle
->geomFactory
;
3763 return gf
->createPoint();
3765 catch (const std::exception
&e
)
3767 handle
->ERROR_MESSAGE("%s", e
.what());
3771 handle
->ERROR_MESSAGE("Unknown exception thrown");
3778 GEOSGeom_createPoint_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
3780 if ( 0 == extHandle
)
3785 GEOSContextHandleInternal_t
*handle
= 0;
3786 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3787 if ( 0 == handle
->initialized
)
3794 const GeometryFactory
*gf
= handle
->geomFactory
;
3795 return gf
->createPoint(cs
);
3797 catch (const std::exception
&e
)
3799 handle
->ERROR_MESSAGE("%s", e
.what());
3803 handle
->ERROR_MESSAGE("Unknown exception thrown");
3810 GEOSGeom_createLinearRing_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
3812 if ( 0 == extHandle
)
3817 GEOSContextHandleInternal_t
*handle
= 0;
3818 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3819 if ( 0 == handle
->initialized
)
3826 const GeometryFactory
*gf
= handle
->geomFactory
;
3828 return gf
->createLinearRing(cs
);
3830 catch (const std::exception
&e
)
3832 handle
->ERROR_MESSAGE("%s", e
.what());
3836 handle
->ERROR_MESSAGE("Unknown exception thrown");
3843 GEOSGeom_createEmptyLineString_r(GEOSContextHandle_t extHandle
)
3845 if ( 0 == extHandle
)
3850 GEOSContextHandleInternal_t
*handle
= 0;
3851 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3852 if ( 0 == handle
->initialized
)
3859 const GeometryFactory
*gf
= handle
->geomFactory
;
3861 return gf
->createLineString();
3863 catch (const std::exception
&e
)
3865 handle
->ERROR_MESSAGE("%s", e
.what());
3869 handle
->ERROR_MESSAGE("Unknown exception thrown");
3876 GEOSGeom_createLineString_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
3878 if ( 0 == extHandle
)
3883 GEOSContextHandleInternal_t
*handle
= 0;
3884 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3885 if ( 0 == handle
->initialized
)
3892 const GeometryFactory
*gf
= handle
->geomFactory
;
3894 return gf
->createLineString(cs
);
3896 catch (const std::exception
&e
)
3898 handle
->ERROR_MESSAGE("%s", e
.what());
3902 handle
->ERROR_MESSAGE("Unknown exception thrown");
3909 GEOSGeom_createEmptyPolygon_r(GEOSContextHandle_t extHandle
)
3911 if ( 0 == extHandle
)
3916 GEOSContextHandleInternal_t
*handle
= 0;
3917 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3918 if ( 0 == handle
->initialized
)
3925 const GeometryFactory
*gf
= handle
->geomFactory
;
3926 return gf
->createPolygon();
3928 catch (const std::exception
&e
)
3930 handle
->ERROR_MESSAGE("%s", e
.what());
3934 handle
->ERROR_MESSAGE("Unknown exception thrown");
3941 GEOSGeom_createPolygon_r(GEOSContextHandle_t extHandle
, Geometry
*shell
, Geometry
**holes
, unsigned int nholes
)
3943 // FIXME: holes must be non-nullptr or may be nullptr?
3944 //assert(0 != holes);
3946 if ( 0 == extHandle
)
3951 GEOSContextHandleInternal_t
*handle
= 0;
3952 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3953 if ( 0 == handle
->initialized
)
3960 using geos::geom::LinearRing
;
3962 std::vector
<Geometry
*> *vholes
= new std::vector
<Geometry
*>(holes
, holes
+ nholes
);
3964 LinearRing
*nshell
= dynamic_cast<LinearRing
*>(shell
);
3967 handle
->ERROR_MESSAGE("Shell is not a LinearRing");
3970 const GeometryFactory
*gf
= handle
->geomFactory
;
3972 return gf
->createPolygon(nshell
, vholes
);
3974 catch (const std::exception
&e
)
3976 handle
->ERROR_MESSAGE("%s", e
.what());
3980 handle
->ERROR_MESSAGE("Unknown exception thrown");
3987 GEOSGeom_clone_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3991 if ( 0 == extHandle
)
3996 GEOSContextHandleInternal_t
*handle
= 0;
3997 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3998 if ( 0 == handle
->initialized
)
4007 catch (const std::exception
&e
)
4009 handle
->ERROR_MESSAGE("%s", e
.what());
4013 handle
->ERROR_MESSAGE("Unknown exception thrown");
4020 GEOSGeom_getDimensions_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
4022 if ( 0 == extHandle
)
4027 GEOSContextHandleInternal_t
*handle
= 0;
4028 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4029 if ( 0 == handle
->initialized
)
4036 return (int) g
->getDimension();
4038 catch (const std::exception
&e
)
4040 handle
->ERROR_MESSAGE("%s", e
.what());
4044 handle
->ERROR_MESSAGE("Unknown exception thrown");
4051 GEOSGeom_getCoordinateDimension_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
4053 if ( 0 == extHandle
)
4058 GEOSContextHandleInternal_t
*handle
= 0;
4059 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4060 if ( 0 == handle
->initialized
)
4067 return g
->getCoordinateDimension();
4069 catch (const std::exception
&e
)
4071 handle
->ERROR_MESSAGE("%s", e
.what());
4075 handle
->ERROR_MESSAGE("Unknown exception thrown");
4082 GEOSSimplify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double tolerance
)
4084 if ( 0 == extHandle
)
4089 GEOSContextHandleInternal_t
*handle
= 0;
4090 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4091 if ( 0 == handle
->initialized
)
4098 using namespace geos::simplify
;
4099 Geometry::AutoPtr
g(DouglasPeuckerSimplifier::simplify(g1
, tolerance
));
4102 catch (const std::exception
&e
)
4104 handle
->ERROR_MESSAGE("%s", e
.what());
4108 handle
->ERROR_MESSAGE("Unknown exception thrown");
4115 GEOSTopologyPreserveSimplify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double tolerance
)
4117 if ( 0 == extHandle
)
4122 GEOSContextHandleInternal_t
*handle
= 0;
4123 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4124 if ( 0 == handle
->initialized
)
4131 using namespace geos::simplify
;
4132 Geometry::AutoPtr
g(TopologyPreservingSimplifier::simplify(g1
, tolerance
));
4135 catch (const std::exception
&e
)
4137 handle
->ERROR_MESSAGE("%s", e
.what());
4141 handle
->ERROR_MESSAGE("Unknown exception thrown");
4150 GEOSWKTReader_create_r(GEOSContextHandle_t extHandle
)
4152 if ( 0 == extHandle
)
4157 GEOSContextHandleInternal_t
*handle
= 0;
4158 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4159 if ( 0 == handle
->initialized
)
4166 using geos::io::WKTReader
;
4167 return new WKTReader((GeometryFactory
*)handle
->geomFactory
);
4169 catch (const std::exception
&e
)
4171 handle
->ERROR_MESSAGE("%s", e
.what());
4175 handle
->ERROR_MESSAGE("Unknown exception thrown");
4182 GEOSWKTReader_destroy_r(GEOSContextHandle_t extHandle
, WKTReader
*reader
)
4184 GEOSContextHandleInternal_t
*handle
= 0;
4190 catch (const std::exception
&e
)
4192 if ( 0 == extHandle
)
4197 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4198 if ( 0 == handle
->initialized
)
4203 handle
->ERROR_MESSAGE("%s", e
.what());
4207 if ( 0 == extHandle
)
4212 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4213 if ( 0 == handle
->initialized
)
4218 handle
->ERROR_MESSAGE("Unknown exception thrown");
4224 GEOSWKTReader_read_r(GEOSContextHandle_t extHandle
, WKTReader
*reader
, const char *wkt
)
4226 assert(0 != reader
);
4228 if ( 0 == extHandle
)
4233 GEOSContextHandleInternal_t
*handle
= 0;
4234 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4235 if ( 0 == handle
->initialized
)
4242 const std::string
wktstring(wkt
);
4243 Geometry
*g
= reader
->read(wktstring
);
4246 catch (const std::exception
&e
)
4248 handle
->ERROR_MESSAGE("%s", e
.what());
4252 handle
->ERROR_MESSAGE("Unknown exception thrown");
4260 GEOSWKTWriter_create_r(GEOSContextHandle_t extHandle
)
4262 if ( 0 == extHandle
)
4267 GEOSContextHandleInternal_t
*handle
= 0;
4268 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4269 if ( 0 == handle
->initialized
)
4276 using geos::io::WKTWriter
;
4277 return new WKTWriter();
4279 catch (const std::exception
&e
)
4281 handle
->ERROR_MESSAGE("%s", e
.what());
4285 handle
->ERROR_MESSAGE("Unknown exception thrown");
4292 GEOSWKTWriter_destroy_r(GEOSContextHandle_t extHandle
, WKTWriter
*Writer
)
4295 GEOSContextHandleInternal_t
*handle
= 0;
4301 catch (const std::exception
&e
)
4303 if ( 0 == extHandle
)
4308 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4309 if ( 0 == handle
->initialized
)
4314 handle
->ERROR_MESSAGE("%s", e
.what());
4318 if ( 0 == extHandle
)
4323 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4324 if ( 0 == handle
->initialized
)
4329 handle
->ERROR_MESSAGE("Unknown exception thrown");
4335 GEOSWKTWriter_write_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, const Geometry
*geom
)
4337 assert(0 != writer
);
4339 if ( 0 == extHandle
)
4344 GEOSContextHandleInternal_t
*handle
= 0;
4345 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4346 if ( 0 == handle
->initialized
)
4353 std::string
sgeom(writer
->write(geom
));
4354 char *result
= gstrdup(sgeom
);
4357 catch (const std::exception
&e
)
4359 handle
->ERROR_MESSAGE("%s", e
.what());
4363 handle
->ERROR_MESSAGE("Unknown exception thrown");
4370 GEOSWKTWriter_setTrim_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, char trim
)
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
)
4386 writer
->setTrim(0 != trim
);
4390 GEOSWKTWriter_setRoundingPrecision_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int precision
)
4392 assert(0 != writer
);
4394 if ( 0 == extHandle
)
4399 GEOSContextHandleInternal_t
*handle
= 0;
4400 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4401 if ( 0 == handle
->initialized
)
4406 writer
->setRoundingPrecision(precision
);
4410 GEOSWKTWriter_setOutputDimension_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int dim
)
4412 assert(0 != writer
);
4414 if ( 0 == extHandle
)
4419 GEOSContextHandleInternal_t
*handle
= 0;
4420 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4421 if ( 0 == handle
->initialized
)
4428 writer
->setOutputDimension(dim
);
4430 catch (const std::exception
&e
)
4432 handle
->ERROR_MESSAGE("%s", e
.what());
4436 handle
->ERROR_MESSAGE("Unknown exception thrown");
4441 GEOSWKTWriter_getOutputDimension_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
)
4443 assert(0 != writer
);
4445 if ( 0 == extHandle
)
4450 GEOSContextHandleInternal_t
*handle
= 0;
4451 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4452 if ( 0 == handle
->initialized
)
4461 dim
= writer
->getOutputDimension();
4463 catch (const std::exception
&e
)
4465 handle
->ERROR_MESSAGE("%s", e
.what());
4469 handle
->ERROR_MESSAGE("Unknown exception thrown");
4476 GEOSWKTWriter_setOld3D_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int useOld3D
)
4478 assert(0 != writer
);
4480 if ( 0 == extHandle
)
4485 GEOSContextHandleInternal_t
*handle
= 0;
4486 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4487 if ( 0 == handle
->initialized
)
4492 writer
->setOld3D(0 != useOld3D
);
4497 GEOSWKBReader_create_r(GEOSContextHandle_t extHandle
)
4499 if ( 0 == extHandle
)
4504 GEOSContextHandleInternal_t
*handle
= 0;
4505 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4506 if ( 0 == handle
->initialized
)
4511 using geos::io::WKBReader
;
4514 return new WKBReader(*(GeometryFactory
*)handle
->geomFactory
);
4516 catch (const std::exception
&e
)
4518 handle
->ERROR_MESSAGE("%s", e
.what());
4522 handle
->ERROR_MESSAGE("Unknown exception thrown");
4529 GEOSWKBReader_destroy_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
)
4531 GEOSContextHandleInternal_t
*handle
= 0;
4537 catch (const std::exception
&e
)
4539 if ( 0 == extHandle
)
4544 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4545 if ( 0 == handle
->initialized
)
4550 handle
->ERROR_MESSAGE("%s", e
.what());
4554 if ( 0 == extHandle
)
4559 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4560 if ( 0 == handle
->initialized
)
4565 handle
->ERROR_MESSAGE("Unknown exception thrown");
4571 GEOSWKBReader_read_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
, const unsigned char *wkb
, 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
wkbstring(reinterpret_cast<const char*>(wkb
), size
); // make it binary !
4591 std::istringstream
is(std::ios_base::binary
);
4593 is
.seekg(0, std::ios::beg
); // rewind reader pointer
4595 Geometry
*g
= reader
->read(is
);
4598 catch (const std::exception
&e
)
4600 handle
->ERROR_MESSAGE("%s", e
.what());
4604 handle
->ERROR_MESSAGE("Unknown exception thrown");
4611 GEOSWKBReader_readHEX_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
, const unsigned char *hex
, size_t size
)
4613 assert(0 != reader
);
4616 if ( 0 == extHandle
)
4621 GEOSContextHandleInternal_t
*handle
= 0;
4622 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4623 if ( 0 == handle
->initialized
)
4630 std::string
hexstring(reinterpret_cast<const char*>(hex
), size
);
4631 std::istringstream
is(std::ios_base::binary
);
4633 is
.seekg(0, std::ios::beg
); // rewind reader pointer
4635 Geometry
*g
= reader
->readHEX(is
);
4638 catch (const std::exception
&e
)
4640 handle
->ERROR_MESSAGE("%s", e
.what());
4644 handle
->ERROR_MESSAGE("Unknown exception thrown");
4652 GEOSWKBWriter_create_r(GEOSContextHandle_t extHandle
)
4654 if ( 0 == extHandle
)
4659 GEOSContextHandleInternal_t
*handle
= 0;
4660 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4661 if ( 0 == handle
->initialized
)
4668 using geos::io::WKBWriter
;
4669 return new WKBWriter();
4671 catch (const std::exception
&e
)
4673 handle
->ERROR_MESSAGE("%s", e
.what());
4677 handle
->ERROR_MESSAGE("Unknown exception thrown");
4684 GEOSWKBWriter_destroy_r(GEOSContextHandle_t extHandle
, WKBWriter
*Writer
)
4686 GEOSContextHandleInternal_t
*handle
= 0;
4692 catch (const std::exception
&e
)
4694 if ( 0 == extHandle
)
4699 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4700 if ( 0 == handle
->initialized
)
4705 handle
->ERROR_MESSAGE("%s", e
.what());
4709 if ( 0 == extHandle
)
4714 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4715 if ( 0 == handle
->initialized
)
4720 handle
->ERROR_MESSAGE("Unknown exception thrown");
4725 /* The caller owns the result */
4727 GEOSWKBWriter_write_r(GEOSContextHandle_t extHandle
, WKBWriter
*writer
, const Geometry
*geom
, size_t *size
)
4729 assert(0 != writer
);
4733 if ( 0 == extHandle
)
4738 GEOSContextHandleInternal_t
*handle
= 0;
4739 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4740 if ( 0 == handle
->initialized
)
4747 std::ostringstream
os(std::ios_base::binary
);
4748 writer
->write(*geom
, os
);
4749 std::string
wkbstring(os
.str());
4750 const std::size_t len
= wkbstring
.length();
4752 unsigned char *result
= NULL
;
4753 result
= (unsigned char*) std::malloc(len
);
4754 std::memcpy(result
, wkbstring
.c_str(), len
);
4758 catch (const std::exception
&e
)
4760 handle
->ERROR_MESSAGE("%s", e
.what());
4764 handle
->ERROR_MESSAGE("Unknown exception thrown");
4769 /* The caller owns the result */
4771 GEOSWKBWriter_writeHEX_r(GEOSContextHandle_t extHandle
, WKBWriter
*writer
, const Geometry
*geom
, size_t *size
)
4773 assert(0 != writer
);
4777 if ( 0 == extHandle
)
4782 GEOSContextHandleInternal_t
*handle
= 0;
4783 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4784 if ( 0 == handle
->initialized
)
4791 std::ostringstream
os(std::ios_base::binary
);
4792 writer
->writeHEX(*geom
, os
);
4793 std::string
wkbstring(os
.str());
4794 const std::size_t len
= wkbstring
.length();
4796 unsigned char *result
= NULL
;
4797 result
= (unsigned char*) std::malloc(len
);
4798 std::memcpy(result
, wkbstring
.c_str(), len
);
4802 catch (const std::exception
&e
)
4804 handle
->ERROR_MESSAGE("%s", e
.what());
4808 handle
->ERROR_MESSAGE("Unknown exception thrown");
4815 GEOSWKBWriter_getOutputDimension_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
4817 assert(0 != writer
);
4819 if ( 0 == extHandle
)
4826 GEOSContextHandleInternal_t
*handle
= 0;
4827 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4828 if ( 0 != handle
->initialized
)
4832 ret
= writer
->getOutputDimension();
4836 handle
->ERROR_MESSAGE("Unknown exception thrown");
4844 GEOSWKBWriter_setOutputDimension_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, int newDimension
)
4846 assert(0 != writer
);
4848 if ( 0 == extHandle
)
4853 GEOSContextHandleInternal_t
*handle
= 0;
4854 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4855 if ( 0 != handle
->initialized
)
4859 writer
->setOutputDimension(newDimension
);
4861 catch (const std::exception
&e
)
4863 handle
->ERROR_MESSAGE("%s", e
.what());
4867 handle
->ERROR_MESSAGE("Unknown exception thrown");
4873 GEOSWKBWriter_getByteOrder_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
4875 assert(0 != writer
);
4877 if ( 0 == extHandle
)
4884 GEOSContextHandleInternal_t
*handle
= 0;
4885 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4886 if ( 0 != handle
->initialized
)
4890 ret
= writer
->getByteOrder();
4895 handle
->ERROR_MESSAGE("Unknown exception thrown");
4903 GEOSWKBWriter_setByteOrder_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, int newByteOrder
)
4905 assert(0 != writer
);
4907 if ( 0 == extHandle
)
4912 GEOSContextHandleInternal_t
*handle
= 0;
4913 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4914 if ( 0 != handle
->initialized
)
4918 writer
->setByteOrder(newByteOrder
);
4920 catch (const std::exception
&e
)
4922 handle
->ERROR_MESSAGE("%s", e
.what());
4926 handle
->ERROR_MESSAGE("Unknown exception thrown");
4932 GEOSWKBWriter_getIncludeSRID_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
4934 assert(0 != writer
);
4936 if ( 0 == extHandle
)
4943 GEOSContextHandleInternal_t
*handle
= 0;
4944 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4945 if ( 0 != handle
->initialized
)
4949 int srid
= writer
->getIncludeSRID();
4954 handle
->ERROR_MESSAGE("Unknown exception thrown");
4958 return static_cast<char>(ret
);
4962 GEOSWKBWriter_setIncludeSRID_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, const char newIncludeSRID
)
4964 assert(0 != writer
);
4966 if ( 0 == extHandle
)
4971 GEOSContextHandleInternal_t
*handle
= 0;
4972 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4973 if ( 0 != handle
->initialized
)
4977 writer
->setIncludeSRID(newIncludeSRID
);
4981 handle
->ERROR_MESSAGE("Unknown exception thrown");
4987 //-----------------------------------------------------------------
4988 // Prepared Geometry
4989 //-----------------------------------------------------------------
4991 const geos::geom::prep::PreparedGeometry
*
4992 GEOSPrepare_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
4994 if ( 0 == extHandle
)
4999 GEOSContextHandleInternal_t
*handle
= 0;
5000 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5001 if ( 0 == handle
->initialized
)
5006 const geos::geom::prep::PreparedGeometry
* prep
= 0;
5010 prep
= geos::geom::prep::PreparedGeometryFactory::prepare(g
);
5012 catch (const std::exception
&e
)
5014 handle
->ERROR_MESSAGE("%s", e
.what());
5018 handle
->ERROR_MESSAGE("Unknown exception thrown");
5025 GEOSPreparedGeom_destroy_r(GEOSContextHandle_t extHandle
, const geos::geom::prep::PreparedGeometry
*a
)
5027 GEOSContextHandleInternal_t
*handle
= 0;
5033 catch (const std::exception
&e
)
5035 if ( 0 == extHandle
)
5040 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5041 if ( 0 == handle
->initialized
)
5046 handle
->ERROR_MESSAGE("%s", e
.what());
5050 if ( 0 == extHandle
)
5055 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5056 if ( 0 == handle
->initialized
)
5061 handle
->ERROR_MESSAGE("Unknown exception thrown");
5066 GEOSPreparedContains_r(GEOSContextHandle_t extHandle
,
5067 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5072 if ( 0 == extHandle
)
5077 GEOSContextHandleInternal_t
*handle
= 0;
5078 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5079 if ( 0 == handle
->initialized
)
5086 bool result
= pg
->contains(g
);
5089 catch (const std::exception
&e
)
5091 handle
->ERROR_MESSAGE("%s", e
.what());
5095 handle
->ERROR_MESSAGE("Unknown exception thrown");
5102 GEOSPreparedContainsProperly_r(GEOSContextHandle_t extHandle
,
5103 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5108 if ( 0 == extHandle
)
5113 GEOSContextHandleInternal_t
*handle
= 0;
5114 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5115 if ( 0 == handle
->initialized
)
5122 bool result
= pg
->containsProperly(g
);
5125 catch (const std::exception
&e
)
5127 handle
->ERROR_MESSAGE("%s", e
.what());
5131 handle
->ERROR_MESSAGE("Unknown exception thrown");
5138 GEOSPreparedCoveredBy_r(GEOSContextHandle_t extHandle
,
5139 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5144 if ( 0 == extHandle
)
5149 GEOSContextHandleInternal_t
*handle
= 0;
5150 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5151 if ( 0 == handle
->initialized
)
5158 bool result
= pg
->coveredBy(g
);
5161 catch (const std::exception
&e
)
5163 handle
->ERROR_MESSAGE("%s", e
.what());
5167 handle
->ERROR_MESSAGE("Unknown exception thrown");
5174 GEOSPreparedCovers_r(GEOSContextHandle_t extHandle
,
5175 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5180 if ( 0 == extHandle
)
5185 GEOSContextHandleInternal_t
*handle
= 0;
5186 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5187 if ( 0 == handle
->initialized
)
5194 bool result
= pg
->covers(g
);
5197 catch (const std::exception
&e
)
5199 handle
->ERROR_MESSAGE("%s", e
.what());
5203 handle
->ERROR_MESSAGE("Unknown exception thrown");
5210 GEOSPreparedCrosses_r(GEOSContextHandle_t extHandle
,
5211 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5216 if ( 0 == extHandle
)
5221 GEOSContextHandleInternal_t
*handle
= 0;
5222 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5223 if ( 0 == handle
->initialized
)
5230 bool result
= pg
->crosses(g
);
5233 catch (const std::exception
&e
)
5235 handle
->ERROR_MESSAGE("%s", e
.what());
5239 handle
->ERROR_MESSAGE("Unknown exception thrown");
5246 GEOSPreparedDisjoint_r(GEOSContextHandle_t extHandle
,
5247 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5252 if ( 0 == extHandle
)
5257 GEOSContextHandleInternal_t
*handle
= 0;
5258 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5259 if ( 0 == handle
->initialized
)
5266 bool result
= pg
->disjoint(g
);
5269 catch (const std::exception
&e
)
5271 handle
->ERROR_MESSAGE("%s", e
.what());
5275 handle
->ERROR_MESSAGE("Unknown exception thrown");
5282 GEOSPreparedIntersects_r(GEOSContextHandle_t extHandle
,
5283 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5288 if ( 0 == extHandle
)
5293 GEOSContextHandleInternal_t
*handle
= 0;
5294 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5295 if ( 0 == handle
->initialized
)
5302 bool result
= pg
->intersects(g
);
5305 catch (const std::exception
&e
)
5307 handle
->ERROR_MESSAGE("%s", e
.what());
5311 handle
->ERROR_MESSAGE("Unknown exception thrown");
5318 GEOSPreparedOverlaps_r(GEOSContextHandle_t extHandle
,
5319 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5324 if ( 0 == extHandle
)
5329 GEOSContextHandleInternal_t
*handle
= 0;
5330 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5331 if ( 0 == handle
->initialized
)
5338 bool result
= pg
->overlaps(g
);
5341 catch (const std::exception
&e
)
5343 handle
->ERROR_MESSAGE("%s", e
.what());
5347 handle
->ERROR_MESSAGE("Unknown exception thrown");
5354 GEOSPreparedTouches_r(GEOSContextHandle_t extHandle
,
5355 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5360 if ( 0 == extHandle
)
5365 GEOSContextHandleInternal_t
*handle
= 0;
5366 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5367 if ( 0 == handle
->initialized
)
5374 bool result
= pg
->touches(g
);
5377 catch (const std::exception
&e
)
5379 handle
->ERROR_MESSAGE("%s", e
.what());
5383 handle
->ERROR_MESSAGE("Unknown exception thrown");
5390 GEOSPreparedWithin_r(GEOSContextHandle_t extHandle
,
5391 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5396 if ( 0 == extHandle
)
5401 GEOSContextHandleInternal_t
*handle
= 0;
5402 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5403 if ( 0 == handle
->initialized
)
5410 bool result
= pg
->within(g
);
5413 catch (const std::exception
&e
)
5415 handle
->ERROR_MESSAGE("%s", e
.what());
5419 handle
->ERROR_MESSAGE("Unknown exception thrown");
5425 //-----------------------------------------------------------------
5427 //-----------------------------------------------------------------
5429 geos::index::strtree::STRtree
*
5430 GEOSSTRtree_create_r(GEOSContextHandle_t extHandle
,
5431 size_t nodeCapacity
)
5433 if ( 0 == extHandle
)
5438 GEOSContextHandleInternal_t
*handle
= 0;
5439 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5440 if ( 0 == handle
->initialized
)
5445 geos::index::strtree::STRtree
*tree
= 0;
5449 tree
= new geos::index::strtree::STRtree(nodeCapacity
);
5451 catch (const std::exception
&e
)
5453 handle
->ERROR_MESSAGE("%s", e
.what());
5457 handle
->ERROR_MESSAGE("Unknown exception thrown");
5464 GEOSSTRtree_insert_r(GEOSContextHandle_t extHandle
,
5465 geos::index::strtree::STRtree
*tree
,
5466 const geos::geom::Geometry
*g
,
5469 GEOSContextHandleInternal_t
*handle
= 0;
5475 tree
->insert(g
->getEnvelopeInternal(), item
);
5477 catch (const std::exception
&e
)
5479 if ( 0 == extHandle
)
5484 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5485 if ( 0 == handle
->initialized
)
5490 handle
->ERROR_MESSAGE("%s", e
.what());
5494 if ( 0 == extHandle
)
5499 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5500 if ( 0 == handle
->initialized
)
5505 handle
->ERROR_MESSAGE("Unknown exception thrown");
5510 GEOSSTRtree_query_r(GEOSContextHandle_t extHandle
,
5511 geos::index::strtree::STRtree
*tree
,
5512 const geos::geom::Geometry
*g
,
5513 GEOSQueryCallback callback
,
5516 GEOSContextHandleInternal_t
*handle
= 0;
5519 assert(callback
!= 0);
5523 CAPI_ItemVisitor
visitor(callback
, userdata
);
5524 tree
->query(g
->getEnvelopeInternal(), visitor
);
5526 catch (const std::exception
&e
)
5528 if ( 0 == extHandle
)
5533 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5534 if ( 0 == handle
->initialized
)
5539 handle
->ERROR_MESSAGE("%s", e
.what());
5543 if ( 0 == extHandle
)
5548 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5549 if ( 0 == handle
->initialized
)
5554 handle
->ERROR_MESSAGE("Unknown exception thrown");
5559 GEOSSTRtree_iterate_r(GEOSContextHandle_t extHandle
,
5560 geos::index::strtree::STRtree
*tree
,
5561 GEOSQueryCallback callback
,
5564 GEOSContextHandleInternal_t
*handle
= 0;
5566 assert(callback
!= 0);
5570 CAPI_ItemVisitor
visitor(callback
, userdata
);
5571 tree
->iterate(visitor
);
5573 catch (const std::exception
&e
)
5575 if ( 0 == extHandle
)
5580 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5581 if ( 0 == handle
->initialized
)
5586 handle
->ERROR_MESSAGE("%s", e
.what());
5590 if ( 0 == extHandle
)
5595 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5596 if ( 0 == handle
->initialized
)
5601 handle
->ERROR_MESSAGE("Unknown exception thrown");
5606 GEOSSTRtree_remove_r(GEOSContextHandle_t extHandle
,
5607 geos::index::strtree::STRtree
*tree
,
5608 const geos::geom::Geometry
*g
,
5614 if ( 0 == extHandle
)
5619 GEOSContextHandleInternal_t
*handle
= 0;
5620 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5621 if ( 0 == handle
->initialized
)
5628 bool result
= tree
->remove(g
->getEnvelopeInternal(), item
);
5631 catch (const std::exception
&e
)
5633 handle
->ERROR_MESSAGE("%s", e
.what());
5637 handle
->ERROR_MESSAGE("Unknown exception thrown");
5644 GEOSSTRtree_destroy_r(GEOSContextHandle_t extHandle
,
5645 geos::index::strtree::STRtree
*tree
)
5647 GEOSContextHandleInternal_t
*handle
= 0;
5653 catch (const std::exception
&e
)
5655 if ( 0 == extHandle
)
5660 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5661 if ( 0 == handle
->initialized
)
5666 handle
->ERROR_MESSAGE("%s", e
.what());
5670 if ( 0 == extHandle
)
5675 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5676 if ( 0 == handle
->initialized
)
5681 handle
->ERROR_MESSAGE("Unknown exception thrown");
5686 GEOSProject_r(GEOSContextHandle_t extHandle
,
5690 if ( 0 == extHandle
) return -1.0;
5691 GEOSContextHandleInternal_t
*handle
=
5692 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5693 if ( handle
->initialized
== 0 ) return -1.0;
5695 const geos::geom::Point
* point
= dynamic_cast<const geos::geom::Point
*>(p
);
5697 handle
->ERROR_MESSAGE("third argument of GEOSProject_r must be Point*");
5701 const geos::geom::Coordinate
* inputPt
= p
->getCoordinate();
5704 return geos::linearref::LengthIndexedLine(g
).project(*inputPt
);
5705 } catch (const std::exception
&e
) {
5706 handle
->ERROR_MESSAGE("%s", e
.what());
5709 handle
->ERROR_MESSAGE("Unknown exception thrown");
5716 GEOSInterpolate_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double d
)
5718 if ( 0 == extHandle
) return 0;
5719 GEOSContextHandleInternal_t
*handle
=
5720 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5721 if ( handle
->initialized
== 0 ) return 0;
5724 geos::linearref::LengthIndexedLine
lil(g
);
5725 geos::geom::Coordinate coord
= lil
.extractPoint(d
);
5726 const GeometryFactory
*gf
= handle
->geomFactory
;
5727 Geometry
* point
= gf
->createPoint(coord
);
5729 } catch (const std::exception
&e
) {
5730 handle
->ERROR_MESSAGE("%s", e
.what());
5733 handle
->ERROR_MESSAGE("Unknown exception thrown");
5740 GEOSProjectNormalized_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
5745 GEOSLength_r(extHandle
, g
, &length
);
5746 return GEOSProject_r(extHandle
, g
, p
) / length
;
5751 GEOSInterpolateNormalized_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
5755 GEOSLength_r(extHandle
, g
, &length
);
5756 return GEOSInterpolate_r(extHandle
, g
, d
* length
);
5760 GEOSGeom_extractUniquePoints_r(GEOSContextHandle_t extHandle
,
5761 const GEOSGeometry
* g
)
5763 if ( 0 == extHandle
) return 0;
5764 GEOSContextHandleInternal_t
*handle
= 0;
5765 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5766 if ( handle
->initialized
== 0 ) return 0;
5768 using namespace geos::geom
;
5769 using namespace geos::util
;
5774 /* 1: extract points */
5775 std::vector
<const Coordinate
*> coords
;
5776 UniqueCoordinateArrayFilter
filter(coords
);
5777 g
->apply_ro(&filter
);
5779 /* 2: for each point, create a geometry and put into a vector */
5780 std::vector
<Geometry
*>* points
= new std::vector
<Geometry
*>();
5781 points
->reserve(coords
.size());
5782 const GeometryFactory
* factory
= g
->getFactory();
5783 for (std::vector
<const Coordinate
*>::iterator it
=coords
.begin(),
5787 Geometry
* point
= factory
->createPoint(*(*it
));
5788 points
->push_back(point
);
5791 /* 3: create a multipoint */
5792 return factory
->createMultiPoint(points
);
5795 catch (const std::exception
&e
)
5797 handle
->ERROR_MESSAGE("%s", e
.what());
5802 handle
->ERROR_MESSAGE("Unknown exception thrown");
5807 int GEOSOrientationIndex_r(GEOSContextHandle_t extHandle
,
5808 double Ax
, double Ay
, double Bx
, double By
, double Px
, double Py
)
5810 GEOSContextHandleInternal_t
*handle
= 0;
5812 using geos::geom::Coordinate
;
5813 using geos::algorithm::CGAlgorithms
;
5815 if ( 0 == extHandle
)
5820 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5821 if ( 0 == handle
->initialized
)
5828 Coordinate
A(Ax
, Ay
);
5829 Coordinate
B(Bx
, By
);
5830 Coordinate
P(Px
, Py
);
5831 return CGAlgorithms::orientationIndex(A
, B
, P
);
5833 catch (const std::exception
&e
)
5835 handle
->ERROR_MESSAGE("%s", e
.what());
5840 handle
->ERROR_MESSAGE("Unknown exception thrown");
5846 GEOSSharedPaths_r(GEOSContextHandle_t extHandle
, const GEOSGeometry
* g1
, const GEOSGeometry
* g2
)
5848 using namespace geos::operation::sharedpaths
;
5850 if ( 0 == extHandle
) return 0;
5851 GEOSContextHandleInternal_t
*handle
=
5852 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5853 if ( handle
->initialized
== 0 ) return 0;
5855 SharedPathsOp::PathList forw
, back
;
5857 SharedPathsOp::sharedPathsOp(*g1
, *g2
, forw
, back
);
5859 catch (const std::exception
&e
)
5861 SharedPathsOp::clearEdges(forw
);
5862 SharedPathsOp::clearEdges(back
);
5863 handle
->ERROR_MESSAGE("%s", e
.what());
5868 SharedPathsOp::clearEdges(forw
);
5869 SharedPathsOp::clearEdges(back
);
5870 handle
->ERROR_MESSAGE("Unknown exception thrown");
5874 // Now forw and back have the geoms we want to use to construct
5875 // our output GeometryCollections...
5877 const GeometryFactory
* factory
= g1
->getFactory();
5880 std::auto_ptr
< std::vector
<Geometry
*> > out1(
5881 new std::vector
<Geometry
*>()
5883 count
= forw
.size();
5884 out1
->reserve(count
);
5885 for (size_t i
=0; i
<count
; ++i
) {
5886 out1
->push_back(forw
[i
]);
5888 std::auto_ptr
<Geometry
> out1g (
5889 factory
->createMultiLineString(out1
.release())
5892 std::auto_ptr
< std::vector
<Geometry
*> > out2(
5893 new std::vector
<Geometry
*>()
5895 count
= back
.size();
5896 out2
->reserve(count
);
5897 for (size_t i
=0; i
<count
; ++i
) {
5898 out2
->push_back(back
[i
]);
5900 std::auto_ptr
<Geometry
> out2g (
5901 factory
->createMultiLineString(out2
.release())
5904 std::auto_ptr
< std::vector
<Geometry
*> > out(
5905 new std::vector
<Geometry
*>()
5908 out
->push_back(out1g
.release());
5909 out
->push_back(out2g
.release());
5911 std::auto_ptr
<Geometry
> outg (
5912 factory
->createGeometryCollection(out
.release())
5915 return outg
.release();
5920 GEOSSnap_r(GEOSContextHandle_t extHandle
, const GEOSGeometry
* g1
,
5921 const GEOSGeometry
* g2
, double tolerance
)
5923 using namespace geos::operation::overlay::snap
;
5925 if ( 0 == extHandle
) return 0;
5926 GEOSContextHandleInternal_t
*handle
=
5927 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5928 if ( handle
->initialized
== 0 ) return 0;
5931 GeometrySnapper
snapper( *g1
);
5932 std::auto_ptr
<Geometry
> ret
= snapper
.snapTo(*g2
, tolerance
);
5933 return ret
.release();
5935 catch (const std::exception
&e
)
5937 handle
->ERROR_MESSAGE("%s", e
.what());
5942 handle
->ERROR_MESSAGE("Unknown exception thrown");
5948 GEOSBufferParams_create_r(GEOSContextHandle_t extHandle
)
5950 if ( 0 == extHandle
) return NULL
;
5952 GEOSContextHandleInternal_t
*handle
= 0;
5953 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5954 if ( 0 == handle
->initialized
) return NULL
;
5958 BufferParameters
*p
= new BufferParameters();
5961 catch (const std::exception
&e
)
5963 handle
->ERROR_MESSAGE("%s", e
.what());
5967 handle
->ERROR_MESSAGE("Unknown exception thrown");
5974 GEOSBufferParams_destroy_r(GEOSContextHandle_t extHandle
, BufferParameters
* p
)
5981 GEOSBufferParams_setEndCapStyle_r(GEOSContextHandle_t extHandle
,
5982 GEOSBufferParams
* p
, int style
)
5984 if ( 0 == extHandle
) return 0;
5986 GEOSContextHandleInternal_t
*handle
= 0;
5987 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5988 if ( 0 == handle
->initialized
) return 0;
5992 if ( style
> BufferParameters::CAP_SQUARE
)
5994 throw IllegalArgumentException("Invalid buffer endCap style");
5996 p
->setEndCapStyle(static_cast<BufferParameters::EndCapStyle
>(style
));
5999 catch (const std::exception
&e
)
6001 handle
->ERROR_MESSAGE("%s", e
.what());
6005 handle
->ERROR_MESSAGE("Unknown exception thrown");
6012 GEOSBufferParams_setJoinStyle_r(GEOSContextHandle_t extHandle
,
6013 GEOSBufferParams
* p
, int style
)
6015 if ( 0 == extHandle
) return 0;
6017 GEOSContextHandleInternal_t
*handle
= 0;
6018 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6019 if ( 0 == handle
->initialized
) return 0;
6023 if ( style
> BufferParameters::JOIN_BEVEL
) {
6024 throw IllegalArgumentException("Invalid buffer join style");
6026 p
->setJoinStyle(static_cast<BufferParameters::JoinStyle
>(style
));
6029 catch (const std::exception
&e
)
6031 handle
->ERROR_MESSAGE("%s", e
.what());
6035 handle
->ERROR_MESSAGE("Unknown exception thrown");
6042 GEOSBufferParams_setMitreLimit_r(GEOSContextHandle_t extHandle
,
6043 GEOSBufferParams
* p
, double limit
)
6045 if ( 0 == extHandle
) return 0;
6047 GEOSContextHandleInternal_t
*handle
= 0;
6048 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6049 if ( 0 == handle
->initialized
) return 0;
6053 p
->setMitreLimit(limit
);
6056 catch (const std::exception
&e
)
6058 handle
->ERROR_MESSAGE("%s", e
.what());
6062 handle
->ERROR_MESSAGE("Unknown exception thrown");
6069 GEOSBufferParams_setQuadrantSegments_r(GEOSContextHandle_t extHandle
,
6070 GEOSBufferParams
* p
, int segs
)
6072 if ( 0 == extHandle
) return 0;
6074 GEOSContextHandleInternal_t
*handle
= 0;
6075 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6076 if ( 0 == handle
->initialized
) return 0;
6080 p
->setQuadrantSegments(segs
);
6083 catch (const std::exception
&e
)
6085 handle
->ERROR_MESSAGE("%s", e
.what());
6089 handle
->ERROR_MESSAGE("Unknown exception thrown");
6096 GEOSBufferParams_setSingleSided_r(GEOSContextHandle_t extHandle
,
6097 GEOSBufferParams
* p
, int ss
)
6099 if ( 0 == extHandle
) return 0;
6101 GEOSContextHandleInternal_t
*handle
= 0;
6102 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6103 if ( 0 == handle
->initialized
) return 0;
6107 p
->setSingleSided( (ss
!= 0) );
6110 catch (const std::exception
&e
)
6112 handle
->ERROR_MESSAGE("%s", e
.what());
6116 handle
->ERROR_MESSAGE("Unknown exception thrown");
6123 GEOSBufferWithParams_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const BufferParameters
* bp
, double width
)
6125 using geos::operation::buffer::BufferOp
;
6127 if ( 0 == extHandle
) return NULL
;
6129 GEOSContextHandleInternal_t
*handle
= 0;
6130 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6131 if ( 0 == handle
->initialized
) return NULL
;
6135 BufferOp
op(g1
, *bp
);
6136 Geometry
*g3
= op
.getResultGeometry(width
);
6139 catch (const std::exception
&e
)
6141 handle
->ERROR_MESSAGE("%s", e
.what());
6145 handle
->ERROR_MESSAGE("Unknown exception thrown");