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

📄 ogrgeometryfactory.cpp

📁 用于读取TAB、MIF、SHP文件的类
💻 CPP
📖 第 1 页 / 共 3 页
字号:
 * * The C function OGR_G_CreateFromWkt() is the same as this method. * * @param ppszData input zero terminated string containing well known text *                representation of the geometry to be created.  The pointer *                is updated to point just beyond that last character consumed. * @param poSR pointer to the spatial reference to be assigned to the *             created geometry object.  This may be NULL. * @param ppoReturn the newly created geometry object will be assigned to the *                  indicated pointer on return.  This will be NULL if the *                  method fails.  * *  <b>Example:</b> * *  <pre> *    const char* wkt= "POINT(0 0)"; *   *    // cast because OGR_G_CreateFromWkt will move the pointer  *    char* pszWkt = (char*) wkt.c_str();  *    OGRSpatialReferenceH ref = OSRNewSpatialReference(NULL); *    OGRGeometryH new_geom; *    OGRErr err = OGR_G_CreateFromWkt(&pszWkt, ref, &new_geom); *  </pre> * * * * @return OGRERR_NONE if all goes well, otherwise any of * OGRERR_NOT_ENOUGH_DATA, OGRERR_UNSUPPORTED_GEOMETRY_TYPE, or * OGRERR_CORRUPT_DATA may be returned. */OGRErr OGRGeometryFactory::createFromWkt(char **ppszData,                                         OGRSpatialReference * poSR,                                         OGRGeometry **ppoReturn ){    OGRErr      eErr;    char        szToken[OGR_WKT_TOKEN_MAX];    char        *pszInput = *ppszData;    OGRGeometry *poGeom;    *ppoReturn = NULL;/* -------------------------------------------------------------------- *//*      Get the first token, which should be the geometry type.         *//* -------------------------------------------------------------------- */    if( OGRWktReadToken( pszInput, szToken ) == NULL )        return OGRERR_CORRUPT_DATA;/* -------------------------------------------------------------------- *//*      Instantiate a geometry of the appropriate type.                 *//* -------------------------------------------------------------------- */    if( EQUAL(szToken,"POINT") )    {        poGeom = new OGRPoint();    }    else if( EQUAL(szToken,"LINESTRING") )    {        poGeom = new OGRLineString();    }    else if( EQUAL(szToken,"POLYGON") )    {        poGeom = new OGRPolygon();    }        else if( EQUAL(szToken,"GEOMETRYCOLLECTION") )    {        poGeom = new OGRGeometryCollection();    }        else if( EQUAL(szToken,"MULTIPOLYGON") )    {        poGeom = new OGRMultiPolygon();    }    else if( EQUAL(szToken,"MULTIPOINT") )    {        poGeom = new OGRMultiPoint();    }    else if( EQUAL(szToken,"MULTILINESTRING") )    {        poGeom = new OGRMultiLineString();    }    else    {        return OGRERR_UNSUPPORTED_GEOMETRY_TYPE;    }/* -------------------------------------------------------------------- *//*      Do the import.                                                  *//* -------------------------------------------------------------------- */    eErr = poGeom->importFromWkt( &pszInput );    /* -------------------------------------------------------------------- *//*      Assign spatial reference system.                                *//* -------------------------------------------------------------------- */    if( eErr == OGRERR_NONE )    {        poGeom->assignSpatialReference( poSR );        *ppoReturn = poGeom;        *ppszData = pszInput;    }    else    {        delete poGeom;    }        return eErr;}/************************************************************************//*                        OGR_G_CreateFromWkt()                         *//************************************************************************//** * Create a geometry object of the appropriate type from it's well known * text representation. * * The OGRGeometryFactory::createFromWkt CPP method is the same as this * function. * * @param ppszData input zero terminated string containing well known text *                representation of the geometry to be created.  The pointer *                is updated to point just beyond that last character consumed. * @param hSRS handle to the spatial reference to be assigned to the *             created geometry object.  This may be NULL. * @param phGeometry the newly created geometry object will be assigned to the *                  indicated handle on return.  This will be NULL if the *                  method fails.  * * @return OGRERR_NONE if all goes well, otherwise any of * OGRERR_NOT_ENOUGH_DATA, OGRERR_UNSUPPORTED_GEOMETRY_TYPE, or * OGRERR_CORRUPT_DATA may be returned. */OGRErr CPL_DLL OGR_G_CreateFromWkt( char **ppszData,                                     OGRSpatialReferenceH hSRS,                                    OGRGeometryH *phGeometry ){    return OGRGeometryFactory::createFromWkt( ppszData,                                              (OGRSpatialReference *) hSRS,                                              (OGRGeometry **) phGeometry );}/************************************************************************//*                           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;

⌨️ 快捷键说明

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