1 : /******************************************************************************
2 : * $Id: ogrgeometry.cpp 23513 2011-12-10 21:12:59Z rouault $
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: Implements a few base methods on OGRGeometry.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 1999, Frank Warmerdam
10 : *
11 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 : #include "ogr_geometry.h"
31 : #include "ogr_api.h"
32 : #include "ogr_p.h"
33 : #include "ogr_geos.h"
34 : #include "cpl_multiproc.h"
35 : #include <assert.h>
36 :
37 : CPL_CVSID("$Id: ogrgeometry.cpp 23513 2011-12-10 21:12:59Z rouault $");
38 :
39 : int OGRGeometry::bGenerate_DB2_V72_BYTE_ORDER = FALSE;
40 :
41 : #ifdef HAVE_GEOS
42 0 : static void _GEOSErrorHandler(const char *fmt, ...)
43 : {
44 : va_list args;
45 :
46 0 : va_start(args, fmt);
47 0 : CPLErrorV( CE_Failure, CPLE_AppDefined, fmt, args );
48 0 : va_end(args);
49 0 : }
50 :
51 1 : static void _GEOSWarningHandler(const char *fmt, ...)
52 : {
53 : va_list args;
54 :
55 1 : va_start(args, fmt);
56 1 : CPLErrorV( CE_Warning, CPLE_AppDefined, fmt, args );
57 1 : va_end(args);
58 1 : }
59 : #endif
60 :
61 : /************************************************************************/
62 : /* OGRGeometry() */
63 : /************************************************************************/
64 :
65 683716 : OGRGeometry::OGRGeometry()
66 :
67 : {
68 683716 : poSRS = NULL;
69 683716 : nCoordDimension = 2;
70 683716 : }
71 :
72 : /************************************************************************/
73 : /* ~OGRGeometry() */
74 : /************************************************************************/
75 :
76 683803 : OGRGeometry::~OGRGeometry()
77 :
78 : {
79 683803 : if( poSRS != NULL )
80 604006 : poSRS->Release();
81 683803 : }
82 :
83 : /************************************************************************/
84 : /* dumpReadable() */
85 : /************************************************************************/
86 :
87 : /**
88 : * \brief Dump geometry in well known text format to indicated output file.
89 : *
90 : * A few options can be defined to change the default dump :
91 : * <ul>
92 : * <li>DISPLAY_GEOMETRY=NO : to hide the dump of the geometry</li>
93 : * <li>DISPLAY_GEOMETRY=WKT or YES (default) : dump the geometry as a WKT</li>
94 : * <li>DISPLAY_GEOMETRY=SUMMARY : to get only a summary of the geometry</li>
95 : * </ul>
96 : *
97 : * This method is the same as the C function OGR_G_DumpReadable().
98 : *
99 : * @param fp the text file to write the geometry to.
100 : * @param pszPrefix the prefix to put on each line of output.
101 : * @param papszOptions NULL terminated list of options (may be NULL)
102 : */
103 :
104 57 : void OGRGeometry::dumpReadable( FILE * fp, const char * pszPrefix, char** papszOptions ) const
105 :
106 : {
107 57 : char *pszWkt = NULL;
108 :
109 57 : if( pszPrefix == NULL )
110 0 : pszPrefix = "";
111 :
112 57 : if( fp == NULL )
113 0 : fp = stdout;
114 :
115 : const char* pszDisplayGeometry =
116 57 : CSLFetchNameValue(papszOptions, "DISPLAY_GEOMETRY");
117 67 : if (pszDisplayGeometry != NULL && EQUAL(pszDisplayGeometry, "SUMMARY"))
118 : {
119 : OGRLineString *poLine;
120 : OGRPolygon *poPoly;
121 : OGRLinearRing *poRing;
122 : OGRGeometryCollection *poColl;
123 10 : fprintf( fp, "%s%s : ", pszPrefix, getGeometryName() );
124 10 : switch( getGeometryType() )
125 : {
126 : case wkbUnknown:
127 : case wkbNone:
128 : case wkbPoint:
129 : case wkbPoint25D:
130 0 : fprintf( fp, "\n");
131 0 : break;
132 : case wkbLineString:
133 : case wkbLineString25D:
134 0 : poLine = (OGRLineString*)this;
135 0 : fprintf( fp, "%d points\n", poLine->getNumPoints() );
136 0 : break;
137 : case wkbPolygon:
138 : case wkbPolygon25D:
139 : {
140 : int ir;
141 : int nRings;
142 10 : poPoly = (OGRPolygon*)this;
143 10 : poRing = poPoly->getExteriorRing();
144 10 : nRings = poPoly->getNumInteriorRings();
145 10 : if (poRing == NULL)
146 0 : fprintf( fp, "empty");
147 : else
148 : {
149 10 : fprintf( fp, "%d points", poRing->getNumPoints() );
150 10 : if (nRings)
151 : {
152 0 : fprintf( fp, ", %d inner rings (", nRings);
153 0 : for( ir = 0; ir < nRings; ir++)
154 : {
155 0 : if (ir)
156 0 : fprintf( fp, ", ");
157 : fprintf( fp, "%d points",
158 0 : poPoly->getInteriorRing(ir)->getNumPoints() );
159 : }
160 0 : fprintf( fp, ")");
161 : }
162 : }
163 10 : fprintf( fp, "\n");
164 10 : break;
165 : }
166 : case wkbMultiPoint:
167 : case wkbMultiPoint25D:
168 : case wkbMultiLineString:
169 : case wkbMultiLineString25D:
170 : case wkbMultiPolygon:
171 : case wkbMultiPolygon25D:
172 : case wkbGeometryCollection:
173 : case wkbGeometryCollection25D:
174 : {
175 : int ig;
176 0 : poColl = (OGRGeometryCollection*)this;
177 0 : fprintf( fp, "%d geometries:\n", poColl->getNumGeometries() );
178 0 : for ( ig = 0; ig < poColl->getNumGeometries(); ig++)
179 : {
180 0 : OGRGeometry * poChild = (OGRGeometry*)poColl->getGeometryRef(ig);
181 0 : fprintf( fp, "%s", pszPrefix);
182 0 : poChild->dumpReadable( fp, pszPrefix, papszOptions );
183 : }
184 : break;
185 : }
186 : case wkbLinearRing:
187 : break;
188 : }
189 : }
190 47 : else if (pszDisplayGeometry == NULL || CSLTestBoolean(pszDisplayGeometry) ||
191 : EQUAL(pszDisplayGeometry, "WKT"))
192 : {
193 47 : if( exportToWkt( &pszWkt ) == OGRERR_NONE )
194 : {
195 47 : fprintf( fp, "%s%s\n", pszPrefix, pszWkt );
196 47 : CPLFree( pszWkt );
197 : }
198 : }
199 57 : }
200 :
201 : /************************************************************************/
202 : /* OGR_G_DumpReadable() */
203 : /************************************************************************/
204 : /**
205 : * \brief Dump geometry in well known text format to indicated output file.
206 : *
207 : * This method is the same as the CPP method OGRGeometry::dumpReadable.
208 : *
209 : * @param hGeom handle on the geometry to dump.
210 : * @param fp the text file to write the geometry to.
211 : * @param pszPrefix the prefix to put on each line of output.
212 : */
213 :
214 0 : void OGR_G_DumpReadable( OGRGeometryH hGeom, FILE *fp, const char *pszPrefix )
215 :
216 : {
217 0 : VALIDATE_POINTER0( hGeom, "OGR_G_DumpReadable" );
218 :
219 0 : ((OGRGeometry *) hGeom)->dumpReadable( fp, pszPrefix );
220 : }
221 :
222 : /************************************************************************/
223 : /* assignSpatialReference() */
224 : /************************************************************************/
225 :
226 : /**
227 : * \fn void OGRGeometry::assignSpatialReference( OGRSpatialReference * poSR );
228 : *
229 : * \brief Assign spatial reference to this object.
230 : *
231 : * Any existing spatial reference
232 : * is replaced, but under no circumstances does this result in the object
233 : * being reprojected. It is just changing the interpretation of the existing
234 : * geometry. Note that assigning a spatial reference increments the
235 : * reference count on the OGRSpatialReference, but does not copy it.
236 : *
237 : * This is similar to the SFCOM IGeometry::put_SpatialReference() method.
238 : *
239 : * This method is the same as the C function OGR_G_AssignSpatialReference().
240 : *
241 : * @param poSR new spatial reference system to apply.
242 : */
243 :
244 682123 : void OGRGeometry::assignSpatialReference( OGRSpatialReference * poSR )
245 :
246 : {
247 682123 : if( poSRS != NULL )
248 24604 : poSRS->Release();
249 :
250 682123 : poSRS = poSR;
251 682123 : if( poSRS != NULL )
252 628610 : poSRS->Reference();
253 682123 : }
254 :
255 : /************************************************************************/
256 : /* OGR_G_AssignSpatialReference() */
257 : /************************************************************************/
258 : /**
259 : * \brief Assign spatial reference to this object.
260 : *
261 : * Any existing spatial reference
262 : * is replaced, but under no circumstances does this result in the object
263 : * being reprojected. It is just changing the interpretation of the existing
264 : * geometry. Note that assigning a spatial reference increments the
265 : * reference count on the OGRSpatialReference, but does not copy it.
266 : *
267 : * This is similar to the SFCOM IGeometry::put_SpatialReference() method.
268 : *
269 : * This function is the same as the CPP method
270 : * OGRGeometry::assignSpatialReference.
271 : *
272 : * @param hGeom handle on the geometry to apply the new spatial reference
273 : * system.
274 : * @param hSRS handle on the new spatial reference system to apply.
275 : */
276 :
277 376 : void OGR_G_AssignSpatialReference( OGRGeometryH hGeom,
278 : OGRSpatialReferenceH hSRS )
279 :
280 : {
281 376 : VALIDATE_POINTER0( hGeom, "OGR_G_AssignSpatialReference" );
282 :
283 : ((OGRGeometry *) hGeom)->assignSpatialReference( (OGRSpatialReference *)
284 376 : hSRS );
285 : }
286 :
287 : /************************************************************************/
288 : /* Intersects() */
289 : /************************************************************************/
290 :
291 : /**
292 : * \brief Do these features intersect?
293 : *
294 : * Determines whether two geometries intersect. If GEOS is enabled, then
295 : * this is done in rigerous fashion otherwise TRUE is returned if the
296 : * envelopes (bounding boxes) of the two features overlap.
297 : *
298 : * The poOtherGeom argument may be safely NULL, but in this case the method
299 : * will always return TRUE. That is, a NULL geometry is treated as being
300 : * everywhere.
301 : *
302 : * This method is the same as the C function OGR_G_Intersects().
303 : *
304 : * @param poOtherGeom the other geometry to test against.
305 : *
306 : * @return TRUE if the geometries intersect, otherwise FALSE.
307 : */
308 :
309 190 : OGRBoolean OGRGeometry::Intersects( OGRGeometry *poOtherGeom ) const
310 :
311 : {
312 190 : OGREnvelope oEnv1, oEnv2;
313 :
314 190 : if( this == NULL || poOtherGeom == NULL )
315 0 : return TRUE;
316 :
317 190 : this->getEnvelope( &oEnv1 );
318 190 : poOtherGeom->getEnvelope( &oEnv2 );
319 :
320 190 : if( oEnv1.MaxX < oEnv2.MinX
321 : || oEnv1.MaxY < oEnv2.MinY
322 : || oEnv2.MaxX < oEnv1.MinX
323 : || oEnv2.MaxY < oEnv1.MinY )
324 15 : return FALSE;
325 :
326 : #ifndef HAVE_GEOS
327 :
328 : // Without GEOS we assume that envelope overlap is equivelent to
329 : // actual intersection.
330 : return TRUE;
331 :
332 : #else
333 :
334 175 : GEOSGeom hThisGeosGeom = NULL;
335 175 : GEOSGeom hOtherGeosGeom = NULL;
336 :
337 175 : hThisGeosGeom = exportToGEOS();
338 175 : hOtherGeosGeom = poOtherGeom->exportToGEOS();
339 :
340 175 : OGRBoolean bResult = FALSE;
341 175 : if( hThisGeosGeom != NULL && hOtherGeosGeom != NULL )
342 : {
343 175 : if( GEOSIntersects( hThisGeosGeom, hOtherGeosGeom ) != 0 )
344 130 : bResult = TRUE;
345 : else
346 45 : bResult = FALSE;
347 : }
348 :
349 175 : GEOSGeom_destroy( hThisGeosGeom );
350 175 : GEOSGeom_destroy( hOtherGeosGeom );
351 :
352 175 : return bResult;
353 : #endif /* HAVE_GEOS */
354 : }
355 :
356 : // Old API compatibility function.
357 :
358 0 : OGRBoolean OGRGeometry::Intersect( OGRGeometry *poOtherGeom ) const
359 :
360 : {
361 0 : return Intersects( poOtherGeom );
362 : }
363 :
364 : /************************************************************************/
365 : /* OGR_G_Intersects() */
366 : /************************************************************************/
367 : /**
368 : * \brief Do these features intersect?
369 : *
370 : * Currently this is not implemented in a rigerous fashion, and generally
371 : * just tests whether the envelopes of the two features intersect. Eventually
372 : * this will be made rigerous.
373 : *
374 : * This function is the same as the CPP method OGRGeometry::Intersects.
375 : *
376 : * @param hGeom handle on the first geometry.
377 : * @param hOtherGeom handle on the other geometry to test against.
378 : *
379 : * @return TRUE if the geometries intersect, otherwise FALSE.
380 : */
381 :
382 2 : int OGR_G_Intersects( OGRGeometryH hGeom, OGRGeometryH hOtherGeom )
383 :
384 : {
385 2 : VALIDATE_POINTER1( hGeom, "OGR_G_Intersects", FALSE );
386 2 : VALIDATE_POINTER1( hOtherGeom, "OGR_G_Intersects", FALSE );
387 :
388 2 : return ((OGRGeometry *) hGeom)->Intersects( (OGRGeometry *) hOtherGeom );
389 : }
390 :
391 0 : int OGR_G_Intersect( OGRGeometryH hGeom, OGRGeometryH hOtherGeom )
392 :
393 : {
394 0 : VALIDATE_POINTER1( hGeom, "OGR_G_Intersect", FALSE );
395 0 : VALIDATE_POINTER1( hOtherGeom, "OGR_G_Intersect", FALSE );
396 :
397 0 : return ((OGRGeometry *) hGeom)->Intersects( (OGRGeometry *) hOtherGeom );
398 : }
399 :
400 : /************************************************************************/
401 : /* transformTo() */
402 : /************************************************************************/
403 :
404 : /**
405 : * \brief Transform geometry to new spatial reference system.
406 : *
407 : * This method will transform the coordinates of a geometry from
408 : * their current spatial reference system to a new target spatial
409 : * reference system. Normally this means reprojecting the vectors,
410 : * but it could include datum shifts, and changes of units.
411 : *
412 : * This method will only work if the geometry already has an assigned
413 : * spatial reference system, and if it is transformable to the target
414 : * coordinate system.
415 : *
416 : * Because this method requires internal creation and initialization of an
417 : * OGRCoordinateTransformation object it is significantly more expensive to
418 : * use this method to transform many geometries than it is to create the
419 : * OGRCoordinateTransformation in advance, and call transform() with that
420 : * transformation. This method exists primarily for convenience when only
421 : * transforming a single geometry.
422 : *
423 : * This method is the same as the C function OGR_G_TransformTo().
424 : *
425 : * @param poSR spatial reference system to transform to.
426 : *
427 : * @return OGRERR_NONE on success, or an error code.
428 : */
429 :
430 27 : OGRErr OGRGeometry::transformTo( OGRSpatialReference *poSR )
431 :
432 : {
433 : #ifdef DISABLE_OGRGEOM_TRANSFORM
434 : return OGRERR_FAILURE;
435 : #else
436 : OGRCoordinateTransformation *poCT;
437 : OGRErr eErr;
438 :
439 27 : if( getSpatialReference() == NULL || poSR == NULL )
440 26 : return OGRERR_FAILURE;
441 :
442 1 : poCT = OGRCreateCoordinateTransformation( getSpatialReference(), poSR );
443 1 : if( poCT == NULL )
444 0 : return OGRERR_FAILURE;
445 :
446 1 : eErr = transform( poCT );
447 :
448 1 : delete poCT;
449 :
450 1 : return eErr;
451 : #endif
452 : }
453 :
454 : /************************************************************************/
455 : /* OGR_G_TransformTo() */
456 : /************************************************************************/
457 : /**
458 : * \brief Transform geometry to new spatial reference system.
459 : *
460 : * This function will transform the coordinates of a geometry from
461 : * their current spatial reference system to a new target spatial
462 : * reference system. Normally this means reprojecting the vectors,
463 : * but it could include datum shifts, and changes of units.
464 : *
465 : * This function will only work if the geometry already has an assigned
466 : * spatial reference system, and if it is transformable to the target
467 : * coordinate system.
468 : *
469 : * Because this function requires internal creation and initialization of an
470 : * OGRCoordinateTransformation object it is significantly more expensive to
471 : * use this function to transform many geometries than it is to create the
472 : * OGRCoordinateTransformation in advance, and call transform() with that
473 : * transformation. This function exists primarily for convenience when only
474 : * transforming a single geometry.
475 : *
476 : * This function is the same as the CPP method OGRGeometry::transformTo.
477 : *
478 : * @param hGeom handle on the geometry to apply the transform to.
479 : * @param hSRS handle on the spatial reference system to apply.
480 : *
481 : * @return OGRERR_NONE on success, or an error code.
482 : */
483 :
484 1 : OGRErr OGR_G_TransformTo( OGRGeometryH hGeom, OGRSpatialReferenceH hSRS )
485 :
486 : {
487 1 : VALIDATE_POINTER1( hGeom, "OGR_G_TransformTo", OGRERR_FAILURE );
488 :
489 1 : return ((OGRGeometry *) hGeom)->transformTo((OGRSpatialReference *) hSRS);
490 : }
491 :
492 : /**
493 : * \fn OGRErr OGRGeometry::transform( OGRCoordinateTransformation *poCT );
494 : *
495 : * \brief Apply arbitrary coordinate transformation to geometry.
496 : *
497 : * This method will transform the coordinates of a geometry from
498 : * their current spatial reference system to a new target spatial
499 : * reference system. Normally this means reprojecting the vectors,
500 : * but it could include datum shifts, and changes of units.
501 : *
502 : * Note that this method does not require that the geometry already
503 : * have a spatial reference system. It will be assumed that they can
504 : * be treated as having the source spatial reference system of the
505 : * OGRCoordinateTransformation object, and the actual SRS of the geometry
506 : * will be ignored. On successful completion the output OGRSpatialReference
507 : * of the OGRCoordinateTransformation will be assigned to the geometry.
508 : *
509 : * This method is the same as the C function OGR_G_Transform().
510 : *
511 : * @param poCT the transformation to apply.
512 : *
513 : * @return OGRERR_NONE on success or an error code.
514 : */
515 :
516 : /************************************************************************/
517 : /* OGR_G_Transform() */
518 : /************************************************************************/
519 : /**
520 : * \brief Apply arbitrary coordinate transformation to geometry.
521 : *
522 : * This function will transform the coordinates of a geometry from
523 : * their current spatial reference system to a new target spatial
524 : * reference system. Normally this means reprojecting the vectors,
525 : * but it could include datum shifts, and changes of units.
526 : *
527 : * Note that this function does not require that the geometry already
528 : * have a spatial reference system. It will be assumed that they can
529 : * be treated as having the source spatial reference system of the
530 : * OGRCoordinateTransformation object, and the actual SRS of the geometry
531 : * will be ignored. On successful completion the output OGRSpatialReference
532 : * of the OGRCoordinateTransformation will be assigned to the geometry.
533 : *
534 : * This function is the same as the CPP method OGRGeometry::transform.
535 : *
536 : * @param hGeom handle on the geometry to apply the transform to.
537 : * @param hTransform handle on the transformation to apply.
538 : *
539 : * @return OGRERR_NONE on success or an error code.
540 : */
541 :
542 15 : OGRErr OGR_G_Transform( OGRGeometryH hGeom,
543 : OGRCoordinateTransformationH hTransform )
544 :
545 : {
546 15 : VALIDATE_POINTER1( hGeom, "OGR_G_Transform", OGRERR_FAILURE );
547 :
548 : return ((OGRGeometry *) hGeom)->transform(
549 15 : (OGRCoordinateTransformation *) hTransform );
550 : }
551 :
552 : /**
553 : * \fn int OGRGeometry::getDimension() const;
554 : *
555 : * \brief Get the dimension of this object.
556 : *
557 : * This method corresponds to the SFCOM IGeometry::GetDimension() method.
558 : * It indicates the dimension of the object, but does not indicate the
559 : * dimension of the underlying space (as indicated by
560 : * OGRGeometry::getCoordinateDimension()).
561 : *
562 : * This method is the same as the C function OGR_G_GetDimension().
563 : *
564 : * @return 0 for points, 1 for lines and 2 for surfaces.
565 : */
566 :
567 :
568 : /************************************************************************/
569 : /* OGRGeometry::segmentize() */
570 : /************************************************************************/
571 : /**
572 : *
573 : * \brief Modify the geometry such it has no segment longer then the given distance.
574 : *
575 : * Interpolated points will have Z and M values (if needed) set to 0.
576 : * Distance computation is performed in 2d only
577 : *
578 : * This function is the same as the C function OGR_G_Segmentize()
579 : *
580 : * @param dfMaxLength the maximum distance between 2 points after segmentization
581 : */
582 :
583 0 : void OGRGeometry::segmentize( double dfMaxLength )
584 : {
585 : /* Do nothing */
586 0 : }
587 :
588 : /************************************************************************/
589 : /* OGR_G_Segmentize() */
590 : /************************************************************************/
591 :
592 : /**
593 : *
594 : * \brief Modify the geometry such it has no segment longer then the given distance.
595 : *
596 : * Interpolated points will have Z and M values (if needed) set to 0.
597 : * Distance computation is performed in 2d only
598 : *
599 : * This function is the same as the CPP method OGRGeometry::segmentize().
600 : *
601 : * @param hGeom handle on the geometry to segmentize
602 : * @param dfMaxLength the maximum distance between 2 points after segmentization
603 : */
604 :
605 1 : void CPL_DLL OGR_G_Segmentize(OGRGeometryH hGeom, double dfMaxLength )
606 : {
607 1 : VALIDATE_POINTER0( hGeom, "OGR_G_Segmentize" );
608 :
609 1 : if (dfMaxLength <= 0)
610 : {
611 : CPLError(CE_Failure, CPLE_AppDefined,
612 0 : "dfMaxLength must be strictly positive");
613 0 : return;
614 : }
615 1 : ((OGRGeometry *) hGeom)->segmentize( dfMaxLength );
616 : }
617 :
618 : /************************************************************************/
619 : /* OGR_G_GetDimension() */
620 : /************************************************************************/
621 : /**
622 : *
623 : * \brief Get the dimension of this geometry.
624 : *
625 : * This function corresponds to the SFCOM IGeometry::GetDimension() method.
626 : * It indicates the dimension of the geometry, but does not indicate the
627 : * dimension of the underlying space (as indicated by
628 : * OGR_G_GetCoordinateDimension() function).
629 : *
630 : * This function is the same as the CPP method OGRGeometry::getDimension().
631 : *
632 : * @param hGeom handle on the geometry to get the dimension from.
633 : * @return 0 for points, 1 for lines and 2 for surfaces.
634 : */
635 :
636 1 : int OGR_G_GetDimension( OGRGeometryH hGeom )
637 :
638 : {
639 1 : VALIDATE_POINTER1( hGeom, "OGR_G_GetDimension", 0 );
640 :
641 1 : return ((OGRGeometry *) hGeom)->getDimension();
642 : }
643 :
644 : /************************************************************************/
645 : /* getCoordinateDimension() */
646 : /************************************************************************/
647 : /**
648 : * \brief Get the dimension of the coordinates in this object.
649 : *
650 : * This method corresponds to the SFCOM IGeometry::GetDimension() method.
651 : *
652 : * This method is the same as the C function OGR_G_GetCoordinateDimension().
653 : *
654 : * @return in practice this will return 2 or 3. It can also return 0 in the
655 : * case of an empty point.
656 : */
657 :
658 3660759 : int OGRGeometry::getCoordinateDimension() const
659 :
660 : {
661 3660759 : return nCoordDimension;
662 : }
663 :
664 : /************************************************************************/
665 : /* OGR_G_GetCoordinateDimension() */
666 : /************************************************************************/
667 : /**
668 : *
669 : * \brief Get the dimension of the coordinates in this geometry.
670 : *
671 : * This function corresponds to the SFCOM IGeometry::GetDimension() method.
672 : *
673 : * This function is the same as the CPP method
674 : * OGRGeometry::getCoordinateDimension().
675 : *
676 : * @param hGeom handle on the geometry to get the dimension of the
677 : * coordinates from.
678 : *
679 : * @return in practice this will return 2 or 3. It can also return 0 in the
680 : * case of an empty point.
681 : */
682 :
683 184 : int OGR_G_GetCoordinateDimension( OGRGeometryH hGeom )
684 :
685 : {
686 184 : VALIDATE_POINTER1( hGeom, "OGR_G_GetCoordinateDimension", 0 );
687 :
688 184 : return ((OGRGeometry *) hGeom)->getCoordinateDimension();
689 : }
690 :
691 : /************************************************************************/
692 : /* setCoordinateDimension() */
693 : /************************************************************************/
694 :
695 : /**
696 : * \brief Set the coordinate dimension.
697 : *
698 : * This method sets the explicit coordinate dimension. Setting the coordinate
699 : * dimension of a geometry to 2 should zero out any existing Z values. Setting
700 : * the dimension of a geometry collection will not necessarily affect the
701 : * children geometries.
702 : *
703 : * @param nNewDimension New coordinate dimension value, either 2 or 3.
704 : */
705 :
706 370 : void OGRGeometry::setCoordinateDimension( int nNewDimension )
707 :
708 : {
709 370 : nCoordDimension = nNewDimension;
710 370 : }
711 :
712 : /************************************************************************/
713 : /* OGR_G_SetCoordinateDimension() */
714 : /************************************************************************/
715 :
716 : /**
717 : * \brief Set the coordinate dimension.
718 : *
719 : * This method sets the explicit coordinate dimension. Setting the coordinate
720 : * dimension of a geometry to 2 should zero out any existing Z values. Setting
721 : * the dimension of a geometry collection will not necessarily affect the
722 : * children geometries.
723 : *
724 : * @param hGeom handle on the geometry to set the dimension of the
725 : * coordinates.
726 : * @param nNewDimension New coordinate dimension value, either 2 or 3.
727 : */
728 :
729 61 : void OGR_G_SetCoordinateDimension( OGRGeometryH hGeom, int nNewDimension)
730 :
731 : {
732 61 : VALIDATE_POINTER0( hGeom, "OGR_G_SetCoordinateDimension" );
733 :
734 61 : ((OGRGeometry *) hGeom)->setCoordinateDimension( nNewDimension );
735 : }
736 :
737 : /**
738 : * \fn int OGRGeometry::Equals( OGRGeometry *poOtherGeom ) const;
739 : *
740 : * \brief Returns TRUE if two geometries are equivalent.
741 : *
742 : * This method is the same as the C function OGR_G_Equals().
743 : *
744 : * @return TRUE if equivalent or FALSE otherwise.
745 : */
746 :
747 :
748 : // Backward compatibility method.
749 :
750 0 : int OGRGeometry::Equal( OGRGeometry *poOtherGeom ) const
751 : {
752 0 : return Equals( poOtherGeom );
753 : }
754 :
755 : /************************************************************************/
756 : /* OGR_G_Equals() */
757 : /************************************************************************/
758 :
759 : /**
760 : * \brief Returns TRUE if two geometries are equivalent.
761 : *
762 : * This function is the same as the CPP method OGRGeometry::Equals() method.
763 : *
764 : * @param hGeom handle on the first geometry.
765 : * @param hOther handle on the other geometry to test against.
766 : * @return TRUE if equivalent or FALSE otherwise.
767 : */
768 :
769 1 : int OGR_G_Equals( OGRGeometryH hGeom, OGRGeometryH hOther )
770 :
771 : {
772 1 : VALIDATE_POINTER1( hGeom, "OGR_G_Equals", FALSE );
773 :
774 1 : if (hGeom == NULL) {
775 0 : CPLError ( CE_Failure, CPLE_ObjectNull, "hGeom was NULL in OGR_G_Equals");
776 0 : return 0;
777 : }
778 :
779 1 : if (hOther == NULL) {
780 0 : CPLError ( CE_Failure, CPLE_ObjectNull, "hOther was NULL in OGR_G_Equals");
781 0 : return 0;
782 : }
783 :
784 1 : return ((OGRGeometry *) hGeom)->Equals( (OGRGeometry *) hOther );
785 : }
786 :
787 0 : int OGR_G_Equal( OGRGeometryH hGeom, OGRGeometryH hOther )
788 :
789 : {
790 0 : if (hGeom == NULL) {
791 0 : CPLError ( CE_Failure, CPLE_ObjectNull, "hGeom was NULL in OGR_G_Equal");
792 0 : return 0;
793 : }
794 :
795 0 : if (hOther == NULL) {
796 0 : CPLError ( CE_Failure, CPLE_ObjectNull, "hOther was NULL in OGR_G_Equal");
797 0 : return 0;
798 : }
799 :
800 0 : return ((OGRGeometry *) hGeom)->Equals( (OGRGeometry *) hOther );
801 : }
802 :
803 :
804 : /**
805 : * \fn int OGRGeometry::WkbSize() const;
806 : *
807 : * \brief Returns size of related binary representation.
808 : *
809 : * This method returns the exact number of bytes required to hold the
810 : * well known binary representation of this geometry object. Its computation
811 : * may be slightly expensive for complex geometries.
812 : *
813 : * This method relates to the SFCOM IWks::WkbSize() method.
814 : *
815 : * This method is the same as the C function OGR_G_WkbSize().
816 : *
817 : * @return size of binary representation in bytes.
818 : */
819 :
820 : /************************************************************************/
821 : /* OGR_G_WkbSize() */
822 : /************************************************************************/
823 : /**
824 : * \brief Returns size of related binary representation.
825 : *
826 : * This function returns the exact number of bytes required to hold the
827 : * well known binary representation of this geometry object. Its computation
828 : * may be slightly expensive for complex geometries.
829 : *
830 : * This function relates to the SFCOM IWks::WkbSize() method.
831 : *
832 : * This function is the same as the CPP method OGRGeometry::WkbSize().
833 : *
834 : * @param hGeom handle on the geometry to get the binary size from.
835 : * @return size of binary representation in bytes.
836 : */
837 :
838 57 : int OGR_G_WkbSize( OGRGeometryH hGeom )
839 :
840 : {
841 57 : VALIDATE_POINTER1( hGeom, "OGR_G_WkbSize", 0 );
842 :
843 57 : return ((OGRGeometry *) hGeom)->WkbSize();
844 : }
845 :
846 : /**
847 : * \fn void OGRGeometry::getEnvelope(OGREnvelope *psEnvelope) const;
848 : *
849 : * \brief Computes and returns the bounding envelope for this geometry in the passed psEnvelope structure.
850 : *
851 : * This method is the same as the C function OGR_G_GetEnvelope().
852 : *
853 : * @param psEnvelope the structure in which to place the results.
854 : */
855 :
856 : /************************************************************************/
857 : /* OGR_G_GetEnvelope() */
858 : /************************************************************************/
859 : /**
860 : * \brief Computes and returns the bounding envelope for this geometry in the passed psEnvelope structure.
861 : *
862 : * This function is the same as the CPP method OGRGeometry::getEnvelope().
863 : *
864 : * @param hGeom handle of the geometry to get envelope from.
865 : * @param psEnvelope the structure in which to place the results.
866 : */
867 :
868 44 : void OGR_G_GetEnvelope( OGRGeometryH hGeom, OGREnvelope *psEnvelope )
869 :
870 : {
871 44 : VALIDATE_POINTER0( hGeom, "OGR_G_GetEnvelope" );
872 :
873 44 : ((OGRGeometry *) hGeom)->getEnvelope( psEnvelope );
874 : }
875 :
876 : /**
877 : * \fn void OGRGeometry::getEnvelope(OGREnvelope3D *psEnvelope) const;
878 : *
879 : * \brief Computes and returns the bounding envelope (3D) for this geometry in the passed psEnvelope structure.
880 : *
881 : * This method is the same as the C function OGR_G_GetEnvelope3D().
882 : *
883 : * @param psEnvelope the structure in which to place the results.
884 : *
885 : * @since OGR 1.9.0
886 : */
887 :
888 : /************************************************************************/
889 : /* OGR_G_GetEnvelope3D() */
890 : /************************************************************************/
891 : /**
892 : * \brief Computes and returns the bounding envelope (3D) for this geometry in the passed psEnvelope structure.
893 : *
894 : * This function is the same as the CPP method OGRGeometry::getEnvelope().
895 : *
896 : * @param hGeom handle of the geometry to get envelope from.
897 : * @param psEnvelope the structure in which to place the results.
898 : *
899 : * @since OGR 1.9.0
900 : */
901 :
902 7 : void OGR_G_GetEnvelope3D( OGRGeometryH hGeom, OGREnvelope3D *psEnvelope )
903 :
904 : {
905 7 : VALIDATE_POINTER0( hGeom, "OGR_G_GetEnvelope3D" );
906 :
907 7 : ((OGRGeometry *) hGeom)->getEnvelope( psEnvelope );
908 : }
909 :
910 : /**
911 : * \fn OGRErr OGRGeometry::importFromWkb( unsigned char * pabyData, int nSize);
912 : *
913 : * \brief Assign geometry from well known binary data.
914 : *
915 : * The object must have already been instantiated as the correct derived
916 : * type of geometry object to match the binaries type. This method is used
917 : * by the OGRGeometryFactory class, but not normally called by application
918 : * code.
919 : *
920 : * This method relates to the SFCOM IWks::ImportFromWKB() method.
921 : *
922 : * This method is the same as the C function OGR_G_ImportFromWkb().
923 : *
924 : * @param pabyData the binary input data.
925 : * @param nSize the size of pabyData in bytes, or zero if not known.
926 : *
927 : * @return OGRERR_NONE if all goes well, otherwise any of
928 : * OGRERR_NOT_ENOUGH_DATA, OGRERR_UNSUPPORTED_GEOMETRY_TYPE, or
929 : * OGRERR_CORRUPT_DATA may be returned.
930 : */
931 :
932 : /************************************************************************/
933 : /* OGR_G_ImportFromWkb() */
934 : /************************************************************************/
935 : /**
936 : * \brief Assign geometry from well known binary data.
937 : *
938 : * The object must have already been instantiated as the correct derived
939 : * type of geometry object to match the binaries type.
940 : *
941 : * This function relates to the SFCOM IWks::ImportFromWKB() method.
942 : *
943 : * This function is the same as the CPP method OGRGeometry::importFromWkb().
944 : *
945 : * @param hGeom handle on the geometry to assign the well know binary data to.
946 : * @param pabyData the binary input data.
947 : * @param nSize the size of pabyData in bytes, or zero if not known.
948 : *
949 : * @return OGRERR_NONE if all goes well, otherwise any of
950 : * OGRERR_NOT_ENOUGH_DATA, OGRERR_UNSUPPORTED_GEOMETRY_TYPE, or
951 : * OGRERR_CORRUPT_DATA may be returned.
952 : */
953 :
954 0 : OGRErr OGR_G_ImportFromWkb( OGRGeometryH hGeom,
955 : unsigned char *pabyData, int nSize )
956 :
957 : {
958 0 : VALIDATE_POINTER1( hGeom, "OGR_G_ImportFromWkb", OGRERR_FAILURE );
959 :
960 0 : return ((OGRGeometry *) hGeom)->importFromWkb( pabyData, nSize );
961 : }
962 :
963 : /**
964 : * \fn OGRErr OGRGeometry::exportToWkb( OGRwkbByteOrder eByteOrder,
965 : unsigned char * pabyData ) const;
966 : *
967 : * \brief Convert a geometry into well known binary format.
968 : *
969 : * This method relates to the SFCOM IWks::ExportToWKB() method.
970 : *
971 : * This method is the same as the C function OGR_G_ExportToWkb().
972 : *
973 : * @param eByteOrder One of wkbXDR or wkbNDR indicating MSB or LSB byte order
974 : * respectively.
975 : * @param pabyData a buffer into which the binary representation is
976 : * written. This buffer must be at least
977 : * OGRGeometry::WkbSize() byte in size.
978 : *
979 : * @return Currently OGRERR_NONE is always returned.
980 : */
981 :
982 : /************************************************************************/
983 : /* OGR_G_ExportToWkb() */
984 : /************************************************************************/
985 : /**
986 : * \brief Convert a geometry into well known binary format.
987 : *
988 : * This function relates to the SFCOM IWks::ExportToWKB() method.
989 : *
990 : * This function is the same as the CPP method OGRGeometry::exportToWkb().
991 : *
992 : * @param hGeom handle on the geometry to convert to a well know binary
993 : * data from.
994 : * @param eOrder One of wkbXDR or wkbNDR indicating MSB or LSB byte order
995 : * respectively.
996 : * @param pabyDstBuffer a buffer into which the binary representation is
997 : * written. This buffer must be at least
998 : * OGR_G_WkbSize() byte in size.
999 : *
1000 : * @return Currently OGRERR_NONE is always returned.
1001 : */
1002 :
1003 57 : OGRErr OGR_G_ExportToWkb( OGRGeometryH hGeom, OGRwkbByteOrder eOrder,
1004 : unsigned char *pabyDstBuffer )
1005 :
1006 : {
1007 57 : VALIDATE_POINTER1( hGeom, "OGR_G_ExportToWkb", OGRERR_FAILURE );
1008 :
1009 57 : return ((OGRGeometry *) hGeom)->exportToWkb( eOrder, pabyDstBuffer );
1010 : }
1011 :
1012 : /**
1013 : * \fn OGRErr OGRGeometry::importFromWkt( char ** ppszInput );
1014 : *
1015 : * \brief Assign geometry from well known text data.
1016 : *
1017 : * The object must have already been instantiated as the correct derived
1018 : * type of geometry object to match the text type. This method is used
1019 : * by the OGRGeometryFactory class, but not normally called by application
1020 : * code.
1021 : *
1022 : * This method relates to the SFCOM IWks::ImportFromWKT() method.
1023 : *
1024 : * This method is the same as the C function OGR_G_ImportFromWkt().
1025 : *
1026 : * @param ppszInput pointer to a pointer to the source text. The pointer is
1027 : * updated to pointer after the consumed text.
1028 : *
1029 : * @return OGRERR_NONE if all goes well, otherwise any of
1030 : * OGRERR_NOT_ENOUGH_DATA, OGRERR_UNSUPPORTED_GEOMETRY_TYPE, or
1031 : * OGRERR_CORRUPT_DATA may be returned.
1032 : */
1033 :
1034 : /************************************************************************/
1035 : /* OGR_G_ImportFromWkt() */
1036 : /************************************************************************/
1037 : /**
1038 : * \brief Assign geometry from well known text data.
1039 : *
1040 : * The object must have already been instantiated as the correct derived
1041 : * type of geometry object to match the text type.
1042 : *
1043 : * This function relates to the SFCOM IWks::ImportFromWKT() method.
1044 : *
1045 : * This function is the same as the CPP method OGRGeometry::importFromWkt().
1046 : *
1047 : * @param hGeom handle on the geometry to assign well know text data to.
1048 : * @param ppszSrcText pointer to a pointer to the source text. The pointer is
1049 : * updated to pointer after the consumed text.
1050 : *
1051 : * @return OGRERR_NONE if all goes well, otherwise any of
1052 : * OGRERR_NOT_ENOUGH_DATA, OGRERR_UNSUPPORTED_GEOMETRY_TYPE, or
1053 : * OGRERR_CORRUPT_DATA may be returned.
1054 : */
1055 :
1056 0 : OGRErr OGR_G_ImportFromWkt( OGRGeometryH hGeom, char ** ppszSrcText )
1057 :
1058 : {
1059 0 : VALIDATE_POINTER1( hGeom, "OGR_G_ImportFromWkt", OGRERR_FAILURE );
1060 :
1061 0 : return ((OGRGeometry *) hGeom)->importFromWkt( ppszSrcText );
1062 : }
1063 :
1064 : /**
1065 : * \fn OGRErr OGRGeometry::exportToWkt( char ** ppszDstText ) const;
1066 : *
1067 : * \brief Convert a geometry into well known text format.
1068 : *
1069 : * This method relates to the SFCOM IWks::ExportToWKT() method.
1070 : *
1071 : * This method is the same as the C function OGR_G_ExportToWkt().
1072 : *
1073 : * @param ppszDstText a text buffer is allocated by the program, and assigned
1074 : * to the passed pointer.
1075 : *
1076 : * @return Currently OGRERR_NONE is always returned.
1077 : */
1078 :
1079 : /************************************************************************/
1080 : /* OGR_G_ExportToWkt() */
1081 : /************************************************************************/
1082 : /**
1083 : * \brief Convert a geometry into well known text format.
1084 : *
1085 : * This function relates to the SFCOM IWks::ExportToWKT() method.
1086 : *
1087 : * This function is the same as the CPP method OGRGeometry::exportToWkt().
1088 : *
1089 : * @param hGeom handle on the geometry to convert to a text format from.
1090 : * @param ppszSrcText a text buffer is allocated by the program, and assigned
1091 : to the passed pointer.
1092 : *
1093 : * @return Currently OGRERR_NONE is always returned.
1094 : */
1095 :
1096 1119 : OGRErr OGR_G_ExportToWkt( OGRGeometryH hGeom, char **ppszSrcText )
1097 :
1098 : {
1099 1119 : VALIDATE_POINTER1( hGeom, "OGR_G_ExportToWkt", OGRERR_FAILURE );
1100 :
1101 1119 : return ((OGRGeometry *) hGeom)->exportToWkt( ppszSrcText );
1102 : }
1103 :
1104 : /**
1105 : * \fn OGRwkbGeometryType OGRGeometry::getGeometryType() const;
1106 : *
1107 : * \brief Fetch geometry type.
1108 : *
1109 : * Note that the geometry type may include the 2.5D flag. To get a 2D
1110 : * flattened version of the geometry type apply the wkbFlatten() macro
1111 : * to the return result.
1112 : *
1113 : * This method is the same as the C function OGR_G_GetGeometryType().
1114 : *
1115 : * @return the geometry type code.
1116 : */
1117 :
1118 : /************************************************************************/
1119 : /* OGR_G_GetGeometryType() */
1120 : /************************************************************************/
1121 : /**
1122 : * \brief Fetch geometry type.
1123 : *
1124 : * Note that the geometry type may include the 2.5D flag. To get a 2D
1125 : * flattened version of the geometry type apply the wkbFlatten() macro
1126 : * to the return result.
1127 : *
1128 : * This function is the same as the CPP method OGRGeometry::getGeometryType().
1129 : *
1130 : * @param hGeom handle on the geometry to get type from.
1131 : * @return the geometry type code.
1132 : */
1133 :
1134 228 : OGRwkbGeometryType OGR_G_GetGeometryType( OGRGeometryH hGeom )
1135 :
1136 : {
1137 228 : VALIDATE_POINTER1( hGeom, "OGR_G_GetGeometryType", wkbUnknown );
1138 :
1139 228 : return ((OGRGeometry *) hGeom)->getGeometryType();
1140 : }
1141 :
1142 : /**
1143 : * \fn const char * OGRGeometry::getGeometryName() const;
1144 : *
1145 : * \brief Fetch WKT name for geometry type.
1146 : *
1147 : * There is no SFCOM analog to this method.
1148 : *
1149 : * This method is the same as the C function OGR_G_GetGeometryName().
1150 : *
1151 : * @return name used for this geometry type in well known text format. The
1152 : * returned pointer is to a static internal string and should not be modified
1153 : * or freed.
1154 : */
1155 :
1156 : /************************************************************************/
1157 : /* OGR_G_GetGeometryName() */
1158 : /************************************************************************/
1159 : /**
1160 : * \brief Fetch WKT name for geometry type.
1161 : *
1162 : * There is no SFCOM analog to this function.
1163 : *
1164 : * This function is the same as the CPP method OGRGeometry::getGeometryName().
1165 : *
1166 : * @param hGeom handle on the geometry to get name from.
1167 : * @return name used for this geometry type in well known text format.
1168 : */
1169 :
1170 2352 : const char *OGR_G_GetGeometryName( OGRGeometryH hGeom )
1171 :
1172 : {
1173 2352 : VALIDATE_POINTER1( hGeom, "OGR_G_GetGeometryName", "" );
1174 :
1175 2352 : return ((OGRGeometry *) hGeom)->getGeometryName();
1176 : }
1177 :
1178 : /**
1179 : * \fn OGRGeometry *OGRGeometry::clone() const;
1180 : *
1181 : * \brief Make a copy of this object.
1182 : *
1183 : * This method relates to the SFCOM IGeometry::clone() method.
1184 : *
1185 : * This method is the same as the C function OGR_G_Clone().
1186 : *
1187 : * @return a new object instance with the same geometry, and spatial
1188 : * reference system as the original.
1189 : */
1190 :
1191 : /************************************************************************/
1192 : /* OGR_G_Clone() */
1193 : /************************************************************************/
1194 : /**
1195 : * \brief Make a copy of this object.
1196 : *
1197 : * This function relates to the SFCOM IGeometry::clone() method.
1198 : *
1199 : * This function is the same as the CPP method OGRGeometry::clone().
1200 : *
1201 : * @param hGeom handle on the geometry to clone from.
1202 : * @return an handle on the copy of the geometry with the spatial
1203 : * reference system as the original.
1204 : */
1205 :
1206 2330 : OGRGeometryH OGR_G_Clone( OGRGeometryH hGeom )
1207 :
1208 : {
1209 2330 : VALIDATE_POINTER1( hGeom, "OGR_G_Clone", NULL );
1210 :
1211 2330 : return (OGRGeometryH) ((OGRGeometry *) hGeom)->clone();
1212 : }
1213 :
1214 : /**
1215 : * \fn OGRSpatialReference *OGRGeometry::getSpatialReference();
1216 : *
1217 : * \brief Returns spatial reference system for object.
1218 : *
1219 : * This method relates to the SFCOM IGeometry::get_SpatialReference() method.
1220 : *
1221 : * This method is the same as the C function OGR_G_GetSpatialReference().
1222 : *
1223 : * @return a reference to the spatial reference object. The object may be
1224 : * shared with many geometry objects, and should not be modified.
1225 : */
1226 :
1227 : /************************************************************************/
1228 : /* OGR_G_GetSpatialReference() */
1229 : /************************************************************************/
1230 : /**
1231 : * \brief Returns spatial reference system for geometry.
1232 : *
1233 : * This function relates to the SFCOM IGeometry::get_SpatialReference() method.
1234 : *
1235 : * This function is the same as the CPP method
1236 : * OGRGeometry::getSpatialReference().
1237 : *
1238 : * @param hGeom handle on the geometry to get spatial reference from.
1239 : * @return a reference to the spatial reference geometry.
1240 : */
1241 :
1242 5 : OGRSpatialReferenceH OGR_G_GetSpatialReference( OGRGeometryH hGeom )
1243 :
1244 : {
1245 5 : VALIDATE_POINTER1( hGeom, "OGR_G_GetSpatialReference", NULL );
1246 :
1247 : return (OGRSpatialReferenceH)
1248 5 : ((OGRGeometry *) hGeom)->getSpatialReference();
1249 : }
1250 :
1251 : /**
1252 : * \fn void OGRGeometry::empty();
1253 : *
1254 : * \brief Clear geometry information.
1255 : * This restores the geometry to it's initial
1256 : * state after construction, and before assignment of actual geometry.
1257 : *
1258 : * This method relates to the SFCOM IGeometry::Empty() method.
1259 : *
1260 : * This method is the same as the C function OGR_G_Empty().
1261 : */
1262 :
1263 : /************************************************************************/
1264 : /* OGR_G_Empty() */
1265 : /************************************************************************/
1266 : /**
1267 : * \brief Clear geometry information.
1268 : * This restores the geometry to it's initial
1269 : * state after construction, and before assignment of actual geometry.
1270 : *
1271 : * This function relates to the SFCOM IGeometry::Empty() method.
1272 : *
1273 : * This function is the same as the CPP method OGRGeometry::empty().
1274 : *
1275 : * @param hGeom handle on the geometry to empty.
1276 : */
1277 :
1278 2 : void OGR_G_Empty( OGRGeometryH hGeom )
1279 :
1280 : {
1281 2 : VALIDATE_POINTER0( hGeom, "OGR_G_Empty" );
1282 :
1283 2 : ((OGRGeometry *) hGeom)->empty();
1284 : }
1285 :
1286 : /**
1287 : * \fn OGRBoolean OGRGeometry::IsEmpty() const;
1288 : *
1289 : * \brief Returns TRUE (non-zero) if the object has no points.
1290 : *
1291 : * Normally this
1292 : * returns FALSE except between when an object is instantiated and points
1293 : * have been assigned.
1294 : *
1295 : * This method relates to the SFCOM IGeometry::IsEmpty() method.
1296 : *
1297 : * @return TRUE if object is empty, otherwise FALSE.
1298 : */
1299 :
1300 : /************************************************************************/
1301 : /* OGR_G_IsEmpty() */
1302 : /************************************************************************/
1303 :
1304 : /**
1305 : * \brief Test if the geometry is empty.
1306 : *
1307 : * This method is the same as the CPP method OGRGeometry::IsEmpty().
1308 : *
1309 : * @param hGeom The Geometry to test.
1310 : *
1311 : * @return TRUE if the geometry has no points, otherwise FALSE.
1312 : */
1313 :
1314 58 : int OGR_G_IsEmpty( OGRGeometryH hGeom )
1315 :
1316 : {
1317 58 : VALIDATE_POINTER1( hGeom, "OGR_G_IsEmpty", TRUE );
1318 :
1319 58 : return ((OGRGeometry *) hGeom)->IsEmpty();
1320 : }
1321 :
1322 : /************************************************************************/
1323 : /* IsValid() */
1324 : /************************************************************************/
1325 :
1326 : /**
1327 : * \brief Test if the geometry is valid.
1328 : *
1329 : * This method is the same as the C function OGR_G_IsValid().
1330 : *
1331 : * This method is built on the GEOS library, check it for the definition
1332 : * of the geometry operation.
1333 : * If OGR is built without the GEOS library, this method will always return
1334 : * FALSE.
1335 : *
1336 : *
1337 : * @return TRUE if the geometry has no points, otherwise FALSE.
1338 : */
1339 :
1340 : OGRBoolean
1341 2 : OGRGeometry::IsValid( ) const
1342 :
1343 : {
1344 : #ifndef HAVE_GEOS
1345 :
1346 : return FALSE;
1347 :
1348 : #else
1349 :
1350 2 : OGRBoolean bResult = FALSE;
1351 2 : GEOSGeom hThisGeosGeom = NULL;
1352 :
1353 2 : hThisGeosGeom = exportToGEOS();
1354 :
1355 2 : if( hThisGeosGeom != NULL )
1356 : {
1357 2 : bResult = GEOSisValid( hThisGeosGeom );
1358 2 : GEOSGeom_destroy( hThisGeosGeom );
1359 : }
1360 :
1361 2 : return bResult;
1362 :
1363 : #endif /* HAVE_GEOS */
1364 : }
1365 :
1366 : /************************************************************************/
1367 : /* OGR_G_IsValid() */
1368 : /************************************************************************/
1369 :
1370 : /**
1371 : * \brief Test if the geometry is valid.
1372 : *
1373 : * This function is the same as the C++ method OGRGeometry::IsValid().
1374 : *
1375 : * This function is built on the GEOS library, check it for the definition
1376 : * of the geometry operation.
1377 : * If OGR is built without the GEOS library, this function will always return
1378 : * FALSE.
1379 : *
1380 : * @param hGeom The Geometry to test.
1381 : *
1382 : * @return TRUE if the geometry has no points, otherwise FALSE.
1383 : */
1384 :
1385 2 : int OGR_G_IsValid( OGRGeometryH hGeom )
1386 :
1387 : {
1388 2 : VALIDATE_POINTER1( hGeom, "OGR_G_IsValid", FALSE );
1389 :
1390 2 : return ((OGRGeometry *) hGeom)->IsValid();
1391 : }
1392 :
1393 : /************************************************************************/
1394 : /* IsSimple() */
1395 : /************************************************************************/
1396 :
1397 : /**
1398 : * \brief Test if the geometry is simple.
1399 : *
1400 : * This method is the same as the C function OGR_G_IsSimple().
1401 : *
1402 : * This method is built on the GEOS library, check it for the definition
1403 : * of the geometry operation.
1404 : * If OGR is built without the GEOS library, this method will always return
1405 : * FALSE.
1406 : *
1407 : *
1408 : * @return TRUE if the geometry has no points, otherwise FALSE.
1409 : */
1410 :
1411 : OGRBoolean
1412 2 : OGRGeometry::IsSimple( ) const
1413 :
1414 : {
1415 : #ifndef HAVE_GEOS
1416 :
1417 : return FALSE;
1418 :
1419 : #else
1420 :
1421 2 : OGRBoolean bResult = FALSE;
1422 2 : GEOSGeom hThisGeosGeom = NULL;
1423 :
1424 2 : hThisGeosGeom = exportToGEOS();
1425 :
1426 2 : if( hThisGeosGeom != NULL )
1427 : {
1428 2 : bResult = GEOSisSimple( hThisGeosGeom );
1429 2 : GEOSGeom_destroy( hThisGeosGeom );
1430 : }
1431 :
1432 2 : return bResult;
1433 :
1434 : #endif /* HAVE_GEOS */
1435 : }
1436 :
1437 :
1438 : /**
1439 : * \brief Returns TRUE if the geometry is simple.
1440 : *
1441 : * Returns TRUE if the geometry has no anomalous geometric points, such
1442 : * as self intersection or self tangency. The description of each
1443 : * instantiable geometric class will include the specific conditions that
1444 : * cause an instance of that class to be classified as not simple.
1445 : *
1446 : * This function is the same as the c++ method OGRGeometry::IsSimple() method.
1447 : *
1448 : * If OGR is built without the GEOS library, this function will always return
1449 : * FALSE.
1450 : *
1451 : * @param hGeom The Geometry to test.
1452 : *
1453 : * @return TRUE if object is simple, otherwise FALSE.
1454 : */
1455 :
1456 2 : int OGR_G_IsSimple( OGRGeometryH hGeom )
1457 :
1458 : {
1459 2 : VALIDATE_POINTER1( hGeom, "OGR_G_IsSimple", TRUE );
1460 :
1461 2 : return ((OGRGeometry *) hGeom)->IsSimple();
1462 : }
1463 :
1464 : /************************************************************************/
1465 : /* IsRing() */
1466 : /************************************************************************/
1467 :
1468 : /**
1469 : * \brief Test if the geometry is a ring
1470 : *
1471 : * This method is the same as the C function OGR_G_IsRing().
1472 : *
1473 : * This method is built on the GEOS library, check it for the definition
1474 : * of the geometry operation.
1475 : * If OGR is built without the GEOS library, this method will always return
1476 : * FALSE.
1477 : *
1478 : *
1479 : * @return TRUE if the geometry has no points, otherwise FALSE.
1480 : */
1481 :
1482 : OGRBoolean
1483 1 : OGRGeometry::IsRing( ) const
1484 :
1485 : {
1486 : #ifndef HAVE_GEOS
1487 :
1488 : return FALSE;
1489 :
1490 : #else
1491 :
1492 1 : OGRBoolean bResult = FALSE;
1493 1 : GEOSGeom hThisGeosGeom = NULL;
1494 :
1495 1 : hThisGeosGeom = exportToGEOS();
1496 :
1497 1 : if( hThisGeosGeom != NULL )
1498 : {
1499 1 : bResult = GEOSisRing( hThisGeosGeom );
1500 1 : GEOSGeom_destroy( hThisGeosGeom );
1501 : }
1502 :
1503 1 : return bResult;
1504 :
1505 : #endif /* HAVE_GEOS */
1506 : }
1507 :
1508 : /************************************************************************/
1509 : /* OGR_G_IsRing() */
1510 : /************************************************************************/
1511 :
1512 : /**
1513 : * \brief Test if the geometry is a ring
1514 : *
1515 : * This function is the same as the C++ method OGRGeometry::IsRing().
1516 : *
1517 : * This function is built on the GEOS library, check it for the definition
1518 : * of the geometry operation.
1519 : * If OGR is built without the GEOS library, this function will always return
1520 : * FALSE.
1521 : *
1522 : * @param hGeom The Geometry to test.
1523 : *
1524 : * @return TRUE if the geometry has no points, otherwise FALSE.
1525 : */
1526 :
1527 1 : int OGR_G_IsRing( OGRGeometryH hGeom )
1528 :
1529 : {
1530 1 : VALIDATE_POINTER1( hGeom, "OGR_G_IsRing", FALSE );
1531 :
1532 1 : return ((OGRGeometry *) hGeom)->IsRing();
1533 : }
1534 :
1535 : /************************************************************************/
1536 : /* OGRFromOGCGeomType() */
1537 : /* Map OGCgeometry format type to corresponding */
1538 : /* OGR constants. */
1539 : /************************************************************************/
1540 :
1541 3624 : OGRwkbGeometryType OGRFromOGCGeomType( const char *pszGeomType )
1542 : {
1543 3624 : if ( EQUAL(pszGeomType, "POINT") )
1544 361 : return wkbPoint;
1545 3263 : else if ( EQUAL(pszGeomType, "LINESTRING") )
1546 445 : return wkbLineString;
1547 2818 : else if ( EQUAL(pszGeomType, "POLYGON") )
1548 1253 : return wkbPolygon;
1549 1565 : else if ( EQUAL(pszGeomType, "MULTIPOINT") )
1550 6 : return wkbMultiPoint;
1551 1559 : else if ( EQUAL(pszGeomType, "MULTILINESTRING") )
1552 75 : return wkbMultiLineString;
1553 1484 : else if ( EQUAL(pszGeomType, "MULTIPOLYGON") )
1554 495 : return wkbMultiPolygon;
1555 989 : else if ( EQUAL(pszGeomType, "GEOMETRYCOLLECTION") )
1556 18 : return wkbGeometryCollection;
1557 : else
1558 971 : return wkbUnknown;
1559 : }
1560 :
1561 : /************************************************************************/
1562 : /* OGRToOGCGeomType() */
1563 : /* Map OGR geometry format constants to corresponding */
1564 : /* OGC geometry type */
1565 : /************************************************************************/
1566 :
1567 128 : const char * OGRToOGCGeomType( OGRwkbGeometryType eGeomType )
1568 : {
1569 128 : switch ( wkbFlatten(eGeomType) )
1570 : {
1571 : case wkbUnknown:
1572 42 : return "GEOMETRY";
1573 : case wkbPoint:
1574 9 : return "POINT";
1575 : case wkbLineString:
1576 13 : return "LINESTRING";
1577 : case wkbPolygon:
1578 17 : return "POLYGON";
1579 : case wkbMultiPoint:
1580 6 : return "MULTIPOINT";
1581 : case wkbMultiLineString:
1582 6 : return "MULTILINESTRING";
1583 : case wkbMultiPolygon:
1584 8 : return "MULTIPOLYGON";
1585 : case wkbGeometryCollection:
1586 18 : return "GEOMETRYCOLLECTION";
1587 : default:
1588 9 : return "";
1589 : }
1590 : }
1591 :
1592 : /************************************************************************/
1593 : /* OGRGeometryTypeToName() */
1594 : /************************************************************************/
1595 :
1596 : /**
1597 : * \brief Fetch a human readable name corresponding to an OGRwkBGeometryType value.
1598 : * The returned value should not be modified, or freed by the application.
1599 : *
1600 : * This function is C callable.
1601 : *
1602 : * @param eType the geometry type.
1603 : *
1604 : * @return internal human readable string, or NULL on failure.
1605 : */
1606 :
1607 3478 : const char *OGRGeometryTypeToName( OGRwkbGeometryType eType )
1608 :
1609 : {
1610 3478 : switch( (int)eType )
1611 : {
1612 : case wkbUnknown:
1613 938 : return "Unknown (any)";
1614 :
1615 : case (wkbUnknown | wkb25DBit):
1616 0 : return "3D Unknown (any)";
1617 :
1618 : case wkbPoint:
1619 295 : return "Point";
1620 :
1621 : case wkbPoint25D:
1622 52 : return "3D Point";
1623 :
1624 : case wkbLineString:
1625 362 : return "Line String";
1626 :
1627 : case wkbLineString25D:
1628 69 : return "3D Line String";
1629 :
1630 : case wkbPolygon:
1631 1210 : return "Polygon";
1632 :
1633 : case wkbPolygon25D:
1634 0 : return "3D Polygon";
1635 :
1636 : case wkbMultiPoint:
1637 0 : return "Multi Point";
1638 :
1639 : case wkbMultiPoint25D:
1640 0 : return "3D Multi Point";
1641 :
1642 : case wkbMultiLineString:
1643 69 : return "Multi Line String";
1644 :
1645 : case wkbMultiLineString25D:
1646 0 : return "3D Multi Line String";
1647 :
1648 : case wkbMultiPolygon:
1649 483 : return "Multi Polygon";
1650 :
1651 : case wkbMultiPolygon25D:
1652 0 : return "3D Multi Polygon";
1653 :
1654 : case wkbGeometryCollection:
1655 0 : return "Geometry Collection";
1656 :
1657 : case wkbGeometryCollection25D:
1658 0 : return "3D Geometry Collection";
1659 :
1660 : case wkbNone:
1661 0 : return "None";
1662 :
1663 : default:
1664 : {
1665 : // OGRThreadSafety: This static is judged to be a very low risk
1666 : // for thread safety because it is only used in case of error,
1667 : // and the worst that can happen is reporting the wrong code
1668 : // in the generated message.
1669 : static char szWorkName[33];
1670 0 : sprintf( szWorkName, "Unrecognised: %d", (int) eType );
1671 0 : return szWorkName;
1672 : }
1673 : }
1674 : }
1675 :
1676 : /************************************************************************/
1677 : /* OGRMergeGeometryTypes() */
1678 : /************************************************************************/
1679 :
1680 : /**
1681 : * \brief Find common geometry type.
1682 : *
1683 : * Given two geometry types, find the most specific common
1684 : * type. Normally used repeatedly with the geometries in a
1685 : * layer to try and establish the most specific geometry type
1686 : * that can be reported for the layer.
1687 : *
1688 : * NOTE: wkbUnknown is the "worst case" indicating a mixture of
1689 : * geometry types with nothing in common but the base geometry
1690 : * type. wkbNone should be used to indicate that no geometries
1691 : * have been encountered yet, and means the first geometry
1692 : * encounted will establish the preliminary type.
1693 : *
1694 : * @param eMain the first input geometry type.
1695 : * @param eExtra the second input geometry type.
1696 : *
1697 : * @return the merged geometry type.
1698 : */
1699 :
1700 : OGRwkbGeometryType
1701 205 : OGRMergeGeometryTypes( OGRwkbGeometryType eMain,
1702 : OGRwkbGeometryType eExtra )
1703 :
1704 : {
1705 205 : int n25DFlag = 0;
1706 205 : OGRwkbGeometryType eFMain = wkbFlatten(eMain);
1707 205 : OGRwkbGeometryType eFExtra = wkbFlatten(eExtra);
1708 :
1709 205 : if( eFMain != eMain || eFExtra != eExtra )
1710 2 : n25DFlag = wkb25DBit;
1711 :
1712 205 : if( eFMain == wkbUnknown || eFExtra == wkbUnknown )
1713 0 : return (OGRwkbGeometryType) (((int) wkbUnknown) | n25DFlag);
1714 :
1715 205 : if( eFMain == wkbNone )
1716 27 : return eExtra;
1717 :
1718 178 : if( eFExtra == wkbNone )
1719 0 : return eMain;
1720 :
1721 178 : if( eFMain == eFExtra )
1722 175 : return (OGRwkbGeometryType) (((int) eFMain) | n25DFlag);
1723 :
1724 : // Both are geometry collections.
1725 3 : if( (eFMain == wkbGeometryCollection
1726 : || eFMain == wkbMultiPoint
1727 : || eFMain == wkbMultiLineString
1728 : || eFMain == wkbMultiPolygon)
1729 : && (eFExtra == wkbGeometryCollection
1730 : || eFExtra == wkbMultiPoint
1731 : || eFExtra == wkbMultiLineString
1732 : || eFMain == wkbMultiPolygon) )
1733 : {
1734 1 : return (OGRwkbGeometryType) (((int) wkbGeometryCollection) | n25DFlag);
1735 : }
1736 :
1737 : // Nothing apparently in common.
1738 2 : return (OGRwkbGeometryType) (((int) wkbUnknown) | n25DFlag);
1739 : }
1740 :
1741 : /**
1742 : * \fn void OGRGeometry::flattenTo2D();
1743 : *
1744 : * \brief Convert geometry to strictly 2D.
1745 : * In a sense this converts all Z coordinates
1746 : * to 0.0.
1747 : *
1748 : * This method is the same as the C function OGR_G_FlattenTo2D().
1749 : */
1750 :
1751 : /************************************************************************/
1752 : /* OGR_G_FlattenTo2D() */
1753 : /************************************************************************/
1754 : /**
1755 : * \brief Convert geometry to strictly 2D.
1756 : * In a sense this converts all Z coordinates
1757 : * to 0.0.
1758 : *
1759 : * This function is the same as the CPP method OGRGeometry::flattenTo2D().
1760 : *
1761 : * @param hGeom handle on the geometry to convert.
1762 : */
1763 :
1764 1 : void OGR_G_FlattenTo2D( OGRGeometryH hGeom )
1765 :
1766 : {
1767 1 : ((OGRGeometry *) hGeom)->flattenTo2D();
1768 1 : }
1769 :
1770 : /************************************************************************/
1771 : /* exportToGML() */
1772 : /************************************************************************/
1773 :
1774 : /**
1775 : * \fn char *OGRGeometry::exportToGML( const char* const * papszOptions = NULL ) const;
1776 : *
1777 : * \brief Convert a geometry into GML format.
1778 : *
1779 : * The GML geometry is expressed directly in terms of GML basic data
1780 : * types assuming the this is available in the gml namespace. The returned
1781 : * string should be freed with CPLFree() when no longer required.
1782 : *
1783 : * The supported options in OGR 1.8.0 are :
1784 : * <ul>
1785 : * <li> FORMAT=GML3. Otherwise it will default to GML 2.1.2 output.
1786 : * <li> GML3_LINESTRING_ELEMENT=curve. (Only valid for FORMAT=GML3) To use gml:Curve element for linestrings.
1787 : * Otherwise gml:LineString will be used .
1788 : * <li> GML3_LONGSRS=YES/NO. (Only valid for FORMAT=GML3) Default to YES. If YES, SRS with EPSG authority will
1789 : * be written with the "urn:ogc:def:crs:EPSG::" prefix.
1790 : * In the case, if the SRS is a geographic SRS without explicit AXIS order, but that the same SRS authority code
1791 : * imported with ImportFromEPSGA() should be treated as lat/long, then the function will take care of coordinate order swapping.
1792 : * If set to NO, SRS with EPSG authority will be written with the "EPSG:" prefix, even if they are in lat/long order.
1793 : * </ul>
1794 : *
1795 : * This method is the same as the C function OGR_G_ExportToGMLEx().
1796 : *
1797 : * @param papszOptions NULL-terminated list of options.
1798 : * @return A GML fragment or NULL in case of error.
1799 : */
1800 :
1801 26 : char *OGRGeometry::exportToGML( const char* const * papszOptions ) const
1802 : {
1803 26 : return OGR_G_ExportToGMLEx( (OGRGeometryH) this, (char**)papszOptions );
1804 : }
1805 :
1806 : /************************************************************************/
1807 : /* exportToKML() */
1808 : /************************************************************************/
1809 :
1810 : /**
1811 : * \fn char *OGRGeometry::exportToKML() const;
1812 : *
1813 : * \brief Convert a geometry into KML format.
1814 : *
1815 : * The returned string should be freed with CPLFree() when no longer required.
1816 : *
1817 : * This method is the same as the C function OGR_G_ExportToKML().
1818 : *
1819 : * @return A KML fragment or NULL in case of error.
1820 : */
1821 :
1822 8 : char *OGRGeometry::exportToKML() const
1823 : {
1824 : #ifndef _WIN32_WCE
1825 : #ifdef OGR_ENABLED
1826 8 : return OGR_G_ExportToKML( (OGRGeometryH) this, NULL );
1827 : #else
1828 : CPLError( CE_Failure, CPLE_AppDefined,
1829 : "OGRGeometry::exportToKML() not supported in builds without OGR drivers." );
1830 : return NULL;
1831 : #endif
1832 : #else
1833 : CPLError( CE_Failure, CPLE_AppDefined,
1834 : "OGRGeometry::exportToKML() not supported in the WinCE build." );
1835 : return NULL;
1836 : #endif
1837 : }
1838 :
1839 : /************************************************************************/
1840 : /* exportToJson() */
1841 : /************************************************************************/
1842 :
1843 : /**
1844 : * \fn char *OGRGeometry::exportToJson() const;
1845 : *
1846 : * \brief Convert a geometry into GeoJSON format.
1847 : *
1848 : * The returned string should be freed with CPLFree() when no longer required.
1849 : *
1850 : * This method is the same as the C function OGR_G_ExportToJson().
1851 : *
1852 : * @return A GeoJSON fragment or NULL in case of error.
1853 : */
1854 :
1855 0 : char *OGRGeometry::exportToJson() const
1856 : {
1857 : #ifndef _WIN32_WCE
1858 : #ifdef OGR_ENABLED
1859 0 : OGRGeometry* poGeometry = const_cast<OGRGeometry*>(this);
1860 0 : return OGR_G_ExportToJson( (OGRGeometryH) (poGeometry) );
1861 : #else
1862 : CPLError( CE_Failure, CPLE_AppDefined,
1863 : "OGRGeometry::exportToJson() not supported in builds without OGR drivers." );
1864 : return NULL;
1865 : #endif
1866 : #else
1867 : CPLError( CE_Failure, CPLE_AppDefined,
1868 : "OGRGeometry::exportToJson() not supported in the WinCE build." );
1869 : return NULL;
1870 : #endif
1871 : }
1872 :
1873 : /************************************************************************/
1874 : /* OGRSetGenerate_DB2_V72_BYTE_ORDER() */
1875 : /************************************************************************/
1876 :
1877 : /**
1878 : * \brief Special entry point to enable the hack for generating DB2 V7.2 style WKB.
1879 : *
1880 : * DB2 seems to have placed (and require) an extra 0x30 or'ed with the byte order in
1881 : * WKB. This entry point is used to turn on or off the
1882 : * generation of such WKB.
1883 : */
1884 4 : OGRErr OGRSetGenerate_DB2_V72_BYTE_ORDER( int bGenerate_DB2_V72_BYTE_ORDER )
1885 :
1886 : {
1887 : #if defined(HACK_FOR_IBM_DB2_V72)
1888 4 : OGRGeometry::bGenerate_DB2_V72_BYTE_ORDER = bGenerate_DB2_V72_BYTE_ORDER;
1889 4 : return OGRERR_NONE;
1890 : #else
1891 : if( bGenerate_DB2_V72_BYTE_ORDER )
1892 : return OGRERR_FAILURE;
1893 : else
1894 : return OGRERR_NONE;
1895 : #endif
1896 : }
1897 : /************************************************************************/
1898 : /* OGRGetGenerate_DB2_V72_BYTE_ORDER() */
1899 : /* */
1900 : /* This is a special entry point to get the value of static flag */
1901 : /* OGRGeometry::bGenerate_DB2_V72_BYTE_ORDER. */
1902 : /************************************************************************/
1903 0 : int OGRGetGenerate_DB2_V72_BYTE_ORDER()
1904 : {
1905 0 : return OGRGeometry::bGenerate_DB2_V72_BYTE_ORDER;
1906 : }
1907 :
1908 : /************************************************************************/
1909 : /* exportToGEOS() */
1910 : /************************************************************************/
1911 :
1912 609 : GEOSGeom OGRGeometry::exportToGEOS() const
1913 :
1914 : {
1915 : #ifndef HAVE_GEOS
1916 :
1917 : CPLError( CE_Failure, CPLE_NotSupported,
1918 : "GEOS support not enabled." );
1919 : return NULL;
1920 :
1921 : #else
1922 :
1923 : static void *hGEOSInitMutex = NULL;
1924 : static int bGEOSInitialized = FALSE;
1925 :
1926 609 : CPLMutexHolderD( &hGEOSInitMutex );
1927 :
1928 609 : if( !bGEOSInitialized )
1929 : {
1930 20 : bGEOSInitialized = TRUE;
1931 20 : initGEOS( _GEOSWarningHandler, _GEOSErrorHandler );
1932 : }
1933 :
1934 : /* POINT EMPTY is exported to WKB as if it were POINT(0 0) */
1935 : /* so that particular case is necessary */
1936 609 : if (wkbFlatten(getGeometryType()) == wkbPoint &&
1937 : nCoordDimension == 0)
1938 : {
1939 1 : return GEOSGeomFromWKT("POINT EMPTY");
1940 : }
1941 :
1942 608 : GEOSGeom hGeom = NULL;
1943 : size_t nDataSize;
1944 608 : unsigned char *pabyData = NULL;
1945 :
1946 608 : nDataSize = WkbSize();
1947 608 : pabyData = (unsigned char *) CPLMalloc(nDataSize);
1948 608 : if( exportToWkb( wkbNDR, pabyData ) == OGRERR_NONE )
1949 608 : hGeom = GEOSGeomFromWKB_buf( pabyData, nDataSize );
1950 :
1951 608 : CPLFree( pabyData );
1952 :
1953 608 : return hGeom;
1954 :
1955 : #endif /* HAVE_GEOS */
1956 : }
1957 :
1958 :
1959 : /************************************************************************/
1960 : /* Distance() */
1961 : /************************************************************************/
1962 :
1963 : /**
1964 : * \brief Compute distance between two geometries.
1965 : *
1966 : * Returns the shortest distance between the two geometries.
1967 : *
1968 : * This method is the same as the C function OGR_G_Distance().
1969 : *
1970 : * This method is built on the GEOS library, check it for the definition
1971 : * of the geometry operation.
1972 : * If OGR is built without the GEOS library, this method will always fail,
1973 : * issuing a CPLE_NotSupported error.
1974 : *
1975 : * @param poOtherGeom the other geometry to compare against.
1976 : *
1977 : * @return the distance between the geometries or -1 if an error occurs.
1978 : */
1979 :
1980 1 : double OGRGeometry::Distance( const OGRGeometry *poOtherGeom ) const
1981 :
1982 : {
1983 1 : if( NULL == poOtherGeom )
1984 : {
1985 0 : CPLDebug( "OGR", "OGRGeometry::Distance called with NULL geometry pointer" );
1986 0 : return -1.0;
1987 : }
1988 :
1989 : #ifndef HAVE_GEOS
1990 :
1991 : CPLError( CE_Failure, CPLE_NotSupported,
1992 : "GEOS support not enabled." );
1993 : return -1.0;
1994 :
1995 : #else
1996 :
1997 : // GEOSGeom is a pointer
1998 1 : GEOSGeom hThis = NULL;
1999 1 : GEOSGeom hOther = NULL;
2000 :
2001 1 : hOther = poOtherGeom->exportToGEOS();
2002 1 : hThis = exportToGEOS();
2003 :
2004 1 : int bIsErr = 0;
2005 1 : double dfDistance = 0.0;
2006 :
2007 1 : if( hThis != NULL && hOther != NULL )
2008 : {
2009 1 : bIsErr = GEOSDistance( hThis, hOther, &dfDistance );
2010 : }
2011 :
2012 1 : GEOSGeom_destroy( hThis );
2013 1 : GEOSGeom_destroy( hOther );
2014 :
2015 1 : if ( bIsErr > 0 )
2016 : {
2017 1 : return dfDistance;
2018 : }
2019 :
2020 : /* Calculations error */
2021 0 : return -1.0;
2022 :
2023 : #endif /* HAVE_GEOS */
2024 : }
2025 :
2026 : /************************************************************************/
2027 : /* OGR_G_Distance() */
2028 : /************************************************************************/
2029 : /**
2030 : * \brief Compute distance between two geometries.
2031 : *
2032 : * Returns the shortest distance between the two geometries.
2033 : *
2034 : * This function is the same as the C++ method OGRGeometry::Distance().
2035 : *
2036 : * This function is built on the GEOS library, check it for the definition
2037 : * of the geometry operation.
2038 : * If OGR is built without the GEOS library, this function will always fail,
2039 : * issuing a CPLE_NotSupported error.
2040 : *
2041 : * @param hFirst the first geometry to compare against.
2042 : * @param hOther the other geometry to compare against.
2043 : *
2044 : * @return the distance between the geometries or -1 if an error occurs.
2045 : */
2046 :
2047 :
2048 1 : double OGR_G_Distance( OGRGeometryH hFirst, OGRGeometryH hOther )
2049 :
2050 : {
2051 1 : VALIDATE_POINTER1( hFirst, "OGR_G_Distance", 0.0 );
2052 :
2053 1 : return ((OGRGeometry *) hFirst)->Distance( (OGRGeometry *) hOther );
2054 : }
2055 :
2056 : /************************************************************************/
2057 : /* ConvexHull() */
2058 : /************************************************************************/
2059 :
2060 : /**
2061 : * \brief Compute convex hull.
2062 : *
2063 : * A new geometry object is created and returned containing the convex
2064 : * hull of the geometry on which the method is invoked.
2065 : *
2066 : * This method is the same as the C function OGR_G_ConvexHull().
2067 : *
2068 : * This method is built on the GEOS library, check it for the definition
2069 : * of the geometry operation.
2070 : * If OGR is built without the GEOS library, this method will always fail,
2071 : * issuing a CPLE_NotSupported error.
2072 : *
2073 : * @return a newly allocated geometry now owned by the caller, or NULL on failure.
2074 : */
2075 :
2076 1 : OGRGeometry *OGRGeometry::ConvexHull() const
2077 :
2078 : {
2079 : #ifndef HAVE_GEOS
2080 :
2081 : CPLError( CE_Failure, CPLE_NotSupported,
2082 : "GEOS support not enabled." );
2083 : return NULL;
2084 :
2085 : #else
2086 :
2087 1 : GEOSGeom hGeosGeom = NULL;
2088 1 : GEOSGeom hGeosHull = NULL;
2089 1 : OGRGeometry *poHullOGRGeom = NULL;
2090 :
2091 1 : hGeosGeom = exportToGEOS();
2092 1 : if( hGeosGeom != NULL )
2093 : {
2094 1 : hGeosHull = GEOSConvexHull( hGeosGeom );
2095 1 : GEOSGeom_destroy( hGeosGeom );
2096 :
2097 1 : if( hGeosHull != NULL )
2098 : {
2099 1 : poHullOGRGeom = OGRGeometryFactory::createFromGEOS(hGeosHull);
2100 1 : GEOSGeom_destroy( hGeosHull);
2101 : }
2102 : }
2103 :
2104 1 : return poHullOGRGeom;
2105 :
2106 : #endif /* HAVE_GEOS */
2107 : }
2108 :
2109 : /************************************************************************/
2110 : /* OGR_G_ConvexHull() */
2111 : /************************************************************************/
2112 : /**
2113 : * \brief Compute convex hull.
2114 : *
2115 : * A new geometry object is created and returned containing the convex
2116 : * hull of the geometry on which the method is invoked.
2117 : *
2118 : * This function is the same as the C++ method OGRGeometry::ConvexHull().
2119 : *
2120 : * This function is built on the GEOS library, check it for the definition
2121 : * of the geometry operation.
2122 : * If OGR is built without the GEOS library, this function will always fail,
2123 : * issuing a CPLE_NotSupported error.
2124 : *
2125 : * @param hTarget The Geometry to calculate the convex hull of.
2126 : *
2127 : * @return a handle to a newly allocated geometry now owned by the caller,
2128 : * or NULL on failure.
2129 : */
2130 :
2131 1 : OGRGeometryH OGR_G_ConvexHull( OGRGeometryH hTarget )
2132 :
2133 : {
2134 1 : VALIDATE_POINTER1( hTarget, "OGR_G_ConvexHull", NULL );
2135 :
2136 1 : return (OGRGeometryH) ((OGRGeometry *) hTarget)->ConvexHull();
2137 : }
2138 :
2139 : /************************************************************************/
2140 : /* Boundary() */
2141 : /************************************************************************/
2142 :
2143 : /**
2144 : * \brief Compute boundary.
2145 : *
2146 : * A new geometry object is created and returned containing the boundary
2147 : * of the geometry on which the method is invoked.
2148 : *
2149 : * This method is the same as the C function OGR_G_Boundary().
2150 : *
2151 : * This method is built on the GEOS library, check it for the definition
2152 : * of the geometry operation.
2153 : * If OGR is built without the GEOS library, this method will always fail,
2154 : * issuing a CPLE_NotSupported error.
2155 : *
2156 : * @return a newly allocated geometry now owned by the caller, or NULL on failure.
2157 : *
2158 : * @since OGR 1.8.0
2159 : */
2160 :
2161 6 : OGRGeometry *OGRGeometry::Boundary() const
2162 :
2163 : {
2164 : #ifndef HAVE_GEOS
2165 :
2166 : CPLError( CE_Failure, CPLE_NotSupported,
2167 : "GEOS support not enabled." );
2168 : return NULL;
2169 :
2170 : #else
2171 :
2172 6 : GEOSGeom hGeosGeom = NULL;
2173 6 : GEOSGeom hGeosProduct = NULL;
2174 6 : OGRGeometry *poOGRProduct = NULL;
2175 :
2176 6 : hGeosGeom = exportToGEOS();
2177 6 : if( hGeosGeom != NULL )
2178 : {
2179 6 : hGeosProduct = GEOSBoundary( hGeosGeom );
2180 6 : GEOSGeom_destroy( hGeosGeom );
2181 :
2182 6 : if( hGeosProduct != NULL )
2183 : {
2184 6 : poOGRProduct = OGRGeometryFactory::createFromGEOS(hGeosProduct);
2185 6 : GEOSGeom_destroy( hGeosProduct );
2186 : }
2187 : }
2188 :
2189 6 : return poOGRProduct;
2190 :
2191 : #endif /* HAVE_GEOS */
2192 : }
2193 :
2194 :
2195 : /**
2196 : * \brief Compute boundary (deprecated)
2197 : *
2198 : * @deprecated
2199 : *
2200 : * @see Boundary()
2201 : */
2202 0 : OGRGeometry *OGRGeometry::getBoundary() const
2203 :
2204 : {
2205 0 : return Boundary();
2206 : }
2207 :
2208 : /************************************************************************/
2209 : /* OGR_G_Boundary() */
2210 : /************************************************************************/
2211 : /**
2212 : * \brief Compute boundary.
2213 : *
2214 : * A new geometry object is created and returned containing the boundary
2215 : * of the geometry on which the method is invoked.
2216 : *
2217 : * This function is the same as the C++ method OGR_G_Boundary().
2218 : *
2219 : * This function is built on the GEOS library, check it for the definition
2220 : * of the geometry operation.
2221 : * If OGR is built without the GEOS library, this function will always fail,
2222 : * issuing a CPLE_NotSupported error.
2223 : *
2224 : * @param hTarget The Geometry to calculate the boundary of.
2225 : *
2226 : * @return a handle to a newly allocated geometry now owned by the caller,
2227 : * or NULL on failure.
2228 : *
2229 : * @since OGR 1.8.0
2230 : */
2231 6 : OGRGeometryH OGR_G_Boundary( OGRGeometryH hTarget )
2232 :
2233 : {
2234 6 : VALIDATE_POINTER1( hTarget, "OGR_G_Boundary", NULL );
2235 :
2236 6 : return (OGRGeometryH) ((OGRGeometry *) hTarget)->Boundary();
2237 : }
2238 :
2239 : /**
2240 : * \brief Compute boundary (deprecated)
2241 : *
2242 : * @deprecated
2243 : *
2244 : * @see OGR_G_Boundary()
2245 : */
2246 0 : OGRGeometryH OGR_G_GetBoundary( OGRGeometryH hTarget )
2247 :
2248 : {
2249 0 : VALIDATE_POINTER1( hTarget, "OGR_G_GetBoundary", NULL );
2250 :
2251 0 : return (OGRGeometryH) ((OGRGeometry *) hTarget)->Boundary();
2252 : }
2253 :
2254 : /************************************************************************/
2255 : /* Buffer() */
2256 : /************************************************************************/
2257 :
2258 : /**
2259 : * \brief Compute buffer of geometry.
2260 : *
2261 : * Builds a new geometry containing the buffer region around the geometry
2262 : * on which it is invoked. The buffer is a polygon containing the region within
2263 : * the buffer distance of the original geometry.
2264 : *
2265 : * Some buffer sections are properly described as curves, but are converted to
2266 : * approximate polygons. The nQuadSegs parameter can be used to control how many
2267 : * segements should be used to define a 90 degree curve - a quadrant of a circle.
2268 : * A value of 30 is a reasonable default. Large values result in large numbers
2269 : * of vertices in the resulting buffer geometry while small numbers reduce the
2270 : * accuracy of the result.
2271 : *
2272 : * This method is the same as the C function OGR_G_Buffer().
2273 : *
2274 : * This method is built on the GEOS library, check it for the definition
2275 : * of the geometry operation.
2276 : * If OGR is built without the GEOS library, this method will always fail,
2277 : * issuing a CPLE_NotSupported error.
2278 : *
2279 : * @param dfDist the buffer distance to be applied.
2280 : *
2281 : * @param nQuadSegs the number of segments used to approximate a 90 degree (quadrant) of
2282 : * curvature.
2283 : *
2284 : * @return the newly created geometry, or NULL if an error occurs.
2285 : */
2286 :
2287 1 : OGRGeometry *OGRGeometry::Buffer( double dfDist, int nQuadSegs ) const
2288 :
2289 : {
2290 : #ifndef HAVE_GEOS
2291 :
2292 : CPLError( CE_Failure, CPLE_NotSupported,
2293 : "GEOS support not enabled." );
2294 : return NULL;
2295 :
2296 : #else
2297 :
2298 1 : GEOSGeom hGeosGeom = NULL;
2299 1 : GEOSGeom hGeosProduct = NULL;
2300 1 : OGRGeometry *poOGRProduct = NULL;
2301 :
2302 1 : hGeosGeom = exportToGEOS();
2303 1 : if( hGeosGeom != NULL )
2304 : {
2305 1 : hGeosProduct = GEOSBuffer( hGeosGeom, dfDist, nQuadSegs );
2306 1 : GEOSGeom_destroy( hGeosGeom );
2307 :
2308 1 : if( hGeosProduct != NULL )
2309 : {
2310 1 : poOGRProduct = OGRGeometryFactory::createFromGEOS(hGeosProduct);
2311 1 : GEOSGeom_destroy( hGeosProduct );
2312 : }
2313 : }
2314 :
2315 1 : return poOGRProduct;
2316 :
2317 : #endif /* HAVE_GEOS */
2318 : }
2319 :
2320 : /************************************************************************/
2321 : /* OGR_G_Buffer() */
2322 : /************************************************************************/
2323 :
2324 : /**
2325 : * \brief Compute buffer of geometry.
2326 : *
2327 : * Builds a new geometry containing the buffer region around the geometry
2328 : * on which it is invoked. The buffer is a polygon containing the region within
2329 : * the buffer distance of the original geometry.
2330 : *
2331 : * Some buffer sections are properly described as curves, but are converted to
2332 : * approximate polygons. The nQuadSegs parameter can be used to control how many
2333 : * segements should be used to define a 90 degree curve - a quadrant of a circle.
2334 : * A value of 30 is a reasonable default. Large values result in large numbers
2335 : * of vertices in the resulting buffer geometry while small numbers reduce the
2336 : * accuracy of the result.
2337 : *
2338 : * This function is the same as the C++ method OGRGeometry::Buffer().
2339 : *
2340 : * This function is built on the GEOS library, check it for the definition
2341 : * of the geometry operation.
2342 : * If OGR is built without the GEOS library, this function will always fail,
2343 : * issuing a CPLE_NotSupported error.
2344 : *
2345 : * @param hTarget the geometry.
2346 : * @param dfDist the buffer distance to be applied.
2347 : *
2348 : * @param nQuadSegs the number of segments used to approximate a 90 degree
2349 : * (quadrant) of curvature.
2350 : *
2351 : * @return the newly created geometry, or NULL if an error occurs.
2352 : */
2353 :
2354 1 : OGRGeometryH OGR_G_Buffer( OGRGeometryH hTarget, double dfDist, int nQuadSegs )
2355 :
2356 : {
2357 1 : VALIDATE_POINTER1( hTarget, "OGR_G_Buffer", NULL );
2358 :
2359 1 : return (OGRGeometryH) ((OGRGeometry *) hTarget)->Buffer( dfDist, nQuadSegs );
2360 : }
2361 :
2362 : /************************************************************************/
2363 : /* Intersection() */
2364 : /************************************************************************/
2365 :
2366 : /**
2367 : * \brief Compute intersection.
2368 : *
2369 : * Generates a new geometry which is the region of intersection of the
2370 : * two geometries operated on. The Intersects() method can be used to test if
2371 : * two geometries intersect.
2372 : *
2373 : * This method is the same as the C function OGR_G_Intersection().
2374 : *
2375 : * This method is built on the GEOS library, check it for the definition
2376 : * of the geometry operation.
2377 : * If OGR is built without the GEOS library, this method will always fail,
2378 : * issuing a CPLE_NotSupported error.
2379 : *
2380 : * @param poOtherGeom the other geometry intersected with "this" geometry.
2381 : *
2382 : * @return a new geometry representing the intersection or NULL if there is
2383 : * no intersection or an error occurs.
2384 : */
2385 :
2386 100 : OGRGeometry *OGRGeometry::Intersection( const OGRGeometry *poOtherGeom ) const
2387 :
2388 : {
2389 : #ifndef HAVE_GEOS
2390 :
2391 : CPLError( CE_Failure, CPLE_NotSupported,
2392 : "GEOS support not enabled." );
2393 : return NULL;
2394 :
2395 : #else
2396 :
2397 100 : GEOSGeom hThisGeosGeom = NULL;
2398 100 : GEOSGeom hOtherGeosGeom = NULL;
2399 100 : GEOSGeom hGeosProduct = NULL;
2400 100 : OGRGeometry *poOGRProduct = NULL;
2401 :
2402 100 : hThisGeosGeom = exportToGEOS();
2403 100 : hOtherGeosGeom = poOtherGeom->exportToGEOS();
2404 100 : if( hThisGeosGeom != NULL && hOtherGeosGeom != NULL )
2405 : {
2406 100 : hGeosProduct = GEOSIntersection( hThisGeosGeom, hOtherGeosGeom );
2407 :
2408 100 : if( hGeosProduct != NULL )
2409 : {
2410 100 : poOGRProduct = OGRGeometryFactory::createFromGEOS(hGeosProduct);
2411 100 : GEOSGeom_destroy( hGeosProduct );
2412 : }
2413 : }
2414 100 : GEOSGeom_destroy( hThisGeosGeom );
2415 100 : GEOSGeom_destroy( hOtherGeosGeom );
2416 :
2417 100 : return poOGRProduct;
2418 :
2419 : #endif /* HAVE_GEOS */
2420 : }
2421 :
2422 : /************************************************************************/
2423 : /* OGR_G_Intersection() */
2424 : /************************************************************************/
2425 :
2426 : /**
2427 : * \brief Compute intersection.
2428 : *
2429 : * Generates a new geometry which is the region of intersection of the
2430 : * two geometries operated on. The OGR_G_Intersects() function can be used to
2431 : * test if two geometries intersect.
2432 : *
2433 : * This function is the same as the C++ method OGRGeometry::Intersection().
2434 : *
2435 : * This function is built on the GEOS library, check it for the definition
2436 : * of the geometry operation.
2437 : * If OGR is built without the GEOS library, this function will always fail,
2438 : * issuing a CPLE_NotSupported error.
2439 : *
2440 : * @param hThis the geometry.
2441 : * @param hOther the other geometry.
2442 : *
2443 : * @return a new geometry representing the intersection or NULL if there is
2444 : * no intersection or an error occurs.
2445 : */
2446 :
2447 45 : OGRGeometryH OGR_G_Intersection( OGRGeometryH hThis, OGRGeometryH hOther )
2448 :
2449 : {
2450 45 : VALIDATE_POINTER1( hThis, "OGR_G_Intersection", NULL );
2451 :
2452 : return (OGRGeometryH)
2453 45 : ((OGRGeometry *) hThis)->Intersection( (OGRGeometry *) hOther );
2454 : }
2455 :
2456 : /************************************************************************/
2457 : /* Union() */
2458 : /************************************************************************/
2459 :
2460 : /**
2461 : * \brief Compute union.
2462 : *
2463 : * Generates a new geometry which is the region of union of the
2464 : * two geometries operated on.
2465 : *
2466 : * This method is the same as the C function OGR_G_Union().
2467 : *
2468 : * This method is built on the GEOS library, check it for the definition
2469 : * of the geometry operation.
2470 : * If OGR is built without the GEOS library, this method will always fail,
2471 : * issuing a CPLE_NotSupported error.
2472 : *
2473 : * @param poOtherGeom the other geometry unioned with "this" geometry.
2474 : *
2475 : * @return a new geometry representing the union or NULL if an error occurs.
2476 : */
2477 :
2478 3 : OGRGeometry *OGRGeometry::Union( const OGRGeometry *poOtherGeom ) const
2479 :
2480 : {
2481 : #ifndef HAVE_GEOS
2482 :
2483 : CPLError( CE_Failure, CPLE_NotSupported,
2484 : "GEOS support not enabled." );
2485 : return NULL;
2486 :
2487 : #else
2488 :
2489 3 : GEOSGeom hThisGeosGeom = NULL;
2490 3 : GEOSGeom hOtherGeosGeom = NULL;
2491 3 : GEOSGeom hGeosProduct = NULL;
2492 3 : OGRGeometry *poOGRProduct = NULL;
2493 :
2494 3 : hThisGeosGeom = exportToGEOS();
2495 3 : hOtherGeosGeom = poOtherGeom->exportToGEOS();
2496 3 : if( hThisGeosGeom != NULL && hOtherGeosGeom != NULL )
2497 : {
2498 3 : hGeosProduct = GEOSUnion( hThisGeosGeom, hOtherGeosGeom );
2499 :
2500 3 : if( hGeosProduct != NULL )
2501 : {
2502 3 : poOGRProduct = OGRGeometryFactory::createFromGEOS(hGeosProduct);
2503 3 : GEOSGeom_destroy( hGeosProduct );
2504 : }
2505 : }
2506 3 : GEOSGeom_destroy( hThisGeosGeom );
2507 3 : GEOSGeom_destroy( hOtherGeosGeom );
2508 :
2509 3 : return poOGRProduct;
2510 :
2511 : #endif /* HAVE_GEOS */
2512 : }
2513 :
2514 : /************************************************************************/
2515 : /* OGR_G_Union() */
2516 : /************************************************************************/
2517 :
2518 : /**
2519 : * \brief Compute union.
2520 : *
2521 : * Generates a new geometry which is the region of union of the
2522 : * two geometries operated on.
2523 : *
2524 : * This function is the same as the C++ method OGRGeometry::Union().
2525 : *
2526 : * This function is built on the GEOS library, check it for the definition
2527 : * of the geometry operation.
2528 : * If OGR is built without the GEOS library, this function will always fail,
2529 : * issuing a CPLE_NotSupported error.
2530 : *
2531 : * @param hThis the geometry.
2532 : * @param hOther the other geometry.
2533 : *
2534 : * @return a new geometry representing the union or NULL if an error occurs.
2535 : */
2536 :
2537 3 : OGRGeometryH OGR_G_Union( OGRGeometryH hThis, OGRGeometryH hOther )
2538 :
2539 : {
2540 3 : VALIDATE_POINTER1( hThis, "OGR_G_Union", NULL );
2541 :
2542 : return (OGRGeometryH)
2543 3 : ((OGRGeometry *) hThis)->Union( (OGRGeometry *) hOther );
2544 : }
2545 :
2546 : /************************************************************************/
2547 : /* UnionCascaded() */
2548 : /************************************************************************/
2549 :
2550 : /**
2551 : * \brief Compute union using cascading.
2552 : *
2553 : * This method is the same as the C function OGR_G_UnionCascaded().
2554 : *
2555 : * This method is built on the GEOS library, check it for the definition
2556 : * of the geometry operation.
2557 : * If OGR is built without the GEOS library, this method will always fail,
2558 : * issuing a CPLE_NotSupported error.
2559 : *
2560 : * @return a new geometry representing the union or NULL if an error occurs.
2561 : *
2562 : * @since OGR 1.8.0
2563 : */
2564 :
2565 1 : OGRGeometry *OGRGeometry::UnionCascaded() const
2566 :
2567 : {
2568 : #ifndef HAVE_GEOS
2569 :
2570 : CPLError( CE_Failure, CPLE_NotSupported,
2571 : "GEOS support not enabled." );
2572 : return NULL;
2573 :
2574 : /* GEOS >= 3.1.0 */
2575 : #elif GEOS_VERSION_MAJOR > 3 || (GEOS_VERSION_MAJOR == 3 && GEOS_VERSION_MINOR >= 1)
2576 :
2577 1 : GEOSGeom hThisGeosGeom = NULL;
2578 1 : GEOSGeom hGeosProduct = NULL;
2579 1 : OGRGeometry *poOGRProduct = NULL;
2580 :
2581 1 : hThisGeosGeom = exportToGEOS();
2582 1 : if( hThisGeosGeom != NULL )
2583 : {
2584 1 : hGeosProduct = GEOSUnionCascaded( hThisGeosGeom );
2585 1 : GEOSGeom_destroy( hThisGeosGeom );
2586 :
2587 1 : if( hGeosProduct != NULL )
2588 : {
2589 1 : poOGRProduct = OGRGeometryFactory::createFromGEOS(hGeosProduct);
2590 1 : GEOSGeom_destroy( hGeosProduct );
2591 : }
2592 : }
2593 :
2594 1 : return poOGRProduct;
2595 :
2596 : #else
2597 : CPLError( CE_Failure, CPLE_NotSupported,
2598 : "GEOS >= 3.1.0 required for UnionCascaded() support." );
2599 : return NULL;
2600 : #endif /* HAVE_GEOS */
2601 : }
2602 :
2603 : /************************************************************************/
2604 : /* OGR_G_UnionCascaded() */
2605 : /************************************************************************/
2606 :
2607 : /**
2608 : * \brief Compute union using cascading.
2609 : *
2610 : * This function is the same as the C++ method OGRGeometry::UnionCascaded().
2611 : *
2612 : * This function is built on the GEOS library, check it for the definition
2613 : * of the geometry operation.
2614 : * If OGR is built without the GEOS library, this function will always fail,
2615 : * issuing a CPLE_NotSupported error.
2616 : *
2617 : * @param hThis the geometry.
2618 : *
2619 : * @return a new geometry representing the union or NULL if an error occurs.
2620 : */
2621 :
2622 1 : OGRGeometryH OGR_G_UnionCascaded( OGRGeometryH hThis )
2623 :
2624 : {
2625 1 : VALIDATE_POINTER1( hThis, "OGR_G_UnionCascaded", NULL );
2626 :
2627 : return (OGRGeometryH)
2628 1 : ((OGRGeometry *) hThis)->UnionCascaded();
2629 : }
2630 :
2631 : /************************************************************************/
2632 : /* Difference() */
2633 : /************************************************************************/
2634 :
2635 : /**
2636 : * \brief Compute difference.
2637 : *
2638 : * Generates a new geometry which is the region of this geometry with the
2639 : * region of the second geometry removed.
2640 : *
2641 : * This method is the same as the C function OGR_G_Difference().
2642 : *
2643 : * This method is built on the GEOS library, check it for the definition
2644 : * of the geometry operation.
2645 : * If OGR is built without the GEOS library, this method will always fail,
2646 : * issuing a CPLE_NotSupported error.
2647 : *
2648 : * @param poOtherGeom the other geometry removed from "this" geometry.
2649 : *
2650 : * @return a new geometry representing the difference or NULL if the
2651 : * difference is empty or an error occurs.
2652 : */
2653 :
2654 1 : OGRGeometry *OGRGeometry::Difference( const OGRGeometry *poOtherGeom ) const
2655 :
2656 : {
2657 : #ifndef HAVE_GEOS
2658 :
2659 : CPLError( CE_Failure, CPLE_NotSupported,
2660 : "GEOS support not enabled." );
2661 : return NULL;
2662 :
2663 : #else
2664 :
2665 1 : GEOSGeom hThisGeosGeom = NULL;
2666 1 : GEOSGeom hOtherGeosGeom = NULL;
2667 1 : GEOSGeom hGeosProduct = NULL;
2668 1 : OGRGeometry *poOGRProduct = NULL;
2669 :
2670 1 : hThisGeosGeom = exportToGEOS();
2671 1 : hOtherGeosGeom = poOtherGeom->exportToGEOS();
2672 1 : if( hThisGeosGeom != NULL && hOtherGeosGeom != NULL )
2673 : {
2674 1 : hGeosProduct = GEOSDifference( hThisGeosGeom, hOtherGeosGeom );
2675 :
2676 1 : if( hGeosProduct != NULL )
2677 : {
2678 1 : poOGRProduct = OGRGeometryFactory::createFromGEOS(hGeosProduct);
2679 1 : GEOSGeom_destroy( hGeosProduct );
2680 : }
2681 : }
2682 1 : GEOSGeom_destroy( hThisGeosGeom );
2683 1 : GEOSGeom_destroy( hOtherGeosGeom );
2684 :
2685 1 : return poOGRProduct;
2686 :
2687 : #endif /* HAVE_GEOS */
2688 : }
2689 :
2690 : /************************************************************************/
2691 : /* OGR_G_Difference() */
2692 : /************************************************************************/
2693 :
2694 : /**
2695 : * \brief Compute difference.
2696 : *
2697 : * Generates a new geometry which is the region of this geometry with the
2698 : * region of the other geometry removed.
2699 : *
2700 : * This function is the same as the C++ method OGRGeometry::Difference().
2701 : *
2702 : * This function is built on the GEOS library, check it for the definition
2703 : * of the geometry operation.
2704 : * If OGR is built without the GEOS library, this function will always fail,
2705 : * issuing a CPLE_NotSupported error.
2706 : *
2707 : * @param hThis the geometry.
2708 : * @param hOther the other geometry.
2709 : *
2710 : * @return a new geometry representing the difference or NULL if the
2711 : * difference is empty or an error occurs.
2712 : */
2713 :
2714 1 : OGRGeometryH OGR_G_Difference( OGRGeometryH hThis, OGRGeometryH hOther )
2715 :
2716 : {
2717 1 : VALIDATE_POINTER1( hThis, "OGR_G_Difference", NULL );
2718 :
2719 : return (OGRGeometryH)
2720 1 : ((OGRGeometry *) hThis)->Difference( (OGRGeometry *) hOther );
2721 : }
2722 :
2723 : /************************************************************************/
2724 : /* SymDifference() */
2725 : /************************************************************************/
2726 :
2727 : /**
2728 : * \brief Compute symmetric difference.
2729 : *
2730 : * Generates a new geometry which is the symmetric difference of this
2731 : * geometry and the second geometry passed into the method.
2732 : *
2733 : * This method is the same as the C function OGR_G_SymDifference().
2734 : *
2735 : * This method is built on the GEOS library, check it for the definition
2736 : * of the geometry operation.
2737 : * If OGR is built without the GEOS library, this method will always fail,
2738 : * issuing a CPLE_NotSupported error.
2739 : *
2740 : * @param poOtherGeom the other geometry.
2741 : *
2742 : * @return a new geometry representing the symmetric difference or NULL if the
2743 : * difference is empty or an error occurs.
2744 : *
2745 : * @since OGR 1.8.0
2746 : */
2747 :
2748 : OGRGeometry *
2749 2 : OGRGeometry::SymDifference( const OGRGeometry *poOtherGeom ) const
2750 :
2751 : {
2752 : #ifndef HAVE_GEOS
2753 :
2754 : CPLError( CE_Failure, CPLE_NotSupported,
2755 : "GEOS support not enabled." );
2756 : return NULL;
2757 :
2758 : #else
2759 :
2760 2 : GEOSGeom hThisGeosGeom = NULL;
2761 2 : GEOSGeom hOtherGeosGeom = NULL;
2762 2 : GEOSGeom hGeosProduct = NULL;
2763 2 : OGRGeometry *poOGRProduct = NULL;
2764 :
2765 2 : hThisGeosGeom = exportToGEOS();
2766 2 : hOtherGeosGeom = poOtherGeom->exportToGEOS();
2767 2 : if( hThisGeosGeom != NULL && hOtherGeosGeom != NULL )
2768 : {
2769 2 : hGeosProduct = GEOSSymDifference( hThisGeosGeom, hOtherGeosGeom );
2770 :
2771 2 : if( hGeosProduct != NULL )
2772 : {
2773 2 : poOGRProduct = OGRGeometryFactory::createFromGEOS(hGeosProduct);
2774 2 : GEOSGeom_destroy( hGeosProduct );
2775 : }
2776 : }
2777 2 : GEOSGeom_destroy( hThisGeosGeom );
2778 2 : GEOSGeom_destroy( hOtherGeosGeom );
2779 :
2780 2 : return poOGRProduct;
2781 :
2782 : #endif /* HAVE_GEOS */
2783 : }
2784 :
2785 :
2786 : /**
2787 : * \brief Compute symmetric difference (deprecated)
2788 : *
2789 : * @deprecated
2790 : *
2791 : * @see OGRGeometry::SymDifference()
2792 : */
2793 : OGRGeometry *
2794 0 : OGRGeometry::SymmetricDifference( const OGRGeometry *poOtherGeom ) const
2795 :
2796 : {
2797 0 : return SymDifference( poOtherGeom );
2798 : }
2799 :
2800 : /************************************************************************/
2801 : /* OGR_G_SymDifference() */
2802 : /************************************************************************/
2803 :
2804 : /**
2805 : * \brief Compute symmetric difference.
2806 : *
2807 : * Generates a new geometry which is the symmetric difference of this
2808 : * geometry and the other geometry.
2809 : *
2810 : * This function is the same as the C++ method OGRGeometry::SymmetricDifference().
2811 : *
2812 : * This function is built on the GEOS library, check it for the definition
2813 : * of the geometry operation.
2814 : * If OGR is built without the GEOS library, this function will always fail,
2815 : * issuing a CPLE_NotSupported error.
2816 : *
2817 : * @param hThis the geometry.
2818 : * @param hOther the other geometry.
2819 : *
2820 : * @return a new geometry representing the symmetric difference or NULL if the
2821 : * difference is empty or an error occurs.
2822 : *
2823 : * @since OGR 1.8.0
2824 : */
2825 :
2826 2 : OGRGeometryH OGR_G_SymDifference( OGRGeometryH hThis, OGRGeometryH hOther )
2827 :
2828 : {
2829 2 : VALIDATE_POINTER1( hThis, "OGR_G_SymDifference", NULL );
2830 :
2831 : return (OGRGeometryH)
2832 2 : ((OGRGeometry *) hThis)->SymDifference( (OGRGeometry *) hOther );
2833 : }
2834 :
2835 : /**
2836 : * \brief Compute symmetric difference (deprecated)
2837 : *
2838 : * @deprecated
2839 : *
2840 : * @see OGR_G_SymmetricDifference()
2841 : */
2842 0 : OGRGeometryH OGR_G_SymmetricDifference( OGRGeometryH hThis, OGRGeometryH hOther )
2843 :
2844 : {
2845 0 : VALIDATE_POINTER1( hThis, "OGR_G_SymmetricDifference", NULL );
2846 :
2847 : return (OGRGeometryH)
2848 0 : ((OGRGeometry *) hThis)->SymDifference( (OGRGeometry *) hOther );
2849 : }
2850 :
2851 : /************************************************************************/
2852 : /* Disjoint() */
2853 : /************************************************************************/
2854 :
2855 : /**
2856 : * \brief Test for disjointness.
2857 : *
2858 : * Tests if this geometry and the other passed into the method are disjoint.
2859 : *
2860 : * This method is the same as the C function OGR_G_Disjoint().
2861 : *
2862 : * This method is built on the GEOS library, check it for the definition
2863 : * of the geometry operation.
2864 : * If OGR is built without the GEOS library, this method will always fail,
2865 : * issuing a CPLE_NotSupported error.
2866 : *
2867 : * @param poOtherGeom the geometry to compare to this geometry.
2868 : *
2869 : * @return TRUE if they are disjoint, otherwise FALSE.
2870 : */
2871 :
2872 : OGRBoolean
2873 2 : OGRGeometry::Disjoint( const OGRGeometry *poOtherGeom ) const
2874 :
2875 : {
2876 : #ifndef HAVE_GEOS
2877 :
2878 : CPLError( CE_Failure, CPLE_NotSupported,
2879 : "GEOS support not enabled." );
2880 : return FALSE;
2881 :
2882 : #else
2883 :
2884 2 : GEOSGeom hThisGeosGeom = NULL;
2885 2 : GEOSGeom hOtherGeosGeom = NULL;
2886 2 : OGRBoolean bResult = FALSE;
2887 :
2888 2 : hThisGeosGeom = exportToGEOS();
2889 2 : hOtherGeosGeom = poOtherGeom->exportToGEOS();
2890 2 : if( hThisGeosGeom != NULL && hOtherGeosGeom != NULL )
2891 : {
2892 2 : bResult = GEOSDisjoint( hThisGeosGeom, hOtherGeosGeom );
2893 : }
2894 2 : GEOSGeom_destroy( hThisGeosGeom );
2895 2 : GEOSGeom_destroy( hOtherGeosGeom );
2896 :
2897 2 : return bResult;
2898 :
2899 : #endif /* HAVE_GEOS */
2900 : }
2901 :
2902 : /************************************************************************/
2903 : /* OGR_G_Disjoint() */
2904 : /************************************************************************/
2905 :
2906 : /**
2907 : * \brief Test for disjointness.
2908 : *
2909 : * Tests if this geometry and the other geometry are disjoint.
2910 : *
2911 : * This function is the same as the C++ method OGRGeometry::Disjoint().
2912 : *
2913 : * This function is built on the GEOS library, check it for the definition
2914 : * of the geometry operation.
2915 : * If OGR is built without the GEOS library, this function will always fail,
2916 : * issuing a CPLE_NotSupported error.
2917 : *
2918 : * @param hThis the geometry to compare.
2919 : * @param hOther the other geometry to compare.
2920 : *
2921 : * @return TRUE if they are disjoint, otherwise FALSE.
2922 : */
2923 2 : int OGR_G_Disjoint( OGRGeometryH hThis, OGRGeometryH hOther )
2924 :
2925 : {
2926 2 : VALIDATE_POINTER1( hThis, "OGR_G_Disjoint", FALSE );
2927 :
2928 2 : return ((OGRGeometry *) hThis)->Disjoint( (OGRGeometry *) hOther );
2929 : }
2930 :
2931 : /************************************************************************/
2932 : /* Touches() */
2933 : /************************************************************************/
2934 :
2935 : /**
2936 : * \brief Test for touching.
2937 : *
2938 : * Tests if this geometry and the other passed into the method are touching.
2939 : *
2940 : * This method is the same as the C function OGR_G_Touches().
2941 : *
2942 : * This method is built on the GEOS library, check it for the definition
2943 : * of the geometry operation.
2944 : * If OGR is built without the GEOS library, this method will always fail,
2945 : * issuing a CPLE_NotSupported error.
2946 : *
2947 : * @param poOtherGeom the geometry to compare to this geometry.
2948 : *
2949 : * @return TRUE if they are touching, otherwise FALSE.
2950 : */
2951 :
2952 : OGRBoolean
2953 2 : OGRGeometry::Touches( const OGRGeometry *poOtherGeom ) const
2954 :
2955 : {
2956 : #ifndef HAVE_GEOS
2957 :
2958 : CPLError( CE_Failure, CPLE_NotSupported,
2959 : "GEOS support not enabled." );
2960 : return FALSE;
2961 :
2962 : #else
2963 :
2964 2 : GEOSGeom hThisGeosGeom = NULL;
2965 2 : GEOSGeom hOtherGeosGeom = NULL;
2966 2 : OGRBoolean bResult = FALSE;
2967 :
2968 2 : hThisGeosGeom = exportToGEOS();
2969 2 : hOtherGeosGeom = poOtherGeom->exportToGEOS();
2970 :
2971 2 : if( hThisGeosGeom != NULL && hOtherGeosGeom != NULL )
2972 : {
2973 2 : bResult = GEOSTouches( hThisGeosGeom, hOtherGeosGeom );
2974 : }
2975 2 : GEOSGeom_destroy( hThisGeosGeom );
2976 2 : GEOSGeom_destroy( hOtherGeosGeom );
2977 :
2978 2 : return bResult;
2979 :
2980 : #endif /* HAVE_GEOS */
2981 : }
2982 :
2983 : /************************************************************************/
2984 : /* OGR_G_Touches() */
2985 : /************************************************************************/
2986 : /**
2987 : * \brief Test for touching.
2988 : *
2989 : * Tests if this geometry and the other geometry are touching.
2990 : *
2991 : * This function is the same as the C++ method OGRGeometry::Touches().
2992 : *
2993 : * This function is built on the GEOS library, check it for the definition
2994 : * of the geometry operation.
2995 : * If OGR is built without the GEOS library, this function will always fail,
2996 : * issuing a CPLE_NotSupported error.
2997 : *
2998 : * @param hThis the geometry to compare.
2999 : * @param hOther the other geometry to compare.
3000 : *
3001 : * @return TRUE if they are touching, otherwise FALSE.
3002 : */
3003 :
3004 2 : int OGR_G_Touches( OGRGeometryH hThis, OGRGeometryH hOther )
3005 :
3006 : {
3007 2 : VALIDATE_POINTER1( hThis, "OGR_G_Touches", FALSE );
3008 :
3009 2 : return ((OGRGeometry *) hThis)->Touches( (OGRGeometry *) hOther );
3010 : }
3011 :
3012 : /************************************************************************/
3013 : /* Crosses() */
3014 : /************************************************************************/
3015 :
3016 : /**
3017 : * \brief Test for crossing.
3018 : *
3019 : * Tests if this geometry and the other passed into the method are crossing.
3020 : *
3021 : * This method is the same as the C function OGR_G_Crosses().
3022 : *
3023 : * This method is built on the GEOS library, check it for the definition
3024 : * of the geometry operation.
3025 : * If OGR is built without the GEOS library, this method will always fail,
3026 : * issuing a CPLE_NotSupported error.
3027 : *
3028 : * @param poOtherGeom the geometry to compare to this geometry.
3029 : *
3030 : * @return TRUE if they are crossing, otherwise FALSE.
3031 : */
3032 :
3033 : OGRBoolean
3034 2 : OGRGeometry::Crosses( const OGRGeometry *poOtherGeom ) const
3035 :
3036 : {
3037 : #ifndef HAVE_GEOS
3038 :
3039 : CPLError( CE_Failure, CPLE_NotSupported,
3040 : "GEOS support not enabled." );
3041 : return FALSE;
3042 :
3043 : #else
3044 :
3045 2 : GEOSGeom hThisGeosGeom = NULL;
3046 2 : GEOSGeom hOtherGeosGeom = NULL;
3047 2 : OGRBoolean bResult = FALSE;
3048 :
3049 2 : hThisGeosGeom = exportToGEOS();
3050 2 : hOtherGeosGeom = poOtherGeom->exportToGEOS();
3051 :
3052 2 : if( hThisGeosGeom != NULL && hOtherGeosGeom != NULL )
3053 : {
3054 2 : bResult = GEOSCrosses( hThisGeosGeom, hOtherGeosGeom );
3055 : }
3056 2 : GEOSGeom_destroy( hThisGeosGeom );
3057 2 : GEOSGeom_destroy( hOtherGeosGeom );
3058 :
3059 2 : return bResult;
3060 :
3061 : #endif /* HAVE_GEOS */
3062 : }
3063 :
3064 : /************************************************************************/
3065 : /* OGR_G_Crosses() */
3066 : /************************************************************************/
3067 : /**
3068 : * \brief Test for crossing.
3069 : *
3070 : * Tests if this geometry and the other geometry are crossing.
3071 : *
3072 : * This function is the same as the C++ method OGRGeometry::Crosses().
3073 : *
3074 : * This function is built on the GEOS library, check it for the definition
3075 : * of the geometry operation.
3076 : * If OGR is built without the GEOS library, this function will always fail,
3077 : * issuing a CPLE_NotSupported error.
3078 : *
3079 : * @param hThis the geometry to compare.
3080 : * @param hOther the other geometry to compare.
3081 : *
3082 : * @return TRUE if they are crossing, otherwise FALSE.
3083 : */
3084 :
3085 2 : int OGR_G_Crosses( OGRGeometryH hThis, OGRGeometryH hOther )
3086 :
3087 : {
3088 2 : VALIDATE_POINTER1( hThis, "OGR_G_Crosses", FALSE );
3089 :
3090 2 : return ((OGRGeometry *) hThis)->Crosses( (OGRGeometry *) hOther );
3091 : }
3092 :
3093 : /************************************************************************/
3094 : /* Within() */
3095 : /************************************************************************/
3096 :
3097 : /**
3098 : * \brief Test for containment.
3099 : *
3100 : * Tests if actual geometry object is within the passed geometry.
3101 : *
3102 : * This method is the same as the C function OGR_G_Within().
3103 : *
3104 : * This method is built on the GEOS library, check it for the definition
3105 : * of the geometry operation.
3106 : * If OGR is built without the GEOS library, this method will always fail,
3107 : * issuing a CPLE_NotSupported error.
3108 : *
3109 : * @param poOtherGeom the geometry to compare to this geometry.
3110 : *
3111 : * @return TRUE if poOtherGeom is within this geometry, otherwise FALSE.
3112 : */
3113 :
3114 : OGRBoolean
3115 2 : OGRGeometry::Within( const OGRGeometry *poOtherGeom ) const
3116 :
3117 : {
3118 : #ifndef HAVE_GEOS
3119 :
3120 : CPLError( CE_Failure, CPLE_NotSupported,
3121 : "GEOS support not enabled." );
3122 : return FALSE;
3123 :
3124 : #else
3125 :
3126 2 : GEOSGeom hThisGeosGeom = NULL;
3127 2 : GEOSGeom hOtherGeosGeom = NULL;
3128 2 : OGRBoolean bResult = FALSE;
3129 :
3130 2 : hThisGeosGeom = exportToGEOS();
3131 2 : hOtherGeosGeom = poOtherGeom->exportToGEOS();
3132 2 : if( hThisGeosGeom != NULL && hOtherGeosGeom != NULL )
3133 : {
3134 2 : bResult = GEOSWithin( hThisGeosGeom, hOtherGeosGeom );
3135 : }
3136 2 : GEOSGeom_destroy( hThisGeosGeom );
3137 2 : GEOSGeom_destroy( hOtherGeosGeom );
3138 :
3139 2 : return bResult;
3140 :
3141 : #endif /* HAVE_GEOS */
3142 : }
3143 :
3144 : /************************************************************************/
3145 : /* OGR_G_Within() */
3146 : /************************************************************************/
3147 :
3148 : /**
3149 : * \brief Test for containment.
3150 : *
3151 : * Tests if this geometry is within the other geometry.
3152 : *
3153 : * This function is the same as the C++ method OGRGeometry::Within().
3154 : *
3155 : * This function is built on the GEOS library, check it for the definition
3156 : * of the geometry operation.
3157 : * If OGR is built without the GEOS library, this function will always fail,
3158 : * issuing a CPLE_NotSupported error.
3159 : *
3160 : * @param hThis the geometry to compare.
3161 : * @param hOther the other geometry to compare.
3162 : *
3163 : * @return TRUE if hThis is within hOther, otherwise FALSE.
3164 : */
3165 2 : int OGR_G_Within( OGRGeometryH hThis, OGRGeometryH hOther )
3166 :
3167 : {
3168 2 : VALIDATE_POINTER1( hThis, "OGR_G_Within", FALSE );
3169 :
3170 2 : return ((OGRGeometry *) hThis)->Within( (OGRGeometry *) hOther );
3171 : }
3172 :
3173 : /************************************************************************/
3174 : /* Contains() */
3175 : /************************************************************************/
3176 :
3177 : /**
3178 : * \brief Test for containment.
3179 : *
3180 : * Tests if actual geometry object contains the passed geometry.
3181 : *
3182 : * This method is the same as the C function OGR_G_Contains().
3183 : *
3184 : * This method is built on the GEOS library, check it for the definition
3185 : * of the geometry operation.
3186 : * If OGR is built without the GEOS library, this method will always fail,
3187 : * issuing a CPLE_NotSupported error.
3188 : *
3189 : * @param poOtherGeom the geometry to compare to this geometry.
3190 : *
3191 : * @return TRUE if poOtherGeom contains this geometry, otherwise FALSE.
3192 : */
3193 :
3194 : OGRBoolean
3195 2 : OGRGeometry::Contains( const OGRGeometry *poOtherGeom ) const
3196 :
3197 : {
3198 : #ifndef HAVE_GEOS
3199 :
3200 : CPLError( CE_Failure, CPLE_NotSupported,
3201 : "GEOS support not enabled." );
3202 : return FALSE;
3203 :
3204 : #else
3205 :
3206 2 : GEOSGeom hThisGeosGeom = NULL;
3207 2 : GEOSGeom hOtherGeosGeom = NULL;
3208 2 : OGRBoolean bResult = FALSE;
3209 :
3210 2 : hThisGeosGeom = exportToGEOS();
3211 2 : hOtherGeosGeom = poOtherGeom->exportToGEOS();
3212 2 : if( hThisGeosGeom != NULL && hOtherGeosGeom != NULL )
3213 : {
3214 2 : bResult = GEOSContains( hThisGeosGeom, hOtherGeosGeom );
3215 : }
3216 2 : GEOSGeom_destroy( hThisGeosGeom );
3217 2 : GEOSGeom_destroy( hOtherGeosGeom );
3218 :
3219 2 : return bResult;
3220 :
3221 : #endif /* HAVE_GEOS */
3222 : }
3223 :
3224 : /************************************************************************/
3225 : /* OGR_G_Contains() */
3226 : /************************************************************************/
3227 :
3228 : /**
3229 : * \brief Test for containment.
3230 : *
3231 : * Tests if this geometry contains the other geometry.
3232 : *
3233 : * This function is the same as the C++ method OGRGeometry::Contains().
3234 : *
3235 : * This function is built on the GEOS library, check it for the definition
3236 : * of the geometry operation.
3237 : * If OGR is built without the GEOS library, this function will always fail,
3238 : * issuing a CPLE_NotSupported error.
3239 : *
3240 : * @param hThis the geometry to compare.
3241 : * @param hOther the other geometry to compare.
3242 : *
3243 : * @return TRUE if hThis contains hOther geometry, otherwise FALSE.
3244 : */
3245 2 : int OGR_G_Contains( OGRGeometryH hThis, OGRGeometryH hOther )
3246 :
3247 : {
3248 2 : VALIDATE_POINTER1( hThis, "OGR_G_Contains", FALSE );
3249 :
3250 2 : return ((OGRGeometry *) hThis)->Contains( (OGRGeometry *) hOther );
3251 : }
3252 :
3253 : /************************************************************************/
3254 : /* Overlaps() */
3255 : /************************************************************************/
3256 :
3257 : /**
3258 : * \brief Test for overlap.
3259 : *
3260 : * Tests if this geometry and the other passed into the method overlap, that is
3261 : * their intersection has a non-zero area.
3262 : *
3263 : * This method is the same as the C function OGR_G_Overlaps().
3264 : *
3265 : * This method is built on the GEOS library, check it for the definition
3266 : * of the geometry operation.
3267 : * If OGR is built without the GEOS library, this method will always fail,
3268 : * issuing a CPLE_NotSupported error.
3269 : *
3270 : * @param poOtherGeom the geometry to compare to this geometry.
3271 : *
3272 : * @return TRUE if they are overlapping, otherwise FALSE.
3273 : */
3274 :
3275 : OGRBoolean
3276 2 : OGRGeometry::Overlaps( const OGRGeometry *poOtherGeom ) const
3277 :
3278 : {
3279 : #ifndef HAVE_GEOS
3280 :
3281 : CPLError( CE_Failure, CPLE_NotSupported,
3282 : "GEOS support not enabled." );
3283 : return FALSE;
3284 :
3285 : #else
3286 :
3287 2 : GEOSGeom hThisGeosGeom = NULL;
3288 2 : GEOSGeom hOtherGeosGeom = NULL;
3289 2 : OGRBoolean bResult = FALSE;
3290 :
3291 2 : hThisGeosGeom = exportToGEOS();
3292 2 : hOtherGeosGeom = poOtherGeom->exportToGEOS();
3293 2 : if( hThisGeosGeom != NULL && hOtherGeosGeom != NULL )
3294 : {
3295 2 : bResult = GEOSOverlaps( hThisGeosGeom, hOtherGeosGeom );
3296 : }
3297 2 : GEOSGeom_destroy( hThisGeosGeom );
3298 2 : GEOSGeom_destroy( hOtherGeosGeom );
3299 :
3300 2 : return bResult;
3301 :
3302 : #endif /* HAVE_GEOS */
3303 : }
3304 :
3305 : /************************************************************************/
3306 : /* OGR_G_Overlaps() */
3307 : /************************************************************************/
3308 : /**
3309 : * \brief Test for overlap.
3310 : *
3311 : * Tests if this geometry and the other geometry overlap, that is their
3312 : * intersection has a non-zero area.
3313 : *
3314 : * This function is the same as the C++ method OGRGeometry::Overlaps().
3315 : *
3316 : * This function is built on the GEOS library, check it for the definition
3317 : * of the geometry operation.
3318 : * If OGR is built without the GEOS library, this function will always fail,
3319 : * issuing a CPLE_NotSupported error.
3320 : *
3321 : * @param hThis the geometry to compare.
3322 : * @param hOther the other geometry to compare.
3323 : *
3324 : * @return TRUE if they are overlapping, otherwise FALSE.
3325 : */
3326 :
3327 2 : int OGR_G_Overlaps( OGRGeometryH hThis, OGRGeometryH hOther )
3328 :
3329 : {
3330 2 : VALIDATE_POINTER1( hThis, "OGR_G_Overlaps", FALSE );
3331 :
3332 2 : return ((OGRGeometry *) hThis)->Overlaps( (OGRGeometry *) hOther );
3333 : }
3334 :
3335 : /************************************************************************/
3336 : /* closeRings() */
3337 : /************************************************************************/
3338 :
3339 : /**
3340 : * \brief Force rings to be closed.
3341 : *
3342 : * If this geometry, or any contained geometries has polygon rings that
3343 : * are not closed, they will be closed by adding the starting point at
3344 : * the end.
3345 : */
3346 :
3347 15 : void OGRGeometry::closeRings()
3348 :
3349 : {
3350 15 : }
3351 :
3352 : /************************************************************************/
3353 : /* OGR_G_CloseRings() */
3354 : /************************************************************************/
3355 :
3356 : /**
3357 : * \brief Force rings to be closed.
3358 : *
3359 : * If this geometry, or any contained geometries has polygon rings that
3360 : * are not closed, they will be closed by adding the starting point at
3361 : * the end.
3362 : *
3363 : * @param hGeom handle to the geometry.
3364 : */
3365 :
3366 4 : void OGR_G_CloseRings( OGRGeometryH hGeom )
3367 :
3368 : {
3369 4 : VALIDATE_POINTER0( hGeom, "OGR_G_CloseRings" );
3370 :
3371 4 : ((OGRGeometry *) hGeom)->closeRings();
3372 : }
3373 :
3374 : /************************************************************************/
3375 : /* Centroid() */
3376 : /************************************************************************/
3377 :
3378 : /**
3379 : * \brief Compute the geometry centroid.
3380 : *
3381 : * The centroid location is applied to the passed in OGRPoint object.
3382 : * The centroid is not necessarily within the geometry.
3383 : *
3384 : * This method relates to the SFCOM ISurface::get_Centroid() method
3385 : * however the current implementation based on GEOS can operate on other
3386 : * geometry types such as multipoint, linestring, geometrycollection such as
3387 : * multipolygons.
3388 : * OGC SF SQL 1.1 defines the operation for surfaces (polygons).
3389 : * SQL/MM-Part 3 defines the operation for surfaces and multisurfaces (multipolygons).
3390 : *
3391 : * This function is the same as the C function OGR_G_Centroid().
3392 : *
3393 : * This function is built on the GEOS library, check it for the definition
3394 : * of the geometry operation.
3395 : * If OGR is built without the GEOS library, this function will always fail,
3396 : * issuing a CPLE_NotSupported error.
3397 : *
3398 : * @return OGRERR_NONE on success or OGRERR_FAILURE on error.
3399 : *
3400 : * @since OGR 1.8.0 as a OGRGeometry method (previously was restricted to OGRPolygon)
3401 : */
3402 :
3403 4 : int OGRGeometry::Centroid( OGRPoint *poPoint ) const
3404 :
3405 : {
3406 4 : if( poPoint == NULL )
3407 0 : return OGRERR_FAILURE;
3408 :
3409 : #ifndef HAVE_GEOS
3410 : // notdef ... not implemented yet.
3411 : CPLError( CE_Failure, CPLE_NotSupported,
3412 : "GEOS support not enabled." );
3413 : return OGRERR_FAILURE;
3414 :
3415 : #else
3416 :
3417 4 : GEOSGeom hThisGeosGeom = NULL;
3418 4 : GEOSGeom hOtherGeosGeom = NULL;
3419 :
3420 4 : hThisGeosGeom = exportToGEOS();
3421 :
3422 4 : if( hThisGeosGeom != NULL )
3423 : {
3424 4 : hOtherGeosGeom = GEOSGetCentroid( hThisGeosGeom );
3425 4 : GEOSGeom_destroy( hThisGeosGeom );
3426 :
3427 4 : if( hOtherGeosGeom == NULL )
3428 0 : return OGRERR_FAILURE;
3429 :
3430 : OGRGeometry *poCentroidGeom =
3431 4 : OGRGeometryFactory::createFromGEOS( hOtherGeosGeom );
3432 :
3433 4 : GEOSGeom_destroy( hOtherGeosGeom );
3434 :
3435 4 : if (poCentroidGeom == NULL)
3436 0 : return OGRERR_FAILURE;
3437 4 : if (wkbFlatten(poCentroidGeom->getGeometryType()) != wkbPoint)
3438 : {
3439 1 : delete poCentroidGeom;
3440 1 : return OGRERR_FAILURE;
3441 : }
3442 :
3443 3 : OGRPoint *poCentroid = (OGRPoint *) poCentroidGeom;
3444 3 : poPoint->setX( poCentroid->getX() );
3445 3 : poPoint->setY( poCentroid->getY() );
3446 :
3447 3 : delete poCentroidGeom;
3448 :
3449 3 : return OGRERR_NONE;
3450 : }
3451 : else
3452 : {
3453 0 : return OGRERR_FAILURE;
3454 : }
3455 :
3456 : #endif /* HAVE_GEOS */
3457 : }
3458 :
3459 : /************************************************************************/
3460 : /* OGR_G_Centroid() */
3461 : /************************************************************************/
3462 :
3463 : /**
3464 : * \brief Compute the geometry centroid.
3465 : *
3466 : * The centroid location is applied to the passed in OGRPoint object.
3467 : * The centroid is not necessarily within the geometry.
3468 : *
3469 : * This method relates to the SFCOM ISurface::get_Centroid() method
3470 : * however the current implementation based on GEOS can operate on other
3471 : * geometry types such as multipoint, linestring, geometrycollection such as
3472 : * multipolygons.
3473 : * OGC SF SQL 1.1 defines the operation for surfaces (polygons).
3474 : * SQL/MM-Part 3 defines the operation for surfaces and multisurfaces (multipolygons).
3475 : *
3476 : * This function is the same as the C++ method OGRGeometry::Centroid().
3477 : *
3478 : * This function is built on the GEOS library, check it for the definition
3479 : * of the geometry operation.
3480 : * If OGR is built without the GEOS library, this function will always fail,
3481 : * issuing a CPLE_NotSupported error.
3482 : *
3483 : * @return OGRERR_NONE on success or OGRERR_FAILURE on error.
3484 : */
3485 :
3486 4 : int OGR_G_Centroid( OGRGeometryH hGeom, OGRGeometryH hCentroidPoint )
3487 :
3488 : {
3489 4 : VALIDATE_POINTER1( hGeom, "OGR_G_Centroid", OGRERR_FAILURE );
3490 :
3491 4 : OGRGeometry *poGeom = ((OGRGeometry *) hGeom);
3492 4 : OGRPoint *poCentroid = ((OGRPoint *) hCentroidPoint);
3493 :
3494 4 : if( poCentroid == NULL )
3495 0 : return OGRERR_FAILURE;
3496 :
3497 4 : if( wkbFlatten(poCentroid->getGeometryType()) != wkbPoint )
3498 : {
3499 : CPLError( CE_Failure, CPLE_AppDefined,
3500 0 : "Passed wrong geometry type as centroid argument." );
3501 0 : return OGRERR_FAILURE;
3502 : }
3503 :
3504 4 : return poGeom->Centroid( poCentroid );
3505 : }
3506 :
3507 : /************************************************************************/
3508 : /* Simplify() */
3509 : /************************************************************************/
3510 :
3511 : /**
3512 : * \brief Simplify the geometry.
3513 : *
3514 : * This function is the same as the C function OGR_G_Simplify().
3515 : *
3516 : * This function is built on the GEOS library, check it for the definition
3517 : * of the geometry operation.
3518 : * If OGR is built without the GEOS library, this function will always fail,
3519 : * issuing a CPLE_NotSupported error.
3520 : *
3521 : * @param dTolerance the distance tolerance for the simplification.
3522 : *
3523 : * @return the simplified geometry or NULL if an error occurs.
3524 : *
3525 : * @since OGR 1.8.0
3526 : */
3527 :
3528 1 : OGRGeometry *OGRGeometry::Simplify(double dTolerance) const
3529 :
3530 : {
3531 : #ifndef HAVE_GEOS
3532 :
3533 : CPLError( CE_Failure, CPLE_NotSupported,
3534 : "GEOS support not enabled." );
3535 : return NULL;
3536 :
3537 : /* GEOS >= 3.0.0 */
3538 : #elif GEOS_CAPI_VERSION_MAJOR >= 2 || (GEOS_CAPI_VERSION_MAJOR == 1 && GEOS_CAPI_VERSION_MINOR >= 4)
3539 :
3540 1 : GEOSGeom hThisGeosGeom = NULL;
3541 1 : GEOSGeom hGeosProduct = NULL;
3542 1 : OGRGeometry *poOGRProduct = NULL;
3543 :
3544 1 : hThisGeosGeom = exportToGEOS();
3545 1 : if( hThisGeosGeom != NULL )
3546 : {
3547 1 : hGeosProduct = GEOSSimplify( hThisGeosGeom, dTolerance );
3548 1 : GEOSGeom_destroy( hThisGeosGeom );
3549 1 : if( hGeosProduct != NULL )
3550 : {
3551 1 : poOGRProduct = OGRGeometryFactory::createFromGEOS( hGeosProduct );
3552 1 : GEOSGeom_destroy( hGeosProduct );
3553 : }
3554 : }
3555 1 : return poOGRProduct;
3556 :
3557 : #else
3558 : CPLError( CE_Failure, CPLE_NotSupported,
3559 : "GEOS >= 3.0.0 required for Simplify() support." );
3560 : return NULL;
3561 : #endif /* HAVE_GEOS */
3562 :
3563 : }
3564 :
3565 : /************************************************************************/
3566 : /* OGR_G_Simplify() */
3567 : /************************************************************************/
3568 :
3569 : /**
3570 : * \brief Compute a simplified geometry.
3571 : *
3572 : * This function is the same as the C++ method OGRGeometry::Simplify().
3573 : *
3574 : * This function is built on the GEOS library, check it for the definition
3575 : * of the geometry operation.
3576 : * If OGR is built without the GEOS library, this function will always fail,
3577 : * issuing a CPLE_NotSupported error.
3578 : *
3579 : * @param hThis the geometry.
3580 : * @param dTolerance the distance tolerance for the simplification.
3581 : *
3582 : * @return the simplified geometry or NULL if an error occurs.
3583 : *
3584 : * @since OGR 1.8.0
3585 : */
3586 :
3587 1 : OGRGeometryH OGR_G_Simplify( OGRGeometryH hThis, double dTolerance )
3588 :
3589 : {
3590 1 : VALIDATE_POINTER1( hThis, "OGR_G_Simplify", NULL );
3591 1 : return (OGRGeometryH) ((OGRGeometry *) hThis)->Simplify( dTolerance );
3592 : }
3593 :
3594 : /************************************************************************/
3595 : /* SimplifyPreserveTopology() */
3596 : /************************************************************************/
3597 :
3598 : /**
3599 : * \brief Simplify the geometry while preserving topology.
3600 : *
3601 : * This function is the same as the C function OGR_G_SimplifyPreserveTopology().
3602 : *
3603 : * This function is built on the GEOS library, check it for the definition
3604 : * of the geometry operation.
3605 : * If OGR is built without the GEOS library, this function will always fail,
3606 : * issuing a CPLE_NotSupported error.
3607 : *
3608 : * @param dTolerance the distance tolerance for the simplification.
3609 : *
3610 : * @return the simplified geometry or NULL if an error occurs.
3611 : *
3612 : * @since OGR 1.9.0
3613 : */
3614 :
3615 1 : OGRGeometry *OGRGeometry::SimplifyPreserveTopology(double dTolerance) const
3616 :
3617 : {
3618 : #ifndef HAVE_GEOS
3619 :
3620 : CPLError( CE_Failure, CPLE_NotSupported,
3621 : "GEOS support not enabled." );
3622 : return NULL;
3623 :
3624 : /* GEOS >= 3.0.0 */
3625 : #elif GEOS_CAPI_VERSION_MAJOR >= 2 || (GEOS_CAPI_VERSION_MAJOR == 1 && GEOS_CAPI_VERSION_MINOR >= 4)
3626 :
3627 1 : GEOSGeom hThisGeosGeom = NULL;
3628 1 : GEOSGeom hGeosProduct = NULL;
3629 1 : OGRGeometry *poOGRProduct = NULL;
3630 :
3631 1 : hThisGeosGeom = exportToGEOS();
3632 1 : if( hThisGeosGeom != NULL )
3633 : {
3634 1 : hGeosProduct = GEOSTopologyPreserveSimplify( hThisGeosGeom, dTolerance );
3635 1 : GEOSGeom_destroy( hThisGeosGeom );
3636 1 : if( hGeosProduct != NULL )
3637 : {
3638 1 : poOGRProduct = OGRGeometryFactory::createFromGEOS( hGeosProduct );
3639 1 : GEOSGeom_destroy( hGeosProduct );
3640 : }
3641 : }
3642 1 : return poOGRProduct;
3643 :
3644 : #else
3645 : CPLError( CE_Failure, CPLE_NotSupported,
3646 : "GEOS >= 3.0.0 required for SimplifyPreserveTopology() support." );
3647 : return NULL;
3648 : #endif /* HAVE_GEOS */
3649 :
3650 : }
3651 :
3652 : /************************************************************************/
3653 : /* OGR_G_SimplifyPreserveTopology() */
3654 : /************************************************************************/
3655 :
3656 : /**
3657 : * \brief Simplify the geometry while preserving topology.
3658 : *
3659 : * This function is the same as the C++ method OGRGeometry::SimplifyPreserveTopology().
3660 : *
3661 : * This function is built on the GEOS library, check it for the definition
3662 : * of the geometry operation.
3663 : * If OGR is built without the GEOS library, this function will always fail,
3664 : * issuing a CPLE_NotSupported error.
3665 : *
3666 : * @param hThis the geometry.
3667 : * @param dTolerance the distance tolerance for the simplification.
3668 : *
3669 : * @return the simplified geometry or NULL if an error occurs.
3670 : *
3671 : * @since OGR 1.9.0
3672 : */
3673 :
3674 1 : OGRGeometryH OGR_G_SimplifyPreserveTopology( OGRGeometryH hThis, double dTolerance )
3675 :
3676 : {
3677 1 : VALIDATE_POINTER1( hThis, "OGR_G_SimplifyPreserveTopology", NULL );
3678 1 : return (OGRGeometryH) ((OGRGeometry *) hThis)->SimplifyPreserveTopology( dTolerance );
3679 : }
3680 :
3681 : /************************************************************************/
3682 : /* swapXY() */
3683 : /************************************************************************/
3684 :
3685 : /**
3686 : * \brief Swap x and y coordinates.
3687 : *
3688 : * @since OGR 1.8.0
3689 : */
3690 :
3691 0 : void OGRGeometry::swapXY()
3692 :
3693 : {
3694 0 : }
|