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

📄 ogravce00layer.cpp

📁 用于读取TAB、MIF、SHP文件的类
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/************************************************************************//*                           TestCapability()                           *//************************************************************************/#if 0int OGRAVCE00Layer::TestCapability( const char * pszCap ){    if( eSectionType == AVCFileARC && EQUAL(pszCap,OLCRandomRead) )        return TRUE;    else         return OGRAVCLayer::TestCapability( pszCap );}#endif/************************************************************************//*                        FormPolygonGeometry()                         *//*                                                                      *//*      Collect all the arcs forming edges to this polygon and form     *//*      them into the appropriate OGR geometry on the target feature.   *//************************************************************************/int OGRAVCE00Layer::FormPolygonGeometry( OGRFeature *poFeature,                                          AVCPal *psPAL ){/* -------------------------------------------------------------------- *//*      Try to find the corresponding ARC layer if not already          *//*      recorded.                                                       *//* -------------------------------------------------------------------- */    if( poArcLayer == NULL )    {        int i;        for( i = 0; i < poDS->GetLayerCount(); i++ )        {            OGRAVCE00Layer *poLayer = (OGRAVCE00Layer *) poDS->GetLayer(i);            if( poLayer->eSectionType == AVCFileARC )                poArcLayer = poLayer;        }        if( poArcLayer == NULL )            return FALSE;    }/* -------------------------------------------------------------------- *//*  Read all the arcs related to this polygon, making a working         *//*  copy of them since the one returned by AVC is temporary.            *//* -------------------------------------------------------------------- */    OGRGeometryCollection oArcs;    int iArc;    for( iArc = 0; iArc < psPAL->numArcs; iArc++ )    {        OGRFeature *poArc;        if( psPAL->pasArcs[iArc].nArcId == 0 )            continue;        // If the other side of the line is the same polygon then this        // arc is a "bridge" arc and can be discarded.  If we don't discard        // it, then we should double it as bridge arcs seem to only appear        // once.  But by discarding it we ensure a multi-ring polygon will be        // properly formed.         if( psPAL->pasArcs[iArc].nAdjPoly == psPAL->nPolyId )            continue;        poArc = poArcLayer->GetFeature( ABS(psPAL->pasArcs[iArc].nArcId) );        if( poArc == NULL )            return FALSE;        if( poArc->GetGeometryRef() == NULL )            return FALSE;        oArcs.addGeometry( poArc->GetGeometryRef() );        OGRFeature::DestroyFeature( poArc );    }    OGRErr  eErr;    OGRPolygon *poPolygon;    poPolygon = (OGRPolygon *)         OGRBuildPolygonFromEdges( (OGRGeometryH) &oArcs, TRUE, FALSE,                                    0.0, &eErr );    if( poPolygon != NULL )        poFeature->SetGeometryDirectly( poPolygon );    return eErr == OGRERR_NONE;}/************************************************************************//*                          CheckSetupTable()                           *//*                                                                      *//*      Check if the named table exists, and if so, setup access to     *//*      it (open it), and add it's fields to the feature class          *//*      definition.                                                     *//************************************************************************/int OGRAVCE00Layer::CheckSetupTable(AVCE00Section *psTblSectionIn){    if (psTableRead)        return FALSE;    const char *pszTableType = NULL;    switch (eSectionType)    {    case AVCFileARC:        pszTableType = ".AAT";        break;    case AVCFilePAL:    case AVCFileLAB:        pszTableType = ".PAT";        break;    default:        break;    }/* -------------------------------------------------------------------- *//*      Is the table type found anywhere in the section pszName?  Do    *//*      a case insensitive check.                                       *//* -------------------------------------------------------------------- */    if( pszTableType == NULL )        return FALSE;        int iCheckOff;    for( iCheckOff = 0;          psTblSectionIn->pszName[iCheckOff] != '\0';          iCheckOff++ )    {        if( EQUALN(psTblSectionIn->pszName + iCheckOff,                    pszTableType, strlen(pszTableType) ) )            break;    }    if( psTblSectionIn->pszName[iCheckOff] == '\0' )        return FALSE;    psTableSection = psTblSectionIn;/* -------------------------------------------------------------------- *//*      Try opening the table.                                          *//* -------------------------------------------------------------------- */    psTableRead = AVCE00ReadOpenE00(psTblSectionIn->pszFilename);    if (psTableRead == NULL)        return FALSE;    /* advance to the specified line number */    if (AVCE00ReadGotoSectionE00(psTableRead, psTableSection, 0) != 0)    {        AVCE00ReadCloseE00(psTableRead);        psTableRead = NULL;        return FALSE;    }        AVCE00ReadNextObjectE00(psTableRead);    bNeedReset = 1;    pszTableFilename = CPLStrdup(psTblSectionIn->pszFilename);    nTableBaseField = poFeatureDefn->GetFieldCount();	if (eSectionType == AVCFileLAB)	{        AVCE00ReadE00Ptr psInfo = ((OGRAVCE00DataSource *) poDS)->GetInfo();        for( int iSection = 0; iSection < psInfo->numSections; iSection++ )        {            if( psInfo->pasSections[iSection].eType == AVCFilePAL )                nTableAttrIndex = poFeatureDefn->GetFieldIndex( "PolyId" );        }	}/* -------------------------------------------------------------------- *//*      Setup attributes.                                               *//* -------------------------------------------------------------------- */    AppendTableDefinition( psTableRead->hParseInfo->hdr.psTableDef );/* -------------------------------------------------------------------- *//*      Close table so we don't have to many files open at once.        *//* -------------------------------------------------------------------- */    /* AVCE00ReadCloseE00( psTableRead ); */    return TRUE;}/************************************************************************//*                         AppendTableFields()                          *//************************************************************************/int OGRAVCE00Layer::AppendTableFields( OGRFeature *poFeature ){    if (psTableRead == NULL)        return FALSE;/* -------------------------------------------------------------------- *//*      Open the table if it is currently closed.                       *//* -------------------------------------------------------------------- */    if (psTableRead == NULL)    {        psTableRead = AVCE00ReadOpenE00(pszTableFilename);        if (psTableRead == NULL)            return FALSE;        /* advance to the specified line number */    	if (AVCE00ReadGotoSectionE00(psTableRead, psTableSection, 0) != 0)        {            AVCE00ReadCloseE00(psTableRead);            psTableRead = NULL;            return FALSE;        }        nTablePos = 0;    }/* -------------------------------------------------------------------- *//*      Read the info record.                                           *//*                                                                      *//*      We usually assume the FID of the feature is the key but in a    *//*      polygon coverage we need to use the PolyId attribute of LAB     *//*      features to lookup the related attributes.  In this case        *//*      nTableAttrIndex will already be setup to refer to the           *//*      PolyId field.                                                   *//* -------------------------------------------------------------------- */    int nRecordId;    void *hRecord;    if( nTableAttrIndex == -1 )        nRecordId = poFeature->GetFID();    else        nRecordId = poFeature->GetFieldAsInteger( nTableAttrIndex );    if (nRecordId <= nTablePos)    {    	if (AVCE00ReadGotoSectionE00(psTableRead, psTableSection, 0) != 0)			return FALSE;        nTablePos = 0;    }    do    {        hRecord = AVCE00ReadNextObjectE00(psTableRead);        ++nTablePos;    }    while (NULL != hRecord && nTablePos < nRecordId);    if( hRecord == NULL )        return FALSE;/* -------------------------------------------------------------------- *//*      Translate it.                                                   *//* -------------------------------------------------------------------- */    return TranslateTableFields( poFeature, nTableBaseField,                                  psTableRead->hParseInfo->hdr.psTableDef,                                  (AVCField *) hRecord );}int OGRAVCE00Layer::GetFeatureCount(int bForce){    if (bForce && nFeatureCount < 0)    {        if (psSection->nFeatureCount < 0)        {            nFeatureCount = OGRLayer::GetFeatureCount(bForce);        }        else        {            nFeatureCount = psSection->nFeatureCount;            if (psSection->eType == AVCFilePAL)                --nFeatureCount;        }    }    return nFeatureCount;}

⌨️ 快捷键说明

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