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/union/CascadedPolygonUnion.h>
54 #include <geos/operation/buffer/BufferOp.h>
55 #include <geos/operation/buffer/BufferParameters.h>
56 #include <geos/operation/buffer/BufferBuilder.h>
57 #include <geos/operation/relate/RelateOp.h>
58 #include <geos/operation/sharedpaths/SharedPathsOp.h>
59 #include <geos/linearref/LengthIndexedLine.h>
60 #include <geos/geom/BinaryOp.h>
61 #include <geos/util/IllegalArgumentException.h>
62 #include <geos/util/UniqueCoordinateArrayFilter.h>
63 #include <geos/util/Machine.h>
64 #include <geos/version.h>
66 // This should go away
67 #include <cmath> // finite
79 #pragma warning(disable : 4099)
82 // Some extra magic to make type declarations in geos_c.h work -
83 // for cross-checking of types in header.
84 #define GEOSGeometry geos::geom::Geometry
85 #define GEOSPreparedGeometry geos::geom::prep::PreparedGeometry
86 #define GEOSCoordSequence geos::geom::CoordinateSequence
87 #define GEOSBufferParams geos::operation::buffer::BufferParameters
88 #define GEOSSTRtree geos::index::strtree::STRtree
89 #define GEOSWKTReader_t geos::io::WKTReader
90 #define GEOSWKTWriter_t geos::io::WKTWriter
91 #define GEOSWKBReader_t geos::io::WKBReader
92 #define GEOSWKBWriter_t geos::io::WKBWriter
96 // Intentional, to allow non-standard C elements like C99 functions to be
97 // imported through C++ headers of C library, like <cmath>.
100 /// Define this if you want operations triggering Exceptions to
102 /// (will use the NOTIFY channel - only implemented for GEOSUnion so far)
104 #undef VERBOSE_EXCEPTIONS
106 #include <geos/export.h>
109 // import the most frequently used definitions globally
110 using geos::geom::Geometry
;
111 using geos::geom::LineString
;
112 using geos::geom::Polygon
;
113 using geos::geom::CoordinateSequence
;
114 using geos::geom::GeometryFactory
;
116 using geos::io::WKTReader
;
117 using geos::io::WKTWriter
;
118 using geos::io::WKBReader
;
119 using geos::io::WKBWriter
;
121 using geos::operation::overlay::OverlayOp
;
122 using geos::operation::overlay::overlayOp
;
123 using geos::operation::geounion::CascadedPolygonUnion
;
124 using geos::operation::buffer::BufferParameters
;
125 using geos::operation::buffer::BufferBuilder
;
126 using geos::util::IllegalArgumentException
;
127 using geos::algorithm::distance::DiscreteHausdorffDistance
;
129 typedef std::auto_ptr
<Geometry
> GeomAutoPtr
;
131 typedef struct GEOSContextHandleInternal
133 const GeometryFactory
*geomFactory
;
134 GEOSMessageHandler NOTICE_MESSAGE
;
135 GEOSMessageHandler ERROR_MESSAGE
;
139 } GEOSContextHandleInternal_t
;
141 // CAPI_ItemVisitor is used internally by the CAPI STRtree
142 // wrappers. It's defined here just to keep it out of the
144 class CAPI_ItemVisitor
: public geos::index::ItemVisitor
{
145 GEOSQueryCallback callback
;
148 CAPI_ItemVisitor (GEOSQueryCallback cb
, void *ud
)
149 : ItemVisitor(), callback(cb
), userdata(ud
) {};
150 void visitItem (void *item
) { callback(item
, userdata
); };
154 //## PROTOTYPES #############################################
156 extern "C" const char GEOS_DLL
*GEOSjtsport();
157 extern "C" char GEOS_DLL
*GEOSasText(Geometry
*g1
);
159 namespace { // anonymous
161 char* gstrdup_s(const char* str
, const std::size_t size
)
163 char* out
= static_cast<char*>(std::malloc(size
+ 1));
166 // as no strlen call necessary, memcpy may be faster than strcpy
167 std::memcpy(out
, str
, size
+ 1);
172 // we haven't been checking allocation before ticket #371
175 throw(std::runtime_error("Failed to allocate memory for duplicate string"));
181 char* gstrdup(std::string
const& str
)
183 return gstrdup_s(str
.c_str(), str
.size());
186 } // namespace anonymous
191 initGEOS_r(GEOSMessageHandler nf
, GEOSMessageHandler ef
)
193 GEOSContextHandleInternal_t
*handle
= 0;
196 extHandle
= std::malloc(sizeof(GEOSContextHandleInternal_t
));
199 handle
= static_cast<GEOSContextHandleInternal_t
*>(extHandle
);
200 handle
->NOTICE_MESSAGE
= nf
;
201 handle
->ERROR_MESSAGE
= ef
;
202 handle
->geomFactory
= GeometryFactory::getDefaultInstance();
203 handle
->WKBOutputDims
= 2;
204 handle
->WKBByteOrder
= getMachineByteOrder();
205 handle
->initialized
= 1;
208 return static_cast<GEOSContextHandle_t
>(extHandle
);
212 GEOSContext_setNoticeHandler_r(GEOSContextHandle_t extHandle
, GEOSMessageHandler nf
)
214 GEOSMessageHandler f
;
215 GEOSContextHandleInternal_t
*handle
= 0;
216 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
217 if ( 0 == handle
->initialized
)
222 f
= handle
->NOTICE_MESSAGE
;
223 handle
->NOTICE_MESSAGE
= nf
;
229 GEOSContext_setErrorHandler_r(GEOSContextHandle_t extHandle
, GEOSMessageHandler nf
)
231 GEOSMessageHandler f
;
232 GEOSContextHandleInternal_t
*handle
= 0;
233 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
234 if ( 0 == handle
->initialized
)
239 f
= handle
->ERROR_MESSAGE
;
240 handle
->ERROR_MESSAGE
= nf
;
246 finishGEOS_r(GEOSContextHandle_t extHandle
)
248 // Fix up freeing handle w.r.t. malloc above
249 std::free(extHandle
);
254 GEOSFree_r (GEOSContextHandle_t extHandle
, void* buffer
)
256 assert(0 != extHandle
);
261 //-----------------------------------------------------------
262 // relate()-related functions
263 // return 0 = false, 1 = true, 2 = error occured
264 //-----------------------------------------------------------
267 GEOSDisjoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
269 if ( 0 == extHandle
)
274 GEOSContextHandleInternal_t
*handle
= 0;
275 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
276 if ( handle
->initialized
== 0 )
283 bool result
= g1
->disjoint(g2
);
287 // TODO: mloskot is going to replace these double-catch block
288 // with a macro to remove redundant code in this and
289 // following functions.
290 catch (const std::exception
&e
)
292 handle
->ERROR_MESSAGE("%s", e
.what());
296 handle
->ERROR_MESSAGE("Unknown exception thrown");
303 GEOSTouches_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
305 if ( 0 == extHandle
)
310 GEOSContextHandleInternal_t
*handle
= 0;
311 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
312 if ( 0 == handle
->initialized
)
319 bool result
= g1
->touches(g2
);
322 catch (const std::exception
&e
)
324 handle
->ERROR_MESSAGE("%s", e
.what());
328 handle
->ERROR_MESSAGE("Unknown exception thrown");
335 GEOSIntersects_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
337 if ( 0 == extHandle
)
342 GEOSContextHandleInternal_t
*handle
= 0;
343 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
344 if ( 0 == handle
->initialized
)
351 bool result
= g1
->intersects(g2
);
354 catch (const std::exception
&e
)
356 handle
->ERROR_MESSAGE("%s", e
.what());
360 handle
->ERROR_MESSAGE("Unknown exception thrown");
367 GEOSCrosses_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
369 if ( 0 == extHandle
)
374 GEOSContextHandleInternal_t
*handle
= 0;
375 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
376 if ( 0 == handle
->initialized
)
383 bool result
= g1
->crosses(g2
);
386 catch (const std::exception
&e
)
388 handle
->ERROR_MESSAGE("%s", e
.what());
392 handle
->ERROR_MESSAGE("Unknown exception thrown");
399 GEOSWithin_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
401 if ( 0 == extHandle
)
406 GEOSContextHandleInternal_t
*handle
= 0;
407 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
408 if ( 0 == handle
->initialized
)
415 bool result
= g1
->within(g2
);
418 catch (const std::exception
&e
)
420 handle
->ERROR_MESSAGE("%s", e
.what());
424 handle
->ERROR_MESSAGE("Unknown exception thrown");
430 // call g1->contains(g2)
433 // 2 = error was trapped
435 GEOSContains_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
437 if ( 0 == extHandle
)
442 GEOSContextHandleInternal_t
*handle
= 0;
443 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
444 if ( 0 == handle
->initialized
)
451 bool result
= g1
->contains(g2
);
454 catch (const std::exception
&e
)
456 handle
->ERROR_MESSAGE("%s", e
.what());
460 handle
->ERROR_MESSAGE("Unknown exception thrown");
467 GEOSOverlaps_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
469 if ( 0 == extHandle
)
474 GEOSContextHandleInternal_t
*handle
= 0;
475 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
476 if ( 0 == handle
->initialized
)
483 bool result
= g1
->overlaps(g2
);
486 catch (const std::exception
&e
)
488 handle
->ERROR_MESSAGE("%s", e
.what());
492 handle
->ERROR_MESSAGE("Unknown exception thrown");
499 GEOSCovers_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
501 if ( 0 == extHandle
)
506 GEOSContextHandleInternal_t
*handle
= 0;
507 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
508 if ( 0 == handle
->initialized
)
515 bool result
= g1
->covers(g2
);
518 catch (const std::exception
&e
)
520 handle
->ERROR_MESSAGE("%s", e
.what());
524 handle
->ERROR_MESSAGE("Unknown exception thrown");
531 GEOSCoveredBy_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
533 if ( 0 == extHandle
)
538 GEOSContextHandleInternal_t
*handle
= 0;
539 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
540 if ( 0 == handle
->initialized
)
547 bool result
= g1
->coveredBy(g2
);
550 catch (const std::exception
&e
)
552 handle
->ERROR_MESSAGE("%s", e
.what());
556 handle
->ERROR_MESSAGE("Unknown exception thrown");
563 //-------------------------------------------------------------------
564 // low-level relate functions
565 //------------------------------------------------------------------
568 GEOSRelatePattern_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, const char *pat
)
570 if ( 0 == extHandle
)
575 GEOSContextHandleInternal_t
*handle
= 0;
576 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
577 if ( 0 == handle
->initialized
)
585 bool result
= g1
->relate(g2
, s
);
588 catch (const std::exception
&e
)
590 handle
->ERROR_MESSAGE("%s", e
.what());
594 handle
->ERROR_MESSAGE("Unknown exception thrown");
601 GEOSRelatePatternMatch_r(GEOSContextHandle_t extHandle
, const char *mat
,
604 if ( 0 == extHandle
)
609 GEOSContextHandleInternal_t
*handle
= 0;
610 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
611 if ( 0 == handle
->initialized
)
618 using geos::geom::IntersectionMatrix
;
622 IntersectionMatrix
im(m
);
624 bool result
= im
.matches(p
);
627 catch (const std::exception
&e
)
629 handle
->ERROR_MESSAGE("%s", e
.what());
633 handle
->ERROR_MESSAGE("Unknown exception thrown");
640 GEOSRelate_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
642 if ( 0 == extHandle
)
647 GEOSContextHandleInternal_t
*handle
= 0;
648 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
649 if ( 0 == handle
->initialized
)
656 using geos::geom::IntersectionMatrix
;
658 IntersectionMatrix
* im
= g1
->relate(g2
);
664 char *result
= gstrdup(im
->toString());
671 catch (const std::exception
&e
)
673 handle
->ERROR_MESSAGE("%s", e
.what());
677 handle
->ERROR_MESSAGE("Unknown exception thrown");
684 GEOSRelateBoundaryNodeRule_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, int bnr
)
686 if ( 0 == extHandle
)
691 GEOSContextHandleInternal_t
*handle
= 0;
692 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
693 if ( 0 == handle
->initialized
)
700 using geos::operation::relate::RelateOp
;
701 using geos::geom::IntersectionMatrix
;
702 using geos::algorithm::BoundaryNodeRule
;
704 IntersectionMatrix
* im
;
706 case GEOSRELATE_BNR_MOD2
: /* same as OGC */
707 im
= RelateOp::relate(g1
, g2
,
708 BoundaryNodeRule::MOD2_BOUNDARY_RULE
);
710 case GEOSRELATE_BNR_ENDPOINT
:
711 im
= RelateOp::relate(g1
, g2
,
712 BoundaryNodeRule::ENDPOINT_BOUNDARY_RULE
);
714 case GEOSRELATE_BNR_MULTIVALENT_ENDPOINT
:
715 im
= RelateOp::relate(g1
, g2
,
716 BoundaryNodeRule::MULTIVALENT_ENDPOINT_BOUNDARY_RULE
);
718 case GEOSRELATE_BNR_MONOVALENT_ENDPOINT
:
719 im
= RelateOp::relate(g1
, g2
,
720 BoundaryNodeRule::MONOVALENT_ENDPOINT_BOUNDARY_RULE
);
723 handle
->ERROR_MESSAGE("Invalid boundary node rule %d", bnr
);
728 if (0 == im
) return 0;
730 char *result
= gstrdup(im
->toString());
737 catch (const std::exception
&e
)
739 handle
->ERROR_MESSAGE("%s", e
.what());
743 handle
->ERROR_MESSAGE("Unknown exception thrown");
751 //-----------------------------------------------------------------
753 //-----------------------------------------------------------------
757 GEOSisValid_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
759 if ( 0 == extHandle
)
764 GEOSContextHandleInternal_t
*handle
= 0;
765 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
766 if ( 0 == handle
->initialized
)
773 using geos::operation::valid::IsValidOp
;
774 using geos::operation::valid::TopologyValidationError
;
777 TopologyValidationError
*err
= ivo
.getValidationError();
780 handle
->NOTICE_MESSAGE("%s", err
->toString().c_str());
788 catch (const std::exception
&e
)
790 handle
->ERROR_MESSAGE("%s", e
.what());
794 handle
->ERROR_MESSAGE("Unknown exception thrown");
801 GEOSisValidReason_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
803 if ( 0 == extHandle
)
808 GEOSContextHandleInternal_t
*handle
= 0;
809 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
810 if ( 0 == handle
->initialized
)
817 using geos::operation::valid::IsValidOp
;
818 using geos::operation::valid::TopologyValidationError
;
821 char const* const validstr
= "Valid Geometry";
824 TopologyValidationError
*err
= ivo
.getValidationError();
827 std::ostringstream ss
;
829 ss
<< err
->getCoordinate();
830 const std::string errloc
= ss
.str();
831 std::string
errmsg(err
->getMessage());
832 errmsg
+= "[" + errloc
+ "]";
833 result
= gstrdup(errmsg
);
837 result
= gstrdup(std::string(validstr
));
842 catch (const std::exception
&e
)
844 handle
->ERROR_MESSAGE("%s", e
.what());
848 handle
->ERROR_MESSAGE("Unknown exception thrown");
855 GEOSisValidDetail_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
856 int flags
, char** reason
, Geometry
** location
)
858 if ( 0 == extHandle
)
863 GEOSContextHandleInternal_t
*handle
= 0;
864 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
865 if ( 0 == handle
->initialized
)
872 using geos::operation::valid::IsValidOp
;
873 using geos::operation::valid::TopologyValidationError
;
876 if ( flags
& GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE
) {
877 ivo
.setSelfTouchingRingFormingHoleValid(true);
879 TopologyValidationError
*err
= ivo
.getValidationError();
883 *location
= handle
->geomFactory
->createPoint(err
->getCoordinate());
886 std::string
errmsg(err
->getMessage());
887 *reason
= gstrdup(errmsg
);
892 if ( location
) *location
= 0;
893 if ( reason
) *reason
= 0;
894 return 1; /* valid */
897 catch (const std::exception
&e
)
899 handle
->ERROR_MESSAGE("%s", e
.what());
903 handle
->ERROR_MESSAGE("Unknown exception thrown");
906 return 2; /* exception */
909 //-----------------------------------------------------------------
911 //-----------------------------------------------------------------
914 GEOSEquals_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
916 if ( 0 == extHandle
)
921 GEOSContextHandleInternal_t
*handle
= 0;
922 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
923 if ( 0 == handle
->initialized
)
930 bool result
= g1
->equals(g2
);
933 catch (const std::exception
&e
)
935 handle
->ERROR_MESSAGE("%s", e
.what());
939 handle
->ERROR_MESSAGE("Unknown exception thrown");
946 GEOSEqualsExact_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double tolerance
)
948 if ( 0 == extHandle
)
953 GEOSContextHandleInternal_t
*handle
= 0;
954 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
955 if ( 0 == handle
->initialized
)
962 bool result
= g1
->equalsExact(g2
, tolerance
);
965 catch (const std::exception
&e
)
967 handle
->ERROR_MESSAGE("%s", e
.what());
971 handle
->ERROR_MESSAGE("Unknown exception thrown");
978 GEOSDistance_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double *dist
)
982 if ( 0 == extHandle
)
987 GEOSContextHandleInternal_t
*handle
= 0;
988 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
989 if ( 0 == handle
->initialized
)
996 *dist
= g1
->distance(g2
);
999 catch (const std::exception
&e
)
1001 handle
->ERROR_MESSAGE("%s", e
.what());
1005 handle
->ERROR_MESSAGE("Unknown exception thrown");
1012 GEOSHausdorffDistance_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double *dist
)
1016 if ( 0 == extHandle
)
1021 GEOSContextHandleInternal_t
*handle
= 0;
1022 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1023 if ( 0 == handle
->initialized
)
1030 *dist
= DiscreteHausdorffDistance::distance(*g1
, *g2
);
1033 catch (const std::exception
&e
)
1035 handle
->ERROR_MESSAGE("%s", e
.what());
1039 handle
->ERROR_MESSAGE("Unknown exception thrown");
1046 GEOSHausdorffDistanceDensify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
, double densifyFrac
, double *dist
)
1050 if ( 0 == extHandle
)
1055 GEOSContextHandleInternal_t
*handle
= 0;
1056 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1057 if ( 0 == handle
->initialized
)
1064 *dist
= DiscreteHausdorffDistance::distance(*g1
, *g2
, densifyFrac
);
1067 catch (const std::exception
&e
)
1069 handle
->ERROR_MESSAGE("%s", e
.what());
1073 handle
->ERROR_MESSAGE("Unknown exception thrown");
1080 GEOSArea_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double *area
)
1084 if ( 0 == extHandle
)
1089 GEOSContextHandleInternal_t
*handle
= 0;
1090 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1091 if ( 0 == handle
->initialized
)
1098 *area
= g
->getArea();
1101 catch (const std::exception
&e
)
1103 handle
->ERROR_MESSAGE("%s", e
.what());
1107 handle
->ERROR_MESSAGE("Unknown exception thrown");
1114 GEOSLength_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double *length
)
1116 assert(0 != length
);
1118 if ( 0 == extHandle
)
1123 GEOSContextHandleInternal_t
*handle
= 0;
1124 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1125 if ( 0 == handle
->initialized
)
1132 *length
= g
->getLength();
1135 catch (const std::exception
&e
)
1137 handle
->ERROR_MESSAGE("%s", e
.what());
1141 handle
->ERROR_MESSAGE("Unknown exception thrown");
1148 GEOSGeomFromWKT_r(GEOSContextHandle_t extHandle
, const char *wkt
)
1150 if ( 0 == extHandle
)
1155 GEOSContextHandleInternal_t
*handle
= 0;
1156 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1157 if ( 0 == handle
->initialized
)
1164 const std::string
wktstring(wkt
);
1165 WKTReader
r(static_cast<GeometryFactory
const*>(handle
->geomFactory
));
1167 Geometry
*g
= r
.read(wktstring
);
1170 catch (const std::exception
&e
)
1172 handle
->ERROR_MESSAGE("%s", e
.what());
1176 handle
->ERROR_MESSAGE("Unknown exception thrown");
1183 GEOSGeomToWKT_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1185 if ( 0 == extHandle
)
1190 GEOSContextHandleInternal_t
*handle
= 0;
1191 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1192 if ( 0 == handle
->initialized
)
1200 char *result
= gstrdup(g1
->toString());
1203 catch (const std::exception
&e
)
1205 handle
->ERROR_MESSAGE("%s", e
.what());
1209 handle
->ERROR_MESSAGE("Unknown exception thrown");
1214 // Remember to free the result!
1216 GEOSGeomToWKB_buf_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, size_t *size
)
1220 if ( 0 == extHandle
)
1225 GEOSContextHandleInternal_t
*handle
= 0;
1226 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1227 if ( 0 == handle
->initialized
)
1232 using geos::io::WKBWriter
;
1235 int byteOrder
= 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 GeomAutoPtr
g3(BinaryOp(g1
, g2
, overlayOp(OverlayOp::opINTERSECTION
)));
1609 return g3
.release();
1612 //Geometry *g3 = g1->intersection(g2);
1615 catch (const std::exception
&e
)
1617 handle
->ERROR_MESSAGE("%s", e
.what());
1621 handle
->ERROR_MESSAGE("Unknown exception thrown");
1628 GEOSBuffer_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadrantsegments
)
1630 if ( 0 == extHandle
)
1635 GEOSContextHandleInternal_t
*handle
= 0;
1636 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1637 if ( 0 == handle
->initialized
)
1644 Geometry
*g3
= g1
->buffer(width
, quadrantsegments
);
1647 catch (const std::exception
&e
)
1649 handle
->ERROR_MESSAGE("%s", e
.what());
1653 handle
->ERROR_MESSAGE("Unknown exception thrown");
1660 GEOSBufferWithStyle_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int endCapStyle
, int joinStyle
, double mitreLimit
)
1662 using geos::operation::buffer::BufferParameters
;
1663 using geos::operation::buffer::BufferOp
;
1664 using geos::util::IllegalArgumentException
;
1666 if ( 0 == extHandle
)
1671 GEOSContextHandleInternal_t
*handle
= 0;
1672 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1673 if ( 0 == handle
->initialized
)
1680 BufferParameters bp
;
1681 bp
.setQuadrantSegments(quadsegs
);
1683 if ( endCapStyle
> BufferParameters::CAP_SQUARE
)
1685 throw IllegalArgumentException("Invalid buffer endCap style");
1688 static_cast<BufferParameters::EndCapStyle
>(endCapStyle
)
1691 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1693 throw IllegalArgumentException("Invalid buffer join style");
1696 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1698 bp
.setMitreLimit(mitreLimit
);
1699 BufferOp
op(g1
, bp
);
1700 Geometry
*g3
= op
.getResultGeometry(width
);
1703 catch (const std::exception
&e
)
1705 handle
->ERROR_MESSAGE("%s", e
.what());
1709 handle
->ERROR_MESSAGE("Unknown exception thrown");
1716 GEOSOffsetCurve_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int joinStyle
, double mitreLimit
)
1718 if ( 0 == extHandle
) return NULL
;
1720 GEOSContextHandleInternal_t
*handle
= 0;
1721 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1722 if ( 0 == handle
->initialized
) return NULL
;
1726 BufferParameters bp
;
1727 bp
.setEndCapStyle( BufferParameters::CAP_FLAT
);
1728 bp
.setQuadrantSegments(quadsegs
);
1730 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1732 throw IllegalArgumentException("Invalid buffer join style");
1735 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1737 bp
.setMitreLimit(mitreLimit
);
1739 bool isLeftSide
= true;
1744 BufferBuilder
bufBuilder (bp
);
1745 Geometry
*g3
= bufBuilder
.bufferLineSingleSided(g1
, width
, isLeftSide
);
1749 catch (const std::exception
&e
)
1751 handle
->ERROR_MESSAGE("%s", e
.what());
1755 handle
->ERROR_MESSAGE("Unknown exception thrown");
1761 /* @deprecated in 3.3.0 */
1763 GEOSSingleSidedBuffer_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double width
, int quadsegs
, int joinStyle
, double mitreLimit
, int leftSide
)
1765 if ( 0 == extHandle
) return NULL
;
1767 GEOSContextHandleInternal_t
*handle
= 0;
1768 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1769 if ( 0 == handle
->initialized
) return NULL
;
1773 BufferParameters bp
;
1774 bp
.setEndCapStyle( BufferParameters::CAP_FLAT
);
1775 bp
.setQuadrantSegments(quadsegs
);
1777 if ( joinStyle
> BufferParameters::JOIN_BEVEL
)
1779 throw IllegalArgumentException("Invalid buffer join style");
1782 static_cast<BufferParameters::JoinStyle
>(joinStyle
)
1784 bp
.setMitreLimit(mitreLimit
);
1786 bool isLeftSide
= leftSide
== 0 ? false : true;
1787 BufferBuilder
bufBuilder (bp
);
1788 Geometry
*g3
= bufBuilder
.bufferLineSingleSided(g1
, width
, isLeftSide
);
1792 catch (const std::exception
&e
)
1794 handle
->ERROR_MESSAGE("%s", e
.what());
1798 handle
->ERROR_MESSAGE("Unknown exception thrown");
1805 GEOSConvexHull_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1807 if ( 0 == extHandle
)
1812 GEOSContextHandleInternal_t
*handle
= 0;
1813 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1814 if ( 0 == handle
->initialized
)
1821 Geometry
*g3
= g1
->convexHull();
1824 catch (const std::exception
&e
)
1826 handle
->ERROR_MESSAGE("%s", e
.what());
1830 handle
->ERROR_MESSAGE("Unknown exception thrown");
1837 GEOSDifference_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1839 if ( 0 == extHandle
)
1844 GEOSContextHandleInternal_t
*handle
= 0;
1845 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1846 if ( 0 == handle
->initialized
)
1853 GeomAutoPtr
g3(BinaryOp(g1
, g2
, overlayOp(OverlayOp::opDIFFERENCE
)));
1854 return g3
.release();
1857 //Geometry *g3 = g1->difference(g2);
1860 catch (const std::exception
&e
)
1862 handle
->ERROR_MESSAGE("%s", e
.what());
1866 handle
->ERROR_MESSAGE("Unknown exception thrown");
1873 GEOSBoundary_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
1875 if ( 0 == extHandle
)
1880 GEOSContextHandleInternal_t
*handle
= 0;
1881 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1882 if ( 0 == handle
->initialized
)
1889 Geometry
*g3
= g1
->getBoundary();
1892 catch (const std::exception
&e
)
1894 handle
->ERROR_MESSAGE("%s", e
.what());
1898 handle
->ERROR_MESSAGE("Unknown exception thrown");
1905 GEOSSymDifference_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1907 if ( 0 == extHandle
)
1912 GEOSContextHandleInternal_t
*handle
= 0;
1913 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1914 if ( 0 == handle
->initialized
)
1921 GeomAutoPtr g3
= BinaryOp(g1
, g2
, overlayOp(OverlayOp::opSYMDIFFERENCE
));
1922 return g3
.release();
1923 //Geometry *g3 = g1->symDifference(g2);
1926 catch (const std::exception
&e
)
1928 handle
->ERROR_MESSAGE("%s", e
.what());
1934 handle
->ERROR_MESSAGE("Unknown exception thrown");
1940 GEOSUnion_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const Geometry
*g2
)
1942 if ( 0 == extHandle
)
1947 GEOSContextHandleInternal_t
*handle
= 0;
1948 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1949 if ( 0 == handle
->initialized
)
1956 GeomAutoPtr g3
= BinaryOp(g1
, g2
, overlayOp(OverlayOp::opUNION
));
1957 return g3
.release();
1960 //Geometry *g3 = g1->Union(g2);
1963 catch (const std::exception
&e
)
1965 #if VERBOSE_EXCEPTIONS
1966 std::ostringstream s
;
1967 s
<< "Exception on GEOSUnion with following inputs:" << std::endl
;
1968 s
<< "A: "<<g1
->toString() << std::endl
;
1969 s
<< "B: "<<g2
->toString() << std::endl
;
1970 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
1971 #endif // VERBOSE_EXCEPTIONS
1972 handle
->ERROR_MESSAGE("%s", e
.what());
1976 handle
->ERROR_MESSAGE("Unknown exception thrown");
1983 GEOSUnaryUnion_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
1985 if ( 0 == extHandle
)
1990 GEOSContextHandleInternal_t
*handle
= 0;
1991 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
1992 if ( 0 == handle
->initialized
)
1999 GeomAutoPtr
g3 ( g
->Union() );
2000 return g3
.release();
2002 catch (const std::exception
&e
)
2004 #if VERBOSE_EXCEPTIONS
2005 std::ostringstream s
;
2006 s
<< "Exception on GEOSUnaryUnion with following inputs:" << std::endl
;
2007 s
<< "A: "<<g1
->toString() << std::endl
;
2008 s
<< "B: "<<g2
->toString() << std::endl
;
2009 handle
->NOTICE_MESSAGE("%s", s
.str().c_str());
2010 #endif // VERBOSE_EXCEPTIONS
2011 handle
->ERROR_MESSAGE("%s", e
.what());
2015 handle
->ERROR_MESSAGE("Unknown exception thrown");
2022 GEOSUnionCascaded_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2024 if ( 0 == extHandle
)
2029 GEOSContextHandleInternal_t
*handle
= 0;
2030 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2031 if ( 0 == handle
->initialized
)
2038 const geos::geom::MultiPolygon
*p
= dynamic_cast<const geos::geom::MultiPolygon
*>(g1
);
2041 handle
->ERROR_MESSAGE("Invalid argument (must be a MultiPolygon)");
2045 using geos::operation::geounion::CascadedPolygonUnion
;
2046 return CascadedPolygonUnion::Union(p
);
2048 catch (const std::exception
&e
)
2050 handle
->ERROR_MESSAGE("%s", e
.what());
2054 handle
->ERROR_MESSAGE("Unknown exception thrown");
2061 GEOSPointOnSurface_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2063 if ( 0 == extHandle
)
2068 GEOSContextHandleInternal_t
*handle
= 0;
2069 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2070 if ( 0 == handle
->initialized
)
2077 Geometry
*ret
= g1
->getInteriorPoint();
2080 const GeometryFactory
* gf
= handle
->geomFactory
;
2081 // return an empty collection
2082 return gf
->createGeometryCollection();
2086 catch (const std::exception
&e
)
2088 handle
->ERROR_MESSAGE("%s", e
.what());
2092 handle
->ERROR_MESSAGE("Unknown exception thrown");
2098 //-------------------------------------------------------------------
2099 // memory management functions
2100 //------------------------------------------------------------------
2103 GEOSGeom_destroy_r(GEOSContextHandle_t extHandle
, Geometry
*a
)
2105 GEOSContextHandleInternal_t
*handle
= 0;
2107 // FIXME: mloskot: Does this try-catch around delete means that
2108 // destructors in GEOS may throw? If it does, this is a serious
2109 // violation of "never throw an exception from a destructor" principle
2115 catch (const std::exception
&e
)
2117 if ( 0 == extHandle
)
2122 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2123 if ( 0 == handle
->initialized
)
2128 handle
->ERROR_MESSAGE("%s", e
.what());
2132 if ( 0 == extHandle
)
2137 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2138 if ( 0 == handle
->initialized
)
2143 handle
->ERROR_MESSAGE("Unknown exception thrown");
2148 GEOSSetSRID_r(GEOSContextHandle_t extHandle
, Geometry
*g
, int srid
)
2152 if ( 0 == extHandle
)
2157 GEOSContextHandleInternal_t
*handle
= 0;
2158 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2159 if ( 0 == handle
->initialized
)
2169 GEOSGetNumCoordinates_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2173 if ( 0 == extHandle
)
2178 GEOSContextHandleInternal_t
*handle
= 0;
2179 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2180 if ( 0 == handle
->initialized
)
2187 return static_cast<int>(g
->getNumPoints());
2189 catch (const std::exception
&e
)
2191 handle
->ERROR_MESSAGE("%s", e
.what());
2195 handle
->ERROR_MESSAGE("Unknown exception thrown");
2202 * Return -1 on exception, 0 otherwise.
2203 * Converts Geometry to normal form (or canonical form).
2206 GEOSNormalize_r(GEOSContextHandle_t extHandle
, Geometry
*g
)
2210 if ( 0 == extHandle
)
2215 GEOSContextHandleInternal_t
*handle
= 0;
2216 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2217 if ( 0 == handle
->initialized
)
2225 return 0; // SUCCESS
2227 catch (const std::exception
&e
)
2229 handle
->ERROR_MESSAGE("%s", e
.what());
2233 handle
->ERROR_MESSAGE("Unknown exception thrown");
2240 GEOSGetNumInteriorRings_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2242 if ( 0 == extHandle
)
2247 GEOSContextHandleInternal_t
*handle
= 0;
2248 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2249 if ( 0 == handle
->initialized
)
2256 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
2259 handle
->ERROR_MESSAGE("Argument is not a Polygon");
2262 return static_cast<int>(p
->getNumInteriorRing());
2264 catch (const std::exception
&e
)
2266 handle
->ERROR_MESSAGE("%s", e
.what());
2270 handle
->ERROR_MESSAGE("Unknown exception thrown");
2277 // returns -1 on error and 1 for non-multi geometries
2279 GEOSGetNumGeometries_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2281 if ( 0 == extHandle
)
2286 GEOSContextHandleInternal_t
*handle
= 0;
2287 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2288 if ( 0 == handle
->initialized
)
2295 return static_cast<int>(g1
->getNumGeometries());
2297 catch (const std::exception
&e
)
2299 handle
->ERROR_MESSAGE("%s", e
.what());
2303 handle
->ERROR_MESSAGE("Unknown exception thrown");
2311 * Call only on GEOMETRYCOLLECTION or MULTI*.
2312 * Return a pointer to the internal Geometry.
2315 GEOSGetGeometryN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2317 if ( 0 == extHandle
)
2322 GEOSContextHandleInternal_t
*handle
= 0;
2323 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2324 if ( 0 == handle
->initialized
)
2331 return g1
->getGeometryN(n
);
2333 catch (const std::exception
&e
)
2335 handle
->ERROR_MESSAGE("%s", e
.what());
2339 handle
->ERROR_MESSAGE("Unknown exception thrown");
2346 * Call only on LINESTRING
2347 * Returns NULL on exception
2350 GEOSGeomGetPointN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2352 if ( 0 == extHandle
)
2357 GEOSContextHandleInternal_t
*handle
= 0;
2358 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2359 if ( 0 == handle
->initialized
)
2366 using geos::geom::LineString
;
2367 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2370 handle
->ERROR_MESSAGE("Argument is not a LineString");
2373 return ls
->getPointN(n
);
2375 catch (const std::exception
&e
)
2377 handle
->ERROR_MESSAGE("%s", e
.what());
2381 handle
->ERROR_MESSAGE("Unknown exception thrown");
2388 * Call only on LINESTRING
2391 GEOSGeomGetStartPoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2393 if ( 0 == extHandle
)
2398 GEOSContextHandleInternal_t
*handle
= 0;
2399 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2400 if ( 0 == handle
->initialized
)
2407 using geos::geom::LineString
;
2408 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2411 handle
->ERROR_MESSAGE("Argument is not a LineString");
2414 return ls
->getStartPoint();
2416 catch (const std::exception
&e
)
2418 handle
->ERROR_MESSAGE("%s", e
.what());
2422 handle
->ERROR_MESSAGE("Unknown exception thrown");
2429 * Call only on LINESTRING
2432 GEOSGeomGetEndPoint_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2434 if ( 0 == extHandle
)
2439 GEOSContextHandleInternal_t
*handle
= 0;
2440 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2441 if ( 0 == handle
->initialized
)
2448 using geos::geom::LineString
;
2449 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2452 handle
->ERROR_MESSAGE("Argument is not a LineString");
2455 return ls
->getEndPoint();
2457 catch (const std::exception
&e
)
2459 handle
->ERROR_MESSAGE("%s", e
.what());
2463 handle
->ERROR_MESSAGE("Unknown exception thrown");
2470 * Call only on LINESTRING
2471 * return 2 on exception, 1 on true, 0 on false
2474 GEOSisClosed_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2476 if ( 0 == extHandle
)
2481 GEOSContextHandleInternal_t
*handle
= 0;
2482 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2483 if ( 0 == handle
->initialized
)
2490 using geos::geom::LineString
;
2491 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2494 handle
->ERROR_MESSAGE("Argument is not a LineString");
2497 return ls
->isClosed();
2499 catch (const std::exception
&e
)
2501 handle
->ERROR_MESSAGE("%s", e
.what());
2505 handle
->ERROR_MESSAGE("Unknown exception thrown");
2512 * Call only on LINESTRING
2513 * return 0 on exception, otherwise 1
2516 GEOSGeomGetLength_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *length
)
2518 if ( 0 == extHandle
)
2523 GEOSContextHandleInternal_t
*handle
= 0;
2524 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2525 if ( 0 == handle
->initialized
)
2532 using geos::geom::LineString
;
2533 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2536 handle
->ERROR_MESSAGE("Argument is not a LineString");
2539 *length
= ls
->getLength();
2542 catch (const std::exception
&e
)
2544 handle
->ERROR_MESSAGE("%s", e
.what());
2548 handle
->ERROR_MESSAGE("Unknown exception thrown");
2555 * Call only on LINESTRING
2558 GEOSGeomGetNumPoints_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2560 if ( 0 == extHandle
)
2565 GEOSContextHandleInternal_t
*handle
= 0;
2566 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2567 if ( 0 == handle
->initialized
)
2574 using geos::geom::LineString
;
2575 const LineString
*ls
= dynamic_cast<const LineString
*>(g1
);
2578 handle
->ERROR_MESSAGE("Argument is not a LineString");
2581 return ls
->getNumPoints();
2583 catch (const std::exception
&e
)
2585 handle
->ERROR_MESSAGE("%s", e
.what());
2589 handle
->ERROR_MESSAGE("Unknown exception thrown");
2597 * returns 0 on exception, otherwise 1
2600 GEOSGeomGetX_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *x
)
2602 if ( 0 == extHandle
)
2607 GEOSContextHandleInternal_t
*handle
= 0;
2608 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2609 if ( 0 == handle
->initialized
)
2616 using geos::geom::Point
;
2617 const Point
*po
= dynamic_cast<const Point
*>(g1
);
2620 handle
->ERROR_MESSAGE("Argument is not a Point");
2626 catch (const std::exception
&e
)
2628 handle
->ERROR_MESSAGE("%s", e
.what());
2632 handle
->ERROR_MESSAGE("Unknown exception thrown");
2640 * returns 0 on exception, otherwise 1
2643 GEOSGeomGetY_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double *y
)
2645 if ( 0 == extHandle
)
2650 GEOSContextHandleInternal_t
*handle
= 0;
2651 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2652 if ( 0 == handle
->initialized
)
2659 using geos::geom::Point
;
2660 const Point
*po
= dynamic_cast<const Point
*>(g1
);
2663 handle
->ERROR_MESSAGE("Argument is not a Point");
2669 catch (const std::exception
&e
)
2671 handle
->ERROR_MESSAGE("%s", e
.what());
2675 handle
->ERROR_MESSAGE("Unknown exception thrown");
2682 * Call only on polygon
2683 * Return a copy of the internal Geometry.
2686 GEOSGetExteriorRing_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
)
2688 if ( 0 == extHandle
)
2693 GEOSContextHandleInternal_t
*handle
= 0;
2694 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2695 if ( 0 == handle
->initialized
)
2702 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
2705 handle
->ERROR_MESSAGE("Invalid argument (must be a Polygon)");
2708 return p
->getExteriorRing();
2710 catch (const std::exception
&e
)
2712 handle
->ERROR_MESSAGE("%s", e
.what());
2716 handle
->ERROR_MESSAGE("Unknown exception thrown");
2723 * Call only on polygon
2724 * Return a pointer to internal storage, do not destroy it.
2727 GEOSGetInteriorRingN_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, int n
)
2729 if ( 0 == extHandle
)
2734 GEOSContextHandleInternal_t
*handle
= 0;
2735 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2736 if ( 0 == handle
->initialized
)
2743 const Polygon
*p
= dynamic_cast<const Polygon
*>(g1
);
2746 handle
->ERROR_MESSAGE("Invalid argument (must be a Polygon)");
2749 return p
->getInteriorRingN(n
);
2751 catch (const std::exception
&e
)
2753 handle
->ERROR_MESSAGE("%s", e
.what());
2757 handle
->ERROR_MESSAGE("Unknown exception thrown");
2764 GEOSGetCentroid_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
2766 if ( 0 == extHandle
)
2771 GEOSContextHandleInternal_t
*handle
= 0;
2772 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2773 if ( 0 == handle
->initialized
)
2780 Geometry
*ret
= g
->getCentroid();
2783 const GeometryFactory
*gf
= handle
->geomFactory
;
2784 return gf
->createGeometryCollection();
2788 catch (const std::exception
&e
)
2790 handle
->ERROR_MESSAGE("%s", e
.what());
2794 handle
->ERROR_MESSAGE("Unknown exception thrown");
2801 GEOSGeom_createEmptyCollection_r(GEOSContextHandle_t extHandle
, int type
)
2803 if ( 0 == extHandle
)
2808 GEOSContextHandleInternal_t
*handle
= 0;
2809 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2810 if ( 0 == handle
->initialized
)
2817 sprintf(buf
, "createCollection: requested type %d, ngeoms: %d",
2819 handle
->NOTICE_MESSAGE("%s", buf
);// TODO: Can handle->NOTICE_MESSAGE format that directly?
2824 const GeometryFactory
* gf
= handle
->geomFactory
;
2829 case GEOS_GEOMETRYCOLLECTION
:
2830 g
= gf
->createGeometryCollection();
2832 case GEOS_MULTIPOINT
:
2833 g
= gf
->createMultiPoint();
2835 case GEOS_MULTILINESTRING
:
2836 g
= gf
->createMultiLineString();
2838 case GEOS_MULTIPOLYGON
:
2839 g
= gf
->createMultiPolygon();
2842 handle
->ERROR_MESSAGE("Unsupported type request for GEOSGeom_createEmptyCollection_r");
2849 catch (const std::exception
&e
)
2851 handle
->ERROR_MESSAGE("%s", e
.what());
2855 handle
->ERROR_MESSAGE("Unknown exception thrown");
2862 GEOSGeom_createCollection_r(GEOSContextHandle_t extHandle
, int type
, Geometry
**geoms
, unsigned int ngeoms
)
2864 if ( 0 == extHandle
)
2869 GEOSContextHandleInternal_t
*handle
= 0;
2870 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2871 if ( 0 == handle
->initialized
)
2878 sprintf(buf
, "PostGIS2GEOS_collection: requested type %d, ngeoms: %d",
2880 handle
->NOTICE_MESSAGE("%s", buf
);// TODO: Can handle->NOTICE_MESSAGE format that directly?
2885 const GeometryFactory
* gf
= handle
->geomFactory
;
2886 std::vector
<Geometry
*>* vgeoms
= new std::vector
<Geometry
*>(geoms
, geoms
+ ngeoms
);
2891 case GEOS_GEOMETRYCOLLECTION
:
2892 g
= gf
->createGeometryCollection(vgeoms
);
2894 case GEOS_MULTIPOINT
:
2895 g
= gf
->createMultiPoint(vgeoms
);
2897 case GEOS_MULTILINESTRING
:
2898 g
= gf
->createMultiLineString(vgeoms
);
2900 case GEOS_MULTIPOLYGON
:
2901 g
= gf
->createMultiPolygon(vgeoms
);
2904 handle
->ERROR_MESSAGE("Unsupported type request for PostGIS2GEOS_collection");
2911 catch (const std::exception
&e
)
2913 handle
->ERROR_MESSAGE("%s", e
.what());
2917 handle
->ERROR_MESSAGE("Unknown exception thrown");
2924 GEOSPolygonize_r(GEOSContextHandle_t extHandle
, const Geometry
* const * g
, unsigned int ngeoms
)
2926 if ( 0 == extHandle
)
2931 GEOSContextHandleInternal_t
*handle
= 0;
2932 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
2933 if ( 0 == handle
->initialized
)
2943 using geos::operation::polygonize::Polygonizer
;
2945 for (std::size_t i
= 0; i
< ngeoms
; ++i
)
2951 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
2954 std::vector
<Polygon
*> *polys
= plgnzr
.getPolygons();
2958 handle
->NOTICE_MESSAGE("output polygons got");
2961 // We need a vector of Geometry pointers, not Polygon pointers.
2962 // STL vector doesn't allow transparent upcast of this
2963 // nature, so we explicitly convert.
2964 // (it's just a waste of processor and memory, btw)
2966 // XXX mloskot: Why not to extent GeometryFactory to accept
2967 // vector of polygons or extend Polygonizer to return list of Geometry*
2968 // or add a wrapper which semantic is similar to:
2969 // std::vector<as_polygon<Geometry*> >
2970 std::vector
<Geometry
*> *polyvec
= new std::vector
<Geometry
*>(polys
->size());
2972 for (std::size_t i
= 0; i
< polys
->size(); ++i
)
2974 (*polyvec
)[i
] = (*polys
)[i
];
2979 const GeometryFactory
*gf
= handle
->geomFactory
;
2981 // The below takes ownership of the passed vector,
2982 // so we must *not* delete it
2983 out
= gf
->createGeometryCollection(polyvec
);
2985 catch (const std::exception
&e
)
2987 handle
->ERROR_MESSAGE("%s", e
.what());
2991 handle
->ERROR_MESSAGE("Unknown exception thrown");
2998 GEOSPolygonizer_getCutEdges_r(GEOSContextHandle_t extHandle
, const Geometry
* const * g
, unsigned int ngeoms
)
3000 if ( 0 == extHandle
)
3005 GEOSContextHandleInternal_t
*handle
= 0;
3006 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3007 if ( 0 == handle
->initialized
)
3017 using geos::operation::polygonize::Polygonizer
;
3019 for (std::size_t i
= 0; i
< ngeoms
; ++i
)
3025 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
3028 const std::vector
<const LineString
*>& lines
= plgnzr
.getCutEdges();
3031 handle
->NOTICE_MESSAGE("output polygons got");
3034 // We need a vector of Geometry pointers, not Polygon pointers.
3035 // STL vector doesn't allow transparent upcast of this
3036 // nature, so we explicitly convert.
3037 // (it's just a waste of processor and memory, btw)
3038 // XXX mloskot: See comment for GEOSPolygonize_r
3039 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3041 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3043 (*linevec
)[i
] = lines
[i
]->clone();
3046 const GeometryFactory
*gf
= handle
->geomFactory
;
3048 // The below takes ownership of the passed vector,
3049 // so we must *not* delete it
3050 out
= gf
->createGeometryCollection(linevec
);
3052 catch (const std::exception
&e
)
3054 handle
->ERROR_MESSAGE("%s", e
.what());
3058 handle
->ERROR_MESSAGE("Unknown exception thrown");
3065 GEOSPolygonize_full_r(GEOSContextHandle_t extHandle
, const Geometry
* g
,
3066 Geometry
** cuts
, Geometry
** dangles
, Geometry
** invalid
)
3068 if ( 0 == extHandle
)
3073 GEOSContextHandleInternal_t
*handle
= 0;
3074 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3075 if ( 0 == handle
->initialized
)
3083 using geos::operation::polygonize::Polygonizer
;
3085 for (std::size_t i
= 0; i
<g
->getNumGeometries(); ++i
)
3087 plgnzr
.add(g
->getGeometryN(i
));
3091 handle
->NOTICE_MESSAGE("geometry vector added to polygonizer");
3093 const GeometryFactory
*gf
= handle
->geomFactory
;
3097 const std::vector
<const LineString
*>& lines
= plgnzr
.getCutEdges();
3098 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3099 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3101 (*linevec
)[i
] = lines
[i
]->clone();
3104 // The below takes ownership of the passed vector,
3105 // so we must *not* delete it
3106 *cuts
= gf
->createGeometryCollection(linevec
);
3111 const std::vector
<const LineString
*>& lines
= plgnzr
.getDangles();
3112 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3113 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3115 (*linevec
)[i
] = lines
[i
]->clone();
3118 // The below takes ownership of the passed vector,
3119 // so we must *not* delete it
3120 *dangles
= gf
->createGeometryCollection(linevec
);
3125 const std::vector
<LineString
*>& lines
= plgnzr
.getInvalidRingLines();
3126 std::vector
<Geometry
*> *linevec
= new std::vector
<Geometry
*>(lines
.size());
3127 for (std::size_t i
= 0, n
=lines
.size(); i
< n
; ++i
)
3129 (*linevec
)[i
] = lines
[i
]->clone();
3132 // The below takes ownership of the passed vector,
3133 // so we must *not* delete it
3134 *invalid
= gf
->createGeometryCollection(linevec
);
3137 std::vector
<Polygon
*> *polys
= plgnzr
.getPolygons();
3138 std::vector
<Geometry
*> *polyvec
= new std::vector
<Geometry
*>(polys
->size());
3139 for (std::size_t i
= 0; i
< polys
->size(); ++i
)
3141 (*polyvec
)[i
] = (*polys
)[i
];
3145 return gf
->createGeometryCollection(polyvec
);
3148 catch (const std::exception
&e
)
3150 handle
->ERROR_MESSAGE("%s", e
.what());
3155 handle
->ERROR_MESSAGE("Unknown exception thrown");
3161 GEOSLineMerge_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3163 if ( 0 == extHandle
)
3168 GEOSContextHandleInternal_t
*handle
= 0;
3169 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3170 if ( 0 == handle
->initialized
)
3179 using geos::operation::linemerge::LineMerger
;
3183 std::vector
<LineString
*>* lines
= lmrgr
.getMergedLineStrings();
3187 handle
->NOTICE_MESSAGE("output lines got");
3190 std::vector
<Geometry
*>*geoms
= new std::vector
<Geometry
*>(lines
->size());
3191 for (std::vector
<Geometry
*>::size_type i
= 0; i
< lines
->size(); ++i
)
3193 (*geoms
)[i
] = (*lines
)[i
];
3198 const GeometryFactory
*gf
= handle
->geomFactory
;
3199 out
= gf
->buildGeometry(geoms
);
3202 //out = gf->createGeometryCollection(geoms);
3204 catch (const std::exception
&e
)
3206 handle
->ERROR_MESSAGE("%s", e
.what());
3210 handle
->ERROR_MESSAGE("Unknown exception thrown");
3217 GEOSGetSRID_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3221 if ( 0 == extHandle
)
3226 GEOSContextHandleInternal_t
*handle
= 0;
3227 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3228 if ( 0 == handle
->initialized
)
3235 return g
->getSRID();
3237 catch (const std::exception
&e
)
3239 handle
->ERROR_MESSAGE("%s", e
.what());
3243 handle
->ERROR_MESSAGE("Unknown exception thrown");
3249 const char* GEOSversion()
3251 return GEOS_CAPI_VERSION
;
3254 const char* GEOSjtsport()
3256 return GEOS_JTS_PORT
;
3260 GEOSHasZ_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3264 if ( 0 == extHandle
)
3269 GEOSContextHandleInternal_t
*handle
= 0;
3270 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3271 if ( 0 == handle
->initialized
)
3280 assert(0 != g
->getCoordinate());
3282 double az
= g
->getCoordinate()->z
;
3283 //handle->ERROR_MESSAGE("ZCoord: %g", az);
3285 return static_cast<char>(FINITE(az
));
3289 GEOS_getWKBOutputDims_r(GEOSContextHandle_t extHandle
)
3291 if ( 0 == extHandle
)
3296 GEOSContextHandleInternal_t
*handle
= 0;
3297 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3298 if ( 0 == handle
->initialized
)
3303 return handle
->WKBOutputDims
;
3307 GEOS_setWKBOutputDims_r(GEOSContextHandle_t extHandle
, int newdims
)
3309 if ( 0 == extHandle
)
3314 GEOSContextHandleInternal_t
*handle
= 0;
3315 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3316 if ( 0 == handle
->initialized
)
3321 if ( newdims
< 2 || newdims
> 3 )
3323 handle
->ERROR_MESSAGE("WKB output dimensions out of range 2..3");
3326 const int olddims
= handle
->WKBOutputDims
;
3327 handle
->WKBOutputDims
= newdims
;
3333 GEOS_getWKBByteOrder_r(GEOSContextHandle_t extHandle
)
3335 if ( 0 == extHandle
)
3340 GEOSContextHandleInternal_t
*handle
= 0;
3341 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3342 if ( 0 == handle
->initialized
)
3347 return handle
->WKBByteOrder
;
3351 GEOS_setWKBByteOrder_r(GEOSContextHandle_t extHandle
, int byteOrder
)
3353 if ( 0 == extHandle
)
3358 GEOSContextHandleInternal_t
*handle
= 0;
3359 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3360 if ( 0 == handle
->initialized
)
3365 const int oldByteOrder
= handle
->WKBByteOrder
;
3366 handle
->WKBByteOrder
= byteOrder
;
3368 return oldByteOrder
;
3372 CoordinateSequence
*
3373 GEOSCoordSeq_create_r(GEOSContextHandle_t extHandle
, unsigned int size
, unsigned int dims
)
3375 if ( 0 == extHandle
)
3380 GEOSContextHandleInternal_t
*handle
= 0;
3381 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3382 if ( 0 == handle
->initialized
)
3389 const GeometryFactory
*gf
= handle
->geomFactory
;
3390 return gf
->getCoordinateSequenceFactory()->create(size
, dims
);
3392 catch (const std::exception
&e
)
3394 handle
->ERROR_MESSAGE("%s", e
.what());
3398 handle
->ERROR_MESSAGE("Unknown exception thrown");
3405 GEOSCoordSeq_setOrdinate_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
,
3406 unsigned int idx
, unsigned int dim
, double val
)
3409 if ( 0 == extHandle
)
3414 GEOSContextHandleInternal_t
*handle
= 0;
3415 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3416 if ( 0 == handle
->initialized
)
3423 cs
->setOrdinate(static_cast<int>(idx
), static_cast<int>(dim
), val
);
3426 catch (const std::exception
&e
)
3428 handle
->ERROR_MESSAGE("%s", e
.what());
3432 handle
->ERROR_MESSAGE("Unknown exception thrown");
3439 GEOSCoordSeq_setX_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3441 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 0, val
);
3445 GEOSCoordSeq_setY_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3447 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 1, val
);
3451 GEOSCoordSeq_setZ_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
, unsigned int idx
, double val
)
3453 return GEOSCoordSeq_setOrdinate_r(extHandle
, s
, idx
, 2, val
);
3456 CoordinateSequence
*
3457 GEOSCoordSeq_clone_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
)
3461 if ( 0 == extHandle
)
3466 GEOSContextHandleInternal_t
*handle
= 0;
3467 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3468 if ( 0 == handle
->initialized
)
3477 catch (const std::exception
&e
)
3479 handle
->ERROR_MESSAGE("%s", e
.what());
3483 handle
->ERROR_MESSAGE("Unknown exception thrown");
3490 GEOSCoordSeq_getOrdinate_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
,
3491 unsigned int idx
, unsigned int dim
, double *val
)
3496 if ( 0 == extHandle
)
3501 GEOSContextHandleInternal_t
*handle
= 0;
3502 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3503 if ( 0 == handle
->initialized
)
3510 double d
= cs
->getOrdinate(static_cast<int>(idx
), static_cast<int>(dim
));
3515 catch (const std::exception
&e
)
3517 handle
->ERROR_MESSAGE("%s", e
.what());
3521 handle
->ERROR_MESSAGE("Unknown exception thrown");
3528 GEOSCoordSeq_getX_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
3530 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 0, val
);
3534 GEOSCoordSeq_getY_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
3536 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 1, val
);
3540 GEOSCoordSeq_getZ_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*s
, unsigned int idx
, double *val
)
3542 return GEOSCoordSeq_getOrdinate_r(extHandle
, s
, idx
, 2, val
);
3546 GEOSCoordSeq_getSize_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
, unsigned int *size
)
3551 if ( 0 == extHandle
)
3556 GEOSContextHandleInternal_t
*handle
= 0;
3557 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3558 if ( 0 == handle
->initialized
)
3565 const std::size_t sz
= cs
->getSize();
3566 *size
= static_cast<unsigned int>(sz
);
3569 catch (const std::exception
&e
)
3571 handle
->ERROR_MESSAGE("%s", e
.what());
3575 handle
->ERROR_MESSAGE("Unknown exception thrown");
3582 GEOSCoordSeq_getDimensions_r(GEOSContextHandle_t extHandle
, const CoordinateSequence
*cs
, unsigned int *dims
)
3587 if ( 0 == extHandle
)
3592 GEOSContextHandleInternal_t
*handle
= 0;
3593 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3594 if ( 0 == handle
->initialized
)
3601 const std::size_t dim
= cs
->getDimension();
3602 *dims
= static_cast<unsigned int>(dim
);
3606 catch (const std::exception
&e
)
3608 handle
->ERROR_MESSAGE("%s", e
.what());
3613 handle
->ERROR_MESSAGE("Unknown exception thrown");
3620 GEOSCoordSeq_destroy_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*s
)
3622 GEOSContextHandleInternal_t
*handle
= 0;
3628 catch (const std::exception
&e
)
3630 if ( 0 == extHandle
)
3635 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3636 if ( 0 == handle
->initialized
)
3641 handle
->ERROR_MESSAGE("%s", e
.what());
3645 if ( 0 == extHandle
)
3650 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3651 if ( 0 == handle
->initialized
)
3656 handle
->ERROR_MESSAGE("Unknown exception thrown");
3660 const CoordinateSequence
*
3661 GEOSGeom_getCoordSeq_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3663 if ( 0 == extHandle
)
3668 GEOSContextHandleInternal_t
*handle
= 0;
3669 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3670 if ( 0 == handle
->initialized
)
3677 using geos::geom::Point
;
3679 const LineString
*ls
= dynamic_cast<const LineString
*>(g
);
3682 return ls
->getCoordinatesRO();
3685 const Point
*p
= dynamic_cast<const Point
*>(g
);
3688 return p
->getCoordinatesRO();
3691 handle
->ERROR_MESSAGE("Geometry must be a Point or LineString");
3694 catch (const std::exception
&e
)
3696 handle
->ERROR_MESSAGE("%s", e
.what());
3700 handle
->ERROR_MESSAGE("Unknown exception thrown");
3707 GEOSGeom_createEmptyPoint_r(GEOSContextHandle_t extHandle
)
3709 if ( 0 == extHandle
)
3714 GEOSContextHandleInternal_t
*handle
= 0;
3715 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3716 if ( 0 == handle
->initialized
)
3723 const GeometryFactory
*gf
= handle
->geomFactory
;
3724 return gf
->createPoint();
3726 catch (const std::exception
&e
)
3728 handle
->ERROR_MESSAGE("%s", e
.what());
3732 handle
->ERROR_MESSAGE("Unknown exception thrown");
3739 GEOSGeom_createPoint_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
3741 if ( 0 == extHandle
)
3746 GEOSContextHandleInternal_t
*handle
= 0;
3747 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3748 if ( 0 == handle
->initialized
)
3755 const GeometryFactory
*gf
= handle
->geomFactory
;
3756 return gf
->createPoint(cs
);
3758 catch (const std::exception
&e
)
3760 handle
->ERROR_MESSAGE("%s", e
.what());
3764 handle
->ERROR_MESSAGE("Unknown exception thrown");
3771 GEOSGeom_createLinearRing_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
3773 if ( 0 == extHandle
)
3778 GEOSContextHandleInternal_t
*handle
= 0;
3779 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3780 if ( 0 == handle
->initialized
)
3787 const GeometryFactory
*gf
= handle
->geomFactory
;
3789 return gf
->createLinearRing(cs
);
3791 catch (const std::exception
&e
)
3793 handle
->ERROR_MESSAGE("%s", e
.what());
3797 handle
->ERROR_MESSAGE("Unknown exception thrown");
3804 GEOSGeom_createEmptyLineString_r(GEOSContextHandle_t extHandle
)
3806 if ( 0 == extHandle
)
3811 GEOSContextHandleInternal_t
*handle
= 0;
3812 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3813 if ( 0 == handle
->initialized
)
3820 const GeometryFactory
*gf
= handle
->geomFactory
;
3822 return gf
->createLineString();
3824 catch (const std::exception
&e
)
3826 handle
->ERROR_MESSAGE("%s", e
.what());
3830 handle
->ERROR_MESSAGE("Unknown exception thrown");
3837 GEOSGeom_createLineString_r(GEOSContextHandle_t extHandle
, CoordinateSequence
*cs
)
3839 if ( 0 == extHandle
)
3844 GEOSContextHandleInternal_t
*handle
= 0;
3845 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3846 if ( 0 == handle
->initialized
)
3853 const GeometryFactory
*gf
= handle
->geomFactory
;
3855 return gf
->createLineString(cs
);
3857 catch (const std::exception
&e
)
3859 handle
->ERROR_MESSAGE("%s", e
.what());
3863 handle
->ERROR_MESSAGE("Unknown exception thrown");
3870 GEOSGeom_createEmptyPolygon_r(GEOSContextHandle_t extHandle
)
3872 if ( 0 == extHandle
)
3877 GEOSContextHandleInternal_t
*handle
= 0;
3878 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3879 if ( 0 == handle
->initialized
)
3886 const GeometryFactory
*gf
= handle
->geomFactory
;
3887 return gf
->createPolygon();
3889 catch (const std::exception
&e
)
3891 handle
->ERROR_MESSAGE("%s", e
.what());
3895 handle
->ERROR_MESSAGE("Unknown exception thrown");
3902 GEOSGeom_createPolygon_r(GEOSContextHandle_t extHandle
, Geometry
*shell
, Geometry
**holes
, unsigned int nholes
)
3904 // FIXME: holes must be non-nullptr or may be nullptr?
3905 //assert(0 != holes);
3907 if ( 0 == extHandle
)
3912 GEOSContextHandleInternal_t
*handle
= 0;
3913 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3914 if ( 0 == handle
->initialized
)
3921 using geos::geom::LinearRing
;
3923 std::vector
<Geometry
*> *vholes
= new std::vector
<Geometry
*>(holes
, holes
+ nholes
);
3925 LinearRing
*nshell
= dynamic_cast<LinearRing
*>(shell
);
3928 handle
->ERROR_MESSAGE("Shell is not a LinearRing");
3931 const GeometryFactory
*gf
= handle
->geomFactory
;
3933 return gf
->createPolygon(nshell
, vholes
);
3935 catch (const std::exception
&e
)
3937 handle
->ERROR_MESSAGE("%s", e
.what());
3941 handle
->ERROR_MESSAGE("Unknown exception thrown");
3948 GEOSGeom_clone_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3952 if ( 0 == extHandle
)
3957 GEOSContextHandleInternal_t
*handle
= 0;
3958 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3959 if ( 0 == handle
->initialized
)
3968 catch (const std::exception
&e
)
3970 handle
->ERROR_MESSAGE("%s", e
.what());
3974 handle
->ERROR_MESSAGE("Unknown exception thrown");
3981 GEOSGeom_getDimensions_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
3983 if ( 0 == extHandle
)
3988 GEOSContextHandleInternal_t
*handle
= 0;
3989 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
3990 if ( 0 == handle
->initialized
)
3997 return (int) g
->getDimension();
3999 catch (const std::exception
&e
)
4001 handle
->ERROR_MESSAGE("%s", e
.what());
4005 handle
->ERROR_MESSAGE("Unknown exception thrown");
4012 GEOSGeom_getCoordinateDimension_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
4014 if ( 0 == extHandle
)
4019 GEOSContextHandleInternal_t
*handle
= 0;
4020 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4021 if ( 0 == handle
->initialized
)
4028 return g
->getCoordinateDimension();
4030 catch (const std::exception
&e
)
4032 handle
->ERROR_MESSAGE("%s", e
.what());
4036 handle
->ERROR_MESSAGE("Unknown exception thrown");
4043 GEOSSimplify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double tolerance
)
4045 if ( 0 == extHandle
)
4050 GEOSContextHandleInternal_t
*handle
= 0;
4051 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4052 if ( 0 == handle
->initialized
)
4059 using namespace geos::simplify
;
4060 Geometry::AutoPtr
g(DouglasPeuckerSimplifier::simplify(g1
, tolerance
));
4063 catch (const std::exception
&e
)
4065 handle
->ERROR_MESSAGE("%s", e
.what());
4069 handle
->ERROR_MESSAGE("Unknown exception thrown");
4076 GEOSTopologyPreserveSimplify_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, double tolerance
)
4078 if ( 0 == extHandle
)
4083 GEOSContextHandleInternal_t
*handle
= 0;
4084 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4085 if ( 0 == handle
->initialized
)
4092 using namespace geos::simplify
;
4093 Geometry::AutoPtr
g(TopologyPreservingSimplifier::simplify(g1
, tolerance
));
4096 catch (const std::exception
&e
)
4098 handle
->ERROR_MESSAGE("%s", e
.what());
4102 handle
->ERROR_MESSAGE("Unknown exception thrown");
4111 GEOSWKTReader_create_r(GEOSContextHandle_t extHandle
)
4113 if ( 0 == extHandle
)
4118 GEOSContextHandleInternal_t
*handle
= 0;
4119 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4120 if ( 0 == handle
->initialized
)
4127 using geos::io::WKTReader
;
4128 return new WKTReader((GeometryFactory
*)handle
->geomFactory
);
4130 catch (const std::exception
&e
)
4132 handle
->ERROR_MESSAGE("%s", e
.what());
4136 handle
->ERROR_MESSAGE("Unknown exception thrown");
4143 GEOSWKTReader_destroy_r(GEOSContextHandle_t extHandle
, WKTReader
*reader
)
4145 GEOSContextHandleInternal_t
*handle
= 0;
4151 catch (const std::exception
&e
)
4153 if ( 0 == extHandle
)
4158 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4159 if ( 0 == handle
->initialized
)
4164 handle
->ERROR_MESSAGE("%s", e
.what());
4168 if ( 0 == extHandle
)
4173 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4174 if ( 0 == handle
->initialized
)
4179 handle
->ERROR_MESSAGE("Unknown exception thrown");
4185 GEOSWKTReader_read_r(GEOSContextHandle_t extHandle
, WKTReader
*reader
, const char *wkt
)
4187 assert(0 != reader
);
4189 if ( 0 == extHandle
)
4194 GEOSContextHandleInternal_t
*handle
= 0;
4195 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4196 if ( 0 == handle
->initialized
)
4203 const std::string
wktstring(wkt
);
4204 Geometry
*g
= reader
->read(wktstring
);
4207 catch (const std::exception
&e
)
4209 handle
->ERROR_MESSAGE("%s", e
.what());
4213 handle
->ERROR_MESSAGE("Unknown exception thrown");
4221 GEOSWKTWriter_create_r(GEOSContextHandle_t extHandle
)
4223 if ( 0 == extHandle
)
4228 GEOSContextHandleInternal_t
*handle
= 0;
4229 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4230 if ( 0 == handle
->initialized
)
4237 using geos::io::WKTWriter
;
4238 return new WKTWriter();
4240 catch (const std::exception
&e
)
4242 handle
->ERROR_MESSAGE("%s", e
.what());
4246 handle
->ERROR_MESSAGE("Unknown exception thrown");
4253 GEOSWKTWriter_destroy_r(GEOSContextHandle_t extHandle
, WKTWriter
*Writer
)
4256 GEOSContextHandleInternal_t
*handle
= 0;
4262 catch (const std::exception
&e
)
4264 if ( 0 == extHandle
)
4269 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4270 if ( 0 == handle
->initialized
)
4275 handle
->ERROR_MESSAGE("%s", e
.what());
4279 if ( 0 == extHandle
)
4284 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4285 if ( 0 == handle
->initialized
)
4290 handle
->ERROR_MESSAGE("Unknown exception thrown");
4296 GEOSWKTWriter_write_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, const Geometry
*geom
)
4298 assert(0 != writer
);
4300 if ( 0 == extHandle
)
4305 GEOSContextHandleInternal_t
*handle
= 0;
4306 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4307 if ( 0 == handle
->initialized
)
4314 std::string
sgeom(writer
->write(geom
));
4315 char *result
= gstrdup(sgeom
);
4318 catch (const std::exception
&e
)
4320 handle
->ERROR_MESSAGE("%s", e
.what());
4324 handle
->ERROR_MESSAGE("Unknown exception thrown");
4331 GEOSWKTWriter_setTrim_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, char trim
)
4333 assert(0 != writer
);
4335 if ( 0 == extHandle
)
4340 GEOSContextHandleInternal_t
*handle
= 0;
4341 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4342 if ( 0 == handle
->initialized
)
4347 writer
->setTrim(0 != trim
);
4351 GEOSWKTWriter_setRoundingPrecision_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int precision
)
4353 assert(0 != writer
);
4355 if ( 0 == extHandle
)
4360 GEOSContextHandleInternal_t
*handle
= 0;
4361 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4362 if ( 0 == handle
->initialized
)
4367 writer
->setRoundingPrecision(precision
);
4371 GEOSWKTWriter_setOutputDimension_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int dim
)
4373 assert(0 != writer
);
4375 if ( 0 == extHandle
)
4380 GEOSContextHandleInternal_t
*handle
= 0;
4381 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4382 if ( 0 == handle
->initialized
)
4389 writer
->setOutputDimension(dim
);
4391 catch (const std::exception
&e
)
4393 handle
->ERROR_MESSAGE("%s", e
.what());
4397 handle
->ERROR_MESSAGE("Unknown exception thrown");
4402 GEOSWKTWriter_getOutputDimension_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
)
4404 assert(0 != writer
);
4406 if ( 0 == extHandle
)
4411 GEOSContextHandleInternal_t
*handle
= 0;
4412 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4413 if ( 0 == handle
->initialized
)
4422 dim
= writer
->getOutputDimension();
4424 catch (const std::exception
&e
)
4426 handle
->ERROR_MESSAGE("%s", e
.what());
4430 handle
->ERROR_MESSAGE("Unknown exception thrown");
4437 GEOSWKTWriter_setOld3D_r(GEOSContextHandle_t extHandle
, WKTWriter
*writer
, int useOld3D
)
4439 assert(0 != writer
);
4441 if ( 0 == extHandle
)
4446 GEOSContextHandleInternal_t
*handle
= 0;
4447 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4448 if ( 0 == handle
->initialized
)
4453 writer
->setOld3D(0 != useOld3D
);
4458 GEOSWKBReader_create_r(GEOSContextHandle_t extHandle
)
4460 if ( 0 == extHandle
)
4465 GEOSContextHandleInternal_t
*handle
= 0;
4466 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4467 if ( 0 == handle
->initialized
)
4472 using geos::io::WKBReader
;
4475 return new WKBReader(*(GeometryFactory
*)handle
->geomFactory
);
4477 catch (const std::exception
&e
)
4479 handle
->ERROR_MESSAGE("%s", e
.what());
4483 handle
->ERROR_MESSAGE("Unknown exception thrown");
4490 GEOSWKBReader_destroy_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
)
4492 GEOSContextHandleInternal_t
*handle
= 0;
4498 catch (const std::exception
&e
)
4500 if ( 0 == extHandle
)
4505 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4506 if ( 0 == handle
->initialized
)
4511 handle
->ERROR_MESSAGE("%s", e
.what());
4515 if ( 0 == extHandle
)
4520 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4521 if ( 0 == handle
->initialized
)
4526 handle
->ERROR_MESSAGE("Unknown exception thrown");
4532 GEOSWKBReader_read_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
, const unsigned char *wkb
, size_t size
)
4534 assert(0 != reader
);
4537 if ( 0 == extHandle
)
4542 GEOSContextHandleInternal_t
*handle
= 0;
4543 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4544 if ( 0 == handle
->initialized
)
4551 std::string
wkbstring(reinterpret_cast<const char*>(wkb
), size
); // make it binary !
4552 std::istringstream
is(std::ios_base::binary
);
4554 is
.seekg(0, std::ios::beg
); // rewind reader pointer
4556 Geometry
*g
= reader
->read(is
);
4559 catch (const std::exception
&e
)
4561 handle
->ERROR_MESSAGE("%s", e
.what());
4565 handle
->ERROR_MESSAGE("Unknown exception thrown");
4572 GEOSWKBReader_readHEX_r(GEOSContextHandle_t extHandle
, WKBReader
*reader
, const unsigned char *hex
, size_t size
)
4574 assert(0 != reader
);
4577 if ( 0 == extHandle
)
4582 GEOSContextHandleInternal_t
*handle
= 0;
4583 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4584 if ( 0 == handle
->initialized
)
4591 std::string
hexstring(reinterpret_cast<const char*>(hex
), size
);
4592 std::istringstream
is(std::ios_base::binary
);
4594 is
.seekg(0, std::ios::beg
); // rewind reader pointer
4596 Geometry
*g
= reader
->readHEX(is
);
4599 catch (const std::exception
&e
)
4601 handle
->ERROR_MESSAGE("%s", e
.what());
4605 handle
->ERROR_MESSAGE("Unknown exception thrown");
4613 GEOSWKBWriter_create_r(GEOSContextHandle_t extHandle
)
4615 if ( 0 == extHandle
)
4620 GEOSContextHandleInternal_t
*handle
= 0;
4621 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4622 if ( 0 == handle
->initialized
)
4629 using geos::io::WKBWriter
;
4630 return new WKBWriter();
4632 catch (const std::exception
&e
)
4634 handle
->ERROR_MESSAGE("%s", e
.what());
4638 handle
->ERROR_MESSAGE("Unknown exception thrown");
4645 GEOSWKBWriter_destroy_r(GEOSContextHandle_t extHandle
, WKBWriter
*Writer
)
4647 GEOSContextHandleInternal_t
*handle
= 0;
4653 catch (const std::exception
&e
)
4655 if ( 0 == extHandle
)
4660 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4661 if ( 0 == handle
->initialized
)
4666 handle
->ERROR_MESSAGE("%s", e
.what());
4670 if ( 0 == extHandle
)
4675 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4676 if ( 0 == handle
->initialized
)
4681 handle
->ERROR_MESSAGE("Unknown exception thrown");
4686 /* The caller owns the result */
4688 GEOSWKBWriter_write_r(GEOSContextHandle_t extHandle
, WKBWriter
*writer
, const Geometry
*geom
, size_t *size
)
4690 assert(0 != writer
);
4694 if ( 0 == extHandle
)
4699 GEOSContextHandleInternal_t
*handle
= 0;
4700 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4701 if ( 0 == handle
->initialized
)
4708 std::ostringstream
os(std::ios_base::binary
);
4709 writer
->write(*geom
, os
);
4710 std::string
wkbstring(os
.str());
4711 const std::size_t len
= wkbstring
.length();
4713 unsigned char *result
= NULL
;
4714 result
= (unsigned char*) std::malloc(len
);
4715 std::memcpy(result
, wkbstring
.c_str(), len
);
4719 catch (const std::exception
&e
)
4721 handle
->ERROR_MESSAGE("%s", e
.what());
4725 handle
->ERROR_MESSAGE("Unknown exception thrown");
4730 /* The caller owns the result */
4732 GEOSWKBWriter_writeHEX_r(GEOSContextHandle_t extHandle
, WKBWriter
*writer
, const Geometry
*geom
, size_t *size
)
4734 assert(0 != writer
);
4738 if ( 0 == extHandle
)
4743 GEOSContextHandleInternal_t
*handle
= 0;
4744 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4745 if ( 0 == handle
->initialized
)
4752 std::ostringstream
os(std::ios_base::binary
);
4753 writer
->writeHEX(*geom
, os
);
4754 std::string
wkbstring(os
.str());
4755 const std::size_t len
= wkbstring
.length();
4757 unsigned char *result
= NULL
;
4758 result
= (unsigned char*) std::malloc(len
);
4759 std::memcpy(result
, wkbstring
.c_str(), len
);
4763 catch (const std::exception
&e
)
4765 handle
->ERROR_MESSAGE("%s", e
.what());
4769 handle
->ERROR_MESSAGE("Unknown exception thrown");
4776 GEOSWKBWriter_getOutputDimension_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
4778 assert(0 != writer
);
4780 if ( 0 == extHandle
)
4787 GEOSContextHandleInternal_t
*handle
= 0;
4788 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4789 if ( 0 != handle
->initialized
)
4793 ret
= writer
->getOutputDimension();
4797 handle
->ERROR_MESSAGE("Unknown exception thrown");
4805 GEOSWKBWriter_setOutputDimension_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, int newDimension
)
4807 assert(0 != writer
);
4809 if ( 0 == extHandle
)
4814 GEOSContextHandleInternal_t
*handle
= 0;
4815 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4816 if ( 0 != handle
->initialized
)
4820 writer
->setOutputDimension(newDimension
);
4822 catch (const std::exception
&e
)
4824 handle
->ERROR_MESSAGE("%s", e
.what());
4828 handle
->ERROR_MESSAGE("Unknown exception thrown");
4834 GEOSWKBWriter_getByteOrder_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
4836 assert(0 != writer
);
4838 if ( 0 == extHandle
)
4845 GEOSContextHandleInternal_t
*handle
= 0;
4846 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4847 if ( 0 != handle
->initialized
)
4851 ret
= writer
->getByteOrder();
4856 handle
->ERROR_MESSAGE("Unknown exception thrown");
4864 GEOSWKBWriter_setByteOrder_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, int newByteOrder
)
4866 assert(0 != writer
);
4868 if ( 0 == extHandle
)
4873 GEOSContextHandleInternal_t
*handle
= 0;
4874 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4875 if ( 0 != handle
->initialized
)
4879 writer
->setByteOrder(newByteOrder
);
4881 catch (const std::exception
&e
)
4883 handle
->ERROR_MESSAGE("%s", e
.what());
4887 handle
->ERROR_MESSAGE("Unknown exception thrown");
4893 GEOSWKBWriter_getIncludeSRID_r(GEOSContextHandle_t extHandle
, const GEOSWKBWriter
* writer
)
4895 assert(0 != writer
);
4897 if ( 0 == extHandle
)
4904 GEOSContextHandleInternal_t
*handle
= 0;
4905 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4906 if ( 0 != handle
->initialized
)
4910 int srid
= writer
->getIncludeSRID();
4911 ret
= static_cast<char>(srid
);
4915 handle
->ERROR_MESSAGE("Unknown exception thrown");
4919 return static_cast<char>(ret
);
4923 GEOSWKBWriter_setIncludeSRID_r(GEOSContextHandle_t extHandle
, GEOSWKBWriter
* writer
, const char newIncludeSRID
)
4925 assert(0 != writer
);
4927 if ( 0 == extHandle
)
4932 GEOSContextHandleInternal_t
*handle
= 0;
4933 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4934 if ( 0 != handle
->initialized
)
4938 writer
->setIncludeSRID(newIncludeSRID
);
4942 handle
->ERROR_MESSAGE("Unknown exception thrown");
4948 //-----------------------------------------------------------------
4949 // Prepared Geometry
4950 //-----------------------------------------------------------------
4952 const geos::geom::prep::PreparedGeometry
*
4953 GEOSPrepare_r(GEOSContextHandle_t extHandle
, const Geometry
*g
)
4955 if ( 0 == extHandle
)
4960 GEOSContextHandleInternal_t
*handle
= 0;
4961 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
4962 if ( 0 == handle
->initialized
)
4967 const geos::geom::prep::PreparedGeometry
* prep
= 0;
4971 prep
= geos::geom::prep::PreparedGeometryFactory::prepare(g
);
4973 catch (const std::exception
&e
)
4975 handle
->ERROR_MESSAGE("%s", e
.what());
4979 handle
->ERROR_MESSAGE("Unknown exception thrown");
4986 GEOSPreparedGeom_destroy_r(GEOSContextHandle_t extHandle
, const geos::geom::prep::PreparedGeometry
*a
)
4988 GEOSContextHandleInternal_t
*handle
= 0;
4994 catch (const std::exception
&e
)
4996 if ( 0 == extHandle
)
5001 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5002 if ( 0 == handle
->initialized
)
5007 handle
->ERROR_MESSAGE("%s", e
.what());
5011 if ( 0 == extHandle
)
5016 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5017 if ( 0 == handle
->initialized
)
5022 handle
->ERROR_MESSAGE("Unknown exception thrown");
5027 GEOSPreparedContains_r(GEOSContextHandle_t extHandle
,
5028 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5033 if ( 0 == extHandle
)
5038 GEOSContextHandleInternal_t
*handle
= 0;
5039 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5040 if ( 0 == handle
->initialized
)
5047 bool result
= pg
->contains(g
);
5050 catch (const std::exception
&e
)
5052 handle
->ERROR_MESSAGE("%s", e
.what());
5056 handle
->ERROR_MESSAGE("Unknown exception thrown");
5063 GEOSPreparedContainsProperly_r(GEOSContextHandle_t extHandle
,
5064 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5069 if ( 0 == extHandle
)
5074 GEOSContextHandleInternal_t
*handle
= 0;
5075 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5076 if ( 0 == handle
->initialized
)
5083 bool result
= pg
->containsProperly(g
);
5086 catch (const std::exception
&e
)
5088 handle
->ERROR_MESSAGE("%s", e
.what());
5092 handle
->ERROR_MESSAGE("Unknown exception thrown");
5099 GEOSPreparedCoveredBy_r(GEOSContextHandle_t extHandle
,
5100 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5105 if ( 0 == extHandle
)
5110 GEOSContextHandleInternal_t
*handle
= 0;
5111 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5112 if ( 0 == handle
->initialized
)
5119 bool result
= pg
->coveredBy(g
);
5122 catch (const std::exception
&e
)
5124 handle
->ERROR_MESSAGE("%s", e
.what());
5128 handle
->ERROR_MESSAGE("Unknown exception thrown");
5135 GEOSPreparedCovers_r(GEOSContextHandle_t extHandle
,
5136 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5141 if ( 0 == extHandle
)
5146 GEOSContextHandleInternal_t
*handle
= 0;
5147 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5148 if ( 0 == handle
->initialized
)
5155 bool result
= pg
->covers(g
);
5158 catch (const std::exception
&e
)
5160 handle
->ERROR_MESSAGE("%s", e
.what());
5164 handle
->ERROR_MESSAGE("Unknown exception thrown");
5171 GEOSPreparedCrosses_r(GEOSContextHandle_t extHandle
,
5172 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5177 if ( 0 == extHandle
)
5182 GEOSContextHandleInternal_t
*handle
= 0;
5183 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5184 if ( 0 == handle
->initialized
)
5191 bool result
= pg
->crosses(g
);
5194 catch (const std::exception
&e
)
5196 handle
->ERROR_MESSAGE("%s", e
.what());
5200 handle
->ERROR_MESSAGE("Unknown exception thrown");
5207 GEOSPreparedDisjoint_r(GEOSContextHandle_t extHandle
,
5208 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5213 if ( 0 == extHandle
)
5218 GEOSContextHandleInternal_t
*handle
= 0;
5219 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5220 if ( 0 == handle
->initialized
)
5227 bool result
= pg
->disjoint(g
);
5230 catch (const std::exception
&e
)
5232 handle
->ERROR_MESSAGE("%s", e
.what());
5236 handle
->ERROR_MESSAGE("Unknown exception thrown");
5243 GEOSPreparedIntersects_r(GEOSContextHandle_t extHandle
,
5244 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5249 if ( 0 == extHandle
)
5254 GEOSContextHandleInternal_t
*handle
= 0;
5255 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5256 if ( 0 == handle
->initialized
)
5263 bool result
= pg
->intersects(g
);
5266 catch (const std::exception
&e
)
5268 handle
->ERROR_MESSAGE("%s", e
.what());
5272 handle
->ERROR_MESSAGE("Unknown exception thrown");
5279 GEOSPreparedOverlaps_r(GEOSContextHandle_t extHandle
,
5280 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5285 if ( 0 == extHandle
)
5290 GEOSContextHandleInternal_t
*handle
= 0;
5291 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5292 if ( 0 == handle
->initialized
)
5299 bool result
= pg
->overlaps(g
);
5302 catch (const std::exception
&e
)
5304 handle
->ERROR_MESSAGE("%s", e
.what());
5308 handle
->ERROR_MESSAGE("Unknown exception thrown");
5315 GEOSPreparedTouches_r(GEOSContextHandle_t extHandle
,
5316 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5321 if ( 0 == extHandle
)
5326 GEOSContextHandleInternal_t
*handle
= 0;
5327 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5328 if ( 0 == handle
->initialized
)
5335 bool result
= pg
->touches(g
);
5338 catch (const std::exception
&e
)
5340 handle
->ERROR_MESSAGE("%s", e
.what());
5344 handle
->ERROR_MESSAGE("Unknown exception thrown");
5351 GEOSPreparedWithin_r(GEOSContextHandle_t extHandle
,
5352 const geos::geom::prep::PreparedGeometry
*pg
, const Geometry
*g
)
5357 if ( 0 == extHandle
)
5362 GEOSContextHandleInternal_t
*handle
= 0;
5363 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5364 if ( 0 == handle
->initialized
)
5371 bool result
= pg
->within(g
);
5374 catch (const std::exception
&e
)
5376 handle
->ERROR_MESSAGE("%s", e
.what());
5380 handle
->ERROR_MESSAGE("Unknown exception thrown");
5386 //-----------------------------------------------------------------
5388 //-----------------------------------------------------------------
5390 geos::index::strtree::STRtree
*
5391 GEOSSTRtree_create_r(GEOSContextHandle_t extHandle
,
5392 size_t nodeCapacity
)
5394 if ( 0 == extHandle
)
5399 GEOSContextHandleInternal_t
*handle
= 0;
5400 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5401 if ( 0 == handle
->initialized
)
5406 geos::index::strtree::STRtree
*tree
= 0;
5410 tree
= new geos::index::strtree::STRtree(nodeCapacity
);
5412 catch (const std::exception
&e
)
5414 handle
->ERROR_MESSAGE("%s", e
.what());
5418 handle
->ERROR_MESSAGE("Unknown exception thrown");
5425 GEOSSTRtree_insert_r(GEOSContextHandle_t extHandle
,
5426 geos::index::strtree::STRtree
*tree
,
5427 const geos::geom::Geometry
*g
,
5430 GEOSContextHandleInternal_t
*handle
= 0;
5436 tree
->insert(g
->getEnvelopeInternal(), item
);
5438 catch (const std::exception
&e
)
5440 if ( 0 == extHandle
)
5445 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5446 if ( 0 == handle
->initialized
)
5451 handle
->ERROR_MESSAGE("%s", e
.what());
5455 if ( 0 == extHandle
)
5460 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5461 if ( 0 == handle
->initialized
)
5466 handle
->ERROR_MESSAGE("Unknown exception thrown");
5471 GEOSSTRtree_query_r(GEOSContextHandle_t extHandle
,
5472 geos::index::strtree::STRtree
*tree
,
5473 const geos::geom::Geometry
*g
,
5474 GEOSQueryCallback callback
,
5477 GEOSContextHandleInternal_t
*handle
= 0;
5480 assert(callback
!= 0);
5484 CAPI_ItemVisitor
visitor(callback
, userdata
);
5485 tree
->query(g
->getEnvelopeInternal(), visitor
);
5487 catch (const std::exception
&e
)
5489 if ( 0 == extHandle
)
5494 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5495 if ( 0 == handle
->initialized
)
5500 handle
->ERROR_MESSAGE("%s", e
.what());
5504 if ( 0 == extHandle
)
5509 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5510 if ( 0 == handle
->initialized
)
5515 handle
->ERROR_MESSAGE("Unknown exception thrown");
5520 GEOSSTRtree_iterate_r(GEOSContextHandle_t extHandle
,
5521 geos::index::strtree::STRtree
*tree
,
5522 GEOSQueryCallback callback
,
5525 GEOSContextHandleInternal_t
*handle
= 0;
5527 assert(callback
!= 0);
5531 CAPI_ItemVisitor
visitor(callback
, userdata
);
5532 tree
->iterate(visitor
);
5534 catch (const std::exception
&e
)
5536 if ( 0 == extHandle
)
5541 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5542 if ( 0 == handle
->initialized
)
5547 handle
->ERROR_MESSAGE("%s", e
.what());
5551 if ( 0 == extHandle
)
5556 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5557 if ( 0 == handle
->initialized
)
5562 handle
->ERROR_MESSAGE("Unknown exception thrown");
5567 GEOSSTRtree_remove_r(GEOSContextHandle_t extHandle
,
5568 geos::index::strtree::STRtree
*tree
,
5569 const geos::geom::Geometry
*g
,
5575 if ( 0 == extHandle
)
5580 GEOSContextHandleInternal_t
*handle
= 0;
5581 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5582 if ( 0 == handle
->initialized
)
5589 bool result
= tree
->remove(g
->getEnvelopeInternal(), item
);
5592 catch (const std::exception
&e
)
5594 handle
->ERROR_MESSAGE("%s", e
.what());
5598 handle
->ERROR_MESSAGE("Unknown exception thrown");
5605 GEOSSTRtree_destroy_r(GEOSContextHandle_t extHandle
,
5606 geos::index::strtree::STRtree
*tree
)
5608 GEOSContextHandleInternal_t
*handle
= 0;
5614 catch (const std::exception
&e
)
5616 if ( 0 == extHandle
)
5621 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5622 if ( 0 == handle
->initialized
)
5627 handle
->ERROR_MESSAGE("%s", e
.what());
5631 if ( 0 == extHandle
)
5636 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5637 if ( 0 == handle
->initialized
)
5642 handle
->ERROR_MESSAGE("Unknown exception thrown");
5647 GEOSProject_r(GEOSContextHandle_t extHandle
,
5651 if ( 0 == extHandle
) return -1.0;
5652 GEOSContextHandleInternal_t
*handle
=
5653 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5654 if ( handle
->initialized
== 0 ) return -1.0;
5656 const geos::geom::Point
* point
= dynamic_cast<const geos::geom::Point
*>(p
);
5658 handle
->ERROR_MESSAGE("third argument of GEOSProject_r must be Point*");
5662 const geos::geom::Coordinate
* inputPt
= p
->getCoordinate();
5665 return geos::linearref::LengthIndexedLine(g
).project(*inputPt
);
5666 } catch (const std::exception
&e
) {
5667 handle
->ERROR_MESSAGE("%s", e
.what());
5670 handle
->ERROR_MESSAGE("Unknown exception thrown");
5677 GEOSInterpolate_r(GEOSContextHandle_t extHandle
, const Geometry
*g
, double d
)
5679 if ( 0 == extHandle
) return 0;
5680 GEOSContextHandleInternal_t
*handle
=
5681 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5682 if ( handle
->initialized
== 0 ) return 0;
5685 geos::linearref::LengthIndexedLine
lil(g
);
5686 geos::geom::Coordinate coord
= lil
.extractPoint(d
);
5687 const GeometryFactory
*gf
= handle
->geomFactory
;
5688 Geometry
* point
= gf
->createPoint(coord
);
5690 } catch (const std::exception
&e
) {
5691 handle
->ERROR_MESSAGE("%s", e
.what());
5694 handle
->ERROR_MESSAGE("Unknown exception thrown");
5701 GEOSProjectNormalized_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
5706 GEOSLength_r(extHandle
, g
, &length
);
5707 return GEOSProject_r(extHandle
, g
, p
) / length
;
5712 GEOSInterpolateNormalized_r(GEOSContextHandle_t extHandle
, const Geometry
*g
,
5716 GEOSLength_r(extHandle
, g
, &length
);
5717 return GEOSInterpolate_r(extHandle
, g
, d
* length
);
5721 GEOSGeom_extractUniquePoints_r(GEOSContextHandle_t extHandle
,
5722 const GEOSGeometry
* g
)
5724 if ( 0 == extHandle
) return 0;
5725 GEOSContextHandleInternal_t
*handle
= 0;
5726 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5727 if ( handle
->initialized
== 0 ) return 0;
5729 using namespace geos::geom
;
5730 using namespace geos::util
;
5735 /* 1: extract points */
5736 std::vector
<const Coordinate
*> coords
;
5737 UniqueCoordinateArrayFilter
filter(coords
);
5738 g
->apply_ro(&filter
);
5740 /* 2: for each point, create a geometry and put into a vector */
5741 std::vector
<Geometry
*>* points
= new std::vector
<Geometry
*>();
5742 points
->reserve(coords
.size());
5743 const GeometryFactory
* factory
= g
->getFactory();
5744 for (std::vector
<const Coordinate
*>::iterator it
=coords
.begin(),
5748 Geometry
* point
= factory
->createPoint(*(*it
));
5749 points
->push_back(point
);
5752 /* 3: create a multipoint */
5753 return factory
->createMultiPoint(points
);
5756 catch (const std::exception
&e
)
5758 handle
->ERROR_MESSAGE("%s", e
.what());
5763 handle
->ERROR_MESSAGE("Unknown exception thrown");
5768 int GEOSOrientationIndex_r(GEOSContextHandle_t extHandle
,
5769 double Ax
, double Ay
, double Bx
, double By
, double Px
, double Py
)
5771 GEOSContextHandleInternal_t
*handle
= 0;
5773 using geos::geom::Coordinate
;
5774 using geos::algorithm::CGAlgorithms
;
5776 if ( 0 == extHandle
)
5781 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5782 if ( 0 == handle
->initialized
)
5789 Coordinate
A(Ax
, Ay
);
5790 Coordinate
B(Bx
, By
);
5791 Coordinate
P(Px
, Py
);
5792 return CGAlgorithms::orientationIndex(A
, B
, P
);
5794 catch (const std::exception
&e
)
5796 handle
->ERROR_MESSAGE("%s", e
.what());
5801 handle
->ERROR_MESSAGE("Unknown exception thrown");
5807 GEOSSharedPaths_r(GEOSContextHandle_t extHandle
, const GEOSGeometry
* g1
, const GEOSGeometry
* g2
)
5809 using namespace geos::operation::sharedpaths
;
5811 if ( 0 == extHandle
) return 0;
5812 GEOSContextHandleInternal_t
*handle
=
5813 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5814 if ( handle
->initialized
== 0 ) return 0;
5816 SharedPathsOp::PathList forw
, back
;
5818 SharedPathsOp::sharedPathsOp(*g1
, *g2
, forw
, back
);
5820 catch (const std::exception
&e
)
5822 SharedPathsOp::clearEdges(forw
);
5823 SharedPathsOp::clearEdges(back
);
5824 handle
->ERROR_MESSAGE("%s", e
.what());
5829 SharedPathsOp::clearEdges(forw
);
5830 SharedPathsOp::clearEdges(back
);
5831 handle
->ERROR_MESSAGE("Unknown exception thrown");
5835 // Now forw and back have the geoms we want to use to construct
5836 // our output GeometryCollections...
5838 const GeometryFactory
* factory
= g1
->getFactory();
5841 std::auto_ptr
< std::vector
<Geometry
*> > out1(
5842 new std::vector
<Geometry
*>()
5844 count
= forw
.size();
5845 out1
->reserve(count
);
5846 for (size_t i
=0; i
<count
; ++i
) {
5847 out1
->push_back(forw
[i
]);
5849 std::auto_ptr
<Geometry
> out1g (
5850 factory
->createMultiLineString(out1
.release())
5853 std::auto_ptr
< std::vector
<Geometry
*> > out2(
5854 new std::vector
<Geometry
*>()
5856 count
= back
.size();
5857 out2
->reserve(count
);
5858 for (size_t i
=0; i
<count
; ++i
) {
5859 out2
->push_back(back
[i
]);
5861 std::auto_ptr
<Geometry
> out2g (
5862 factory
->createMultiLineString(out2
.release())
5865 std::auto_ptr
< std::vector
<Geometry
*> > out(
5866 new std::vector
<Geometry
*>()
5869 out
->push_back(out1g
.release());
5870 out
->push_back(out2g
.release());
5872 std::auto_ptr
<Geometry
> outg (
5873 factory
->createGeometryCollection(out
.release())
5876 return outg
.release();
5881 GEOSSnap_r(GEOSContextHandle_t extHandle
, const GEOSGeometry
* g1
,
5882 const GEOSGeometry
* g2
, double tolerance
)
5884 using namespace geos::operation::overlay::snap
;
5886 if ( 0 == extHandle
) return 0;
5887 GEOSContextHandleInternal_t
*handle
=
5888 reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5889 if ( handle
->initialized
== 0 ) return 0;
5892 GeometrySnapper
snapper( *g1
);
5893 std::auto_ptr
<Geometry
> ret
= snapper
.snapTo(*g2
, tolerance
);
5894 return ret
.release();
5896 catch (const std::exception
&e
)
5898 handle
->ERROR_MESSAGE("%s", e
.what());
5903 handle
->ERROR_MESSAGE("Unknown exception thrown");
5909 GEOSBufferParams_create_r(GEOSContextHandle_t extHandle
)
5911 if ( 0 == extHandle
) return NULL
;
5913 GEOSContextHandleInternal_t
*handle
= 0;
5914 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5915 if ( 0 == handle
->initialized
) return NULL
;
5919 BufferParameters
*p
= new BufferParameters();
5922 catch (const std::exception
&e
)
5924 handle
->ERROR_MESSAGE("%s", e
.what());
5928 handle
->ERROR_MESSAGE("Unknown exception thrown");
5935 GEOSBufferParams_destroy_r(GEOSContextHandle_t extHandle
, BufferParameters
* p
)
5941 GEOSBufferParams_setEndCapStyle_r(GEOSContextHandle_t extHandle
,
5942 GEOSBufferParams
* p
, int style
)
5944 if ( 0 == extHandle
) return 0;
5946 GEOSContextHandleInternal_t
*handle
= 0;
5947 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5948 if ( 0 == handle
->initialized
) return 0;
5952 if ( style
> BufferParameters::CAP_SQUARE
)
5954 throw IllegalArgumentException("Invalid buffer endCap style");
5956 p
->setEndCapStyle(static_cast<BufferParameters::EndCapStyle
>(style
));
5959 catch (const std::exception
&e
)
5961 handle
->ERROR_MESSAGE("%s", e
.what());
5965 handle
->ERROR_MESSAGE("Unknown exception thrown");
5972 GEOSBufferParams_setJoinStyle_r(GEOSContextHandle_t extHandle
,
5973 GEOSBufferParams
* p
, int style
)
5975 if ( 0 == extHandle
) return 0;
5977 GEOSContextHandleInternal_t
*handle
= 0;
5978 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
5979 if ( 0 == handle
->initialized
) return 0;
5983 if ( style
> BufferParameters::JOIN_BEVEL
) {
5984 throw IllegalArgumentException("Invalid buffer join style");
5986 p
->setJoinStyle(static_cast<BufferParameters::JoinStyle
>(style
));
5989 catch (const std::exception
&e
)
5991 handle
->ERROR_MESSAGE("%s", e
.what());
5995 handle
->ERROR_MESSAGE("Unknown exception thrown");
6002 GEOSBufferParams_setMitreLimit_r(GEOSContextHandle_t extHandle
,
6003 GEOSBufferParams
* p
, double limit
)
6005 if ( 0 == extHandle
) return 0;
6007 GEOSContextHandleInternal_t
*handle
= 0;
6008 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6009 if ( 0 == handle
->initialized
) return 0;
6013 p
->setMitreLimit(limit
);
6016 catch (const std::exception
&e
)
6018 handle
->ERROR_MESSAGE("%s", e
.what());
6022 handle
->ERROR_MESSAGE("Unknown exception thrown");
6029 GEOSBufferParams_setQuadrantSegments_r(GEOSContextHandle_t extHandle
,
6030 GEOSBufferParams
* p
, int segs
)
6032 if ( 0 == extHandle
) return 0;
6034 GEOSContextHandleInternal_t
*handle
= 0;
6035 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6036 if ( 0 == handle
->initialized
) return 0;
6040 p
->setQuadrantSegments(segs
);
6043 catch (const std::exception
&e
)
6045 handle
->ERROR_MESSAGE("%s", e
.what());
6049 handle
->ERROR_MESSAGE("Unknown exception thrown");
6056 GEOSBufferParams_setSingleSided_r(GEOSContextHandle_t extHandle
,
6057 GEOSBufferParams
* p
, int ss
)
6059 if ( 0 == extHandle
) return 0;
6061 GEOSContextHandleInternal_t
*handle
= 0;
6062 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6063 if ( 0 == handle
->initialized
) return 0;
6067 p
->setSingleSided( (ss
!= 0) );
6070 catch (const std::exception
&e
)
6072 handle
->ERROR_MESSAGE("%s", e
.what());
6076 handle
->ERROR_MESSAGE("Unknown exception thrown");
6083 GEOSBufferWithParams_r(GEOSContextHandle_t extHandle
, const Geometry
*g1
, const BufferParameters
* bp
, double width
)
6085 using geos::operation::buffer::BufferOp
;
6087 if ( 0 == extHandle
) return NULL
;
6089 GEOSContextHandleInternal_t
*handle
= 0;
6090 handle
= reinterpret_cast<GEOSContextHandleInternal_t
*>(extHandle
);
6091 if ( 0 == handle
->initialized
) return NULL
;
6095 BufferOp
op(g1
, *bp
);
6096 Geometry
*g3
= op
.getResultGeometry(width
);
6099 catch (const std::exception
&e
)
6101 handle
->ERROR_MESSAGE("%s", e
.what());
6105 handle
->ERROR_MESSAGE("Unknown exception thrown");