📄 ogrgeometryfactory.cpp
字号:
poPolygon->addRing( poOldPoly->getExteriorRing() ); for( iRing = 0; iRing < poOldPoly->getNumInteriorRings(); iRing++ ) poPolygon->addRing( poOldPoly->getInteriorRing( iRing ) ); } delete poGC; return poPolygon;}/************************************************************************//* forceToMultiPolygon() *//************************************************************************//** * Convert to multipolygon. * * Tries to force the provided geometry to be a multipolygon. Currently * this just effects a change on polygons. The passed in geometry is * consumed and a new one returned (or potentially the same one). * * @return new geometry. */OGRGeometry *OGRGeometryFactory::forceToMultiPolygon( OGRGeometry *poGeom ){ if( poGeom == NULL ) return NULL;/* -------------------------------------------------------------------- *//* Check for the case of a geometrycollection that can be *//* promoted to MultiPolygon. *//* -------------------------------------------------------------------- */ if( wkbFlatten(poGeom->getGeometryType()) == wkbGeometryCollection ) { int iGeom; int bAllPoly = TRUE; OGRGeometryCollection *poGC = (OGRGeometryCollection *) poGeom; for( iGeom = 0; iGeom < poGC->getNumGeometries(); iGeom++ ) { if( wkbFlatten(poGC->getGeometryRef(iGeom)->getGeometryType()) != wkbPolygon ) bAllPoly = FALSE; } if( !bAllPoly ) return poGeom; OGRMultiPolygon *poMP = new OGRMultiPolygon(); while( poGC->getNumGeometries() > 0 ) { poMP->addGeometryDirectly( poGC->getGeometryRef(0) ); poGC->removeGeometry( 0, FALSE ); } delete poGC; return poMP; }/* -------------------------------------------------------------------- *//* Eventually we should try to split the polygon into component *//* island polygons. But thats alot of work and can be put off. *//* -------------------------------------------------------------------- */ if( wkbFlatten(poGeom->getGeometryType()) != wkbPolygon ) return poGeom; OGRMultiPolygon *poMP = new OGRMultiPolygon(); poMP->addGeometryDirectly( poGeom ); return poMP;}/************************************************************************//* forceToMultiPoint() *//************************************************************************//** * Convert to multipoint. * * Tries to force the provided geometry to be a multipoint. Currently * this just effects a change on points. The passed in geometry is * consumed and a new one returned (or potentially the same one). * * @return new geometry. */OGRGeometry *OGRGeometryFactory::forceToMultiPoint( OGRGeometry *poGeom ){ if( poGeom == NULL ) return NULL;/* -------------------------------------------------------------------- *//* Check for the case of a geometrycollection that can be *//* promoted to MultiPoint. *//* -------------------------------------------------------------------- */ if( wkbFlatten(poGeom->getGeometryType()) == wkbGeometryCollection ) { int iGeom; int bAllPoint = TRUE; OGRGeometryCollection *poGC = (OGRGeometryCollection *) poGeom; for( iGeom = 0; iGeom < poGC->getNumGeometries(); iGeom++ ) { if( wkbFlatten(poGC->getGeometryRef(iGeom)->getGeometryType()) != wkbPoint ) bAllPoint = FALSE; } if( !bAllPoint ) return poGeom; OGRMultiPoint *poMP = new OGRMultiPoint(); while( poGC->getNumGeometries() > 0 ) { poMP->addGeometryDirectly( poGC->getGeometryRef(0) ); poGC->removeGeometry( 0, FALSE ); } delete poGC; return poMP; } if( wkbFlatten(poGeom->getGeometryType()) != wkbPoint ) return poGeom; OGRMultiPoint *poMP = new OGRMultiPoint(); poMP->addGeometryDirectly( poGeom ); return poMP;}/************************************************************************//* forceToMultiLinestring() *//************************************************************************//** * Convert to multilinestring. * * Tries to force the provided geometry to be a multilinestring. Currently * this just effects a change on linestrings. The passed in geometry is * consumed and a new one returned (or potentially the same one). * * @return new geometry. */OGRGeometry *OGRGeometryFactory::forceToMultiLineString( OGRGeometry *poGeom ){ if( poGeom == NULL ) return NULL;/* -------------------------------------------------------------------- *//* Check for the case of a geometrycollection that can be *//* promoted to MultiLineString. *//* -------------------------------------------------------------------- */ if( wkbFlatten(poGeom->getGeometryType()) == wkbGeometryCollection ) { int iGeom; int bAllLines = TRUE; OGRGeometryCollection *poGC = (OGRGeometryCollection *) poGeom; for( iGeom = 0; iGeom < poGC->getNumGeometries(); iGeom++ ) { if( wkbFlatten(poGC->getGeometryRef(iGeom)->getGeometryType()) != wkbLineString ) bAllLines = FALSE; } if( !bAllLines ) return poGeom; OGRMultiLineString *poMP = new OGRMultiLineString(); while( poGC->getNumGeometries() > 0 ) { poMP->addGeometryDirectly( poGC->getGeometryRef(0) ); poGC->removeGeometry( 0, FALSE ); } delete poGC; return poMP; } if( wkbFlatten(poGeom->getGeometryType()) != wkbLineString ) return poGeom; OGRMultiLineString *poMP = new OGRMultiLineString(); poMP->addGeometryDirectly( poGeom ); return poMP;}/************************************************************************//* createFromGML() *//************************************************************************//** * Create geometry from GML. * * This method translates a fragment of GML containing only the geometry * portion into a corresponding OGRGeometry. There are many limitations * on the forms of GML geometries supported by this parser, but they are * too numerous to list here. * * The C function OGR_G_CreateFromGML() is the same as this method. * * @param pszData The GML fragment for the geometry. * * @return a geometry on succes, or NULL on error. */OGRGeometry *OGRGeometryFactory::createFromGML( const char *pszData ){ OGRGeometryH hGeom; hGeom = OGR_G_CreateFromGML( pszData ); return (OGRGeometry *) hGeom;}/************************************************************************//* createFromGEOS() *//************************************************************************/OGRGeometry *OGRGeometryFactory::createFromGEOS( GEOSGeom geosGeom ){#ifndef HAVE_GEOS CPLError( CE_Failure, CPLE_NotSupported, "GEOS support not enabled." ); return NULL;#else size_t nSize = 0; unsigned char *pabyBuf = NULL; OGRGeometry *poGeometry = NULL; pabyBuf = GEOSGeomToWKB_buf( geosGeom, &nSize ); if( pabyBuf == NULL || nSize == 0 ) { return NULL; } if( OGRGeometryFactory::createFromWkb( (unsigned char *) pabyBuf, NULL, &poGeometry, (int) nSize ) != OGRERR_NONE ) { poGeometry = NULL; } if( pabyBuf != NULL ) { free( pabyBuf ); } return poGeometry;#endif /* HAVE_GEOS */}/************************************************************************//* getGEOSGeometryFactory() *//************************************************************************/void *OGRGeometryFactory::getGEOSGeometryFactory() { // XXX - mloskot - What to do with this call // after GEOS C++ API has been stripped? return NULL;}/************************************************************************//* haveGEOS() *//************************************************************************//** * Test if GEOS enabled. * * This static method returns TRUE if GEOS support is built into OGR, * otherwise it returns FALSE. * * @return TRUE if available, otherwise FALSE. */int OGRGeometryFactory::haveGEOS(){#ifndef HAVE_GEOS return FALSE;#else return TRUE;#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -