📄 ogrgeometry.cpp
字号:
case wkbPoint25D: return "3D Point"; case wkbLineString: return "Line String"; case wkbLineString25D: return "3D Line String"; case wkbPolygon: return "Polygon"; case wkbPolygon25D: return "3D Polygon"; case wkbMultiPoint: return "Multi Point"; case wkbMultiPoint25D: return "3D Multi Point"; case wkbMultiLineString: return "Multi Line String"; case wkbMultiLineString25D: return "3D Multi Line String"; case wkbMultiPolygon: return "Multi Polygon"; case wkbMultiPolygon25D: return "3D Multi Polygon"; case wkbGeometryCollection: return "Geometry Collection"; case wkbGeometryCollection25D: return "3D Geometry Collection"; case wkbNone: return "None"; default: { static char szWorkName[33]; sprintf( szWorkName, "Unrecognised: %d", (int) eType ); return szWorkName; } }}/** * \fn void OGRGeometry::flattenTo2D(); * * Convert geometry to strictly 2D. In a sense this converts all Z coordinates * to 0.0. * * This method is the same as the C function OGR_G_FlattenTo2D(). *//************************************************************************//* OGR_G_FlattenTo2D() *//************************************************************************//** * Convert geometry to strictly 2D. In a sense this converts all Z coordinates * to 0.0. * * This function is the same as the CPP method OGRGeometry::flattenTo2D(). * * @param hGeom handle on the geometry to convert. */void OGR_G_FlattenTo2D( OGRGeometryH hGeom ){ ((OGRGeometry *) hGeom)->flattenTo2D();}/************************************************************************//* exportToGML() *//************************************************************************//** * \fn char *OGRGeometry::exportToGML() const; * * Convert a geometry into GML format. * * The GML geometry is expressed directly in terms of GML basic data * types assuming the this is available in the gml namespace. The returned * string should be freed with CPLFree() when no longer required. * * This method is the same as the C function OGR_G_ExportToGML(). * * @return A GML fragment or NULL in case of error. */char *OGRGeometry::exportToGML() const{ return OGR_G_ExportToGML( (OGRGeometryH) this );}/************************************************************************//* OGRSetGenerate_DB2_V72_BYTE_ORDER() *//* *//* This is a special entry point to enable the hack for *//* generating DB2 V7.2 style WKB. DB2 seems to have placed *//* (and require) an extra 0x30 or'ed with the byte order in *//* WKB. This entry point is used to turn on or off the *//* generation of such WKB. *//************************************************************************/OGRErr OGRSetGenerate_DB2_V72_BYTE_ORDER( int bGenerate_DB2_V72_BYTE_ORDER ){#if defined(HACK_FOR_IBM_DB2_V72) OGRGeometry::bGenerate_DB2_V72_BYTE_ORDER = bGenerate_DB2_V72_BYTE_ORDER; return OGRERR_NONE;#else if( bGenerate_DB2_V72_BYTE_ORDER ) return OGRERR_FAILURE; else return OGRERR_NONE;#endif}/************************************************************************//* OGRGetGenerate_DB2_V72_BYTE_ORDER() *//* *//* This is a special entry point to get the value of static flag *//* OGRGeometry::bGenerate_DB2_V72_BYTE_ORDER. *//************************************************************************/int OGRGetGenerate_DB2_V72_BYTE_ORDER(){ return OGRGeometry::bGenerate_DB2_V72_BYTE_ORDER;}/************************************************************************//* exportToGEOS() *//************************************************************************/GEOSGeom OGRGeometry::exportToGEOS() const{#ifndef HAVE_GEOS CPLError( CE_Failure, CPLE_NotSupported, "GEOS support not enabled." ); return NULL;#else static int bGEOSInitialized = FALSE; if( !bGEOSInitialized ) { bGEOSInitialized = TRUE; initGEOS( _GEOSWarningHandler, _GEOSErrorHandler ); } GEOSGeom hGeom = NULL; size_t nDataSize; unsigned char *pabyData = NULL; nDataSize = WkbSize(); pabyData = (unsigned char *) CPLMalloc(nDataSize); if( exportToWkb( wkbNDR, pabyData ) == OGRERR_NONE ) hGeom = GEOSGeomFromWKB_buf( pabyData, nDataSize ); CPLFree( pabyData ); return hGeom;#endif /* HAVE_GEOS */}/************************************************************************//* Distance() *//************************************************************************//** * Compute distance between two geometries. * * Returns the shortest distance between the two geometries. * * This method is the same as the C function OGR_G_Distance(). * * This method is built on the GEOS library, check it for the definition * of the geometry operation. * If OGR is built without the GEOS library, this method will always fail, * issuing a CPLE_NotSupported error. * * @param poOtherGeom the other geometry to compare against. * * @return the distance between the geometries or -1 if an error occurs. */double OGRGeometry::Distance( const OGRGeometry *poOtherGeom ) const{ if( NULL == poOtherGeom ) { CPLDebug( "OGR", "OGRGeometry::Distance called with NULL geometry pointer" ); return -1.0; }#ifndef HAVE_GEOS CPLError( CE_Failure, CPLE_NotSupported, "GEOS support not enabled." ); return -1.0;#else // GEOSGeom is a pointer GEOSGeom hThis = NULL; GEOSGeom hOther = NULL; hOther = poOtherGeom->exportToGEOS(); hThis = exportToGEOS(); int bIsErr = 0; double dfDistance = 0.0; if( hThis != NULL && hOther != NULL ) { bIsErr = GEOSDistance( hThis, hOther, &dfDistance ); } GEOSGeom_destroy( hThis ); GEOSGeom_destroy( hOther ); if ( bIsErr > 0 ) { return dfDistance; } /* Calculations error */ return -1.0;#endif /* HAVE_GEOS */}/************************************************************************//* OGR_G_Distance() *//************************************************************************/double OGR_G_Distance( OGRGeometryH hFirst, OGRGeometryH hOther ){ return ((OGRGeometry *) hFirst)->Distance( (OGRGeometry *) hOther );}/************************************************************************//* ConvexHull() *//************************************************************************//** * Compute convex hull. * * A new geometry object is created and returned containing the convex * hull of the geometry on which the method is invoked. * * This method is the same as the C function OGR_G_ConvexHull(). * * This method is built on the GEOS library, check it for the definition * of the geometry operation. * If OGR is built without the GEOS library, this method will always fail, * issuing a CPLE_NotSupported error. * * @return a newly allocated geometry now owned by the caller, or NULL on failure. */OGRGeometry *OGRGeometry::ConvexHull() const{#ifndef HAVE_GEOS CPLError( CE_Failure, CPLE_NotSupported, "GEOS support not enabled." ); return NULL;#else GEOSGeom hGeosGeom = NULL; GEOSGeom hGeosHull = NULL; OGRGeometry *poHullOGRGeom = NULL; hGeosGeom = exportToGEOS(); if( hGeosGeom != NULL ) { hGeosHull = GEOSConvexHull( hGeosGeom ); GEOSGeom_destroy( hGeosGeom ); if( hGeosHull != NULL ) { poHullOGRGeom = OGRGeometryFactory::createFromGEOS(hGeosHull); GEOSGeom_destroy( hGeosHull); } } return poHullOGRGeom;#endif /* HAVE_GEOS */}/************************************************************************//* OGR_G_ConvexHull() *//************************************************************************/OGRGeometryH OGR_G_ConvexHull( OGRGeometryH hTarget ){ return (OGRGeometryH) ((OGRGeometry *) hTarget)->ConvexHull();}/************************************************************************//* getBoundary() *//************************************************************************//** * Compute boundary. * * A new geometry object is created and returned containing the boundary * of the geometry on which the method is invoked. * * This method is the same as the C function OGR_G_GetBoundary(). * * This method is built on the GEOS library, check it for the definition * of the geometry operation. * If OGR is built without the GEOS library, this method will always fail, * issuing a CPLE_NotSupported error. * * @return a newly allocated geometry now owned by the caller, or NULL on failure. */OGRGeometry *OGRGeometry::getBoundary() const{#ifndef HAVE_GEOS CPLError( CE_Failure, CPLE_NotSupported, "GEOS support not enabled." ); return NULL;#else GEOSGeom hGeosGeom = NULL; GEOSGeom hGeosProduct = NULL; OGRGeometry *poOGRProduct = NULL; hGeosGeom = exportToGEOS(); if( hGeosGeom != NULL ) { hGeosProduct = GEOSBoundary( hGeosGeom ); GEOSGeom_destroy( hGeosGeom ); if( hGeosProduct != NULL ) { poOGRProduct = OGRGeometryFactory::createFromGEOS(hGeosProduct); GEOSGeom_destroy( hGeosProduct ); } } return poOGRProduct;#endif /* HAVE_GEOS */}/************************************************************************//* OGR_G_GetBoundary() *//************************************************************************/OGRGeometryH OGR_G_GetBoundary( OGRGeometryH hTarget ){ return (OGRGeometryH) ((OGRGeometry *) hTarget)->getBoundary();}/************************************************************************//* Buffer() *//************************************************************************//** * Compute buffer of geometry. * * Builds a new geometry containing the buffer region around the geometry * on which it is invoked. The buffer is a polygon containing the region within * the buffer distance of the original geometry. * * Some buffer sections are properly described as curves, but are converted to * approximate polygons. The nQuadSegs parameter can be used to control how many * segements should be used to define a 90 degree curve - a quadrant of a circle. * A value of 30 is a reasonable default. Large values result in large numbers * of vertices in the resulting buffer geometry while small numbers reduce the * accuracy of the result. * * This method is the same as the C function OGR_G_Buffer(). * * This method is built on the GEOS library, check it for the definition * of the geometry operation. * If OGR is built without the GEOS library, this method will always fail, * issuing a CPLE_NotSupported error. * * @param dfDist the buffer distance to be applied. * * @param nQuadSegs the number of segments used to approximate a 90 degree (quadrant) of * curvature.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -