⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ogrgeometryfactory.cpp

📁 在linux环境下
💻 CPP
📖 第 1 页 / 共 2 页
字号:
}/************************************************************************//*                           createGeometry()                           *//************************************************************************//**  * Create an empty geometry of desired type. * * This is equivelent to allocating the desired geometry with new, but * the allocation is guaranteed to take place in the context of the  * GDAL/OGR heap.  * * This method is the same as the C function OGR_G_CreateGeometry(). * * @param eGeometryType the type code of the geometry class to be instantiated. * * @return the newly create geometry or NULL on failure. */OGRGeometry *OGRGeometryFactory::createGeometry( OGRwkbGeometryType eGeometryType ){    switch( wkbFlatten(eGeometryType) )    {      case wkbPoint:          return new OGRPoint();      case wkbLineString:          return new OGRLineString();      case wkbPolygon:          return new OGRPolygon();      case wkbGeometryCollection:          return new OGRGeometryCollection();      case wkbMultiPolygon:          return new OGRMultiPolygon();      case wkbMultiPoint:          return new OGRMultiPoint();      case wkbMultiLineString:          return new OGRMultiLineString();      case wkbLinearRing:          return new OGRLinearRing();      default:          return NULL;    }    return NULL;}/************************************************************************//*                        OGR_G_CreateGeometry()                        *//************************************************************************//**  * Create an empty geometry of desired type. * * This is equivelent to allocating the desired geometry with new, but * the allocation is guaranteed to take place in the context of the  * GDAL/OGR heap.  * * This function is the same as the CPP method  * OGRGeometryFactory::createGeometry. * * @param eGeometryType the type code of the geometry to be created. * * @return handle to the newly create geometry or NULL on failure. */OGRGeometryH OGR_G_CreateGeometry( OGRwkbGeometryType eGeometryType ){    return (OGRGeometryH) OGRGeometryFactory::createGeometry( eGeometryType );}/************************************************************************//*                          destroyGeometry()                           *//************************************************************************//** * Destroy geometry object. * * Equivalent to invoking delete on a geometry, but it guaranteed to take  * place within the context of the GDAL/OGR heap. * * This method is the same as the C function OGR_G_DestroyGeometry(). * * @param poGeom the geometry to deallocate. */void OGRGeometryFactory::destroyGeometry( OGRGeometry *poGeom ){    delete poGeom;}/************************************************************************//*                        OGR_G_DestroyGeometry()                       *//************************************************************************//** * Destroy geometry object. * * Equivalent to invoking delete on a geometry, but it guaranteed to take  * place within the context of the GDAL/OGR heap. * * This function is the same as the CPP method  * OGRGeometryFactory::destroyGeometry. * * @param hGeom handle to the geometry to delete. */void OGR_G_DestroyGeometry( OGRGeometryH hGeom ){    OGRGeometryFactory::destroyGeometry( (OGRGeometry *) hGeom );}/************************************************************************//*                           forceToPolygon()                           *//************************************************************************//** * Convert to polygon. * * Tries to force the provided geometry to be a polygon.  Currently * this just effects a change on multipolygons.  The passed in geometry is * consumed and a new one returned (or potentially the same one).  *  * @return new geometry. */OGRGeometry *OGRGeometryFactory::forceToPolygon( OGRGeometry *poGeom ){    if( poGeom == NULL )        return NULL;    if( wkbFlatten(poGeom->getGeometryType()) != wkbGeometryCollection        || wkbFlatten(poGeom->getGeometryType()) != wkbMultiPolygon )        return poGeom;    // build an aggregated polygon from all the polygon rings in the container.    OGRPolygon *poPolygon = new OGRPolygon();    OGRGeometryCollection *poGC = (OGRGeometryCollection *) poGeom;    int iGeom;    for( iGeom = 0; iGeom < poGC->getNumGeometries(); iGeom++ )    {        if( wkbFlatten(poGC->getGeometryRef(iGeom)->getGeometryType())             != wkbPolygon )            continue;        OGRPolygon *poOldPoly = (OGRPolygon *) poGC->getGeometryRef(iGeom);        int   iRing;        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->addGeometry( 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->addGeometry( 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 MultiPoint.                                         *//* -------------------------------------------------------------------- */    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->addGeometry( 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;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -