geos_c.h 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850
  1. /************************************************************************
  2. *
  3. *
  4. * C-Wrapper for GEOS library
  5. *
  6. * Copyright (C) 2010 2011 Sandro Santilli <strk@keybit.net>
  7. * Copyright (C) 2005 Refractions Research Inc.
  8. *
  9. * This is free software; you can redistribute and/or modify it under
  10. * the terms of the GNU Lesser General Public Licence as published
  11. * by the Free Software Foundation.
  12. * See the COPYING file for more information.
  13. *
  14. * Author: Sandro Santilli <strk@keybit.net>
  15. *
  16. ***********************************************************************
  17. *
  18. * GENERAL NOTES:
  19. *
  20. * - Remember to call initGEOS() before any use of this library's
  21. * functions, and call finishGEOS() when done.
  22. *
  23. * - Currently you have to explicitly GEOSGeom_destroy() all
  24. * GEOSGeom objects to avoid memory leaks, and to GEOSFree()
  25. * all returned char * (unless const).
  26. *
  27. * - Functions ending with _r are thread safe; see details in RFC 3
  28. * http://trac.osgeo.org/geos/wiki/RFC3.
  29. * To avoid using by accident non _r functions,
  30. * define GEOS_USE_ONLY_R_API before including geos_c.h
  31. *
  32. ***********************************************************************/
  33. #ifndef GEOS_C_H_INCLUDED
  34. #define GEOS_C_H_INCLUDED
  35. #ifndef __cplusplus
  36. # include <stddef.h> /* for size_t definition */
  37. #else
  38. # include <cstddef>
  39. using std::size_t;
  40. #endif
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /************************************************************************
  45. *
  46. * Version
  47. *
  48. ***********************************************************************/
  49. /*
  50. * Following 'ifdef' hack fixes problem with generating geos_c.h on Windows,
  51. * when building with Visual C++ compiler.
  52. *
  53. */
  54. #if defined(_MSC_VER)
  55. #include <geos/version.h>
  56. #define GEOS_CAPI_VERSION_MAJOR 1
  57. #define GEOS_CAPI_VERSION_MINOR 9
  58. #define GEOS_CAPI_VERSION_PATCH 0
  59. #define GEOS_CAPI_VERSION "3.5.0-CAPI-1.9.0"
  60. #else
  61. #ifndef GEOS_VERSION_MAJOR
  62. #define GEOS_VERSION_MAJOR 3
  63. #endif
  64. #ifndef GEOS_VERSION_MINOR
  65. #define GEOS_VERSION_MINOR 5
  66. #endif
  67. #ifndef GEOS_VERSION_PATCH
  68. #define GEOS_VERSION_PATCH 0
  69. #endif
  70. #ifndef GEOS_VERSION
  71. #define GEOS_VERSION "3.5.0"
  72. #endif
  73. #ifndef GEOS_JTS_PORT
  74. #define GEOS_JTS_PORT "1.13.0"
  75. #endif
  76. #define GEOS_CAPI_VERSION_MAJOR 1
  77. #define GEOS_CAPI_VERSION_MINOR 9
  78. #define GEOS_CAPI_VERSION_PATCH 0
  79. #define GEOS_CAPI_VERSION "3.5.0-CAPI-1.9.0"
  80. #endif
  81. #define GEOS_CAPI_FIRST_INTERFACE GEOS_CAPI_VERSION_MAJOR
  82. #define GEOS_CAPI_LAST_INTERFACE (GEOS_CAPI_VERSION_MAJOR+GEOS_CAPI_VERSION_MINOR)
  83. /************************************************************************
  84. *
  85. * (Abstract) type definitions
  86. *
  87. ************************************************************************/
  88. typedef struct GEOSContextHandle_HS *GEOSContextHandle_t;
  89. typedef void (*GEOSMessageHandler)(const char *fmt, ...);
  90. /*
  91. * A GEOS message handler function.
  92. *
  93. * @param message the message contents
  94. * @param userdata the user data pointer that was passed to GEOS when registering this message handler.
  95. *
  96. *
  97. * @see GEOSContext_setErrorMessageHandler
  98. * @see GEOSContext_setNoticeMessageHandler
  99. */
  100. typedef void (*GEOSMessageHandler_r)(const char *message, void *userdata);
  101. /* When we're included by geos_c.cpp, those are #defined to the original
  102. * JTS definitions via preprocessor. We don't touch them to allow the
  103. * compiler to cross-check the declarations. However, for all "normal"
  104. * C-API users, we need to define them as "opaque" struct pointers, as
  105. * those clients don't have access to the original C++ headers, by design.
  106. */
  107. #ifndef GEOSGeometry
  108. typedef struct GEOSGeom_t GEOSGeometry;
  109. typedef struct GEOSPrepGeom_t GEOSPreparedGeometry;
  110. typedef struct GEOSCoordSeq_t GEOSCoordSequence;
  111. typedef struct GEOSSTRtree_t GEOSSTRtree;
  112. typedef struct GEOSBufParams_t GEOSBufferParams;
  113. #endif
  114. /* Those are compatibility definitions for source compatibility
  115. * with GEOS 2.X clients relying on that type.
  116. */
  117. typedef GEOSGeometry* GEOSGeom;
  118. typedef GEOSCoordSequence* GEOSCoordSeq;
  119. /* Supported geometry types
  120. * This was renamed from GEOSGeomTypeId in GEOS 2.2.X, which might
  121. * break compatibility, this issue is still under investigation.
  122. */
  123. enum GEOSGeomTypes {
  124. GEOS_POINT,
  125. GEOS_LINESTRING,
  126. GEOS_LINEARRING,
  127. GEOS_POLYGON,
  128. GEOS_MULTIPOINT,
  129. GEOS_MULTILINESTRING,
  130. GEOS_MULTIPOLYGON,
  131. GEOS_GEOMETRYCOLLECTION
  132. };
  133. /* Byte oders exposed via the c api */
  134. enum GEOSByteOrders {
  135. GEOS_WKB_XDR = 0, /* Big Endian */
  136. GEOS_WKB_NDR = 1 /* Little Endian */
  137. };
  138. typedef void (*GEOSQueryCallback)(void *item, void *userdata);
  139. /************************************************************************
  140. *
  141. * Initialization, cleanup, version
  142. *
  143. ***********************************************************************/
  144. #include <geos/export.h>
  145. /*
  146. * Register an interruption checking callback
  147. *
  148. * The callback will be invoked _before_ checking for
  149. * interruption, so can be used to request it.
  150. */
  151. typedef void (GEOSInterruptCallback)();
  152. extern GEOSInterruptCallback GEOS_DLL *GEOS_interruptRegisterCallback(GEOSInterruptCallback* cb);
  153. /* Request safe interruption of operations */
  154. extern void GEOS_DLL GEOS_interruptRequest();
  155. /* Cancel a pending interruption request */
  156. extern void GEOS_DLL GEOS_interruptCancel();
  157. /*
  158. * @deprecated in 3.5.0
  159. * initialize using GEOS_init_r() and set the message handlers using
  160. * GEOSContext_setNoticeHandler_r and/or GEOSContext_setErrorHandler_r
  161. */
  162. extern GEOSContextHandle_t GEOS_DLL initGEOS_r(
  163. GEOSMessageHandler notice_function,
  164. GEOSMessageHandler error_function);
  165. /*
  166. * @deprecated in 3.5.0 replaced by GEOS_finish_r.
  167. */
  168. extern void GEOS_DLL finishGEOS_r(GEOSContextHandle_t handle);
  169. extern GEOSContextHandle_t GEOS_DLL GEOS_init_r();
  170. extern void GEOS_DLL GEOS_finish_r(GEOSContextHandle_t handle);
  171. extern GEOSMessageHandler GEOS_DLL GEOSContext_setNoticeHandler_r(GEOSContextHandle_t extHandle,
  172. GEOSMessageHandler nf);
  173. extern GEOSMessageHandler GEOS_DLL GEOSContext_setErrorHandler_r(GEOSContextHandle_t extHandle,
  174. GEOSMessageHandler ef);
  175. /*
  176. * Sets a notice message handler on the given GEOS context.
  177. *
  178. * @param extHandle the GEOS context
  179. * @param nf the message handler
  180. * @param userData optional user data pointer that will be passed to the message handler
  181. *
  182. * @return the previously configured message handler or NULL if no message handler was configured
  183. */
  184. extern GEOSMessageHandler_r GEOS_DLL GEOSContext_setNoticeMessageHandler_r(GEOSContextHandle_t extHandle,
  185. GEOSMessageHandler_r nf,
  186. void *userData);
  187. /*
  188. * Sets an error message handler on the given GEOS context.
  189. *
  190. * @param extHandle the GEOS context
  191. * @param ef the message handler
  192. * @param userData optional user data pointer that will be passed to the message handler
  193. *
  194. * @return the previously configured message handler or NULL if no message handler was configured
  195. */
  196. extern GEOSMessageHandler_r GEOS_DLL GEOSContext_setErrorMessageHandler_r(GEOSContextHandle_t extHandle,
  197. GEOSMessageHandler_r ef,
  198. void *userData);
  199. extern const char GEOS_DLL *GEOSversion();
  200. /************************************************************************
  201. *
  202. * NOTE - These functions are DEPRECATED. Please use the new Reader and
  203. * writer APIS!
  204. *
  205. ***********************************************************************/
  206. extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKT_r(GEOSContextHandle_t handle,
  207. const char *wkt);
  208. extern char GEOS_DLL *GEOSGeomToWKT_r(GEOSContextHandle_t handle,
  209. const GEOSGeometry* g);
  210. /*
  211. * Specify whether output WKB should be 2d or 3d.
  212. * Return previously set number of dimensions.
  213. */
  214. extern int GEOS_DLL GEOS_getWKBOutputDims_r(GEOSContextHandle_t handle);
  215. extern int GEOS_DLL GEOS_setWKBOutputDims_r(GEOSContextHandle_t handle,
  216. int newDims);
  217. /*
  218. * Specify whether the WKB byte order is big or little endian.
  219. * The return value is the previous byte order.
  220. */
  221. extern int GEOS_DLL GEOS_getWKBByteOrder_r(GEOSContextHandle_t handle);
  222. extern int GEOS_DLL GEOS_setWKBByteOrder_r(GEOSContextHandle_t handle,
  223. int byteOrder);
  224. extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKB_buf_r(GEOSContextHandle_t handle,
  225. const unsigned char *wkb,
  226. size_t size);
  227. extern unsigned char GEOS_DLL *GEOSGeomToWKB_buf_r(GEOSContextHandle_t handle,
  228. const GEOSGeometry* g,
  229. size_t *size);
  230. extern GEOSGeometry GEOS_DLL *GEOSGeomFromHEX_buf_r(GEOSContextHandle_t handle,
  231. const unsigned char *hex,
  232. size_t size);
  233. extern unsigned char GEOS_DLL *GEOSGeomToHEX_buf_r(GEOSContextHandle_t handle,
  234. const GEOSGeometry* g,
  235. size_t *size);
  236. /************************************************************************
  237. *
  238. * Coordinate Sequence functions
  239. *
  240. ***********************************************************************/
  241. /*
  242. * Create a Coordinate sequence with ``size'' coordinates
  243. * of ``dims'' dimensions.
  244. * Return NULL on exception.
  245. */
  246. extern GEOSCoordSequence GEOS_DLL *GEOSCoordSeq_create_r(
  247. GEOSContextHandle_t handle,
  248. unsigned int size,
  249. unsigned int dims);
  250. /*
  251. * Clone a Coordinate Sequence.
  252. * Return NULL on exception.
  253. */
  254. extern GEOSCoordSequence GEOS_DLL *GEOSCoordSeq_clone_r(
  255. GEOSContextHandle_t handle,
  256. const GEOSCoordSequence* s);
  257. /*
  258. * Destroy a Coordinate Sequence.
  259. */
  260. extern void GEOS_DLL GEOSCoordSeq_destroy_r(GEOSContextHandle_t handle,
  261. GEOSCoordSequence* s);
  262. /*
  263. * Set ordinate values in a Coordinate Sequence.
  264. * Return 0 on exception.
  265. */
  266. extern int GEOS_DLL GEOSCoordSeq_setX_r(GEOSContextHandle_t handle,
  267. GEOSCoordSequence* s, unsigned int idx,
  268. double val);
  269. extern int GEOS_DLL GEOSCoordSeq_setY_r(GEOSContextHandle_t handle,
  270. GEOSCoordSequence* s, unsigned int idx,
  271. double val);
  272. extern int GEOS_DLL GEOSCoordSeq_setZ_r(GEOSContextHandle_t handle,
  273. GEOSCoordSequence* s, unsigned int idx,
  274. double val);
  275. extern int GEOS_DLL GEOSCoordSeq_setOrdinate_r(GEOSContextHandle_t handle,
  276. GEOSCoordSequence* s,
  277. unsigned int idx,
  278. unsigned int dim, double val);
  279. /*
  280. * Get ordinate values from a Coordinate Sequence.
  281. * Return 0 on exception.
  282. */
  283. extern int GEOS_DLL GEOSCoordSeq_getX_r(GEOSContextHandle_t handle,
  284. const GEOSCoordSequence* s,
  285. unsigned int idx, double *val);
  286. extern int GEOS_DLL GEOSCoordSeq_getY_r(GEOSContextHandle_t handle,
  287. const GEOSCoordSequence* s,
  288. unsigned int idx, double *val);
  289. extern int GEOS_DLL GEOSCoordSeq_getZ_r(GEOSContextHandle_t handle,
  290. const GEOSCoordSequence* s,
  291. unsigned int idx, double *val);
  292. extern int GEOS_DLL GEOSCoordSeq_getOrdinate_r(GEOSContextHandle_t handle,
  293. const GEOSCoordSequence* s,
  294. unsigned int idx,
  295. unsigned int dim, double *val);
  296. /*
  297. * Get size and dimensions info from a Coordinate Sequence.
  298. * Return 0 on exception.
  299. */
  300. extern int GEOS_DLL GEOSCoordSeq_getSize_r(GEOSContextHandle_t handle,
  301. const GEOSCoordSequence* s,
  302. unsigned int *size);
  303. extern int GEOS_DLL GEOSCoordSeq_getDimensions_r(GEOSContextHandle_t handle,
  304. const GEOSCoordSequence* s,
  305. unsigned int *dims);
  306. /************************************************************************
  307. *
  308. * Linear referencing functions -- there are more, but these are
  309. * probably sufficient for most purposes
  310. *
  311. ***********************************************************************/
  312. /*
  313. * GEOSGeometry ownership is retained by caller
  314. */
  315. /* Return distance of point 'p' projected on 'g' from origin
  316. * of 'g'. Geometry 'g' must be a lineal geometry */
  317. extern double GEOS_DLL GEOSProject_r(GEOSContextHandle_t handle,
  318. const GEOSGeometry *g,
  319. const GEOSGeometry *p);
  320. /* Return closest point to given distance within geometry
  321. * Geometry must be a LineString */
  322. extern GEOSGeometry GEOS_DLL *GEOSInterpolate_r(GEOSContextHandle_t handle,
  323. const GEOSGeometry *g,
  324. double d);
  325. extern double GEOS_DLL GEOSProjectNormalized_r(GEOSContextHandle_t handle,
  326. const GEOSGeometry *g,
  327. const GEOSGeometry *p);
  328. extern GEOSGeometry GEOS_DLL *GEOSInterpolateNormalized_r(
  329. GEOSContextHandle_t handle,
  330. const GEOSGeometry *g,
  331. double d);
  332. /************************************************************************
  333. *
  334. * Buffer related functions
  335. *
  336. ***********************************************************************/
  337. /* @return NULL on exception */
  338. extern GEOSGeometry GEOS_DLL *GEOSBuffer_r(GEOSContextHandle_t handle,
  339. const GEOSGeometry* g,
  340. double width, int quadsegs);
  341. enum GEOSBufCapStyles {
  342. GEOSBUF_CAP_ROUND=1,
  343. GEOSBUF_CAP_FLAT=2,
  344. GEOSBUF_CAP_SQUARE=3
  345. };
  346. enum GEOSBufJoinStyles {
  347. GEOSBUF_JOIN_ROUND=1,
  348. GEOSBUF_JOIN_MITRE=2,
  349. GEOSBUF_JOIN_BEVEL=3
  350. };
  351. /* @return 0 on exception */
  352. extern GEOSBufferParams GEOS_DLL *GEOSBufferParams_create_r(
  353. GEOSContextHandle_t handle);
  354. extern void GEOS_DLL GEOSBufferParams_destroy_r(
  355. GEOSContextHandle_t handle,
  356. GEOSBufferParams* parms);
  357. /* @return 0 on exception */
  358. extern int GEOS_DLL GEOSBufferParams_setEndCapStyle_r(
  359. GEOSContextHandle_t handle,
  360. GEOSBufferParams* p,
  361. int style);
  362. /* @return 0 on exception */
  363. extern int GEOS_DLL GEOSBufferParams_setJoinStyle_r(
  364. GEOSContextHandle_t handle,
  365. GEOSBufferParams* p,
  366. int joinStyle);
  367. /* @return 0 on exception */
  368. extern int GEOS_DLL GEOSBufferParams_setMitreLimit_r(
  369. GEOSContextHandle_t handle,
  370. GEOSBufferParams* p,
  371. double mitreLimit);
  372. /* @return 0 on exception */
  373. extern int GEOS_DLL GEOSBufferParams_setQuadrantSegments_r(
  374. GEOSContextHandle_t handle,
  375. GEOSBufferParams* p,
  376. int quadSegs);
  377. /* @param singleSided: 1 for single sided, 0 otherwise */
  378. /* @return 0 on exception */
  379. extern int GEOS_DLL GEOSBufferParams_setSingleSided_r(
  380. GEOSContextHandle_t handle,
  381. GEOSBufferParams* p,
  382. int singleSided);
  383. /* @return NULL on exception */
  384. extern GEOSGeometry GEOS_DLL *GEOSBufferWithParams_r(
  385. GEOSContextHandle_t handle,
  386. const GEOSGeometry* g,
  387. const GEOSBufferParams* p,
  388. double width);
  389. /* These functions return NULL on exception. */
  390. extern GEOSGeometry GEOS_DLL *GEOSBufferWithStyle_r(GEOSContextHandle_t handle,
  391. const GEOSGeometry* g, double width, int quadsegs, int endCapStyle,
  392. int joinStyle, double mitreLimit);
  393. /* These functions return NULL on exception. Only LINESTRINGs are accepted. */
  394. /* @deprecated in 3.3.0: use GEOSOffsetCurve instead */
  395. extern GEOSGeometry GEOS_DLL *GEOSSingleSidedBuffer_r(
  396. GEOSContextHandle_t handle,
  397. const GEOSGeometry* g, double width, int quadsegs,
  398. int joinStyle, double mitreLimit, int leftSide);
  399. /*
  400. * Only LINESTRINGs are accepted.
  401. * @param width : offset distance.
  402. * negative for right side offset.
  403. * positive for left side offset.
  404. * @return NULL on exception
  405. */
  406. extern GEOSGeometry GEOS_DLL *GEOSOffsetCurve_r(GEOSContextHandle_t handle,
  407. const GEOSGeometry* g, double width, int quadsegs,
  408. int joinStyle, double mitreLimit);
  409. /************************************************************************
  410. *
  411. * Geometry Constructors.
  412. * GEOSCoordSequence* arguments will become ownership of the returned object.
  413. * All functions return NULL on exception.
  414. *
  415. ***********************************************************************/
  416. extern GEOSGeometry GEOS_DLL *GEOSGeom_createPoint_r(
  417. GEOSContextHandle_t handle,
  418. GEOSCoordSequence* s);
  419. extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPoint_r(
  420. GEOSContextHandle_t handle);
  421. extern GEOSGeometry GEOS_DLL *GEOSGeom_createLinearRing_r(
  422. GEOSContextHandle_t handle,
  423. GEOSCoordSequence* s);
  424. extern GEOSGeometry GEOS_DLL *GEOSGeom_createLineString_r(
  425. GEOSContextHandle_t handle,
  426. GEOSCoordSequence* s);
  427. extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyLineString_r(
  428. GEOSContextHandle_t handle);
  429. /*
  430. * Second argument is an array of GEOSGeometry* objects.
  431. * The caller remains owner of the array, but pointed-to
  432. * objects become ownership of the returned GEOSGeometry.
  433. */
  434. extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPolygon_r(
  435. GEOSContextHandle_t handle);
  436. extern GEOSGeometry GEOS_DLL *GEOSGeom_createPolygon_r(
  437. GEOSContextHandle_t handle,
  438. GEOSGeometry* shell,
  439. GEOSGeometry** holes,
  440. unsigned int nholes);
  441. extern GEOSGeometry GEOS_DLL *GEOSGeom_createCollection_r(
  442. GEOSContextHandle_t handle, int type,
  443. GEOSGeometry* *geoms,
  444. unsigned int ngeoms);
  445. extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyCollection_r(
  446. GEOSContextHandle_t handle, int type);
  447. extern GEOSGeometry GEOS_DLL *GEOSGeom_clone_r(GEOSContextHandle_t handle,
  448. const GEOSGeometry* g);
  449. /************************************************************************
  450. *
  451. * Memory management
  452. *
  453. ***********************************************************************/
  454. extern void GEOS_DLL GEOSGeom_destroy_r(GEOSContextHandle_t handle,
  455. GEOSGeometry* g);
  456. /************************************************************************
  457. *
  458. * Topology operations - return NULL on exception.
  459. *
  460. ***********************************************************************/
  461. extern GEOSGeometry GEOS_DLL *GEOSEnvelope_r(GEOSContextHandle_t handle,
  462. const GEOSGeometry* g);
  463. extern GEOSGeometry GEOS_DLL *GEOSIntersection_r(GEOSContextHandle_t handle,
  464. const GEOSGeometry* g1,
  465. const GEOSGeometry* g2);
  466. extern GEOSGeometry GEOS_DLL *GEOSConvexHull_r(GEOSContextHandle_t handle,
  467. const GEOSGeometry* g);
  468. extern GEOSGeometry GEOS_DLL *GEOSDifference_r(GEOSContextHandle_t handle,
  469. const GEOSGeometry* g1,
  470. const GEOSGeometry* g2);
  471. extern GEOSGeometry GEOS_DLL *GEOSSymDifference_r(GEOSContextHandle_t handle,
  472. const GEOSGeometry* g1,
  473. const GEOSGeometry* g2);
  474. extern GEOSGeometry GEOS_DLL *GEOSBoundary_r(GEOSContextHandle_t handle,
  475. const GEOSGeometry* g);
  476. extern GEOSGeometry GEOS_DLL *GEOSUnion_r(GEOSContextHandle_t handle,
  477. const GEOSGeometry* g1,
  478. const GEOSGeometry* g2);
  479. extern GEOSGeometry GEOS_DLL *GEOSUnaryUnion_r(GEOSContextHandle_t handle,
  480. const GEOSGeometry* g);
  481. /* @deprecated in 3.3.0: use GEOSUnaryUnion_r instead */
  482. extern GEOSGeometry GEOS_DLL *GEOSUnionCascaded_r(GEOSContextHandle_t handle,
  483. const GEOSGeometry* g);
  484. extern GEOSGeometry GEOS_DLL *GEOSPointOnSurface_r(GEOSContextHandle_t handle,
  485. const GEOSGeometry* g);
  486. extern GEOSGeometry GEOS_DLL *GEOSGetCentroid_r(GEOSContextHandle_t handle,
  487. const GEOSGeometry* g);
  488. extern GEOSGeometry GEOS_DLL *GEOSNode_r(GEOSContextHandle_t handle,
  489. const GEOSGeometry* g);
  490. /* Fast, non-robust intersection between an arbitrary geometry and
  491. * a rectangle. The returned geometry may be invalid. */
  492. extern GEOSGeometry GEOS_DLL *GEOSClipByRect_r(GEOSContextHandle_t handle,
  493. const GEOSGeometry* g,
  494. double xmin, double ymin,
  495. double xmax, double ymax);
  496. /*
  497. * all arguments remain ownership of the caller
  498. * (both Geometries and pointers)
  499. */
  500. /*
  501. * Polygonizes a set of Geometries which contain linework that
  502. * represents the edges of a planar graph.
  503. *
  504. * Any dimension of Geometry is handled - the constituent linework
  505. * is extracted to form the edges.
  506. *
  507. * The edges must be correctly noded; that is, they must only meet
  508. * at their endpoints.
  509. * The Polygonizer will still run on incorrectly noded input
  510. * but will not form polygons from incorrectly noded edges.
  511. *
  512. * The Polygonizer reports the follow kinds of errors:
  513. *
  514. * - Dangles - edges which have one or both ends which are
  515. * not incident on another edge endpoint
  516. * - Cut Edges - edges which are connected at both ends but
  517. * which do not form part of polygon
  518. * - Invalid Ring Lines - edges which form rings which are invalid
  519. * (e.g. the component lines contain a self-intersection)
  520. *
  521. * Errors are reported to output parameters "cuts", "dangles" and
  522. * "invalid" (if not-null). Formed polygons are returned as a
  523. * collection. NULL is returned on exception. All returned
  524. * geometries must be destroyed by caller.
  525. *
  526. */
  527. extern GEOSGeometry GEOS_DLL *GEOSPolygonize_r(GEOSContextHandle_t handle,
  528. const GEOSGeometry *const geoms[],
  529. unsigned int ngeoms);
  530. extern GEOSGeometry GEOS_DLL *GEOSPolygonizer_getCutEdges_r(
  531. GEOSContextHandle_t handle,
  532. const GEOSGeometry * const geoms[],
  533. unsigned int ngeoms);
  534. extern GEOSGeometry GEOS_DLL *GEOSPolygonize_full_r(GEOSContextHandle_t handle,
  535. const GEOSGeometry* input, GEOSGeometry** cuts,
  536. GEOSGeometry** dangles, GEOSGeometry** invalidRings);
  537. extern GEOSGeometry GEOS_DLL *GEOSLineMerge_r(GEOSContextHandle_t handle,
  538. const GEOSGeometry* g);
  539. extern GEOSGeometry GEOS_DLL *GEOSSimplify_r(GEOSContextHandle_t handle,
  540. const GEOSGeometry* g,
  541. double tolerance);
  542. extern GEOSGeometry GEOS_DLL *GEOSTopologyPreserveSimplify_r(
  543. GEOSContextHandle_t handle,
  544. const GEOSGeometry* g, double tolerance);
  545. /*
  546. * Return all distinct vertices of input geometry as a MULTIPOINT.
  547. * Note that only 2 dimensions of the vertices are considered when
  548. * testing for equality.
  549. */
  550. extern GEOSGeometry GEOS_DLL *GEOSGeom_extractUniquePoints_r(
  551. GEOSContextHandle_t handle,
  552. const GEOSGeometry* g);
  553. /*
  554. * Find paths shared between the two given lineal geometries.
  555. *
  556. * Returns a GEOMETRYCOLLECTION having two elements:
  557. * - first element is a MULTILINESTRING containing shared paths
  558. * having the _same_ direction on both inputs
  559. * - second element is a MULTILINESTRING containing shared paths
  560. * having the _opposite_ direction on the two inputs
  561. *
  562. * Returns NULL on exception
  563. */
  564. extern GEOSGeometry GEOS_DLL *GEOSSharedPaths_r(GEOSContextHandle_t handle,
  565. const GEOSGeometry* g1, const GEOSGeometry* g2);
  566. /*
  567. * Snap first geometry on to second with given tolerance
  568. * Returns a newly allocated geometry, or NULL on exception
  569. */
  570. extern GEOSGeometry GEOS_DLL *GEOSSnap_r(GEOSContextHandle_t handle,
  571. const GEOSGeometry* g1, const GEOSGeometry* g2, double tolerance);
  572. /*
  573. * Return a Delaunay triangulation of the vertex of the given geometry
  574. *
  575. * @param g the input geometry whose vertex will be used as "sites"
  576. * @param tolerance optional snapping tolerance to use for improved robustness
  577. * @param onlyEdges if non-zero will return a MULTILINESTRING, otherwise it will
  578. * return a GEOMETRYCOLLECTION containing triangular POLYGONs.
  579. *
  580. * @return a newly allocated geometry, or NULL on exception
  581. */
  582. extern GEOSGeometry GEOS_DLL * GEOSDelaunayTriangulation_r(
  583. GEOSContextHandle_t handle,
  584. const GEOSGeometry *g,
  585. double tolerance,
  586. int onlyEdges);
  587. /*
  588. * Returns the Voronoi polygons of a set of Vertices given as input
  589. *
  590. * @param g the input geometry whose vertex will be used as sites.
  591. * @param tolerance snapping tolerance to use for improved robustness
  592. * @param onlyEdges whether to return only edges of the voronoi cells
  593. * @param env clipping envelope for the returned diagram, automatically
  594. * determined if NULL.
  595. * The diagram will be clipped to the larger
  596. * of this envelope or an envelope surrounding the sites.
  597. *
  598. * @return a newly allocated geometry, or NULL on exception.
  599. */
  600. extern GEOSGeometry GEOS_DLL * GEOSVoronoiDiagram_r(
  601. GEOSContextHandle_t extHandle,
  602. const GEOSGeometry *g,
  603. const GEOSGeometry *env,
  604. double tolerance,
  605. int onlyEdges);
  606. /************************************************************************
  607. *
  608. * Binary predicates - return 2 on exception, 1 on true, 0 on false
  609. *
  610. ***********************************************************************/
  611. extern char GEOS_DLL GEOSDisjoint_r(GEOSContextHandle_t handle,
  612. const GEOSGeometry* g1,
  613. const GEOSGeometry* g2);
  614. extern char GEOS_DLL GEOSTouches_r(GEOSContextHandle_t handle,
  615. const GEOSGeometry* g1,
  616. const GEOSGeometry* g2);
  617. extern char GEOS_DLL GEOSIntersects_r(GEOSContextHandle_t handle,
  618. const GEOSGeometry* g1,
  619. const GEOSGeometry* g2);
  620. extern char GEOS_DLL GEOSCrosses_r(GEOSContextHandle_t handle,
  621. const GEOSGeometry* g1,
  622. const GEOSGeometry* g2);
  623. extern char GEOS_DLL GEOSWithin_r(GEOSContextHandle_t handle,
  624. const GEOSGeometry* g1,
  625. const GEOSGeometry* g2);
  626. extern char GEOS_DLL GEOSContains_r(GEOSContextHandle_t handle,
  627. const GEOSGeometry* g1,
  628. const GEOSGeometry* g2);
  629. extern char GEOS_DLL GEOSOverlaps_r(GEOSContextHandle_t handle,
  630. const GEOSGeometry* g1,
  631. const GEOSGeometry* g2);
  632. extern char GEOS_DLL GEOSEquals_r(GEOSContextHandle_t handle,
  633. const GEOSGeometry* g1,
  634. const GEOSGeometry* g2);
  635. extern char GEOS_DLL GEOSEqualsExact_r(GEOSContextHandle_t handle,
  636. const GEOSGeometry* g1,
  637. const GEOSGeometry* g2,
  638. double tolerance);
  639. extern char GEOS_DLL GEOSCovers_r(GEOSContextHandle_t handle,
  640. const GEOSGeometry* g1,
  641. const GEOSGeometry* g2);
  642. extern char GEOS_DLL GEOSCoveredBy_r(GEOSContextHandle_t handle,
  643. const GEOSGeometry* g1,
  644. const GEOSGeometry* g2);
  645. /************************************************************************
  646. *
  647. * Prepared Geometry Binary predicates - return 2 on exception, 1 on true, 0 on false
  648. *
  649. ***********************************************************************/
  650. /*
  651. * GEOSGeometry ownership is retained by caller
  652. */
  653. extern const GEOSPreparedGeometry GEOS_DLL *GEOSPrepare_r(
  654. GEOSContextHandle_t handle,
  655. const GEOSGeometry* g);
  656. extern void GEOS_DLL GEOSPreparedGeom_destroy_r(GEOSContextHandle_t handle,
  657. const GEOSPreparedGeometry* g);
  658. extern char GEOS_DLL GEOSPreparedContains_r(GEOSContextHandle_t handle,
  659. const GEOSPreparedGeometry* pg1,
  660. const GEOSGeometry* g2);
  661. extern char GEOS_DLL GEOSPreparedContainsProperly_r(GEOSContextHandle_t handle,
  662. const GEOSPreparedGeometry* pg1,
  663. const GEOSGeometry* g2);
  664. extern char GEOS_DLL GEOSPreparedCoveredBy_r(GEOSContextHandle_t handle,
  665. const GEOSPreparedGeometry* pg1,
  666. const GEOSGeometry* g2);
  667. extern char GEOS_DLL GEOSPreparedCovers_r(GEOSContextHandle_t handle,
  668. const GEOSPreparedGeometry* pg1,
  669. const GEOSGeometry* g2);
  670. extern char GEOS_DLL GEOSPreparedCrosses_r(GEOSContextHandle_t handle,
  671. const GEOSPreparedGeometry* pg1,
  672. const GEOSGeometry* g2);
  673. extern char GEOS_DLL GEOSPreparedDisjoint_r(GEOSContextHandle_t handle,
  674. const GEOSPreparedGeometry* pg1,
  675. const GEOSGeometry* g2);
  676. extern char GEOS_DLL GEOSPreparedIntersects_r(GEOSContextHandle_t handle,
  677. const GEOSPreparedGeometry* pg1,
  678. const GEOSGeometry* g2);
  679. extern char GEOS_DLL GEOSPreparedOverlaps_r(GEOSContextHandle_t handle,
  680. const GEOSPreparedGeometry* pg1,
  681. const GEOSGeometry* g2);
  682. extern char GEOS_DLL GEOSPreparedTouches_r(GEOSContextHandle_t handle,
  683. const GEOSPreparedGeometry* pg1,
  684. const GEOSGeometry* g2);
  685. extern char GEOS_DLL GEOSPreparedWithin_r(GEOSContextHandle_t handle,
  686. const GEOSPreparedGeometry* pg1,
  687. const GEOSGeometry* g2);
  688. /************************************************************************
  689. *
  690. * STRtree functions
  691. *
  692. ***********************************************************************/
  693. /*
  694. * GEOSGeometry ownership is retained by caller
  695. */
  696. extern GEOSSTRtree GEOS_DLL *GEOSSTRtree_create_r(
  697. GEOSContextHandle_t handle,
  698. size_t nodeCapacity);
  699. extern void GEOS_DLL GEOSSTRtree_insert_r(GEOSContextHandle_t handle,
  700. GEOSSTRtree *tree,
  701. const GEOSGeometry *g,
  702. void *item);
  703. extern void GEOS_DLL GEOSSTRtree_query_r(GEOSContextHandle_t handle,
  704. GEOSSTRtree *tree,
  705. const GEOSGeometry *g,
  706. GEOSQueryCallback callback,
  707. void *userdata);
  708. extern void GEOS_DLL GEOSSTRtree_iterate_r(GEOSContextHandle_t handle,
  709. GEOSSTRtree *tree,
  710. GEOSQueryCallback callback,
  711. void *userdata);
  712. extern char GEOS_DLL GEOSSTRtree_remove_r(GEOSContextHandle_t handle,
  713. GEOSSTRtree *tree,
  714. const GEOSGeometry *g,
  715. void *item);
  716. extern void GEOS_DLL GEOSSTRtree_destroy_r(GEOSContextHandle_t handle,
  717. GEOSSTRtree *tree);
  718. /************************************************************************
  719. *
  720. * Unary predicate - return 2 on exception, 1 on true, 0 on false
  721. *
  722. ***********************************************************************/
  723. extern char GEOS_DLL GEOSisEmpty_r(GEOSContextHandle_t handle,
  724. const GEOSGeometry* g);
  725. extern char GEOS_DLL GEOSisSimple_r(GEOSContextHandle_t handle,
  726. const GEOSGeometry* g);
  727. extern char GEOS_DLL GEOSisRing_r(GEOSContextHandle_t handle,
  728. const GEOSGeometry* g);
  729. extern char GEOS_DLL GEOSHasZ_r(GEOSContextHandle_t handle,
  730. const GEOSGeometry* g);
  731. extern char GEOS_DLL GEOSisClosed_r(GEOSContextHandle_t handle,
  732. const GEOSGeometry *g);
  733. /************************************************************************
  734. *
  735. * Dimensionally Extended 9 Intersection Model related
  736. *
  737. ***********************************************************************/
  738. /* These are for use with GEOSRelateBoundaryNodeRule (flags param) */
  739. enum GEOSRelateBoundaryNodeRules {
  740. /* MOD2 and OGC are the same rule, and is the default
  741. * used by GEOSRelatePattern
  742. */
  743. GEOSRELATE_BNR_MOD2=1,
  744. GEOSRELATE_BNR_OGC=1,
  745. GEOSRELATE_BNR_ENDPOINT=2,
  746. GEOSRELATE_BNR_MULTIVALENT_ENDPOINT=3,
  747. GEOSRELATE_BNR_MONOVALENT_ENDPOINT=4
  748. };
  749. /* return 2 on exception, 1 on true, 0 on false */
  750. extern char GEOS_DLL GEOSRelatePattern_r(GEOSContextHandle_t handle,
  751. const GEOSGeometry* g1,
  752. const GEOSGeometry* g2,
  753. const char *pat);
  754. /* return NULL on exception, a string to GEOSFree otherwise */
  755. extern char GEOS_DLL *GEOSRelate_r(GEOSContextHandle_t handle,
  756. const GEOSGeometry* g1,
  757. const GEOSGeometry* g2);
  758. /* return 2 on exception, 1 on true, 0 on false */
  759. extern char GEOS_DLL GEOSRelatePatternMatch_r(GEOSContextHandle_t handle,
  760. const char *mat,
  761. const char *pat);
  762. /* return NULL on exception, a string to GEOSFree otherwise */
  763. extern char GEOS_DLL *GEOSRelateBoundaryNodeRule_r(GEOSContextHandle_t handle,
  764. const GEOSGeometry* g1,
  765. const GEOSGeometry* g2,
  766. int bnr);
  767. /************************************************************************
  768. *
  769. * Validity checking
  770. *
  771. ***********************************************************************/
  772. /* These are for use with GEOSisValidDetail (flags param) */
  773. enum GEOSValidFlags {
  774. GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE=1
  775. };
  776. /* return 2 on exception, 1 on true, 0 on false */
  777. extern char GEOS_DLL GEOSisValid_r(GEOSContextHandle_t handle,
  778. const GEOSGeometry* g);
  779. /* return NULL on exception, a string to GEOSFree otherwise */
  780. extern char GEOS_DLL *GEOSisValidReason_r(GEOSContextHandle_t handle,
  781. const GEOSGeometry* g);
  782. /*
  783. * Caller has the responsibility to destroy 'reason' (GEOSFree)
  784. * and 'location' (GEOSGeom_destroy) params
  785. * return 2 on exception, 1 when valid, 0 when invalid
  786. */
  787. extern char GEOS_DLL GEOSisValidDetail_r(GEOSContextHandle_t handle,
  788. const GEOSGeometry* g,
  789. int flags,
  790. char** reason,
  791. GEOSGeometry** location);
  792. /************************************************************************
  793. *
  794. * Geometry info
  795. *
  796. ***********************************************************************/
  797. /* Return NULL on exception, result must be freed by caller. */
  798. extern char GEOS_DLL *GEOSGeomType_r(GEOSContextHandle_t handle,
  799. const GEOSGeometry* g);
  800. /* Return -1 on exception */
  801. extern int GEOS_DLL GEOSGeomTypeId_r(GEOSContextHandle_t handle,
  802. const GEOSGeometry* g);
  803. /* Return 0 on exception */
  804. extern int GEOS_DLL GEOSGetSRID_r(GEOSContextHandle_t handle,
  805. const GEOSGeometry* g);
  806. extern void GEOS_DLL GEOSSetSRID_r(GEOSContextHandle_t handle,
  807. GEOSGeometry* g, int SRID);
  808. /* May be called on all geometries in GEOS 3.x, returns -1 on error and 1
  809. * for non-multi geometries. Older GEOS versions only accept
  810. * GeometryCollections or Multi* geometries here, and are likely to crash
  811. * when fed simple geometries, so beware if you need compatibility with
  812. * old GEOS versions.
  813. */
  814. extern int GEOS_DLL GEOSGetNumGeometries_r(GEOSContextHandle_t handle,
  815. const GEOSGeometry* g);
  816. /*
  817. * Return NULL on exception.
  818. * Returned object is a pointer to internal storage:
  819. * it must NOT be destroyed directly.
  820. * Up to GEOS 3.2.0 the input geometry must be a Collection, in
  821. * later version it doesn't matter (getGeometryN(0) for a single will
  822. * return the input).
  823. */
  824. extern const GEOSGeometry GEOS_DLL *GEOSGetGeometryN_r(
  825. GEOSContextHandle_t handle,
  826. const GEOSGeometry* g, int n);
  827. /* Return -1 on exception */
  828. extern int GEOS_DLL GEOSNormalize_r(GEOSContextHandle_t handle,
  829. GEOSGeometry* g);
  830. /* Return -1 on exception */
  831. extern int GEOS_DLL GEOSGetNumInteriorRings_r(GEOSContextHandle_t handle,
  832. const GEOSGeometry* g);
  833. /* Return -1 on exception, Geometry must be a LineString. */
  834. extern int GEOS_DLL GEOSGeomGetNumPoints_r(GEOSContextHandle_t handle,
  835. const GEOSGeometry* g);
  836. /* Return -1 on exception, Geometry must be a Point. */
  837. extern int GEOS_DLL GEOSGeomGetX_r(GEOSContextHandle_t handle, const GEOSGeometry *g, double *x);
  838. extern int GEOS_DLL GEOSGeomGetY_r(GEOSContextHandle_t handle, const GEOSGeometry *g, double *y);
  839. /*
  840. * Return NULL on exception, Geometry must be a Polygon.
  841. * Returned object is a pointer to internal storage:
  842. * it must NOT be destroyed directly.
  843. */
  844. extern const GEOSGeometry GEOS_DLL *GEOSGetInteriorRingN_r(
  845. GEOSContextHandle_t handle,
  846. const GEOSGeometry* g, int n);
  847. /*
  848. * Return NULL on exception, Geometry must be a Polygon.
  849. * Returned object is a pointer to internal storage:
  850. * it must NOT be destroyed directly.
  851. */
  852. extern const GEOSGeometry GEOS_DLL *GEOSGetExteriorRing_r(
  853. GEOSContextHandle_t handle,
  854. const GEOSGeometry* g);
  855. /* Return -1 on exception */
  856. extern int GEOS_DLL GEOSGetNumCoordinates_r(GEOSContextHandle_t handle,
  857. const GEOSGeometry* g);
  858. /*
  859. * Return NULL on exception.
  860. * Geometry must be a LineString, LinearRing or Point.
  861. */
  862. extern const GEOSCoordSequence GEOS_DLL *GEOSGeom_getCoordSeq_r(
  863. GEOSContextHandle_t handle,
  864. const GEOSGeometry* g);
  865. /*
  866. * Return 0 on exception (or empty geometry)
  867. */
  868. extern int GEOS_DLL GEOSGeom_getDimensions_r(GEOSContextHandle_t handle,
  869. const GEOSGeometry* g);
  870. /*
  871. * Return 2 or 3.
  872. */
  873. extern int GEOS_DLL GEOSGeom_getCoordinateDimension_r(GEOSContextHandle_t handle,
  874. const GEOSGeometry* g);
  875. /*
  876. * Return NULL on exception.
  877. * Must be LineString and must be freed by called.
  878. */
  879. extern GEOSGeometry GEOS_DLL *GEOSGeomGetPointN_r(GEOSContextHandle_t handle, const GEOSGeometry *g, int n);
  880. extern GEOSGeometry GEOS_DLL *GEOSGeomGetStartPoint_r(GEOSContextHandle_t handle, const GEOSGeometry *g);
  881. extern GEOSGeometry GEOS_DLL *GEOSGeomGetEndPoint_r(GEOSContextHandle_t handle, const GEOSGeometry *g);
  882. /************************************************************************
  883. *
  884. * Misc functions
  885. *
  886. ***********************************************************************/
  887. /* Return 0 on exception, 1 otherwise */
  888. extern int GEOS_DLL GEOSArea_r(GEOSContextHandle_t handle,
  889. const GEOSGeometry* g, double *area);
  890. extern int GEOS_DLL GEOSLength_r(GEOSContextHandle_t handle,
  891. const GEOSGeometry* g, double *length);
  892. extern int GEOS_DLL GEOSDistance_r(GEOSContextHandle_t handle,
  893. const GEOSGeometry* g1,
  894. const GEOSGeometry* g2, double *dist);
  895. extern int GEOS_DLL GEOSHausdorffDistance_r(GEOSContextHandle_t handle,
  896. const GEOSGeometry *g1,
  897. const GEOSGeometry *g2,
  898. double *dist);
  899. extern int GEOS_DLL GEOSHausdorffDistanceDensify_r(GEOSContextHandle_t handle,
  900. const GEOSGeometry *g1,
  901. const GEOSGeometry *g2,
  902. double densifyFrac, double *dist);
  903. extern int GEOS_DLL GEOSGeomGetLength_r(GEOSContextHandle_t handle,
  904. const GEOSGeometry *g, double *length);
  905. /* Return 0 on exception, the closest points of the two geometries otherwise.
  906. * The first point comes from g1 geometry and the second point comes from g2.
  907. */
  908. extern GEOSCoordSequence GEOS_DLL *GEOSNearestPoints_r(
  909. GEOSContextHandle_t handle, const GEOSGeometry* g1, const GEOSGeometry* g2);
  910. /************************************************************************
  911. *
  912. * Algorithms
  913. *
  914. ***********************************************************************/
  915. /* Walking from A to B:
  916. * return -1 if reaching P takes a counter-clockwise (left) turn
  917. * return 1 if reaching P takes a clockwise (right) turn
  918. * return 0 if P is collinear with A-B
  919. *
  920. * On exceptions, return 2.
  921. *
  922. */
  923. extern int GEOS_DLL GEOSOrientationIndex_r(GEOSContextHandle_t handle,
  924. double Ax, double Ay, double Bx, double By, double Px, double Py);
  925. /************************************************************************
  926. *
  927. * Reader and Writer APIs
  928. *
  929. ***********************************************************************/
  930. typedef struct GEOSWKTReader_t GEOSWKTReader;
  931. typedef struct GEOSWKTWriter_t GEOSWKTWriter;
  932. typedef struct GEOSWKBReader_t GEOSWKBReader;
  933. typedef struct GEOSWKBWriter_t GEOSWKBWriter;
  934. /* WKT Reader */
  935. extern GEOSWKTReader GEOS_DLL *GEOSWKTReader_create_r(
  936. GEOSContextHandle_t handle);
  937. extern void GEOS_DLL GEOSWKTReader_destroy_r(GEOSContextHandle_t handle,
  938. GEOSWKTReader* reader);
  939. extern GEOSGeometry GEOS_DLL *GEOSWKTReader_read_r(GEOSContextHandle_t handle,
  940. GEOSWKTReader* reader,
  941. const char *wkt);
  942. /* WKT Writer */
  943. extern GEOSWKTWriter GEOS_DLL *GEOSWKTWriter_create_r(
  944. GEOSContextHandle_t handle);
  945. extern void GEOS_DLL GEOSWKTWriter_destroy_r(GEOSContextHandle_t handle,
  946. GEOSWKTWriter* writer);
  947. extern char GEOS_DLL *GEOSWKTWriter_write_r(GEOSContextHandle_t handle,
  948. GEOSWKTWriter* writer,
  949. const GEOSGeometry* g);
  950. extern void GEOS_DLL GEOSWKTWriter_setTrim_r(GEOSContextHandle_t handle,
  951. GEOSWKTWriter *writer,
  952. char trim);
  953. extern void GEOS_DLL GEOSWKTWriter_setRoundingPrecision_r(GEOSContextHandle_t handle,
  954. GEOSWKTWriter *writer,
  955. int precision);
  956. extern void GEOS_DLL GEOSWKTWriter_setOutputDimension_r(GEOSContextHandle_t handle,
  957. GEOSWKTWriter *writer,
  958. int dim);
  959. extern int GEOS_DLL GEOSWKTWriter_getOutputDimension_r(GEOSContextHandle_t handle,
  960. GEOSWKTWriter *writer);
  961. extern void GEOS_DLL GEOSWKTWriter_setOld3D_r(GEOSContextHandle_t handle,
  962. GEOSWKTWriter *writer,
  963. int useOld3D);
  964. /* WKB Reader */
  965. extern GEOSWKBReader GEOS_DLL *GEOSWKBReader_create_r(
  966. GEOSContextHandle_t handle);
  967. extern void GEOS_DLL GEOSWKBReader_destroy_r(GEOSContextHandle_t handle,
  968. GEOSWKBReader* reader);
  969. extern GEOSGeometry GEOS_DLL *GEOSWKBReader_read_r(GEOSContextHandle_t handle,
  970. GEOSWKBReader* reader,
  971. const unsigned char *wkb,
  972. size_t size);
  973. extern GEOSGeometry GEOS_DLL *GEOSWKBReader_readHEX_r(
  974. GEOSContextHandle_t handle,
  975. GEOSWKBReader* reader,
  976. const unsigned char *hex,
  977. size_t size);
  978. /* WKB Writer */
  979. extern GEOSWKBWriter GEOS_DLL *GEOSWKBWriter_create_r(
  980. GEOSContextHandle_t handle);
  981. extern void GEOS_DLL GEOSWKBWriter_destroy_r(GEOSContextHandle_t handle,
  982. GEOSWKBWriter* writer);
  983. /* The caller owns the results for these two methods! */
  984. extern unsigned char GEOS_DLL *GEOSWKBWriter_write_r(
  985. GEOSContextHandle_t handle,
  986. GEOSWKBWriter* writer,
  987. const GEOSGeometry* g,
  988. size_t *size);
  989. extern unsigned char GEOS_DLL *GEOSWKBWriter_writeHEX_r(
  990. GEOSContextHandle_t handle,
  991. GEOSWKBWriter* writer,
  992. const GEOSGeometry* g,
  993. size_t *size);
  994. /*
  995. * Specify whether output WKB should be 2d or 3d.
  996. * Return previously set number of dimensions.
  997. */
  998. extern int GEOS_DLL GEOSWKBWriter_getOutputDimension_r(
  999. GEOSContextHandle_t handle,
  1000. const GEOSWKBWriter* writer);
  1001. extern void GEOS_DLL GEOSWKBWriter_setOutputDimension_r(
  1002. GEOSContextHandle_t handle,
  1003. GEOSWKBWriter* writer, int newDimension);
  1004. /*
  1005. * Specify whether the WKB byte order is big or little endian.
  1006. * The return value is the previous byte order.
  1007. */
  1008. extern int GEOS_DLL GEOSWKBWriter_getByteOrder_r(GEOSContextHandle_t handle,
  1009. const GEOSWKBWriter* writer);
  1010. extern void GEOS_DLL GEOSWKBWriter_setByteOrder_r(GEOSContextHandle_t handle,
  1011. GEOSWKBWriter* writer,
  1012. int byteOrder);
  1013. /*
  1014. * Specify whether SRID values should be output.
  1015. */
  1016. extern char GEOS_DLL GEOSWKBWriter_getIncludeSRID_r(GEOSContextHandle_t handle,
  1017. const GEOSWKBWriter* writer);
  1018. extern void GEOS_DLL GEOSWKBWriter_setIncludeSRID_r(GEOSContextHandle_t handle,
  1019. GEOSWKBWriter* writer, const char writeSRID);
  1020. /*
  1021. * Free buffers returned by stuff like GEOSWKBWriter_write(),
  1022. * GEOSWKBWriter_writeHEX() and GEOSWKTWriter_write().
  1023. */
  1024. extern void GEOS_DLL GEOSFree_r(GEOSContextHandle_t handle, void *buffer);
  1025. /* External code to GEOS can define GEOS_USE_ONLY_R_API to avoid the */
  1026. /* non _r API to be available */
  1027. #ifndef GEOS_USE_ONLY_R_API
  1028. /************************************************************************
  1029. *
  1030. * Initialization, cleanup, version
  1031. *
  1032. ***********************************************************************/
  1033. extern void GEOS_DLL initGEOS(GEOSMessageHandler notice_function,
  1034. GEOSMessageHandler error_function);
  1035. extern void GEOS_DLL finishGEOS(void);
  1036. /************************************************************************
  1037. *
  1038. * NOTE - These functions are DEPRECATED. Please use the new Reader and
  1039. * writer APIS!
  1040. *
  1041. ***********************************************************************/
  1042. extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKT(const char *wkt);
  1043. extern char GEOS_DLL *GEOSGeomToWKT(const GEOSGeometry* g);
  1044. /*
  1045. * Specify whether output WKB should be 2d or 3d.
  1046. * Return previously set number of dimensions.
  1047. */
  1048. extern int GEOS_DLL GEOS_getWKBOutputDims();
  1049. extern int GEOS_DLL GEOS_setWKBOutputDims(int newDims);
  1050. /*
  1051. * Specify whether the WKB byte order is big or little endian.
  1052. * The return value is the previous byte order.
  1053. */
  1054. extern int GEOS_DLL GEOS_getWKBByteOrder();
  1055. extern int GEOS_DLL GEOS_setWKBByteOrder(int byteOrder);
  1056. extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKB_buf(const unsigned char *wkb, size_t size);
  1057. extern unsigned char GEOS_DLL *GEOSGeomToWKB_buf(const GEOSGeometry* g, size_t *size);
  1058. extern GEOSGeometry GEOS_DLL *GEOSGeomFromHEX_buf(const unsigned char *hex, size_t size);
  1059. extern unsigned char GEOS_DLL *GEOSGeomToHEX_buf(const GEOSGeometry* g, size_t *size);
  1060. /************************************************************************
  1061. *
  1062. * Coordinate Sequence functions
  1063. *
  1064. ***********************************************************************/
  1065. /*
  1066. * Create a Coordinate sequence with ``size'' coordinates
  1067. * of ``dims'' dimensions.
  1068. * Return NULL on exception.
  1069. */
  1070. extern GEOSCoordSequence GEOS_DLL *GEOSCoordSeq_create(unsigned int size, unsigned int dims);
  1071. /*
  1072. * Clone a Coordinate Sequence.
  1073. * Return NULL on exception.
  1074. */
  1075. extern GEOSCoordSequence GEOS_DLL *GEOSCoordSeq_clone(const GEOSCoordSequence* s);
  1076. /*
  1077. * Destroy a Coordinate Sequence.
  1078. */
  1079. extern void GEOS_DLL GEOSCoordSeq_destroy(GEOSCoordSequence* s);
  1080. /*
  1081. * Set ordinate values in a Coordinate Sequence.
  1082. * Return 0 on exception.
  1083. */
  1084. extern int GEOS_DLL GEOSCoordSeq_setX(GEOSCoordSequence* s,
  1085. unsigned int idx, double val);
  1086. extern int GEOS_DLL GEOSCoordSeq_setY(GEOSCoordSequence* s,
  1087. unsigned int idx, double val);
  1088. extern int GEOS_DLL GEOSCoordSeq_setZ(GEOSCoordSequence* s,
  1089. unsigned int idx, double val);
  1090. extern int GEOS_DLL GEOSCoordSeq_setOrdinate(GEOSCoordSequence* s,
  1091. unsigned int idx, unsigned int dim, double val);
  1092. /*
  1093. * Get ordinate values from a Coordinate Sequence.
  1094. * Return 0 on exception.
  1095. */
  1096. extern int GEOS_DLL GEOSCoordSeq_getX(const GEOSCoordSequence* s,
  1097. unsigned int idx, double *val);
  1098. extern int GEOS_DLL GEOSCoordSeq_getY(const GEOSCoordSequence* s,
  1099. unsigned int idx, double *val);
  1100. extern int GEOS_DLL GEOSCoordSeq_getZ(const GEOSCoordSequence* s,
  1101. unsigned int idx, double *val);
  1102. extern int GEOS_DLL GEOSCoordSeq_getOrdinate(const GEOSCoordSequence* s,
  1103. unsigned int idx, unsigned int dim, double *val);
  1104. /*
  1105. * Get size and dimensions info from a Coordinate Sequence.
  1106. * Return 0 on exception.
  1107. */
  1108. extern int GEOS_DLL GEOSCoordSeq_getSize(const GEOSCoordSequence* s,
  1109. unsigned int *size);
  1110. extern int GEOS_DLL GEOSCoordSeq_getDimensions(const GEOSCoordSequence* s,
  1111. unsigned int *dims);
  1112. /************************************************************************
  1113. *
  1114. * Linear referencing functions -- there are more, but these are
  1115. * probably sufficient for most purposes
  1116. *
  1117. ***********************************************************************/
  1118. /*
  1119. * GEOSGeometry ownership is retained by caller
  1120. */
  1121. /* Return distance of point 'p' projected on 'g' from origin
  1122. * of 'g'. Geometry 'g' must be a lineal geometry */
  1123. extern double GEOS_DLL GEOSProject(const GEOSGeometry *g,
  1124. const GEOSGeometry* p);
  1125. /* Return closest point to given distance within geometry
  1126. * Geometry must be a LineString */
  1127. extern GEOSGeometry GEOS_DLL *GEOSInterpolate(const GEOSGeometry *g,
  1128. double d);
  1129. extern double GEOS_DLL GEOSProjectNormalized(const GEOSGeometry *g,
  1130. const GEOSGeometry* p);
  1131. extern GEOSGeometry GEOS_DLL *GEOSInterpolateNormalized(const GEOSGeometry *g,
  1132. double d);
  1133. /************************************************************************
  1134. *
  1135. * Buffer related functions
  1136. *
  1137. ***********************************************************************/
  1138. /* @return NULL on exception */
  1139. extern GEOSGeometry GEOS_DLL *GEOSBuffer(const GEOSGeometry* g,
  1140. double width, int quadsegs);
  1141. /* @return 0 on exception */
  1142. extern GEOSBufferParams GEOS_DLL *GEOSBufferParams_create();
  1143. extern void GEOS_DLL GEOSBufferParams_destroy(GEOSBufferParams* parms);
  1144. /* @return 0 on exception */
  1145. extern int GEOS_DLL GEOSBufferParams_setEndCapStyle(
  1146. GEOSBufferParams* p,
  1147. int style);
  1148. /* @return 0 on exception */
  1149. extern int GEOS_DLL GEOSBufferParams_setJoinStyle(
  1150. GEOSBufferParams* p,
  1151. int joinStyle);
  1152. /* @return 0 on exception */
  1153. extern int GEOS_DLL GEOSBufferParams_setMitreLimit(
  1154. GEOSBufferParams* p,
  1155. double mitreLimit);
  1156. /* @return 0 on exception */
  1157. extern int GEOS_DLL GEOSBufferParams_setQuadrantSegments(
  1158. GEOSBufferParams* p,
  1159. int quadSegs);
  1160. /* @param singleSided: 1 for single sided, 0 otherwise */
  1161. /* @return 0 on exception */
  1162. extern int GEOS_DLL GEOSBufferParams_setSingleSided(
  1163. GEOSBufferParams* p,
  1164. int singleSided);
  1165. /* @return NULL on exception */
  1166. extern GEOSGeometry GEOS_DLL *GEOSBufferWithParams(
  1167. const GEOSGeometry* g,
  1168. const GEOSBufferParams* p,
  1169. double width);
  1170. /* These functions return NULL on exception. */
  1171. extern GEOSGeometry GEOS_DLL *GEOSBufferWithStyle(const GEOSGeometry* g,
  1172. double width, int quadsegs, int endCapStyle, int joinStyle,
  1173. double mitreLimit);
  1174. /* These functions return NULL on exception. Only LINESTRINGs are accepted. */
  1175. /* @deprecated in 3.3.0: use GEOSOffsetCurve instead */
  1176. extern GEOSGeometry GEOS_DLL *GEOSSingleSidedBuffer(const GEOSGeometry* g,
  1177. double width, int quadsegs, int joinStyle, double mitreLimit,
  1178. int leftSide);
  1179. /*
  1180. * Only LINESTRINGs are accepted.
  1181. * @param width : offset distance.
  1182. * negative for right side offset.
  1183. * positive for left side offset.
  1184. * @return NULL on exception
  1185. */
  1186. extern GEOSGeometry GEOS_DLL *GEOSOffsetCurve(const GEOSGeometry* g,
  1187. double width, int quadsegs, int joinStyle, double mitreLimit);
  1188. /************************************************************************
  1189. *
  1190. * Geometry Constructors.
  1191. * GEOSCoordSequence* arguments will become ownership of the returned object.
  1192. * All functions return NULL on exception.
  1193. *
  1194. ***********************************************************************/
  1195. extern GEOSGeometry GEOS_DLL *GEOSGeom_createPoint(GEOSCoordSequence* s);
  1196. extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPoint();
  1197. extern GEOSGeometry GEOS_DLL *GEOSGeom_createLinearRing(GEOSCoordSequence* s);
  1198. extern GEOSGeometry GEOS_DLL *GEOSGeom_createLineString(GEOSCoordSequence* s);
  1199. extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyLineString();
  1200. /*
  1201. * Second argument is an array of GEOSGeometry* objects.
  1202. * The caller remains owner of the array, but pointed-to
  1203. * objects become ownership of the returned GEOSGeometry.
  1204. */
  1205. extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPolygon();
  1206. extern GEOSGeometry GEOS_DLL *GEOSGeom_createPolygon(GEOSGeometry* shell,
  1207. GEOSGeometry** holes, unsigned int nholes);
  1208. extern GEOSGeometry GEOS_DLL *GEOSGeom_createCollection(int type,
  1209. GEOSGeometry* *geoms, unsigned int ngeoms);
  1210. extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyCollection(int type);
  1211. extern GEOSGeometry GEOS_DLL *GEOSGeom_clone(const GEOSGeometry* g);
  1212. /************************************************************************
  1213. *
  1214. * Memory management
  1215. *
  1216. ***********************************************************************/
  1217. extern void GEOS_DLL GEOSGeom_destroy(GEOSGeometry* g);
  1218. /************************************************************************
  1219. *
  1220. * Topology operations - return NULL on exception.
  1221. *
  1222. ***********************************************************************/
  1223. extern GEOSGeometry GEOS_DLL *GEOSEnvelope(const GEOSGeometry* g);
  1224. extern GEOSGeometry GEOS_DLL *GEOSIntersection(const GEOSGeometry* g1, const GEOSGeometry* g2);
  1225. extern GEOSGeometry GEOS_DLL *GEOSConvexHull(const GEOSGeometry* g);
  1226. extern GEOSGeometry GEOS_DLL *GEOSDifference(const GEOSGeometry* g1, const GEOSGeometry* g2);
  1227. extern GEOSGeometry GEOS_DLL *GEOSSymDifference(const GEOSGeometry* g1, const GEOSGeometry* g2);
  1228. extern GEOSGeometry GEOS_DLL *GEOSBoundary(const GEOSGeometry* g);
  1229. extern GEOSGeometry GEOS_DLL *GEOSUnion(const GEOSGeometry* g1, const GEOSGeometry* g2);
  1230. extern GEOSGeometry GEOS_DLL *GEOSUnaryUnion(const GEOSGeometry* g);
  1231. /* @deprecated in 3.3.0: use GEOSUnaryUnion instead */
  1232. extern GEOSGeometry GEOS_DLL *GEOSUnionCascaded(const GEOSGeometry* g);
  1233. extern GEOSGeometry GEOS_DLL *GEOSPointOnSurface(const GEOSGeometry* g);
  1234. extern GEOSGeometry GEOS_DLL *GEOSGetCentroid(const GEOSGeometry* g);
  1235. extern GEOSGeometry GEOS_DLL *GEOSNode(const GEOSGeometry* g);
  1236. extern GEOSGeometry GEOS_DLL *GEOSClipByRect(const GEOSGeometry* g, double xmin, double ymin, double xmax, double ymax);
  1237. /*
  1238. * all arguments remain ownership of the caller
  1239. * (both Geometries and pointers)
  1240. */
  1241. extern GEOSGeometry GEOS_DLL *GEOSPolygonize(const GEOSGeometry * const geoms[], unsigned int ngeoms);
  1242. extern GEOSGeometry GEOS_DLL *GEOSPolygonizer_getCutEdges(const GEOSGeometry * const geoms[], unsigned int ngeoms);
  1243. /*
  1244. * Polygonizes a set of Geometries which contain linework that
  1245. * represents the edges of a planar graph.
  1246. *
  1247. * Any dimension of Geometry is handled - the constituent linework
  1248. * is extracted to form the edges.
  1249. *
  1250. * The edges must be correctly noded; that is, they must only meet
  1251. * at their endpoints.
  1252. * The Polygonizer will still run on incorrectly noded input
  1253. * but will not form polygons from incorrectly noded edges.
  1254. *
  1255. * The Polygonizer reports the follow kinds of errors:
  1256. *
  1257. * - Dangles - edges which have one or both ends which are
  1258. * not incident on another edge endpoint
  1259. * - Cut Edges - edges which are connected at both ends but
  1260. * which do not form part of polygon
  1261. * - Invalid Ring Lines - edges which form rings which are invalid
  1262. * (e.g. the component lines contain a self-intersection)
  1263. *
  1264. * Errors are reported to output parameters "cuts", "dangles" and
  1265. * "invalid" (if not-null). Formed polygons are returned as a
  1266. * collection. NULL is returned on exception. All returned
  1267. * geometries must be destroyed by caller.
  1268. *
  1269. */
  1270. extern GEOSGeometry GEOS_DLL *GEOSPolygonize_full(const GEOSGeometry* input,
  1271. GEOSGeometry** cuts, GEOSGeometry** dangles, GEOSGeometry** invalid);
  1272. extern GEOSGeometry GEOS_DLL *GEOSLineMerge(const GEOSGeometry* g);
  1273. extern GEOSGeometry GEOS_DLL *GEOSSimplify(const GEOSGeometry* g, double tolerance);
  1274. extern GEOSGeometry GEOS_DLL *GEOSTopologyPreserveSimplify(const GEOSGeometry* g,
  1275. double tolerance);
  1276. /*
  1277. * Return all distinct vertices of input geometry as a MULTIPOINT.
  1278. * Note that only 2 dimensions of the vertices are considered when
  1279. * testing for equality.
  1280. */
  1281. extern GEOSGeometry GEOS_DLL *GEOSGeom_extractUniquePoints(
  1282. const GEOSGeometry* g);
  1283. /*
  1284. * Find paths shared between the two given lineal geometries.
  1285. *
  1286. * Returns a GEOMETRYCOLLECTION having two elements:
  1287. * - first element is a MULTILINESTRING containing shared paths
  1288. * having the _same_ direction on both inputs
  1289. * - second element is a MULTILINESTRING containing shared paths
  1290. * having the _opposite_ direction on the two inputs
  1291. *
  1292. * Returns NULL on exception
  1293. */
  1294. extern GEOSGeometry GEOS_DLL *GEOSSharedPaths(const GEOSGeometry* g1,
  1295. const GEOSGeometry* g2);
  1296. /*
  1297. * Snap first geometry on to second with given tolerance
  1298. * Returns a newly allocated geometry, or NULL on exception
  1299. */
  1300. extern GEOSGeometry GEOS_DLL *GEOSSnap(const GEOSGeometry* g1,
  1301. const GEOSGeometry* g2, double tolerance);
  1302. /*
  1303. * Return a Delaunay triangulation of the vertex of the given geometry
  1304. *
  1305. * @param g the input geometry whose vertex will be used as "sites"
  1306. * @param tolerance optional snapping tolerance to use for improved robustness
  1307. * @param onlyEdges if non-zero will return a MULTILINESTRING, otherwise it will
  1308. * return a GEOMETRYCOLLECTION containing triangular POLYGONs.
  1309. *
  1310. * @return a newly allocated geometry, or NULL on exception
  1311. */
  1312. extern GEOSGeometry GEOS_DLL * GEOSDelaunayTriangulation(
  1313. const GEOSGeometry *g,
  1314. double tolerance,
  1315. int onlyEdges);
  1316. /*
  1317. * Returns the Voronoi polygons of a set of Vertices given as input
  1318. *
  1319. * @param g the input geometry whose vertex will be used as sites.
  1320. * @param tolerance snapping tolerance to use for improved robustness
  1321. * @param onlyEdges whether to return only edges of the voronoi cells
  1322. * @param env clipping envelope for the returned diagram, automatically
  1323. * determined if NULL.
  1324. * The diagram will be clipped to the larger
  1325. * of this envelope or an envelope surrounding the sites.
  1326. *
  1327. * @return a newly allocated geometry, or NULL on exception.
  1328. */
  1329. extern GEOSGeometry GEOS_DLL * GEOSVoronoiDiagram(
  1330. const GEOSGeometry *g,
  1331. const GEOSGeometry *env,
  1332. double tolerance,
  1333. int onlyEdges);
  1334. /************************************************************************
  1335. *
  1336. * Binary predicates - return 2 on exception, 1 on true, 0 on false
  1337. *
  1338. ***********************************************************************/
  1339. extern char GEOS_DLL GEOSDisjoint(const GEOSGeometry* g1, const GEOSGeometry* g2);
  1340. extern char GEOS_DLL GEOSTouches(const GEOSGeometry* g1, const GEOSGeometry* g2);
  1341. extern char GEOS_DLL GEOSIntersects(const GEOSGeometry* g1, const GEOSGeometry* g2);
  1342. extern char GEOS_DLL GEOSCrosses(const GEOSGeometry* g1, const GEOSGeometry* g2);
  1343. extern char GEOS_DLL GEOSWithin(const GEOSGeometry* g1, const GEOSGeometry* g2);
  1344. extern char GEOS_DLL GEOSContains(const GEOSGeometry* g1, const GEOSGeometry* g2);
  1345. extern char GEOS_DLL GEOSOverlaps(const GEOSGeometry* g1, const GEOSGeometry* g2);
  1346. extern char GEOS_DLL GEOSEquals(const GEOSGeometry* g1, const GEOSGeometry* g2);
  1347. extern char GEOS_DLL GEOSEqualsExact(const GEOSGeometry* g1, const GEOSGeometry* g2, double tolerance);
  1348. extern char GEOS_DLL GEOSCovers(const GEOSGeometry* g1, const GEOSGeometry* g2);
  1349. extern char GEOS_DLL GEOSCoveredBy(const GEOSGeometry* g1, const GEOSGeometry* g2);
  1350. /************************************************************************
  1351. *
  1352. * Prepared Geometry Binary predicates - return 2 on exception, 1 on true, 0 on false
  1353. *
  1354. ***********************************************************************/
  1355. /*
  1356. * GEOSGeometry ownership is retained by caller
  1357. */
  1358. extern const GEOSPreparedGeometry GEOS_DLL *GEOSPrepare(const GEOSGeometry* g);
  1359. extern void GEOS_DLL GEOSPreparedGeom_destroy(const GEOSPreparedGeometry* g);
  1360. extern char GEOS_DLL GEOSPreparedContains(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
  1361. extern char GEOS_DLL GEOSPreparedContainsProperly(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
  1362. extern char GEOS_DLL GEOSPreparedCoveredBy(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
  1363. extern char GEOS_DLL GEOSPreparedCovers(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
  1364. extern char GEOS_DLL GEOSPreparedCrosses(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
  1365. extern char GEOS_DLL GEOSPreparedDisjoint(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
  1366. extern char GEOS_DLL GEOSPreparedIntersects(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
  1367. extern char GEOS_DLL GEOSPreparedOverlaps(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
  1368. extern char GEOS_DLL GEOSPreparedTouches(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
  1369. extern char GEOS_DLL GEOSPreparedWithin(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
  1370. /************************************************************************
  1371. *
  1372. * STRtree functions
  1373. *
  1374. ***********************************************************************/
  1375. /*
  1376. * GEOSGeometry ownership is retained by caller
  1377. */
  1378. extern GEOSSTRtree GEOS_DLL *GEOSSTRtree_create(size_t nodeCapacity);
  1379. extern void GEOS_DLL GEOSSTRtree_insert(GEOSSTRtree *tree,
  1380. const GEOSGeometry *g,
  1381. void *item);
  1382. extern void GEOS_DLL GEOSSTRtree_query(GEOSSTRtree *tree,
  1383. const GEOSGeometry *g,
  1384. GEOSQueryCallback callback,
  1385. void *userdata);
  1386. extern void GEOS_DLL GEOSSTRtree_iterate(GEOSSTRtree *tree,
  1387. GEOSQueryCallback callback,
  1388. void *userdata);
  1389. extern char GEOS_DLL GEOSSTRtree_remove(GEOSSTRtree *tree,
  1390. const GEOSGeometry *g,
  1391. void *item);
  1392. extern void GEOS_DLL GEOSSTRtree_destroy(GEOSSTRtree *tree);
  1393. /************************************************************************
  1394. *
  1395. * Unary predicate - return 2 on exception, 1 on true, 0 on false
  1396. *
  1397. ***********************************************************************/
  1398. extern char GEOS_DLL GEOSisEmpty(const GEOSGeometry* g);
  1399. extern char GEOS_DLL GEOSisSimple(const GEOSGeometry* g);
  1400. extern char GEOS_DLL GEOSisRing(const GEOSGeometry* g);
  1401. extern char GEOS_DLL GEOSHasZ(const GEOSGeometry* g);
  1402. extern char GEOS_DLL GEOSisClosed(const GEOSGeometry *g);
  1403. /************************************************************************
  1404. *
  1405. * Dimensionally Extended 9 Intersection Model related
  1406. *
  1407. ***********************************************************************/
  1408. /* return 2 on exception, 1 on true, 0 on false */
  1409. extern char GEOS_DLL GEOSRelatePattern(const GEOSGeometry* g1, const GEOSGeometry* g2, const char *pat);
  1410. /* return NULL on exception, a string to GEOSFree otherwise */
  1411. extern char GEOS_DLL *GEOSRelate(const GEOSGeometry* g1, const GEOSGeometry* g2);
  1412. /* return 2 on exception, 1 on true, 0 on false */
  1413. extern char GEOS_DLL GEOSRelatePatternMatch(const char *mat, const char *pat);
  1414. /* return NULL on exception, a string to GEOSFree otherwise */
  1415. extern char GEOS_DLL *GEOSRelateBoundaryNodeRule(const GEOSGeometry* g1,
  1416. const GEOSGeometry* g2,
  1417. int bnr);
  1418. /************************************************************************
  1419. *
  1420. * Validity checking
  1421. *
  1422. ***********************************************************************/
  1423. /* return 2 on exception, 1 on true, 0 on false */
  1424. extern char GEOS_DLL GEOSisValid(const GEOSGeometry* g);
  1425. /* return NULL on exception, a string to GEOSFree otherwise */
  1426. extern char GEOS_DLL *GEOSisValidReason(const GEOSGeometry *g);
  1427. /*
  1428. * Caller has the responsibility to destroy 'reason' (GEOSFree)
  1429. * and 'location' (GEOSGeom_destroy) params
  1430. * return 2 on exception, 1 when valid, 0 when invalid
  1431. * Use enum GEOSValidFlags values for the flags param.
  1432. */
  1433. extern char GEOS_DLL GEOSisValidDetail(const GEOSGeometry* g,
  1434. int flags,
  1435. char** reason, GEOSGeometry** location);
  1436. /************************************************************************
  1437. *
  1438. * Geometry info
  1439. *
  1440. ***********************************************************************/
  1441. /* Return NULL on exception, result must be freed by caller. */
  1442. extern char GEOS_DLL *GEOSGeomType(const GEOSGeometry* g);
  1443. /* Return -1 on exception */
  1444. extern int GEOS_DLL GEOSGeomTypeId(const GEOSGeometry* g);
  1445. /* Return 0 on exception */
  1446. extern int GEOS_DLL GEOSGetSRID(const GEOSGeometry* g);
  1447. extern void GEOS_DLL GEOSSetSRID(GEOSGeometry* g, int SRID);
  1448. /* May be called on all geometries in GEOS 3.x, returns -1 on error and 1
  1449. * for non-multi geometries. Older GEOS versions only accept
  1450. * GeometryCollections or Multi* geometries here, and are likely to crash
  1451. * when fed simple geometries, so beware if you need compatibility with
  1452. * old GEOS versions.
  1453. */
  1454. extern int GEOS_DLL GEOSGetNumGeometries(const GEOSGeometry* g);
  1455. /*
  1456. * Return NULL on exception.
  1457. * Returned object is a pointer to internal storage:
  1458. * it must NOT be destroyed directly.
  1459. * Up to GEOS 3.2.0 the input geometry must be a Collection, in
  1460. * later version it doesn't matter (getGeometryN(0) for a single will
  1461. * return the input).
  1462. */
  1463. extern const GEOSGeometry GEOS_DLL *GEOSGetGeometryN(const GEOSGeometry* g, int n);
  1464. /* Return -1 on exception */
  1465. extern int GEOS_DLL GEOSNormalize(GEOSGeometry* g);
  1466. /* Return -1 on exception */
  1467. extern int GEOS_DLL GEOSGetNumInteriorRings(const GEOSGeometry* g);
  1468. /* Return -1 on exception, Geometry must be a LineString. */
  1469. extern int GEOS_DLL GEOSGeomGetNumPoints(const GEOSGeometry* g);
  1470. /* Return -1 on exception, Geometry must be a Point. */
  1471. extern int GEOS_DLL GEOSGeomGetX(const GEOSGeometry *g, double *x);
  1472. extern int GEOS_DLL GEOSGeomGetY(const GEOSGeometry *g, double *y);
  1473. /*
  1474. * Return NULL on exception, Geometry must be a Polygon.
  1475. * Returned object is a pointer to internal storage:
  1476. * it must NOT be destroyed directly.
  1477. */
  1478. extern const GEOSGeometry GEOS_DLL *GEOSGetInteriorRingN(const GEOSGeometry* g, int n);
  1479. /*
  1480. * Return NULL on exception, Geometry must be a Polygon.
  1481. * Returned object is a pointer to internal storage:
  1482. * it must NOT be destroyed directly.
  1483. */
  1484. extern const GEOSGeometry GEOS_DLL *GEOSGetExteriorRing(const GEOSGeometry* g);
  1485. /* Return -1 on exception */
  1486. extern int GEOS_DLL GEOSGetNumCoordinates(const GEOSGeometry* g);
  1487. /*
  1488. * Return NULL on exception.
  1489. * Geometry must be a LineString, LinearRing or Point.
  1490. */
  1491. extern const GEOSCoordSequence GEOS_DLL *GEOSGeom_getCoordSeq(const GEOSGeometry* g);
  1492. /*
  1493. * Return 0 on exception (or empty geometry)
  1494. */
  1495. extern int GEOS_DLL GEOSGeom_getDimensions(const GEOSGeometry* g);
  1496. /*
  1497. * Return 2 or 3.
  1498. */
  1499. extern int GEOS_DLL GEOSGeom_getCoordinateDimension(const GEOSGeometry* g);
  1500. /*
  1501. * Return NULL on exception.
  1502. * Must be LineString and must be freed by called.
  1503. */
  1504. extern GEOSGeometry GEOS_DLL *GEOSGeomGetPointN(const GEOSGeometry *g, int n);
  1505. extern GEOSGeometry GEOS_DLL *GEOSGeomGetStartPoint(const GEOSGeometry *g);
  1506. extern GEOSGeometry GEOS_DLL *GEOSGeomGetEndPoint(const GEOSGeometry *g);
  1507. /************************************************************************
  1508. *
  1509. * Misc functions
  1510. *
  1511. ***********************************************************************/
  1512. /* Return 0 on exception, 1 otherwise */
  1513. extern int GEOS_DLL GEOSArea(const GEOSGeometry* g, double *area);
  1514. extern int GEOS_DLL GEOSLength(const GEOSGeometry* g, double *length);
  1515. extern int GEOS_DLL GEOSDistance(const GEOSGeometry* g1, const GEOSGeometry* g2,
  1516. double *dist);
  1517. extern int GEOS_DLL GEOSHausdorffDistance(const GEOSGeometry *g1,
  1518. const GEOSGeometry *g2, double *dist);
  1519. extern int GEOS_DLL GEOSHausdorffDistanceDensify(const GEOSGeometry *g1,
  1520. const GEOSGeometry *g2, double densifyFrac, double *dist);
  1521. extern int GEOS_DLL GEOSGeomGetLength(const GEOSGeometry *g, double *length);
  1522. /* Return 0 on exception, the closest points of the two geometries otherwise.
  1523. * The first point comes from g1 geometry and the second point comes from g2.
  1524. */
  1525. extern GEOSCoordSequence GEOS_DLL *GEOSNearestPoints(
  1526. const GEOSGeometry* g1, const GEOSGeometry* g2);
  1527. /************************************************************************
  1528. *
  1529. * Algorithms
  1530. *
  1531. ***********************************************************************/
  1532. /* Walking from A to B:
  1533. * return -1 if reaching P takes a counter-clockwise (left) turn
  1534. * return 1 if reaching P takes a clockwise (right) turn
  1535. * return 0 if P is collinear with A-B
  1536. *
  1537. * On exceptions, return 2.
  1538. *
  1539. */
  1540. extern int GEOS_DLL GEOSOrientationIndex(double Ax, double Ay, double Bx, double By,
  1541. double Px, double Py);
  1542. /************************************************************************
  1543. *
  1544. * Reader and Writer APIs
  1545. *
  1546. ***********************************************************************/
  1547. /* WKT Reader */
  1548. extern GEOSWKTReader GEOS_DLL *GEOSWKTReader_create();
  1549. extern void GEOS_DLL GEOSWKTReader_destroy(GEOSWKTReader* reader);
  1550. extern GEOSGeometry GEOS_DLL *GEOSWKTReader_read(GEOSWKTReader* reader, const char *wkt);
  1551. /* WKT Writer */
  1552. extern GEOSWKTWriter GEOS_DLL *GEOSWKTWriter_create();
  1553. extern void GEOS_DLL GEOSWKTWriter_destroy(GEOSWKTWriter* writer);
  1554. extern char GEOS_DLL *GEOSWKTWriter_write(GEOSWKTWriter* writer, const GEOSGeometry* g);
  1555. extern void GEOS_DLL GEOSWKTWriter_setTrim(GEOSWKTWriter *writer, char trim);
  1556. extern void GEOS_DLL GEOSWKTWriter_setRoundingPrecision(GEOSWKTWriter *writer, int precision);
  1557. extern void GEOS_DLL GEOSWKTWriter_setOutputDimension(GEOSWKTWriter *writer, int dim);
  1558. extern int GEOS_DLL GEOSWKTWriter_getOutputDimension(GEOSWKTWriter *writer);
  1559. extern void GEOS_DLL GEOSWKTWriter_setOld3D(GEOSWKTWriter *writer, int useOld3D);
  1560. /* WKB Reader */
  1561. extern GEOSWKBReader GEOS_DLL *GEOSWKBReader_create();
  1562. extern void GEOS_DLL GEOSWKBReader_destroy(GEOSWKBReader* reader);
  1563. extern GEOSGeometry GEOS_DLL *GEOSWKBReader_read(GEOSWKBReader* reader, const unsigned char *wkb, size_t size);
  1564. extern GEOSGeometry GEOS_DLL *GEOSWKBReader_readHEX(GEOSWKBReader* reader, const unsigned char *hex, size_t size);
  1565. /* WKB Writer */
  1566. extern GEOSWKBWriter GEOS_DLL *GEOSWKBWriter_create();
  1567. extern void GEOS_DLL GEOSWKBWriter_destroy(GEOSWKBWriter* writer);
  1568. /* The caller owns the results for these two methods! */
  1569. extern unsigned char GEOS_DLL *GEOSWKBWriter_write(GEOSWKBWriter* writer, const GEOSGeometry* g, size_t *size);
  1570. extern unsigned char GEOS_DLL *GEOSWKBWriter_writeHEX(GEOSWKBWriter* writer, const GEOSGeometry* g, size_t *size);
  1571. /*
  1572. * Specify whether output WKB should be 2d or 3d.
  1573. * Return previously set number of dimensions.
  1574. */
  1575. extern int GEOS_DLL GEOSWKBWriter_getOutputDimension(const GEOSWKBWriter* writer);
  1576. extern void GEOS_DLL GEOSWKBWriter_setOutputDimension(GEOSWKBWriter* writer, int newDimension);
  1577. /*
  1578. * Specify whether the WKB byte order is big or little endian.
  1579. * The return value is the previous byte order.
  1580. */
  1581. extern int GEOS_DLL GEOSWKBWriter_getByteOrder(const GEOSWKBWriter* writer);
  1582. extern void GEOS_DLL GEOSWKBWriter_setByteOrder(GEOSWKBWriter* writer, int byteOrder);
  1583. /*
  1584. * Specify whether SRID values should be output.
  1585. */
  1586. extern char GEOS_DLL GEOSWKBWriter_getIncludeSRID(const GEOSWKBWriter* writer);
  1587. extern void GEOS_DLL GEOSWKBWriter_setIncludeSRID(GEOSWKBWriter* writer, const char writeSRID);
  1588. /*
  1589. * Free buffers returned by stuff like GEOSWKBWriter_write(),
  1590. * GEOSWKBWriter_writeHEX() and GEOSWKTWriter_write().
  1591. */
  1592. extern void GEOS_DLL GEOSFree(void *buffer);
  1593. #endif /* #ifndef GEOS_USE_ONLY_R_API */
  1594. #ifdef __cplusplus
  1595. } // extern "C"
  1596. #endif
  1597. #endif /* #ifndef GEOS_C_H_INCLUDED */