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