当前位置: 首页>>代码示例>>C++>>正文


C++ OGRLayer::GetMetadata方法代码示例

本文整理汇总了C++中OGRLayer::GetMetadata方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRLayer::GetMetadata方法的具体用法?C++ OGRLayer::GetMetadata怎么用?C++ OGRLayer::GetMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OGRLayer的用法示例。


在下文中一共展示了OGRLayer::GetMetadata方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: oMutexHolder


//.........这里部分代码省略.........
    /* the layer definition. */
    int bUseStatementForGetNextFeature = TRUE;
    int bEmptyLayer = FALSE;

    sqlite3_stmt *hSQLStmt = NULL;
    int rc = sqlite3_prepare( hDB,
                              pszStatement, -1,
                              &hSQLStmt, NULL );

    if( rc != SQLITE_OK )
    {
        CPLError( CE_Failure, CPLE_AppDefined,
                "In ExecuteSQL(): sqlite3_prepare(%s):\n  %s",
                pszStatement, sqlite3_errmsg(hDB) );

        if( hSQLStmt != NULL )
        {
            sqlite3_finalize( hSQLStmt );
        }

        delete poSQLiteDS;
        VSIUnlink(pszTmpDBName);
        CPLFree(pszTmpDBName);

        return NULL;
    }

/* -------------------------------------------------------------------- */
/*      Do we get a resultset?                                          */
/* -------------------------------------------------------------------- */
    rc = sqlite3_step( hSQLStmt );
    if( rc != SQLITE_ROW )
    {
        if ( rc != SQLITE_DONE )
        {
            CPLError( CE_Failure, CPLE_AppDefined,
                  "In ExecuteSQL(): sqlite3_step(%s):\n  %s",
                  pszStatement, sqlite3_errmsg(hDB) );

            sqlite3_finalize( hSQLStmt );

            delete poSQLiteDS;
            VSIUnlink(pszTmpDBName);
            CPLFree(pszTmpDBName);

            return NULL;
        }

        if( !STARTS_WITH_CI(pszStatement, "SELECT ") )
        {

            sqlite3_finalize( hSQLStmt );

            delete poSQLiteDS;
            VSIUnlink(pszTmpDBName);
            CPLFree(pszTmpDBName);

            return NULL;
        }

        bUseStatementForGetNextFeature = FALSE;
        bEmptyLayer = TRUE;
    }

/* -------------------------------------------------------------------- */
/*      Create layer.                                                   */
/* -------------------------------------------------------------------- */
    OGRSQLiteSelectLayer *poLayer = NULL;

    poLayer = new OGRSQLiteExecuteSQLLayer( pszTmpDBName,
                                            poSQLiteDS, pszStatement, hSQLStmt,
                                            bUseStatementForGetNextFeature, bEmptyLayer );

    if( poSpatialFilter != NULL )
        poLayer->SetSpatialFilter( 0, poSpatialFilter );

    if( poSingleSrcLayer != NULL )
        poLayer->SetMetadata( poSingleSrcLayer->GetMetadata( "NATIVE_DATA" ),
                              "NATIVE_DATA" );

    return poLayer;
}

/************************************************************************/
/*                   OGRSQLiteGetReferencedLayers()                     */
/************************************************************************/

std::set<LayerDesc> OGRSQLiteGetReferencedLayers(const char* pszStatement)
{
/* -------------------------------------------------------------------- */
/*      Analysze the statement to determine which tables will be used.  */
/* -------------------------------------------------------------------- */
    std::set<LayerDesc> oSetLayers;
    std::set<CPLString> oSetSpatialIndex;
    CPLString osModifiedSQL;
    OGR2SQLITEGetPotentialLayerNames(pszStatement, oSetLayers,
                                     oSetSpatialIndex, osModifiedSQL);

    return oSetLayers;
}
开发者ID:bbradbury,项目名称:lib_gdal,代码行数:101,代码来源:ogrsqliteexecutesql.cpp

示例2: createLayer

bool NgwGdalIo::createLayer (int &new_layer_id, const NgwLayerInfo &layer_info, QString base_url,
                             int resource_group_id, QString base_url_copy_features, int layer_id_copy_features)
{
    GDALDatasetPtr dataset_p;
    u_openDataset(dataset_p, base_url, resource_group_id, false);
    if (dataset_p.data() == NULL)
    {
        error = QObject::tr("Unable to open NGW dataset via GDAL");
        return false;
    }

    QByteArray ba_name(layer_info.name.toUtf8());

    OGRwkbGeometryType geom_type = Core::g_findGeomTypeGdal(layer_info.geom_type);

    OGRSpatialReference *srs = new OGRSpatialReference();
    srs->importFromEPSG(3857);

    char **papszOptions = NULL;
    papszOptions = CSLAddString(papszOptions, "OVERWRITE=NO");
    OGRLayer *layer = dataset_p.data()->CreateLayer(ba_name.data(), srs, geom_type, papszOptions);
    CSLDestroy(papszOptions);
    OSRRelease(srs);

    if (layer == NULL)
    {
        error = QObject::tr("Unable to create NGW layer via GDAL");
        error += QString("\nGDAL error: %1").arg(CPLGetLastErrorMsg());
        return false;
    }

    for (int i = 0; i < layer_info.fields.size(); i++)
    {
        QByteArray ba_field_name = std::get<0>(layer_info.fields[i]).toUtf8();
        OGRFieldType field_type = Core::g_findFieldTypeGdal(std::get<2>(layer_info.fields[i]));

        OGRFieldDefn field_defn(ba_field_name.data(), field_type);
        layer->CreateField(&field_defn);

        // TEMP. There may be another way to create field aliases via GDAL in future.
        QString s_field_alias = QString("FIELD_%1_ALIAS").arg(i);
        layer->SetMetadataItem(s_field_alias.toUtf8().data(),
                               std::get<1>(layer_info.fields[i]).toUtf8().data());

        // TODO: delete layer if the creation of field was not successfull? What if at the time
        // between creation and this deletion some other layer have been created outside? How to
        // remove layer in GDAL not by layer index & how to properly get index of a layer in
        // GDALDataset?
    }

    layer->SyncToDisk(); // otherwise NGW id of created resource will not be assigned to the new layer

    auto metadata = layer->GetMetadata("");
    QString s_new_layer_id = {CSLFetchNameValue(metadata, "id")};
    new_layer_id = s_new_layer_id.toInt();

    if (base_url_copy_features != "" && layer_id_copy_features != -1)
    {
        // TODO (important): here we need own credentioals for dataset_p2 !

        GDALDatasetPtr dataset_p2;
        u_openDataset(dataset_p2, base_url_copy_features.toUtf8().data(), layer_id_copy_features, true);
        if (dataset_p2.data() == NULL)
        {
            // TODO: warning
            error = QObject::tr("Unable to open NGW dataset to copy features from");
            //return false;
        }
        else
        {
            OGRLayer *layer2 = dataset_p2.data()->GetLayer(0);
            if (layer2 == NULL)
            {
                // TODO: warning
                error = QObject::tr("Unable to open NGW layer to copy features from");
                //return false;
            }
            else
            {
                layer2->ResetReading();
                OGRFeature *feature;
                while ((feature = layer2->GetNextFeature()) != NULL)
                {
                    layer->CreateFeature(feature);
                    OGRFeature::DestroyFeature(feature);
                }

                layer->SyncToDisk();
            }
        }
    }

    return true;
}
开发者ID:nextgis,项目名称:formbuilder,代码行数:94,代码来源:ngw_gdal_io.cpp


注:本文中的OGRLayer::GetMetadata方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。