Exemplo n.º 1
0
OGRErr GNMFileNetwork::DeleteLayer(int nIndex)
{
    OGRLayer* pLayer = GetLayer(nIndex);

    GDALDataset* poDS = m_mpLayerDatasetMap[pLayer];
    if(NULL == poDS)
    {
        return OGRERR_FAILURE;
    }

    CPLDebug("GNM", "Delete network layer '%s'", pLayer->GetName());

    if(poDS->DeleteLayer(0) != OGRERR_NONE)
    {
        return OGRERR_FAILURE;
    }

    GDALClose(poDS);

    // remove pointer from map
    m_mpLayerDatasetMap.erase(pLayer);

    return GNMGenericNetwork::DeleteLayer(nIndex);
}
Exemplo n.º 2
0
SEXP ogrDeleteLayer (SEXP ogrSource, SEXP Layer, SEXP ogrDriver) {
    OGRLayer *poLayer;
#ifdef GDALV2
    GDALDataset *poDS;
    GDALDriver *poDriver;
#else
    OGRDataSource *poDS;
    OGRSFDriver *poDriver;
#endif
    int iLayer = -1;
    int flag = 0;

    installErrorHandler();
#ifdef GDALV2
    poDriver = GetGDALDriverManager()->GetDriverByName(CHAR(STRING_ELT(ogrDriver, 0)));
#else
    poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(
                   CHAR(STRING_ELT(ogrDriver, 0)) );
#endif
    uninstallErrorHandlerAndTriggerError();
    if (poDriver == NULL) {
        error("Driver not available");
    }

    installErrorHandler();
#ifdef GDALV2
    poDS=(GDALDataset*) GDALOpenEx(CHAR(STRING_ELT(ogrSource, 0)), GDAL_OF_VECTOR, NULL, NULL, NULL);
    if(poDS==NULL) {
        error("Cannot open data source");
    }
    if (!EQUAL(CHAR(STRING_ELT(ogrDriver, 0)),
               poDS->GetDriver()->GetDescription())) {
        GDALClose( poDS );
        poDS = NULL;
    }
#else
    poDS = poDriver->Open(CHAR(STRING_ELT(ogrSource, 0)),
                          TRUE);
#endif
    uninstallErrorHandlerAndTriggerError();

    if (poDS==NULL)
        error("Cannot open data source for update");

    installErrorHandler();
    for(iLayer = 0; iLayer < poDS->GetLayerCount(); iLayer++) {
        poLayer = poDS->GetLayer(iLayer);
#ifdef GDALV2
        if (poLayer != NULL && EQUAL(poLayer->GetName(),
                                     CHAR(STRING_ELT(Layer, 0)))) {
            flag = 1;
            break;
        }
#else
        if (poLayer != NULL && EQUAL(poLayer->GetLayerDefn()->GetName(),
                                     CHAR(STRING_ELT(Layer, 0)))) {
            flag = 1;
            break;
        }
#endif
    }
    uninstallErrorHandlerAndTriggerError();
    installErrorHandler();
    if (flag != 0) {
        int res = poDS->DeleteLayer(iLayer);
        if (res != OGRERR_NONE) {
#ifdef GDALV2
            GDALClose( poDS );
#else
            OGRDataSource::DestroyDataSource( poDS );
#endif
            uninstallErrorHandlerAndTriggerError();
            error("ogrDeleteLayer: failed to delete layer");
        }
    } else {
        warning("ogrDeleteLayer: no such layer");
    }
#ifdef GDALV2
    GDALClose( poDS );
#else
    OGRDataSource::DestroyDataSource( poDS );
#endif
    uninstallErrorHandlerAndTriggerError();
    return(R_NilValue);
}