1 /************************************************************************
5 * C-Wrapper for GEOS library
7 * Copyright (C) 2010 2011 Sandro Santilli <strk@keybit.net>
8 * Copyright (C) 2005-2006 Refractions Research Inc.
10 * This is free software; you can redistribute and/or modify it under
11 * the terms of the GNU Lesser General Public Licence as published
12 * by the Free Software Foundation.
13 * See the COPYING file for more information.
15 * Author: Sandro Santilli <strk@refractions.net>
16 * Thread Safety modifications: Chuck Thibert <charles.thibert@ingres.com>
18 ***********************************************************************/
20 #include <geos/platform.h> // for FINITE
21 #include <geos/geom/Geometry.h>
22 #include <geos/geom/prep/PreparedGeometry.h>
23 #include <geos/geom/prep/PreparedGeometryFactory.h>
24 #include <geos/geom/GeometryCollection.h>
25 #include <geos/geom/Polygon.h>
26 #include <geos/geom/Point.h>
27 #include <geos/geom/MultiPoint.h>
28 #include <geos/geom/MultiLineString.h>
29 #include <geos/geom/MultiPolygon.h>
30 #include <geos/geom/LinearRing.h>
31 #include <geos/geom/LineString.h>
32 #include <geos/geom/PrecisionModel.h>
33 #include <geos/geom/GeometryFactory.h>
34 #include <geos/geom/CoordinateSequenceFactory.h>
35 #include <geos/geom/Coordinate.h>
36 #include <geos/geom/IntersectionMatrix.h>
37 #include <geos/geom/Envelope.h>
38 #include <geos/index/strtree/STRtree.h>
39 #include <geos/index/ItemVisitor.h>
40 #include <geos/io/WKTReader.h>
41 #include <geos/io/WKBReader.h>
42 #include <geos/io/WKTWriter.h>
43 #include <geos/io/WKBWriter.h>
44 #include <geos/algorithm/distance/DiscreteHausdorffDistance.h>
45 #include <geos/algorithm/CGAlgorithms.h>
46 #include <geos/algorithm/BoundaryNodeRule.h>
47 #include <geos/simplify/DouglasPeuckerSimplifier.h>
48 #include <geos/simplify/TopologyPreservingSimplifier.h>
49 #include <geos/operation/valid/IsValidOp.h>
50 #include <geos/operation/polygonize/Polygonizer.h>
51 #include <geos/operation/linemerge/LineMerger.h>
52 #include <geos/operation/overlay/OverlayOp.h>
53 #include <geos/operation/overlay/snap/GeometrySnapper.h>
54 #include <geos/operation/union/CascadedPolygonUnion.h>
55 #include <geos/operation/buffer/BufferOp.h>
56 #include <geos/operation/buffer/BufferParameters.h>
57 #include <geos/operation/buffer/BufferBuilder.h>
58 #include <geos/operation/relate/RelateOp.h>
59 #include <geos/operation/sharedpaths/SharedPathsOp.h>
60 #include <geos/linearref/LengthIndexedLine.h>
61 #include <geos/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
= static_cast<int>(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
= static_cast<int>(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 return g1
->intersection(g2
);
1610 catch (const std::exception
&e
)
1612 handle
->ERROR_MESSAGE("%s", e
.what());
1616 handle
->ERROR_MESSAGE("Unknown exception thrown");
1623 GEOSBuffer_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadrantsegments
)
1625 if ( 0 == extHandle
)
1630 GEOSContextHandleInternal_t
*handle
= 0;
1631 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1632 if ( 0 == handle
->initialized
)
1639 Geometry
*g3
= g1
->buffer(width
, quadrantsegments
);
1642 catch (const std::exception
&e
)
1644 handle
->ERROR_MESSAGE("%s", e
.what());
1648 handle
->ERROR_MESSAGE("Unknown exception thrown");
1655 GEOSBufferWithStyle_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int endCapStyle
, int joinStyle
, double mitreLimit
)
1657 using geos::operation::buffer::BufferParameters
;
1658 using geos::operation::buffer::BufferOp
;
1659 using geos::util::IllegalArgumentException
;
1661 if ( 0 == extHandle
)
1666 GEOSContextHandleInternal_t
*handle
= 0;
1667 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1668 if ( 0 == handle
->initialized
)
1675 BufferParameters bp
;
1676 bp
.setQuadrantSegments(quadsegs
);
1678 if ( endCapStyle
> BufferParameters::CAP_SQUARE
)
1680 throw IllegalArgumentException("Invalid buffer endCap style");
1683 static_cast<BufferParameters::EndCapStyle
>(endCapStyle
)
1686 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1688 throw IllegalArgumentException("Invalid buffer join style");
1691 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1693 bp
.setMitreLimit(mitreLimit
);
1694 BufferOp
op(g1
, bp
);
1695 Geometry
*g3
= op
.getResultGeometry(width
);
1698 catch (const std::exception
&e
)
1700 handle
->ERROR_MESSAGE("%s", e
.what());
1704 handle
->ERROR_MESSAGE("Unknown exception thrown");
1711 GEOSOffsetCurve_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int joinStyle
, double mitreLimit
)
1713 if ( 0 == extHandle
) return NULL
;
1715 GEOSContextHandleInternal_t
*handle
= 0;
1716 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1717 if ( 0 == handle
->initialized
) return NULL
;
1721 BufferParameters bp
;
1722 bp
.setEndCapStyle( BufferParameters::CAP_FLAT
);
1723 bp
.setQuadrantSegments(quadsegs
);
1725 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1727 throw IllegalArgumentException("Invalid buffer join style");
1730 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1732 bp
.setMitreLimit(mitreLimit
);
1734 bool isLeftSide
= true;
1739 BufferBuilder
bufBuilder (bp
);
1740 Geometry
*g3
= bufBuilder
.bufferLineSingleSided(g1
, width
, isLeftSide
);
1744 catch (const std::exception
&e
)
1746 handle
->ERROR_MESSAGE("%s", e
.what());
1750 handle
->ERROR_MESSAGE("Unknown exception thrown");
1756 /* @deprecated in 3.3.0 */
1758 GEOSSingleSidedBuffer_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int joinStyle
, double mitreLimit
, int leftSide
)
1760 if ( 0 == extHandle
) return NULL
;
1762 GEOSContextHandleInternal_t
*handle
= 0;
1763 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1764 if ( 0 == handle
->initialized
) return NULL
;
1768 BufferParameters bp
;
1769 bp
.setEndCapStyle( BufferParameters::CAP_FLAT
);
1770 bp
.setQuadrantSegments(quadsegs
);
1772 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1774 throw IllegalArgumentException("Invalid buffer join style");
1777 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1779 bp
.setMitreLimit(mitreLimit
);
1781 bool isLeftSide
= leftSide
== 0 ? false : true;
1782 BufferBuilder
bufBuilder (bp
);
1783 Geometry
*g3
= bufBuilder
.bufferLineSingleSided(g1
, width
, isLeftSide
);
1787 catch (const std::exception
&e
)
1789 handle
->ERROR_MESSAGE("%s", e
.what());
1793 handle
->ERROR_MESSAGE("Unknown exception thrown");
1800 GEOSConvexHull_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1802 if ( 0 == extHandle
)
1807 GEOSContextHandleInternal_t
*handle
= 0;
1808 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1809 if ( 0 == handle
->initialized
)
1816 Geometry
*g3
= g1
->convexHull();
1819 catch (const std::exception
&e
)
1821 handle
->ERROR_MESSAGE("%s", e
.what());
1825 handle
->ERROR_MESSAGE("Unknown exception thrown");
1832 GEOSDifference_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1834 if ( 0 == extHandle
)
1839 GEOSContextHandleInternal_t
*handle
= 0;
1840 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1841 if ( 0 == handle
->initialized
)
1848 return g1
->difference(g2
);
1850 catch (const std::exception
&e
)
1852 handle
->ERROR_MESSAGE("%s", e
.what());
1856 handle
->ERROR_MESSAGE("Unknown exception thrown");
1863 GEOSBoundary_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1865 if ( 0 == extHandle
)
1870 GEOSContextHandleInternal_t
*handle
= 0;
1871 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1872 if ( 0 == handle
->initialized
)
1879 Geometry
*g3
= g1
->getBoundary();
1882 catch (const std::exception
&e
)
1884 handle
->ERROR_MESSAGE("%s", e
.what());
1888 handle
->ERROR_MESSAGE("Unknown exception thrown");
1895 GEOSSymDifference_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1897 if ( 0 == extHandle
)
1902 GEOSContextHandleInternal_t
*handle
= 0;
1903 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1904 if ( 0 == handle
->initialized
)
1911 return g1
->symDifference(g2
);
1913 catch (const std::exception
&e
)
1915 handle
->ERROR_MESSAGE("%s", e
.what());
1921 handle
->ERROR_MESSAGE("Unknown exception thrown");
1927 GEOSUnion_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1929 if ( 0 == extHandle
)
1934 GEOSContextHandleInternal_t
*handle
= 0;
1935 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1936 if ( 0 == handle
->initialized
)
1943 return g1
->Union(g2
);
1945 catch (const std::exception
&e
)
1947 #if VERBOSE_EXCEPTIONS
1948 std::ostringstream s
;
1949 s
<< "Exception on GEOSUnion with following inputs:" << std::endl
;
1950 s
<< "A: "<<g1
->toString() << std::endl
;
1951 s
<< "B: "<<g2
->toString() << std::endl
;
1952 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
1953 #endif // VERBOSE_EXCEPTIONS
1954 handle
->ERROR_MESSAGE("%s", e
.what());
1958 handle
->ERROR_MESSAGE("Unknown exception thrown");
1965 GEOSUnaryUnion_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
1967 if ( 0 == extHandle
)
1972 GEOSContextHandleInternal_t
*handle
= 0;
1973 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1974 if ( 0 == handle
->initialized
)
1981 GeomAutoPtr
g3 ( g
->Union() );
1982 return g3
.release();
1984 catch (const std::exception
&e
)
1986 #if VERBOSE_EXCEPTIONS
1987 std::ostringstream s
;
1988 s
<< "Exception on GEOSUnaryUnion with following inputs:" << std::endl
;
1989 s
<< "A: "<<g1
->toString() << std::endl
;
1990 s
<< "B: "<<g2
->toString() << std::endl
;
1991 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
1992 #endif // VERBOSE_EXCEPTIONS
1993 handle
->ERROR_MESSAGE("%s", e
.what());
1997 handle
->ERROR_MESSAGE("Unknown exception thrown");
2004 GEOSUnionCascaded_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2006 if ( 0 == extHandle
)
2011 GEOSContextHandleInternal_t
*handle
= 0;
2012 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2013 if ( 0 == handle
->initialized
)
2020 const geos::geom::MultiPolygon
*p
= dynamic_cast<const geos::geom::MultiPolygon
*>(g1
);
2023 handle
->ERROR_MESSAGE("Invalid argument (must be a MultiPolygon)");
2027 using geos::operation::geounion::CascadedPolygonUnion
;
2028 return CascadedPolygonUnion::Union(p
);
2030 catch (const std::exception
&e
)
2032 handle
->ERROR_MESSAGE("%s", e
.what());
2036 handle
->ERROR_MESSAGE("Unknown exception thrown");
2043 GEOSPointOnSurface_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2045 if ( 0 == extHandle
)
2050 GEOSContextHandleInternal_t
*handle
= 0;
2051 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2052 if ( 0 == handle
->initialized
)
2059 Geometry
*ret
= g1
->getInteriorPoint();
2062 const GeometryFactory
* gf
= handle
->geomFactory
;
2063 // return an empty collection
2064 return gf
->createGeometryCollection();
2068 catch (const std::exception
&e
)
2070 handle
->ERROR_MESSAGE("%s", e
.what());
2074 handle
->ERROR_MESSAGE("Unknown exception thrown");
2080 //-------------------------------------------------------------------
2081 // memory management functions
2082 //------------------------------------------------------------------
2085 GEOSGeom_destroy_r(GEOSContextHandle_t extHandle
, Geometry
*a
)
2087 GEOSContextHandleInternal_t
*handle
= 0;
2089 // FIXME: mloskot: Does this try-catch around delete means that
2090 // destructors in GEOS may throw? If it does, this is a serious
2091 // violation of "never throw an exception from a destructor" principle
2097 catch (const std::exception
&e
)
2099 if ( 0 == extHandle
)
2104 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2105 if ( 0 == handle
->initialized
)
2110 handle
->ERROR_MESSAGE("%s", e
.what());
2114 if ( 0 == extHandle
)
2119 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2120 if ( 0 == handle
->initialized
)
2125 handle
->ERROR_MESSAGE("Unknown exception thrown");
2130 GEOSSetSRID_r(GEOSContextHandle_t extHandle
, Geometry
*g
, int srid
)
2134 if ( 0 == extHandle
)
2139 GEOSContextHandleInternal_t
*handle
= 0;
2140 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2141 if ( 0 == handle
->initialized
)
2151 GEOSGetNumCoordinates_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2155 if ( 0 == extHandle
)
2160 GEOSContextHandleInternal_t
*handle
= 0;
2161 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2162 if ( 0 == handle
->initialized
)
2169 return static_cast<int>(g
->getNumPoints());
2171 catch (const std::exception
&e
)
2173 handle
->ERROR_MESSAGE("%s", e
.what());
2177 handle
->ERROR_MESSAGE("Unknown exception thrown");
2184 * Return -1 on exception, 0 otherwise.
2185 * Converts Geometry to normal form (or canonical form).
2188 GEOSNormalize_r(GEOSContextHandle_t extHandle
, Geometry
*g
)
2192 if ( 0 == extHandle
)
2197 GEOSContextHandleInternal_t
*handle
= 0;
2198 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2199 if ( 0 == handle
->initialized
)
2207 return 0; // SUCCESS
2209 catch (const std::exception
&e
)
2211 handle
->ERROR_MESSAGE("%s", e
.what());
2215 handle
->ERROR_MESSAGE("Unknown exception thrown");
2222 GEOSGetNumInteriorRings_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2224 if ( 0 == extHandle
)
2229 GEOSContextHandleInternal_t
*handle
= 0;
2230 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2231 if ( 0 == handle
->initialized
)
2238 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
2241 handle
->ERROR_MESSAGE("Argument is not a Polygon");
2244 return static_cast<int>(p
->getNumInteriorRing());
2246 catch (const std::exception
&e
)
2248 handle
->ERROR_MESSAGE("%s", e
.what());
2252 handle
->ERROR_MESSAGE("Unknown exception thrown");
2259 // returns -1 on error and 1 for non-multi geometries
2261 GEOSGetNumGeometries_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2263 if ( 0 == extHandle
)
2268 GEOSContextHandleInternal_t
*handle
= 0;
2269 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2270 if ( 0 == handle
->initialized
)
2277 return static_cast<int>(g1
->getNumGeometries());
2279 catch (const std::exception
&e
)
2281 handle
->ERROR_MESSAGE("%s", e
.what());
2285 handle
->ERROR_MESSAGE("Unknown exception thrown");
2293 * Call only on GEOMETRYCOLLECTION or MULTI*.
2294 * Return a pointer to the internal Geometry.
2297 GEOSGetGeometryN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2299 if ( 0 == extHandle
)
2304 GEOSContextHandleInternal_t
*handle
= 0;
2305 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2306 if ( 0 == handle
->initialized
)
2313 return g1
->getGeometryN(n
);
2315 catch (const std::exception
&e
)
2317 handle
->ERROR_MESSAGE("%s", e
.what());
2321 handle
->ERROR_MESSAGE("Unknown exception thrown");
2328 * Call only on LINESTRING
2329 * Returns NULL on exception
2332 GEOSGeomGetPointN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2334 if ( 0 == extHandle
)
2339 GEOSContextHandleInternal_t
*handle
= 0;
2340 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2341 if ( 0 == handle
->initialized
)
2348 using geos::geom::LineString
;
2349 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2352 handle
->ERROR_MESSAGE("Argument is not a LineString");
2355 return ls
->getPointN(n
);
2357 catch (const std::exception
&e
)
2359 handle
->ERROR_MESSAGE("%s", e
.what());
2363 handle
->ERROR_MESSAGE("Unknown exception thrown");
2370 * Call only on LINESTRING
2373 GEOSGeomGetStartPoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2375 if ( 0 == extHandle
)
2380 GEOSContextHandleInternal_t
*handle
= 0;
2381 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2382 if ( 0 == handle
->initialized
)
2389 using geos::geom::LineString
;
2390 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2393 handle
->ERROR_MESSAGE("Argument is not a LineString");
2396 return ls
->getStartPoint();
2398 catch (const std::exception
&e
)
2400 handle
->ERROR_MESSAGE("%s", e
.what());
2404 handle
->ERROR_MESSAGE("Unknown exception thrown");
2411 * Call only on LINESTRING
2414 GEOSGeomGetEndPoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2416 if ( 0 == extHandle
)
2421 GEOSContextHandleInternal_t
*handle
= 0;
2422 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2423 if ( 0 == handle
->initialized
)
2430 using geos::geom::LineString
;
2431 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2434 handle
->ERROR_MESSAGE("Argument is not a LineString");
2437 return ls
->getEndPoint();
2439 catch (const std::exception
&e
)
2441 handle
->ERROR_MESSAGE("%s", e
.what());
2445 handle
->ERROR_MESSAGE("Unknown exception thrown");
2452 * Call only on LINESTRING
2453 * return 2 on exception, 1 on true, 0 on false
2456 GEOSisClosed_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2458 if ( 0 == extHandle
)
2463 GEOSContextHandleInternal_t
*handle
= 0;
2464 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2465 if ( 0 == handle
->initialized
)
2472 using geos::geom::LineString
;
2473 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2476 handle
->ERROR_MESSAGE("Argument is not a LineString");
2479 return ls
->isClosed();
2481 catch (const std::exception
&e
)
2483 handle
->ERROR_MESSAGE("%s", e
.what());
2487 handle
->ERROR_MESSAGE("Unknown exception thrown");
2494 * Call only on LINESTRING
2495 * return 0 on exception, otherwise 1
2498 GEOSGeomGetLength_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *length
)
2500 if ( 0 == extHandle
)
2505 GEOSContextHandleInternal_t
*handle
= 0;
2506 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2507 if ( 0 == handle
->initialized
)
2514 using geos::geom::LineString
;
2515 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2518 handle
->ERROR_MESSAGE("Argument is not a LineString");
2521 *length
= ls
->getLength();
2524 catch (const std::exception
&e
)
2526 handle
->ERROR_MESSAGE("%s", e
.what());
2530 handle
->ERROR_MESSAGE("Unknown exception thrown");
2537 * Call only on LINESTRING
2540 GEOSGeomGetNumPoints_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2542 if ( 0 == extHandle
)
2547 GEOSContextHandleInternal_t
*handle
= 0;
2548 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2549 if ( 0 == handle
->initialized
)
2556 using geos::geom::LineString
;
2557 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2560 handle
->ERROR_MESSAGE("Argument is not a LineString");
2563 return ls
->getNumPoints();
2565 catch (const std::exception
&e
)
2567 handle
->ERROR_MESSAGE("%s", e
.what());
2571 handle
->ERROR_MESSAGE("Unknown exception thrown");
2579 * returns 0 on exception, otherwise 1
2582 GEOSGeomGetX_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *x
)
2584 if ( 0 == extHandle
)
2589 GEOSContextHandleInternal_t
*handle
= 0;
2590 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2591 if ( 0 == handle
->initialized
)
2598 using geos::geom::Point
;
2599 const Point
*po
= dynamic_cast<const Point
*>(g1
);
2602 handle
->ERROR_MESSAGE("Argument is not a Point");
2608 catch (const std::exception
&e
)
2610 handle
->ERROR_MESSAGE("%s", e
.what());
2614 handle
->ERROR_MESSAGE("Unknown exception thrown");
2622 * returns 0 on exception, otherwise 1
2625 GEOSGeomGetY_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *y
)
2627 if ( 0 == extHandle
)
2632 GEOSContextHandleInternal_t
*handle
= 0;
2633 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2634 if ( 0 == handle
->initialized
)
2641 using geos::geom::Point
;
2642 const Point
*po
= dynamic_cast<const Point
*>(g1
);
2645 handle
->ERROR_MESSAGE("Argument is not a Point");
2651 catch (const std::exception
&e
)
2653 handle
->ERROR_MESSAGE("%s", e
.what());
2657 handle
->ERROR_MESSAGE("Unknown exception thrown");
2664 * Call only on polygon
2665 * Return a copy of the internal Geometry.
2668 GEOSGetExteriorRing_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2670 if ( 0 == extHandle
)
2675 GEOSContextHandleInternal_t
*handle
= 0;
2676 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2677 if ( 0 == handle
->initialized
)
2684 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
2687 handle
->ERROR_MESSAGE("Invalid argument (must be a Polygon)");
2690 return p
->getExteriorRing();
2692 catch (const std::exception
&e
)
2694 handle
->ERROR_MESSAGE("%s", e
.what());
2698 handle
->ERROR_MESSAGE("Unknown exception thrown");
2705 * Call only on polygon
2706 * Return a pointer to internal storage, do not destroy it.
2709 GEOSGetInteriorRingN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2711 if ( 0 == extHandle
)
2716 GEOSContextHandleInternal_t
*handle
= 0;
2717 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2718 if ( 0 == handle
->initialized
)
2725 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
2728 handle
->ERROR_MESSAGE("Invalid argument (must be a Polygon)");
2731 return p
->getInteriorRingN(n
);
2733 catch (const std::exception
&e
)
2735 handle
->ERROR_MESSAGE("%s", e
.what());
2739 handle
->ERROR_MESSAGE("Unknown exception thrown");
2746 GEOSGetCentroid_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2748 if ( 0 == extHandle
)
2753 GEOSContextHandleInternal_t
*handle
= 0;
2754 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2755 if ( 0 == handle
->initialized
)
2762 Geometry
*ret
= g
->getCentroid();
2765 const GeometryFactory
*gf
= handle
->geomFactory
;
2766 return gf
->createGeometryCollection();
2770 catch (const std::exception
&e
)
2772 handle
->ERROR_MESSAGE("%s", e
.what());
2776 handle
->ERROR_MESSAGE("Unknown exception thrown");
2783 GEOSGeom_createEmptyCollection_r(GEOSContextHandle_t extHandle
, int type
)
2785 if ( 0 == extHandle
)
2790 GEOSContextHandleInternal_t
*handle
= 0;
2791 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2792 if ( 0 == handle
->initialized
)
2799 sprintf(buf
, "createCollection: requested type %d, ngeoms: %d",
2801 handle
->NOTICE_MESSAGE("%s", buf
);// TODO: Can handle->NOTICE_MESSAGE format that directly?
2806 const GeometryFactory
* gf
= handle
->geomFactory
;
2811 case GEOS_GEOMETRYCOLLECTION
:
2812 g
= gf
->createGeometryCollection();
2814 case GEOS_MULTIPOINT
:
2815 g
= gf
->createMultiPoint();
2817 case GEOS_MULTILINESTRING
:
2818 g
= gf
->createMultiLineString();
2820 case GEOS_MULTIPOLYGON
:
2821 g
= gf
->createMultiPolygon();
2824 handle
->ERROR_MESSAGE("Unsupported type request for GEOSGeom_createEmptyCollection_r");
2831 catch (const std::exception
&e
)
2833 handle
->ERROR_MESSAGE("%s", e
.what());
2837 handle
->ERROR_MESSAGE("Unknown exception thrown");
2844 GEOSGeom_createCollection_r(GEOSContextHandle_t extHandle
, int type
, Geometry
**geoms
, unsigned int ngeoms
)
2846 if ( 0 == extHandle
)
2851 GEOSContextHandleInternal_t
*handle
= 0;
2852 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2853 if ( 0 == handle
->initialized
)
2860 sprintf(buf
, "PostGIS2GEOS_collection: requested type %d, ngeoms: %d",
2862 handle
->NOTICE_MESSAGE("%s", buf
);// TODO: Can handle->NOTICE_MESSAGE format that directly?
2867 const GeometryFactory
* gf
= handle
->geomFactory
;
2868 std::vector
<Geometry
*>* vgeoms
= new std::vector
<Geometry
*>(geoms
, geoms
+ ngeoms
);
2873 case GEOS_GEOMETRYCOLLECTION
:
2874 g
= gf
->createGeometryCollection(vgeoms
);
2876 case GEOS_MULTIPOINT
:
2877 g
= gf
->createMultiPoint(vgeoms
);
2879 case GEOS_MULTILINESTRING
:
2880 g
= gf
->createMultiLineString(vgeoms
);
2882 case GEOS_MULTIPOLYGON
:
2883 g
= gf
->createMultiPolygon(vgeoms
);
2886 handle
->ERROR_MESSAGE("Unsupported type request for PostGIS2GEOS_collection");
2893 catch (const std::exception
&e
)
2895 handle
->ERROR_MESSAGE("%s", e
.what());
2899 handle
->ERROR_MESSAGE("Unknown exception thrown");
2906 GEOSPolygonize_r(GEOSContextHandle_t extHandle
, const Geometry
* const * g
, unsigned int ngeoms
)
2908 if ( 0 == extHandle
)
2913 GEOSContextHandleInternal_t
*handle
= 0;
2914 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2915 if ( 0 == handle
->initialized
)
2925 using geos::operation::polygonize::Polygonizer
;
2927 for (std::size_t i
= 0; i
< ngeoms
; ++i
)
2933 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
2936 std::vector
<Polygon
*> *polys
= plgnzr
.getPolygons();
2940 handle
->NOTICE_MESSAGE("output polygons got");
2943 // We need a vector of Geometry pointers, not Polygon pointers.
2944 // STL vector doesn't allow transparent upcast of this
2945 // nature, so we explicitly convert.
2946 // (it's just a waste of processor and memory, btw)
2948 // XXX mloskot: Why not to extent GeometryFactory to accept
2949 // vector of polygons or extend Polygonizer to return list of Geometry*
2950 // or add a wrapper which semantic is similar to:
2951 // std::vector<as_polygon<Geometry*> >
2952 std::vector
<Geometry
*> *polyvec
= new std::vector
<Geometry
*>(polys
->size());
2954 for (std::size_t i
= 0; i
< polys
->size(); ++i
)
2956 (*polyvec
)[i
] = (*polys
)[i
];
2961 const GeometryFactory
*gf
= handle
->geomFactory
;
2963 // The below takes ownership of the passed vector,
2964 // so we must *not* delete it
2965 out
= gf
->createGeometryCollection(polyvec
);
2967 catch (const std::exception
&e
)
2969 handle
->ERROR_MESSAGE("%s", e
.what());
2973 handle
->ERROR_MESSAGE("Unknown exception thrown");
2980 GEOSPolygonizer_getCutEdges_r(GEOSContextHandle_t extHandle
, const Geometry
* const * g
, unsigned int ngeoms
)
2982 if ( 0 == extHandle
)
2987 GEOSContextHandleInternal_t
*handle
= 0;
2988 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2989 if ( 0 == handle
->initialized
)
2999 using geos::operation::polygonize::Polygonizer
;
3001 for (std::size_t i
= 0; i
< ngeoms
; ++i
)
3007 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
3010 const std::vector
<const LineString
*>& lines
= plgnzr
.getCutEdges();
3013 handle
->NOTICE_MESSAGE("output polygons got");
3016 // We need a vector of Geometry pointers, not Polygon pointers.
3017 // STL vector doesn't allow transparent upcast of this
3018 // nature, so we explicitly convert.
3019 // (it's just a waste of processor and memory, btw)
3020 // XXX mloskot: See comment for GEOSPolygonize_r
3021 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3023 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3025 (*linevec
)[i
] = lines
[i
]->clone();
3028 const GeometryFactory
*gf
= handle
->geomFactory
;
3030 // The below takes ownership of the passed vector,
3031 // so we must *not* delete it
3032 out
= gf
->createGeometryCollection(linevec
);
3034 catch (const std::exception
&e
)
3036 handle
->ERROR_MESSAGE("%s", e
.what());
3040 handle
->ERROR_MESSAGE("Unknown exception thrown");
3047 GEOSPolygonize_full_r(GEOSContextHandle_t extHandle
, const Geometry
* g
,
3048 Geometry
** cuts
, Geometry
** dangles
, Geometry
** invalid
)
3050 if ( 0 == extHandle
)
3055 GEOSContextHandleInternal_t
*handle
= 0;
3056 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3057 if ( 0 == handle
->initialized
)
3065 using geos::operation::polygonize::Polygonizer
;
3067 for (std::size_t i
= 0; i
<g
->getNumGeometries(); ++i
)
3069 plgnzr
.add(g
->getGeometryN(i
));
3073 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
3075 const GeometryFactory
*gf
= handle
->geomFactory
;
3079 const std::vector
<const LineString
*>& lines
= plgnzr
.getCutEdges();
3080 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3081 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3083 (*linevec
)[i
] = lines
[i
]->clone();
3086 // The below takes ownership of the passed vector,
3087 // so we must *not* delete it
3088 *cuts
= gf
->createGeometryCollection(linevec
);
3093 const std::vector
<const LineString
*>& lines
= plgnzr
.getDangles();
3094 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3095 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3097 (*linevec
)[i
] = lines
[i
]->clone();
3100 // The below takes ownership of the passed vector,
3101 // so we must *not* delete it
3102 *dangles
= gf
->createGeometryCollection(linevec
);
3107 const std::vector
<LineString
*>& lines
= plgnzr
.getInvalidRingLines();
3108 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3109 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3111 (*linevec
)[i
] = lines
[i
]->clone();
3114 // The below takes ownership of the passed vector,
3115 // so we must *not* delete it
3116 *invalid
= gf
->createGeometryCollection(linevec
);
3119 std::vector
<Polygon
*> *polys
= plgnzr
.getPolygons();
3120 std::vector
<Geometry
*> *polyvec
= new std::vector
<Geometry
*>(polys
->size());
3121 for (std::size_t i
= 0; i
< polys
->size(); ++i
)
3123 (*polyvec
)[i
] = (*polys
)[i
];
3127 return gf
->createGeometryCollection(polyvec
);
3130 catch (const std::exception
&e
)
3132 handle
->ERROR_MESSAGE("%s", e
.what());
3137 handle
->ERROR_MESSAGE("Unknown exception thrown");
3143 GEOSLineMerge_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3145 if ( 0 == extHandle
)
3150 GEOSContextHandleInternal_t
*handle
= 0;
3151 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3152 if ( 0 == handle
->initialized
)
3161 using geos::operation::linemerge::LineMerger
;
3165 std::vector
<LineString
*>* lines
= lmrgr
.getMergedLineStrings();
3169 handle
->NOTICE_MESSAGE("output lines got");
3172 std::vector
<Geometry
*>*geoms
= new std::vector
<Geometry
*>(lines
->size());
3173 for (std::vector
<Geometry
*>::size_type i
= 0; i
< lines
->size(); ++i
)
3175 (*geoms
)[i
] = (*lines
)[i
];
3180 const GeometryFactory
*gf
= handle
->geomFactory
;
3181 out
= gf
->buildGeometry(geoms
);
3184 //out = gf->createGeometryCollection(geoms);
3186 catch (const std::exception
&e
)
3188 handle
->ERROR_MESSAGE("%s", e
.what());
3192 handle
->ERROR_MESSAGE("Unknown exception thrown");
3199 GEOSGetSRID_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3203 if ( 0 == extHandle
)
3208 GEOSContextHandleInternal_t
*handle
= 0;
3209 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3210 if ( 0 == handle
->initialized
)
3217 return g
->getSRID();
3219 catch (const std::exception
&e
)
3221 handle
->ERROR_MESSAGE("%s", e
.what());
3225 handle
->ERROR_MESSAGE("Unknown exception thrown");
3231 const char* GEOSversion()
3233 return GEOS_CAPI_VERSION
;
3236 const char* GEOSjtsport()
3238 return GEOS_JTS_PORT
;
3242 GEOSHasZ_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3246 if ( 0 == extHandle
)
3251 GEOSContextHandleInternal_t
*handle
= 0;
3252 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3253 if ( 0 == handle
->initialized
)
3262 assert(0 != g
->getCoordinate());
3264 double az
= g
->getCoordinate()->z
;
3265 //handle->ERROR_MESSAGE("ZCoord: %g", az);
3267 return static_cast<char>(FINITE(az
));
3271 GEOS_getWKBOutputDims_r(GEOSContextHandle_t extHandle
)
3273 if ( 0 == extHandle
)
3278 GEOSContextHandleInternal_t
*handle
= 0;
3279 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3280 if ( 0 == handle
->initialized
)
3285 return handle
->WKBOutputDims
;
3289 GEOS_setWKBOutputDims_r(GEOSContextHandle_t extHandle
, int newdims
)
3291 if ( 0 == extHandle
)
3296 GEOSContextHandleInternal_t
*handle
= 0;
3297 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3298 if ( 0 == handle
->initialized
)
3303 if ( newdims
< 2 || newdims
> 3 )
3305 handle
->ERROR_MESSAGE("WKB output dimensions out of range 2..3");
3308 const int olddims
= handle
->WKBOutputDims
;
3309 handle
->WKBOutputDims
= newdims
;
3315 GEOS_getWKBByteOrder_r(GEOSContextHandle_t extHandle
)
3317 if ( 0 == extHandle
)
3322 GEOSContextHandleInternal_t
*handle
= 0;
3323 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3324 if ( 0 == handle
->initialized
)
3329 return handle
->WKBByteOrder
;
3333 GEOS_setWKBByteOrder_r(GEOSContextHandle_t extHandle
, int byteOrder
)
3335 if ( 0 == extHandle
)
3340 GEOSContextHandleInternal_t
*handle
= 0;
3341 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3342 if ( 0 == handle
->initialized
)
3347 const int oldByteOrder
= handle
->WKBByteOrder
;
3348 handle
->WKBByteOrder
= byteOrder
;
3350 return oldByteOrder
;
3354 CoordinateSequence
*
3355 GEOSCoordSeq_create_r(GEOSContextHandle_t extHandle
, unsigned int size
, unsigned int dims
)
3357 if ( 0 == extHandle
)
3362 GEOSContextHandleInternal_t
*handle
= 0;
3363 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3364 if ( 0 == handle
->initialized
)
3371 const GeometryFactory
*gf
= handle
->geomFactory
;
3372 return gf
->getCoordinateSequenceFactory()->create(size
, dims
);
3374 catch (const std::exception
&e
)
3376 handle
->ERROR_MESSAGE("%s", e
.what());
3380 handle
->ERROR_MESSAGE("Unknown exception thrown");
3387 GEOSCoordSeq_setOrdinate_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
,
3388 unsigned int idx
, unsigned int dim
, double val
)
3391 if ( 0 == extHandle
)
3396 GEOSContextHandleInternal_t
*handle
= 0;
3397 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3398 if ( 0 == handle
->initialized
)
3405 cs
->setOrdinate(static_cast<int>(idx
), static_cast<int>(dim
), val
);
3408 catch (const std::exception
&e
)
3410 handle
->ERROR_MESSAGE("%s", e
.what());
3414 handle
->ERROR_MESSAGE("Unknown exception thrown");
3421 GEOSCoordSeq_setX_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3423 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 0, val
);
3427 GEOSCoordSeq_setY_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3429 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 1, val
);
3433 GEOSCoordSeq_setZ_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3435 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 2, val
);
3438 CoordinateSequence
*
3439 GEOSCoordSeq_clone_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
)
3443 if ( 0 == extHandle
)
3448 GEOSContextHandleInternal_t
*handle
= 0;
3449 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3450 if ( 0 == handle
->initialized
)
3459 catch (const std::exception
&e
)
3461 handle
->ERROR_MESSAGE("%s", e
.what());
3465 handle
->ERROR_MESSAGE("Unknown exception thrown");
3472 GEOSCoordSeq_getOrdinate_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
,
3473 unsigned int idx
, unsigned int dim
, double *val
)
3478 if ( 0 == extHandle
)
3483 GEOSContextHandleInternal_t
*handle
= 0;
3484 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3485 if ( 0 == handle
->initialized
)
3492 double d
= cs
->getOrdinate(static_cast<int>(idx
), static_cast<int>(dim
));
3497 catch (const std::exception
&e
)
3499 handle
->ERROR_MESSAGE("%s", e
.what());
3503 handle
->ERROR_MESSAGE("Unknown exception thrown");
3510 GEOSCoordSeq_getX_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
3512 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 0, val
);
3516 GEOSCoordSeq_getY_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
3518 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 1, val
);
3522 GEOSCoordSeq_getZ_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
3524 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 2, val
);
3528 GEOSCoordSeq_getSize_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
, unsigned int *size
)
3533 if ( 0 == extHandle
)
3538 GEOSContextHandleInternal_t
*handle
= 0;
3539 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3540 if ( 0 == handle
->initialized
)
3547 const std::size_t sz
= cs
->getSize();
3548 *size
= static_cast<unsigned int>(sz
);
3551 catch (const std::exception
&e
)
3553 handle
->ERROR_MESSAGE("%s", e
.what());
3557 handle
->ERROR_MESSAGE("Unknown exception thrown");
3564 GEOSCoordSeq_getDimensions_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
, unsigned int *dims
)
3569 if ( 0 == extHandle
)
3574 GEOSContextHandleInternal_t
*handle
= 0;
3575 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3576 if ( 0 == handle
->initialized
)
3583 const std::size_t dim
= cs
->getDimension();
3584 *dims
= static_cast<unsigned int>(dim
);
3588 catch (const std::exception
&e
)
3590 handle
->ERROR_MESSAGE("%s", e
.what());
3595 handle
->ERROR_MESSAGE("Unknown exception thrown");
3602 GEOSCoordSeq_destroy_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
)
3604 GEOSContextHandleInternal_t
*handle
= 0;
3610 catch (const std::exception
&e
)
3612 if ( 0 == extHandle
)
3617 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3618 if ( 0 == handle
->initialized
)
3623 handle
->ERROR_MESSAGE("%s", e
.what());
3627 if ( 0 == extHandle
)
3632 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3633 if ( 0 == handle
->initialized
)
3638 handle
->ERROR_MESSAGE("Unknown exception thrown");
3642 const CoordinateSequence
*
3643 GEOSGeom_getCoordSeq_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3645 if ( 0 == extHandle
)
3650 GEOSContextHandleInternal_t
*handle
= 0;
3651 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3652 if ( 0 == handle
->initialized
)
3659 using geos::geom::Point
;
3661 const LineString
*ls
= dynamic_cast<const LineString
*>(g
);
3664 return ls
->getCoordinatesRO();
3667 const Point
*p
= dynamic_cast<const Point
*>(g
);
3670 return p
->getCoordinatesRO();
3673 handle
->ERROR_MESSAGE("Geometry must be a Point or LineString");
3676 catch (const std::exception
&e
)
3678 handle
->ERROR_MESSAGE("%s", e
.what());
3682 handle
->ERROR_MESSAGE("Unknown exception thrown");
3689 GEOSGeom_createEmptyPoint_r(GEOSContextHandle_t extHandle
)
3691 if ( 0 == extHandle
)
3696 GEOSContextHandleInternal_t
*handle
= 0;
3697 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3698 if ( 0 == handle
->initialized
)
3705 const GeometryFactory
*gf
= handle
->geomFactory
;
3706 return gf
->createPoint();
3708 catch (const std::exception
&e
)
3710 handle
->ERROR_MESSAGE("%s", e
.what());
3714 handle
->ERROR_MESSAGE("Unknown exception thrown");
3721 GEOSGeom_createPoint_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
3723 if ( 0 == extHandle
)
3728 GEOSContextHandleInternal_t
*handle
= 0;
3729 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3730 if ( 0 == handle
->initialized
)
3737 const GeometryFactory
*gf
= handle
->geomFactory
;
3738 return gf
->createPoint(cs
);
3740 catch (const std::exception
&e
)
3742 handle
->ERROR_MESSAGE("%s", e
.what());
3746 handle
->ERROR_MESSAGE("Unknown exception thrown");
3753 GEOSGeom_createLinearRing_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
3755 if ( 0 == extHandle
)
3760 GEOSContextHandleInternal_t
*handle
= 0;
3761 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3762 if ( 0 == handle
->initialized
)
3769 const GeometryFactory
*gf
= handle
->geomFactory
;
3771 return gf
->createLinearRing(cs
);
3773 catch (const std::exception
&e
)
3775 handle
->ERROR_MESSAGE("%s", e
.what());
3779 handle
->ERROR_MESSAGE("Unknown exception thrown");
3786 GEOSGeom_createEmptyLineString_r(GEOSContextHandle_t extHandle
)
3788 if ( 0 == extHandle
)
3793 GEOSContextHandleInternal_t
*handle
= 0;
3794 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3795 if ( 0 == handle
->initialized
)
3802 const GeometryFactory
*gf
= handle
->geomFactory
;
3804 return gf
->createLineString();
3806 catch (const std::exception
&e
)
3808 handle
->ERROR_MESSAGE("%s", e
.what());
3812 handle
->ERROR_MESSAGE("Unknown exception thrown");
3819 GEOSGeom_createLineString_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
3821 if ( 0 == extHandle
)
3826 GEOSContextHandleInternal_t
*handle
= 0;
3827 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3828 if ( 0 == handle
->initialized
)
3835 const GeometryFactory
*gf
= handle
->geomFactory
;
3837 return gf
->createLineString(cs
);
3839 catch (const std::exception
&e
)
3841 handle
->ERROR_MESSAGE("%s", e
.what());
3845 handle
->ERROR_MESSAGE("Unknown exception thrown");
3852 GEOSGeom_createEmptyPolygon_r(GEOSContextHandle_t extHandle
)
3854 if ( 0 == extHandle
)
3859 GEOSContextHandleInternal_t
*handle
= 0;
3860 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3861 if ( 0 == handle
->initialized
)
3868 const GeometryFactory
*gf
= handle
->geomFactory
;
3869 return gf
->createPolygon();
3871 catch (const std::exception
&e
)
3873 handle
->ERROR_MESSAGE("%s", e
.what());
3877 handle
->ERROR_MESSAGE("Unknown exception thrown");
3884 GEOSGeom_createPolygon_r(GEOSContextHandle_t extHandle
, Geometry
*shell
, Geometry
**holes
, unsigned int nholes
)
3886 // FIXME: holes must be non-nullptr or may be nullptr?
3887 //assert(0 != holes);
3889 if ( 0 == extHandle
)
3894 GEOSContextHandleInternal_t
*handle
= 0;
3895 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3896 if ( 0 == handle
->initialized
)
3903 using geos::geom::LinearRing
;
3905 std::vector
<Geometry
*> *vholes
= new std::vector
<Geometry
*>(holes
, holes
+ nholes
);
3907 LinearRing
*nshell
= dynamic_cast<LinearRing
*>(shell
);
3910 handle
->ERROR_MESSAGE("Shell is not a LinearRing");
3913 const GeometryFactory
*gf
= handle
->geomFactory
;
3915 return gf
->createPolygon(nshell
, vholes
);
3917 catch (const std::exception
&e
)
3919 handle
->ERROR_MESSAGE("%s", e
.what());
3923 handle
->ERROR_MESSAGE("Unknown exception thrown");
3930 GEOSGeom_clone_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3934 if ( 0 == extHandle
)
3939 GEOSContextHandleInternal_t
*handle
= 0;
3940 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3941 if ( 0 == handle
->initialized
)
3950 catch (const std::exception
&e
)
3952 handle
->ERROR_MESSAGE("%s", e
.what());
3956 handle
->ERROR_MESSAGE("Unknown exception thrown");
3963 GEOSGeom_getDimensions_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3965 if ( 0 == extHandle
)
3970 GEOSContextHandleInternal_t
*handle
= 0;
3971 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3972 if ( 0 == handle
->initialized
)
3979 return (int) g
->getDimension();
3981 catch (const std::exception
&e
)
3983 handle
->ERROR_MESSAGE("%s", e
.what());
3987 handle
->ERROR_MESSAGE("Unknown exception thrown");
3994 GEOSGeom_getCoordinateDimension_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3996 if ( 0 == extHandle
)
4001 GEOSContextHandleInternal_t
*handle
= 0;
4002 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4003 if ( 0 == handle
->initialized
)
4010 return g
->getCoordinateDimension();
4012 catch (const std::exception
&e
)
4014 handle
->ERROR_MESSAGE("%s", e
.what());
4018 handle
->ERROR_MESSAGE("Unknown exception thrown");
4025 GEOSSimplify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double tolerance
)
4027 if ( 0 == extHandle
)
4032 GEOSContextHandleInternal_t
*handle
= 0;
4033 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4034 if ( 0 == handle
->initialized
)
4041 using namespace geos::simplify
;
4042 Geometry::AutoPtr
g(DouglasPeuckerSimplifier::simplify(g1
, tolerance
));
4045 catch (const std::exception
&e
)
4047 handle
->ERROR_MESSAGE("%s", e
.what());
4051 handle
->ERROR_MESSAGE("Unknown exception thrown");
4058 GEOSTopologyPreserveSimplify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double tolerance
)
4060 if ( 0 == extHandle
)
4065 GEOSContextHandleInternal_t
*handle
= 0;
4066 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4067 if ( 0 == handle
->initialized
)
4074 using namespace geos::simplify
;
4075 Geometry::AutoPtr
g(TopologyPreservingSimplifier::simplify(g1
, tolerance
));
4078 catch (const std::exception
&e
)
4080 handle
->ERROR_MESSAGE("%s", e
.what());
4084 handle
->ERROR_MESSAGE("Unknown exception thrown");
4093 GEOSWKTReader_create_r(GEOSContextHandle_t extHandle
)
4095 if ( 0 == extHandle
)
4100 GEOSContextHandleInternal_t
*handle
= 0;
4101 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4102 if ( 0 == handle
->initialized
)
4109 using geos::io::WKTReader
;
4110 return new WKTReader((GeometryFactory
*)handle
->geomFactory
);
4112 catch (const std::exception
&e
)
4114 handle
->ERROR_MESSAGE("%s", e
.what());
4118 handle
->ERROR_MESSAGE("Unknown exception thrown");
4125 GEOSWKTReader_destroy_r(GEOSContextHandle_t extHandle
, WKTReader
*reader
)
4127 GEOSContextHandleInternal_t
*handle
= 0;
4133 catch (const std::exception
&e
)
4135 if ( 0 == extHandle
)
4140 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4141 if ( 0 == handle
->initialized
)
4146 handle
->ERROR_MESSAGE("%s", e
.what());
4150 if ( 0 == extHandle
)
4155 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4156 if ( 0 == handle
->initialized
)
4161 handle
->ERROR_MESSAGE("Unknown exception thrown");
4167 GEOSWKTReader_read_r(GEOSContextHandle_t extHandle
, WKTReader
*reader
, const char *wkt
)
4169 assert(0 != reader
);
4171 if ( 0 == extHandle
)
4176 GEOSContextHandleInternal_t
*handle
= 0;
4177 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4178 if ( 0 == handle
->initialized
)
4185 const std::string
wktstring(wkt
);
4186 Geometry
*g
= reader
->read(wktstring
);
4189 catch (const std::exception
&e
)
4191 handle
->ERROR_MESSAGE("%s", e
.what());
4195 handle
->ERROR_MESSAGE("Unknown exception thrown");
4203 GEOSWKTWriter_create_r(GEOSContextHandle_t extHandle
)
4205 if ( 0 == extHandle
)
4210 GEOSContextHandleInternal_t
*handle
= 0;
4211 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4212 if ( 0 == handle
->initialized
)
4219 using geos::io::WKTWriter
;
4220 return new WKTWriter();
4222 catch (const std::exception
&e
)
4224 handle
->ERROR_MESSAGE("%s", e
.what());
4228 handle
->ERROR_MESSAGE("Unknown exception thrown");
4235 GEOSWKTWriter_destroy_r(GEOSContextHandle_t extHandle
, WKTWriter
*Writer
)
4238 GEOSContextHandleInternal_t
*handle
= 0;
4244 catch (const std::exception
&e
)
4246 if ( 0 == extHandle
)
4251 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4252 if ( 0 == handle
->initialized
)
4257 handle
->ERROR_MESSAGE("%s", e
.what());
4261 if ( 0 == extHandle
)
4266 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4267 if ( 0 == handle
->initialized
)
4272 handle
->ERROR_MESSAGE("Unknown exception thrown");
4278 GEOSWKTWriter_write_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, const Geometry
*geom
)
4280 assert(0 != writer
);
4282 if ( 0 == extHandle
)
4287 GEOSContextHandleInternal_t
*handle
= 0;
4288 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4289 if ( 0 == handle
->initialized
)
4296 std::string
sgeom(writer
->write(geom
));
4297 char *result
= gstrdup(sgeom
);
4300 catch (const std::exception
&e
)
4302 handle
->ERROR_MESSAGE("%s", e
.what());
4306 handle
->ERROR_MESSAGE("Unknown exception thrown");
4313 GEOSWKTWriter_setTrim_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, char trim
)
4315 assert(0 != writer
);
4317 if ( 0 == extHandle
)
4322 GEOSContextHandleInternal_t
*handle
= 0;
4323 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4324 if ( 0 == handle
->initialized
)
4329 writer
->setTrim(0 != trim
);
4333 GEOSWKTWriter_setRoundingPrecision_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int precision
)
4335 assert(0 != writer
);
4337 if ( 0 == extHandle
)
4342 GEOSContextHandleInternal_t
*handle
= 0;
4343 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4344 if ( 0 == handle
->initialized
)
4349 writer
->setRoundingPrecision(precision
);
4353 GEOSWKTWriter_setOutputDimension_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int dim
)
4355 assert(0 != writer
);
4357 if ( 0 == extHandle
)
4362 GEOSContextHandleInternal_t
*handle
= 0;
4363 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4364 if ( 0 == handle
->initialized
)
4371 writer
->setOutputDimension(dim
);
4373 catch (const std::exception
&e
)
4375 handle
->ERROR_MESSAGE("%s", e
.what());
4379 handle
->ERROR_MESSAGE("Unknown exception thrown");
4384 GEOSWKTWriter_getOutputDimension_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
)
4386 assert(0 != writer
);
4388 if ( 0 == extHandle
)
4393 GEOSContextHandleInternal_t
*handle
= 0;
4394 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4395 if ( 0 == handle
->initialized
)
4404 dim
= writer
->getOutputDimension();
4406 catch (const std::exception
&e
)
4408 handle
->ERROR_MESSAGE("%s", e
.what());
4412 handle
->ERROR_MESSAGE("Unknown exception thrown");
4419 GEOSWKTWriter_setOld3D_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int useOld3D
)
4421 assert(0 != writer
);
4423 if ( 0 == extHandle
)
4428 GEOSContextHandleInternal_t
*handle
= 0;
4429 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4430 if ( 0 == handle
->initialized
)
4435 writer
->setOld3D(0 != useOld3D
);
4440 GEOSWKBReader_create_r(GEOSContextHandle_t extHandle
)
4442 if ( 0 == extHandle
)
4447 GEOSContextHandleInternal_t
*handle
= 0;
4448 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4449 if ( 0 == handle
->initialized
)
4454 using geos::io::WKBReader
;
4457 return new WKBReader(*(GeometryFactory
*)handle
->geomFactory
);
4459 catch (const std::exception
&e
)
4461 handle
->ERROR_MESSAGE("%s", e
.what());
4465 handle
->ERROR_MESSAGE("Unknown exception thrown");
4472 GEOSWKBReader_destroy_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
)
4474 GEOSContextHandleInternal_t
*handle
= 0;
4480 catch (const std::exception
&e
)
4482 if ( 0 == extHandle
)
4487 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4488 if ( 0 == handle
->initialized
)
4493 handle
->ERROR_MESSAGE("%s", e
.what());
4497 if ( 0 == extHandle
)
4502 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4503 if ( 0 == handle
->initialized
)
4508 handle
->ERROR_MESSAGE("Unknown exception thrown");
4514 GEOSWKBReader_read_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
, const unsigned char *wkb
, size_t size
)
4516 assert(0 != reader
);
4519 if ( 0 == extHandle
)
4524 GEOSContextHandleInternal_t
*handle
= 0;
4525 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4526 if ( 0 == handle
->initialized
)
4533 std::string
wkbstring(reinterpret_cast<const char*>(wkb
), size
); // make it binary !
4534 std::istringstream
is(std::ios_base::binary
);
4536 is
.seekg(0, std::ios::beg
); // rewind reader pointer
4538 Geometry
*g
= reader
->read(is
);
4541 catch (const std::exception
&e
)
4543 handle
->ERROR_MESSAGE("%s", e
.what());
4547 handle
->ERROR_MESSAGE("Unknown exception thrown");
4554 GEOSWKBReader_readHEX_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
, const unsigned char *hex
, size_t size
)
4556 assert(0 != reader
);
4559 if ( 0 == extHandle
)
4564 GEOSContextHandleInternal_t
*handle
= 0;
4565 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4566 if ( 0 == handle
->initialized
)
4573 std::string
hexstring(reinterpret_cast<const char*>(hex
), size
);
4574 std::istringstream
is(std::ios_base::binary
);
4576 is
.seekg(0, std::ios::beg
); // rewind reader pointer
4578 Geometry
*g
= reader
->readHEX(is
);
4581 catch (const std::exception
&e
)
4583 handle
->ERROR_MESSAGE("%s", e
.what());
4587 handle
->ERROR_MESSAGE("Unknown exception thrown");
4595 GEOSWKBWriter_create_r(GEOSContextHandle_t extHandle
)
4597 if ( 0 == extHandle
)
4602 GEOSContextHandleInternal_t
*handle
= 0;
4603 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4604 if ( 0 == handle
->initialized
)
4611 using geos::io::WKBWriter
;
4612 return new WKBWriter();
4614 catch (const std::exception
&e
)
4616 handle
->ERROR_MESSAGE("%s", e
.what());
4620 handle
->ERROR_MESSAGE("Unknown exception thrown");
4627 GEOSWKBWriter_destroy_r(GEOSContextHandle_t extHandle
, WKBWriter
*Writer
)
4629 GEOSContextHandleInternal_t
*handle
= 0;
4635 catch (const std::exception
&e
)
4637 if ( 0 == extHandle
)
4642 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4643 if ( 0 == handle
->initialized
)
4648 handle
->ERROR_MESSAGE("%s", e
.what());
4652 if ( 0 == extHandle
)
4657 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4658 if ( 0 == handle
->initialized
)
4663 handle
->ERROR_MESSAGE("Unknown exception thrown");
4668 /* The caller owns the result */
4670 GEOSWKBWriter_write_r(GEOSContextHandle_t extHandle
, WKBWriter
*writer
, const Geometry
*geom
, size_t *size
)
4672 assert(0 != writer
);
4676 if ( 0 == extHandle
)
4681 GEOSContextHandleInternal_t
*handle
= 0;
4682 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4683 if ( 0 == handle
->initialized
)
4690 std::ostringstream
os(std::ios_base::binary
);
4691 writer
->write(*geom
, os
);
4692 std::string
wkbstring(os
.str());
4693 const std::size_t len
= wkbstring
.length();
4695 unsigned char *result
= NULL
;
4696 result
= (unsigned char*) std::malloc(len
);
4697 std::memcpy(result
, wkbstring
.c_str(), len
);
4701 catch (const std::exception
&e
)
4703 handle
->ERROR_MESSAGE("%s", e
.what());
4707 handle
->ERROR_MESSAGE("Unknown exception thrown");
4712 /* The caller owns the result */
4714 GEOSWKBWriter_writeHEX_r(GEOSContextHandle_t extHandle
, WKBWriter
*writer
, const Geometry
*geom
, size_t *size
)
4716 assert(0 != writer
);
4720 if ( 0 == extHandle
)
4725 GEOSContextHandleInternal_t
*handle
= 0;
4726 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4727 if ( 0 == handle
->initialized
)
4734 std::ostringstream
os(std::ios_base::binary
);
4735 writer
->writeHEX(*geom
, os
);
4736 std::string
wkbstring(os
.str());
4737 const std::size_t len
= wkbstring
.length();
4739 unsigned char *result
= NULL
;
4740 result
= (unsigned char*) std::malloc(len
);
4741 std::memcpy(result
, wkbstring
.c_str(), len
);
4745 catch (const std::exception
&e
)
4747 handle
->ERROR_MESSAGE("%s", e
.what());
4751 handle
->ERROR_MESSAGE("Unknown exception thrown");
4758 GEOSWKBWriter_getOutputDimension_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
4760 assert(0 != writer
);
4762 if ( 0 == extHandle
)
4769 GEOSContextHandleInternal_t
*handle
= 0;
4770 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4771 if ( 0 != handle
->initialized
)
4775 ret
= writer
->getOutputDimension();
4779 handle
->ERROR_MESSAGE("Unknown exception thrown");
4787 GEOSWKBWriter_setOutputDimension_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, int newDimension
)
4789 assert(0 != writer
);
4791 if ( 0 == extHandle
)
4796 GEOSContextHandleInternal_t
*handle
= 0;
4797 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4798 if ( 0 != handle
->initialized
)
4802 writer
->setOutputDimension(newDimension
);
4804 catch (const std::exception
&e
)
4806 handle
->ERROR_MESSAGE("%s", e
.what());
4810 handle
->ERROR_MESSAGE("Unknown exception thrown");
4816 GEOSWKBWriter_getByteOrder_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
4818 assert(0 != writer
);
4820 if ( 0 == extHandle
)
4827 GEOSContextHandleInternal_t
*handle
= 0;
4828 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4829 if ( 0 != handle
->initialized
)
4833 ret
= writer
->getByteOrder();
4838 handle
->ERROR_MESSAGE("Unknown exception thrown");
4846 GEOSWKBWriter_setByteOrder_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, int newByteOrder
)
4848 assert(0 != writer
);
4850 if ( 0 == extHandle
)
4855 GEOSContextHandleInternal_t
*handle
= 0;
4856 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4857 if ( 0 != handle
->initialized
)
4861 writer
->setByteOrder(newByteOrder
);
4863 catch (const std::exception
&e
)
4865 handle
->ERROR_MESSAGE("%s", e
.what());
4869 handle
->ERROR_MESSAGE("Unknown exception thrown");
4875 GEOSWKBWriter_getIncludeSRID_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
4877 assert(0 != writer
);
4879 if ( 0 == extHandle
)
4886 GEOSContextHandleInternal_t
*handle
= 0;
4887 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4888 if ( 0 != handle
->initialized
)
4892 int srid
= writer
->getIncludeSRID();
4893 ret
= static_cast<char>(srid
);
4897 handle
->ERROR_MESSAGE("Unknown exception thrown");
4901 return static_cast<char>(ret
);
4905 GEOSWKBWriter_setIncludeSRID_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, const char newIncludeSRID
)
4907 assert(0 != writer
);
4909 if ( 0 == extHandle
)
4914 GEOSContextHandleInternal_t
*handle
= 0;
4915 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4916 if ( 0 != handle
->initialized
)
4920 writer
->setIncludeSRID(newIncludeSRID
);
4924 handle
->ERROR_MESSAGE("Unknown exception thrown");
4930 //-----------------------------------------------------------------
4931 // Prepared Geometry
4932 //-----------------------------------------------------------------
4934 const geos::geom::prep::PreparedGeometry
*
4935 GEOSPrepare_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
4937 if ( 0 == extHandle
)
4942 GEOSContextHandleInternal_t
*handle
= 0;
4943 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4944 if ( 0 == handle
->initialized
)
4949 const geos::geom::prep::PreparedGeometry
* prep
= 0;
4953 prep
= geos::geom::prep::PreparedGeometryFactory::prepare(g
);
4955 catch (const std::exception
&e
)
4957 handle
->ERROR_MESSAGE("%s", e
.what());
4961 handle
->ERROR_MESSAGE("Unknown exception thrown");
4968 GEOSPreparedGeom_destroy_r(GEOSContextHandle_t extHandle
, const geos::geom::prep::PreparedGeometry
*a
)
4970 GEOSContextHandleInternal_t
*handle
= 0;
4976 catch (const std::exception
&e
)
4978 if ( 0 == extHandle
)
4983 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4984 if ( 0 == handle
->initialized
)
4989 handle
->ERROR_MESSAGE("%s", e
.what());
4993 if ( 0 == extHandle
)
4998 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4999 if ( 0 == handle
->initialized
)
5004 handle
->ERROR_MESSAGE("Unknown exception thrown");
5009 GEOSPreparedContains_r(GEOSContextHandle_t extHandle
,
5010 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5015 if ( 0 == extHandle
)
5020 GEOSContextHandleInternal_t
*handle
= 0;
5021 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5022 if ( 0 == handle
->initialized
)
5029 bool result
= pg
->contains(g
);
5032 catch (const std::exception
&e
)
5034 handle
->ERROR_MESSAGE("%s", e
.what());
5038 handle
->ERROR_MESSAGE("Unknown exception thrown");
5045 GEOSPreparedContainsProperly_r(GEOSContextHandle_t extHandle
,
5046 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5051 if ( 0 == extHandle
)
5056 GEOSContextHandleInternal_t
*handle
= 0;
5057 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5058 if ( 0 == handle
->initialized
)
5065 bool result
= pg
->containsProperly(g
);
5068 catch (const std::exception
&e
)
5070 handle
->ERROR_MESSAGE("%s", e
.what());
5074 handle
->ERROR_MESSAGE("Unknown exception thrown");
5081 GEOSPreparedCoveredBy_r(GEOSContextHandle_t extHandle
,
5082 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5087 if ( 0 == extHandle
)
5092 GEOSContextHandleInternal_t
*handle
= 0;
5093 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5094 if ( 0 == handle
->initialized
)
5101 bool result
= pg
->coveredBy(g
);
5104 catch (const std::exception
&e
)
5106 handle
->ERROR_MESSAGE("%s", e
.what());
5110 handle
->ERROR_MESSAGE("Unknown exception thrown");
5117 GEOSPreparedCovers_r(GEOSContextHandle_t extHandle
,
5118 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5123 if ( 0 == extHandle
)
5128 GEOSContextHandleInternal_t
*handle
= 0;
5129 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5130 if ( 0 == handle
->initialized
)
5137 bool result
= pg
->covers(g
);
5140 catch (const std::exception
&e
)
5142 handle
->ERROR_MESSAGE("%s", e
.what());
5146 handle
->ERROR_MESSAGE("Unknown exception thrown");
5153 GEOSPreparedCrosses_r(GEOSContextHandle_t extHandle
,
5154 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5159 if ( 0 == extHandle
)
5164 GEOSContextHandleInternal_t
*handle
= 0;
5165 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5166 if ( 0 == handle
->initialized
)
5173 bool result
= pg
->crosses(g
);
5176 catch (const std::exception
&e
)
5178 handle
->ERROR_MESSAGE("%s", e
.what());
5182 handle
->ERROR_MESSAGE("Unknown exception thrown");
5189 GEOSPreparedDisjoint_r(GEOSContextHandle_t extHandle
,
5190 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5195 if ( 0 == extHandle
)
5200 GEOSContextHandleInternal_t
*handle
= 0;
5201 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5202 if ( 0 == handle
->initialized
)
5209 bool result
= pg
->disjoint(g
);
5212 catch (const std::exception
&e
)
5214 handle
->ERROR_MESSAGE("%s", e
.what());
5218 handle
->ERROR_MESSAGE("Unknown exception thrown");
5225 GEOSPreparedIntersects_r(GEOSContextHandle_t extHandle
,
5226 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5231 if ( 0 == extHandle
)
5236 GEOSContextHandleInternal_t
*handle
= 0;
5237 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5238 if ( 0 == handle
->initialized
)
5245 bool result
= pg
->intersects(g
);
5248 catch (const std::exception
&e
)
5250 handle
->ERROR_MESSAGE("%s", e
.what());
5254 handle
->ERROR_MESSAGE("Unknown exception thrown");
5261 GEOSPreparedOverlaps_r(GEOSContextHandle_t extHandle
,
5262 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5267 if ( 0 == extHandle
)
5272 GEOSContextHandleInternal_t
*handle
= 0;
5273 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5274 if ( 0 == handle
->initialized
)
5281 bool result
= pg
->overlaps(g
);
5284 catch (const std::exception
&e
)
5286 handle
->ERROR_MESSAGE("%s", e
.what());
5290 handle
->ERROR_MESSAGE("Unknown exception thrown");
5297 GEOSPreparedTouches_r(GEOSContextHandle_t extHandle
,
5298 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5303 if ( 0 == extHandle
)
5308 GEOSContextHandleInternal_t
*handle
= 0;
5309 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5310 if ( 0 == handle
->initialized
)
5317 bool result
= pg
->touches(g
);
5320 catch (const std::exception
&e
)
5322 handle
->ERROR_MESSAGE("%s", e
.what());
5326 handle
->ERROR_MESSAGE("Unknown exception thrown");
5333 GEOSPreparedWithin_r(GEOSContextHandle_t extHandle
,
5334 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5339 if ( 0 == extHandle
)
5344 GEOSContextHandleInternal_t
*handle
= 0;
5345 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5346 if ( 0 == handle
->initialized
)
5353 bool result
= pg
->within(g
);
5356 catch (const std::exception
&e
)
5358 handle
->ERROR_MESSAGE("%s", e
.what());
5362 handle
->ERROR_MESSAGE("Unknown exception thrown");
5368 //-----------------------------------------------------------------
5370 //-----------------------------------------------------------------
5372 geos::index::strtree::STRtree
*
5373 GEOSSTRtree_create_r(GEOSContextHandle_t extHandle
,
5374 size_t nodeCapacity
)
5376 if ( 0 == extHandle
)
5381 GEOSContextHandleInternal_t
*handle
= 0;
5382 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5383 if ( 0 == handle
->initialized
)
5388 geos::index::strtree::STRtree
*tree
= 0;
5392 tree
= new geos::index::strtree::STRtree(nodeCapacity
);
5394 catch (const std::exception
&e
)
5396 handle
->ERROR_MESSAGE("%s", e
.what());
5400 handle
->ERROR_MESSAGE("Unknown exception thrown");
5407 GEOSSTRtree_insert_r(GEOSContextHandle_t extHandle
,
5408 geos::index::strtree::STRtree
*tree
,
5409 const geos::geom::Geometry
*g
,
5412 GEOSContextHandleInternal_t
*handle
= 0;
5418 tree
->insert(g
->getEnvelopeInternal(), item
);
5420 catch (const std::exception
&e
)
5422 if ( 0 == extHandle
)
5427 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5428 if ( 0 == handle
->initialized
)
5433 handle
->ERROR_MESSAGE("%s", e
.what());
5437 if ( 0 == extHandle
)
5442 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5443 if ( 0 == handle
->initialized
)
5448 handle
->ERROR_MESSAGE("Unknown exception thrown");
5453 GEOSSTRtree_query_r(GEOSContextHandle_t extHandle
,
5454 geos::index::strtree::STRtree
*tree
,
5455 const geos::geom::Geometry
*g
,
5456 GEOSQueryCallback callback
,
5459 GEOSContextHandleInternal_t
*handle
= 0;
5462 assert(callback
!= 0);
5466 CAPI_ItemVisitor
visitor(callback
, userdata
);
5467 tree
->query(g
->getEnvelopeInternal(), visitor
);
5469 catch (const std::exception
&e
)
5471 if ( 0 == extHandle
)
5476 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5477 if ( 0 == handle
->initialized
)
5482 handle
->ERROR_MESSAGE("%s", e
.what());
5486 if ( 0 == extHandle
)
5491 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5492 if ( 0 == handle
->initialized
)
5497 handle
->ERROR_MESSAGE("Unknown exception thrown");
5502 GEOSSTRtree_iterate_r(GEOSContextHandle_t extHandle
,
5503 geos::index::strtree::STRtree
*tree
,
5504 GEOSQueryCallback callback
,
5507 GEOSContextHandleInternal_t
*handle
= 0;
5509 assert(callback
!= 0);
5513 CAPI_ItemVisitor
visitor(callback
, userdata
);
5514 tree
->iterate(visitor
);
5516 catch (const std::exception
&e
)
5518 if ( 0 == extHandle
)
5523 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5524 if ( 0 == handle
->initialized
)
5529 handle
->ERROR_MESSAGE("%s", e
.what());
5533 if ( 0 == extHandle
)
5538 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5539 if ( 0 == handle
->initialized
)
5544 handle
->ERROR_MESSAGE("Unknown exception thrown");
5549 GEOSSTRtree_remove_r(GEOSContextHandle_t extHandle
,
5550 geos::index::strtree::STRtree
*tree
,
5551 const geos::geom::Geometry
*g
,
5557 if ( 0 == extHandle
)
5562 GEOSContextHandleInternal_t
*handle
= 0;
5563 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5564 if ( 0 == handle
->initialized
)
5571 bool result
= tree
->remove(g
->getEnvelopeInternal(), item
);
5574 catch (const std::exception
&e
)
5576 handle
->ERROR_MESSAGE("%s", e
.what());
5580 handle
->ERROR_MESSAGE("Unknown exception thrown");
5587 GEOSSTRtree_destroy_r(GEOSContextHandle_t extHandle
,
5588 geos::index::strtree::STRtree
*tree
)
5590 GEOSContextHandleInternal_t
*handle
= 0;
5596 catch (const std::exception
&e
)
5598 if ( 0 == extHandle
)
5603 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5604 if ( 0 == handle
->initialized
)
5609 handle
->ERROR_MESSAGE("%s", e
.what());
5613 if ( 0 == extHandle
)
5618 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5619 if ( 0 == handle
->initialized
)
5624 handle
->ERROR_MESSAGE("Unknown exception thrown");
5629 GEOSProject_r(GEOSContextHandle_t extHandle
,
5633 if ( 0 == extHandle
) return -1.0;
5634 GEOSContextHandleInternal_t
*handle
=
5635 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5636 if ( handle
->initialized
== 0 ) return -1.0;
5638 const geos::geom::Point
* point
= dynamic_cast<const geos::geom::Point
*>(p
);
5640 handle
->ERROR_MESSAGE("third argument of GEOSProject_r must be Point*");
5644 const geos::geom::Coordinate
* inputPt
= p
->getCoordinate();
5647 return geos::linearref::LengthIndexedLine(g
).project(*inputPt
);
5648 } catch (const std::exception
&e
) {
5649 handle
->ERROR_MESSAGE("%s", e
.what());
5652 handle
->ERROR_MESSAGE("Unknown exception thrown");
5659 GEOSInterpolate_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double d
)
5661 if ( 0 == extHandle
) return 0;
5662 GEOSContextHandleInternal_t
*handle
=
5663 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5664 if ( handle
->initialized
== 0 ) return 0;
5667 geos::linearref::LengthIndexedLine
lil(g
);
5668 geos::geom::Coordinate coord
= lil
.extractPoint(d
);
5669 const GeometryFactory
*gf
= handle
->geomFactory
;
5670 Geometry
* point
= gf
->createPoint(coord
);
5672 } catch (const std::exception
&e
) {
5673 handle
->ERROR_MESSAGE("%s", e
.what());
5676 handle
->ERROR_MESSAGE("Unknown exception thrown");
5683 GEOSProjectNormalized_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
5688 GEOSLength_r(extHandle
, g
, &length
);
5689 return GEOSProject_r(extHandle
, g
, p
) / length
;
5694 GEOSInterpolateNormalized_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
5698 GEOSLength_r(extHandle
, g
, &length
);
5699 return GEOSInterpolate_r(extHandle
, g
, d
* length
);
5703 GEOSGeom_extractUniquePoints_r(GEOSContextHandle_t extHandle
,
5704 const GEOSGeometry
* g
)
5706 if ( 0 == extHandle
) return 0;
5707 GEOSContextHandleInternal_t
*handle
= 0;
5708 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5709 if ( handle
->initialized
== 0 ) return 0;
5711 using namespace geos::geom
;
5712 using namespace geos::util
;
5717 /* 1: extract points */
5718 std::vector
<const Coordinate
*> coords
;
5719 UniqueCoordinateArrayFilter
filter(coords
);
5720 g
->apply_ro(&filter
);
5722 /* 2: for each point, create a geometry and put into a vector */
5723 std::vector
<Geometry
*>* points
= new std::vector
<Geometry
*>();
5724 points
->reserve(coords
.size());
5725 const GeometryFactory
* factory
= g
->getFactory();
5726 for (std::vector
<const Coordinate
*>::iterator it
=coords
.begin(),
5730 Geometry
* point
= factory
->createPoint(*(*it
));
5731 points
->push_back(point
);
5734 /* 3: create a multipoint */
5735 return factory
->createMultiPoint(points
);
5738 catch (const std::exception
&e
)
5740 handle
->ERROR_MESSAGE("%s", e
.what());
5745 handle
->ERROR_MESSAGE("Unknown exception thrown");
5750 int GEOSOrientationIndex_r(GEOSContextHandle_t extHandle
,
5751 double Ax
, double Ay
, double Bx
, double By
, double Px
, double Py
)
5753 GEOSContextHandleInternal_t
*handle
= 0;
5755 using geos::geom::Coordinate
;
5756 using geos::algorithm::CGAlgorithms
;
5758 if ( 0 == extHandle
)
5763 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5764 if ( 0 == handle
->initialized
)
5771 Coordinate
A(Ax
, Ay
);
5772 Coordinate
B(Bx
, By
);
5773 Coordinate
P(Px
, Py
);
5774 return CGAlgorithms::orientationIndex(A
, B
, P
);
5776 catch (const std::exception
&e
)
5778 handle
->ERROR_MESSAGE("%s", e
.what());
5783 handle
->ERROR_MESSAGE("Unknown exception thrown");
5789 GEOSSharedPaths_r(GEOSContextHandle_t extHandle
, const GEOSGeometry
* g1
, const GEOSGeometry
* g2
)
5791 using namespace geos::operation::sharedpaths
;
5793 if ( 0 == extHandle
) return 0;
5794 GEOSContextHandleInternal_t
*handle
=
5795 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5796 if ( handle
->initialized
== 0 ) return 0;
5798 SharedPathsOp::PathList forw
, back
;
5800 SharedPathsOp::sharedPathsOp(*g1
, *g2
, forw
, back
);
5802 catch (const std::exception
&e
)
5804 SharedPathsOp::clearEdges(forw
);
5805 SharedPathsOp::clearEdges(back
);
5806 handle
->ERROR_MESSAGE("%s", e
.what());
5811 SharedPathsOp::clearEdges(forw
);
5812 SharedPathsOp::clearEdges(back
);
5813 handle
->ERROR_MESSAGE("Unknown exception thrown");
5817 // Now forw and back have the geoms we want to use to construct
5818 // our output GeometryCollections...
5820 const GeometryFactory
* factory
= g1
->getFactory();
5823 std::auto_ptr
< std::vector
<Geometry
*> > out1(
5824 new std::vector
<Geometry
*>()
5826 count
= forw
.size();
5827 out1
->reserve(count
);
5828 for (size_t i
=0; i
<count
; ++i
) {
5829 out1
->push_back(forw
[i
]);
5831 std::auto_ptr
<Geometry
> out1g (
5832 factory
->createMultiLineString(out1
.release())
5835 std::auto_ptr
< std::vector
<Geometry
*> > out2(
5836 new std::vector
<Geometry
*>()
5838 count
= back
.size();
5839 out2
->reserve(count
);
5840 for (size_t i
=0; i
<count
; ++i
) {
5841 out2
->push_back(back
[i
]);
5843 std::auto_ptr
<Geometry
> out2g (
5844 factory
->createMultiLineString(out2
.release())
5847 std::auto_ptr
< std::vector
<Geometry
*> > out(
5848 new std::vector
<Geometry
*>()
5851 out
->push_back(out1g
.release());
5852 out
->push_back(out2g
.release());
5854 std::auto_ptr
<Geometry
> outg (
5855 factory
->createGeometryCollection(out
.release())
5858 return outg
.release();
5863 GEOSSnap_r(GEOSContextHandle_t extHandle
, const GEOSGeometry
* g1
,
5864 const GEOSGeometry
* g2
, double tolerance
)
5866 using namespace geos::operation::overlay::snap
;
5868 if ( 0 == extHandle
) return 0;
5869 GEOSContextHandleInternal_t
*handle
=
5870 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5871 if ( handle
->initialized
== 0 ) return 0;
5874 GeometrySnapper
snapper( *g1
);
5875 std::auto_ptr
<Geometry
> ret
= snapper
.snapTo(*g2
, tolerance
);
5876 return ret
.release();
5878 catch (const std::exception
&e
)
5880 handle
->ERROR_MESSAGE("%s", e
.what());
5885 handle
->ERROR_MESSAGE("Unknown exception thrown");
5891 GEOSBufferParams_create_r(GEOSContextHandle_t extHandle
)
5893 if ( 0 == extHandle
) return NULL
;
5895 GEOSContextHandleInternal_t
*handle
= 0;
5896 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5897 if ( 0 == handle
->initialized
) return NULL
;
5901 BufferParameters
*p
= new BufferParameters();
5904 catch (const std::exception
&e
)
5906 handle
->ERROR_MESSAGE("%s", e
.what());
5910 handle
->ERROR_MESSAGE("Unknown exception thrown");
5917 GEOSBufferParams_destroy_r(GEOSContextHandle_t extHandle
, BufferParameters
* p
)
5923 GEOSBufferParams_setEndCapStyle_r(GEOSContextHandle_t extHandle
,
5924 GEOSBufferParams
* p
, int style
)
5926 if ( 0 == extHandle
) return 0;
5928 GEOSContextHandleInternal_t
*handle
= 0;
5929 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5930 if ( 0 == handle
->initialized
) return 0;
5934 if ( style
> BufferParameters::CAP_SQUARE
)
5936 throw IllegalArgumentException("Invalid buffer endCap style");
5938 p
->setEndCapStyle(static_cast<BufferParameters::EndCapStyle
>(style
));
5941 catch (const std::exception
&e
)
5943 handle
->ERROR_MESSAGE("%s", e
.what());
5947 handle
->ERROR_MESSAGE("Unknown exception thrown");
5954 GEOSBufferParams_setJoinStyle_r(GEOSContextHandle_t extHandle
,
5955 GEOSBufferParams
* p
, int style
)
5957 if ( 0 == extHandle
) return 0;
5959 GEOSContextHandleInternal_t
*handle
= 0;
5960 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5961 if ( 0 == handle
->initialized
) return 0;
5965 if ( style
> BufferParameters::JOIN_BEVEL
) {
5966 throw IllegalArgumentException("Invalid buffer join style");
5968 p
->setJoinStyle(static_cast<BufferParameters::JoinStyle
>(style
));
5971 catch (const std::exception
&e
)
5973 handle
->ERROR_MESSAGE("%s", e
.what());
5977 handle
->ERROR_MESSAGE("Unknown exception thrown");
5984 GEOSBufferParams_setMitreLimit_r(GEOSContextHandle_t extHandle
,
5985 GEOSBufferParams
* p
, double limit
)
5987 if ( 0 == extHandle
) return 0;
5989 GEOSContextHandleInternal_t
*handle
= 0;
5990 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5991 if ( 0 == handle
->initialized
) return 0;
5995 p
->setMitreLimit(limit
);
5998 catch (const std::exception
&e
)
6000 handle
->ERROR_MESSAGE("%s", e
.what());
6004 handle
->ERROR_MESSAGE("Unknown exception thrown");
6011 GEOSBufferParams_setQuadrantSegments_r(GEOSContextHandle_t extHandle
,
6012 GEOSBufferParams
* p
, int segs
)
6014 if ( 0 == extHandle
) return 0;
6016 GEOSContextHandleInternal_t
*handle
= 0;
6017 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6018 if ( 0 == handle
->initialized
) return 0;
6022 p
->setQuadrantSegments(segs
);
6025 catch (const std::exception
&e
)
6027 handle
->ERROR_MESSAGE("%s", e
.what());
6031 handle
->ERROR_MESSAGE("Unknown exception thrown");
6038 GEOSBufferParams_setSingleSided_r(GEOSContextHandle_t extHandle
,
6039 GEOSBufferParams
* p
, int ss
)
6041 if ( 0 == extHandle
) return 0;
6043 GEOSContextHandleInternal_t
*handle
= 0;
6044 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6045 if ( 0 == handle
->initialized
) return 0;
6049 p
->setSingleSided( (ss
!= 0) );
6052 catch (const std::exception
&e
)
6054 handle
->ERROR_MESSAGE("%s", e
.what());
6058 handle
->ERROR_MESSAGE("Unknown exception thrown");
6065 GEOSBufferWithParams_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const BufferParameters
* bp
, double width
)
6067 using geos::operation::buffer::BufferOp
;
6069 if ( 0 == extHandle
) return NULL
;
6071 GEOSContextHandleInternal_t
*handle
= 0;
6072 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6073 if ( 0 == handle
->initialized
) return NULL
;
6077 BufferOp
op(g1
, *bp
);
6078 Geometry
*g3
= op
.getResultGeometry(width
);
6081 catch (const std::exception
&e
)
6083 handle
->ERROR_MESSAGE("%s", e
.what());
6087 handle
->ERROR_MESSAGE("Unknown exception thrown");