本文整理汇总了C++中OGRLayer::SetMetadataItem方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRLayer::SetMetadataItem方法的具体用法?C++ OGRLayer::SetMetadataItem怎么用?C++ OGRLayer::SetMetadataItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRLayer
的用法示例。
在下文中一共展示了OGRLayer::SetMetadataItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}