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

📄 ogrfmedatasource.cpp

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                CPLDebug( "FME_LOG", "Setting geom type from %d to %d",                           poLayer->GetLayerDefn()->GetGeomType(),                          psCLI->eBestGeomType );                                          poLayer->GetLayerDefn()->SetGeomType( psCLI->eBestGeomType );            }        }                    CPLFree( psCLI->pszIndFile );        CPLFree( psCLI->pszCoordSys );    }    CPLFree( pasCLI );/* -------------------------------------------------------------------- *//*      Compress missing layers from the layer list.                    *//* -------------------------------------------------------------------- */    for( iLayer = 0; iLayer < nLayers; iLayer++ )    {        if( papoLayers[iLayer] == NULL )        {            papoLayers[iLayer] = papoLayers[nLayers-1];            nLayers--;            iLayer--;        }    }}/************************************************************************//*                        ClarifyGeometryClass()                        *//*                                                                      *//*      Examine an FME features geometry, and ensure the wkb            *//*      geometry type we are using will include it.  That is, we        *//*      generally make the geometry type sufficiently general to        *//*      include the type of geometry of this feature.                   *//*                                                                      *//*      Exceptions are when the existing type is unknown, in which      *//*      case we assign it the type of the geometry we find, and if      *//*      it is a mixture of polygon and multipolygon in which case we    *//*      use multipolygon with the understanding that we will force      *//*      the polygons to multipolygon.                                   *//************************************************************************/void OGRFMEDataSource::ClarifyGeometryClass(     IFMEFeature *poFeature,    OGRwkbGeometryType &eBestGeomType ){    FME_GeometryType      eFMEType = poFeature->getGeometryType();    OGRwkbGeometryType    eThisType;/* -------------------------------------------------------------------- *//*      Classify this FME geometry.  The hard case is aggregate.        *//* -------------------------------------------------------------------- */    if( eFMEType == FME_GEOM_POINT )        eThisType = wkbPoint;    else if( eFMEType == FME_GEOM_LINE )        eThisType = wkbLineString;    else if( eFMEType == FME_GEOM_POLYGON || eFMEType == FME_GEOM_DONUT )        eThisType = wkbPolygon;    else if( eFMEType == FME_GEOM_AGGREGATE )    {        // This is the hard case!  Split the aggregate to see if we can        // categorize it more specifically.        OGRwkbGeometryType eComponentType = (OGRwkbGeometryType) 500;        IFMEFeatureVector *poFeatVector;        poFeatVector = poSession->createFeatureVector();                poFeature->splitAggregate( *poFeatVector );                for( int iPart = 0; iPart < (int)poFeatVector->entries(); iPart++ )        {            IFMEFeature      *poFMEPart = (*poFeatVector)(iPart);            if( poFMEPart != NULL )                ClarifyGeometryClass( poFMEPart, eComponentType );        }        poSession->destroyFeatureVector( poFeatVector );        if( wkbFlatten(eComponentType) == wkbPolygon )            eThisType = wkbMultiPolygon;        else if( wkbFlatten(eComponentType) == wkbPoint )            eThisType = wkbMultiPoint;        else if( wkbFlatten(eComponentType) == wkbLineString )            eThisType = wkbMultiLineString;        else            eThisType = wkbGeometryCollection;    }    else         eThisType = wkbUnknown;    // Is this 3D?    if( poFeature->getDimension() == FME_THREE_D )        eThisType = (OGRwkbGeometryType) (eThisType | wkb25DBit);    /* -------------------------------------------------------------------- *//*      Now adjust the working type.                                    *//* -------------------------------------------------------------------- */    OGRwkbGeometryType eNewBestGeomType = eBestGeomType;    if( eBestGeomType == 500 )        eNewBestGeomType = eThisType;    else if( eThisType == wkbNone )        /* do nothing */;    else if( wkbFlatten(eThisType) == wkbFlatten(eBestGeomType) )        /* no change */;    else if( wkbFlatten(eThisType) == wkbPolygon              && wkbFlatten(eBestGeomType) == wkbMultiPolygon )        /* do nothing */;    else if( wkbFlatten(eThisType) == wkbMultiPolygon              && wkbFlatten(eBestGeomType) == wkbPolygon )        eNewBestGeomType = wkbMultiPolygon;    else if( wkbFlatten(eThisType) >= 4 && wkbFlatten(eThisType) <= 7           && wkbFlatten(eBestGeomType) >= 4 && wkbFlatten(eBestGeomType) <= 7 )        /* they are both collections, but not the same ... go to generic coll*/        eNewBestGeomType = wkbGeometryCollection;    else        eNewBestGeomType = wkbUnknown;    if( ((eBestGeomType & wkb25DBit) || (eThisType & wkb25DBit))         && (int) eNewBestGeomType != 500 )    {        eNewBestGeomType = (OGRwkbGeometryType)(((int) eBestGeomType) | wkb25DBit);    }     eBestGeomType = eNewBestGeomType;}/************************************************************************//*                           ReadFMEFeature()                           *//*                                                                      *//*      Internal working function to read an FME feature into the       *//*      poFMEFeature object, and increment the nPreviousFeature         *//*      counter.  Returns FALSE on end of input, or on error.           *//************************************************************************/int OGRFMEDataSource::ReadFMEFeature(){    FME_Boolean     eEndOfSchema;    FME_MsgNum      err;    poFMEFeature->resetFeature();    err = poReader->read( *poFMEFeature, eEndOfSchema );    if( err )    {        CPLFMEError( poSession, "Error while reading feature." );        return FALSE;    }    if( eEndOfSchema == FME_TRUE )    {        return FALSE;    }    return TRUE;}/************************************************************************//*                          ProcessGeometry()                           *//*                                                                      *//*      Translate an FME geometry into an OGR geometry.                 *//************************************************************************/OGRGeometry *OGRFMEDataSource::ProcessGeometry( OGRFMELayer * poLayer,                                    IFMEFeature * poGeomFeat,                                   OGRwkbGeometryType eDesiredType  ){        FME_GeometryType      eGeomType = poGeomFeat->getGeometryType();    int                   bForceToMulti = FALSE;        if( wkbFlatten(eDesiredType) == wkbGeometryCollection        || wkbFlatten(eDesiredType) == wkbMultiPolygon )        bForceToMulti = TRUE;/* -------------------------------------------------------------------- *//*      Point                                                           *//* -------------------------------------------------------------------- */    if( eGeomType == FME_GEOM_POINT )    {        return            new OGRPoint(poGeomFeat->getXCoordinate(0),                         poGeomFeat->getYCoordinate(0),                         poGeomFeat->getZCoordinate(0));    }/* -------------------------------------------------------------------- *//*      Line                                                            *//* -------------------------------------------------------------------- */    else if( eGeomType == FME_GEOM_LINE )    {        OGRLineString *poLine = new OGRLineString();        poLine->setNumPoints( poGeomFeat->numCoords() );                for( int iPoint = 0; iPoint < (int) poGeomFeat->numCoords(); iPoint++ )        {            poLine->setPoint( iPoint,                               poGeomFeat->getXCoordinate(iPoint),                              poGeomFeat->getYCoordinate(iPoint),                              poGeomFeat->getZCoordinate(iPoint) );        }        return poLine;    }/* -------------------------------------------------------------------- *//*      Polygon                                                         *//* -------------------------------------------------------------------- */    else if( eGeomType == FME_GEOM_POLYGON )    {        OGRLinearRing *poLine = new OGRLinearRing();        OGRPolygon *poPolygon = new OGRPolygon();        poLine->setNumPoints( poGeomFeat->numCoords() );                for( int iPoint = 0; iPoint < (int)poGeomFeat->numCoords(); iPoint++ )        {            poLine->setPoint( iPoint,                               poGeomFeat->getXCoordinate(iPoint),                              poGeomFeat->getYCoordinate(iPoint),                              poGeomFeat->getZCoordinate(iPoint) );        }        poPolygon->addRingDirectly( poLine );        if( !bForceToMulti )            return poPolygon;        OGRMultiPolygon *poMP = new OGRMultiPolygon();        poMP->addGeometryDirectly( poPolygon );        return poMP;    }/* -------------------------------------------------------------------- *//*      Donut                                                           *//* -------------------------------------------------------------------- */    else if( eGeomType == FME_GEOM_DONUT )    {        OGRPolygon      *poPolygon = new OGRPolygon();        IFMEFeatureVector *poFeatVector;        IFMEFeature      *poFMERing = NULL;        poFeatVector = poSession->createFeatureVector();                poGeomFeat->getDonutParts( *poFeatVector );                for( int iPart = 0; iPart < (int)poFeatVector->entries(); iPart++ )        {            OGRLinearRing      *poRing;            poFMERing = (*poFeatVector)(iPart);            if( poFMERing == NULL )                continue;            poRing = new OGRLinearRing();                        poRing->setNumPoints( poFMERing->numCoords() );                    for( int iPoint=0; iPoint < (int)poFMERing->numCoords(); iPoint++ )            {                poRing->setPoint( iPoint,                                   poFMERing->getXCoordinate(iPoint),                                  poFMERing->getYCoordinate(iPoint),                                  poFMERing->getZCoordinate(iPoint) );            }            poPolygon->addRingDirectly( poRing );        }        poFeatVector->clearAndDestroy();        poSession->destroyFeatureVector( poFeatVector );        if( !bForceToMulti )            return poPolygon;        OGRMultiPolygon *poMP = new OGRMultiPolygon();        poMP->addGeometryDirectly( poPolygon );        return poMP;    }/* -------------------------------------------------------------------- *//*      Aggregate                                                       *//* -------------------------------------------------------------------- */    else if( eGeomType == FME_GEOM_AGGREGATE )    {        OGRGeometryCollection *poCollection;        IFMEFeatureVector *poFeatVector;        OGRwkbGeometryType eSubType = wkbUnknown;        if( bForceToMulti && eDesiredType == wkbMultiPolygon )        {            poCollection = new OGRMultiPolygon();            eSubType = wkbPolygon;        }        else            poCollection = new OGRGeometryCollection();        poFeatVector = poSession->createFeatureVector();                poGeomFeat->splitAggregate( *poFeatVector );                for( int iPart = 0; iPart < (int)poFeatVector->entries(); iPart++ )        {            OGRGeometry      *poOGRPart;            IFMEFeature      *poFMEPart;            poFMEPart = (*poFeatVector)(iPart);            if( poFMEPart == NULL )                continue;            poOGRPart = ProcessGeometry( poLayer, poFMEPart, eSubType );            if( poOGRPart == NULL )                continue;            poCollection->addGeometryDirectly( poOGRPart );        }        poSession->destroyFeatureVector( poFeatVector );        return poCollection;    }    else if( eGeomType == FME_GEOM_UNDEFINED )    {        return NULL;    }    else    {        CPLDebug( kPROVIDERNAME,                   "unable to translate unsupported geometry type: %d\n",                  eGeomType  );        return NULL;    }} /************************************************************************//*                           ProcessFeature()                           *//*                                                                      *//*      Process the current fme feature into an OGR feature of the      *//*      passed layer types.                                             *//************************************************************************/OGRFeature *OGRFMEDataSource::ProcessFeature( OGRFMELayer *poLayer,                                              IFMEFeature *poSrcFeature ){    OGRFeatureDefn  *poDefn = poLayer->GetLayerDefn();    OGRFeature      *poFeature = new OGRFeature( poDefn );    int             iAttr;

⌨️ 快捷键说明

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