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