Пример #1
0
CPLErr GNMGenericNetwork::Delete()
{
    CPLErr eResult = DeleteNetworkLayers();
    if(eResult != CE_None)
        return eResult;
    eResult = DeleteMetadataLayer();
    if(eResult != CE_None)
        return eResult;
    eResult = DeleteGraphLayer();
    if(eResult != CE_None)
        return eResult;

    return DeleteFeaturesLayer();
}
Пример #2
0
CPLErr GNMFileNetwork::Create( const char* pszFilename, char** papszOptions )
{
    // check required options

    // check name
    const char* pszNetworkName = CSLFetchNameValue(papszOptions, GNM_MD_NAME);

    if( NULL == pszNetworkName )
    {
        CPLError( CE_Failure, CPLE_IllegalArg,
                  "The network name should be present" );
        return CE_Failure;
    }
    else
    {
        m_soName = pszNetworkName;
    }

    const char* pszNetworkDescription = CSLFetchNameValue(papszOptions,
                                                         GNM_MD_DESCR);
    if(NULL != pszNetworkDescription)
        sDescription = pszNetworkDescription;

    // check Spatial reference
    const char* pszSRS = CSLFetchNameValue(papszOptions, GNM_MD_SRS);
    if( NULL == pszSRS )
    {
        CPLError( CE_Failure, CPLE_IllegalArg,
                  "The network spatial reference should be present" );
        return CE_Failure;
    }
    else
    {
        OGRSpatialReference spatialRef;
        if (spatialRef.SetFromUserInput(pszSRS) != OGRERR_NONE)
        {
            CPLError( CE_Failure, CPLE_IllegalArg,
                      "The network spatial reference should be present" );
            return CE_Failure;
        }

        char *wktSrs = NULL;
        if (spatialRef.exportToWkt(&wktSrs) != OGRERR_NONE)
        {
            CPLError( CE_Failure, CPLE_IllegalArg,
                      "The network spatial reference should be present" );
            return CE_Failure;
        }
        m_soSRS = wktSrs;

        CPLFree(wktSrs);
    }

    int nResult = CheckNetworkExist(pszFilename, papszOptions);

    if(TRUE == nResult)
    {
        CPLError( CE_Failure, CPLE_IllegalArg, "The network already exist" );
        return CE_Failure;
    }

    // Create the necessary system layers and fields

    // Create meta layer

    CPLErr eResult = CreateMetadataLayerFromFile(pszFilename, GNM_VERSION_NUM, papszOptions);

    if(CE_None != eResult)
    {
        //an error message should come from function
        return CE_Failure;
    }

    // Create graph layer

    eResult = CreateGraphLayerFromFile(pszFilename, papszOptions);

    if(CE_None != eResult)
    {
        DeleteMetadataLayer();
        return CE_Failure;
    }

    // Create features layer

    eResult = CreateFeaturesLayerFromFile(pszFilename, papszOptions);

    if(CE_None != eResult)
    {
        DeleteMetadataLayer();
        DeleteGraphLayer();
        return CE_Failure;
    }

    return CE_None;
}
Пример #3
0
CPLErr GNMDatabaseNetwork::Create( const char* pszFilename, char** papszOptions )
{
    FormName(pszFilename, papszOptions);

    if(m_soName.empty() || m_soNetworkFullName.empty())
    {
        CPLError( CE_Failure, CPLE_IllegalArg,
                  "The network name should be present" );
        return CE_Failure;
    }

    if(NULL == m_poDS)
    {
        m_poDS = (GDALDataset*) GDALOpenEx( m_soNetworkFullName, GDAL_OF_VECTOR |
                                       GDAL_OF_UPDATE, NULL, NULL, papszOptions );
    }

    if( NULL == m_poDS )
    {
        CPLError( CE_Failure, CPLE_OpenFailed, "Open '%s' failed",
                  m_soNetworkFullName.c_str() );
        return CE_Failure;
    }

    GDALDriver *l_poDriver = m_poDS->GetDriver();
    if(NULL == l_poDriver)
    {
        CPLError( CE_Failure, CPLE_OpenFailed, "Get dataset driver failed");
        return CE_Failure;
    }

    if(!CheckStorageDriverSupport(l_poDriver->GetDescription()))
    {
        return CE_Failure;
    }

    // check required options

    const char* pszNetworkDescription = CSLFetchNameValue(papszOptions,
                                                         GNM_MD_DESCR);
    if(NULL != pszNetworkDescription)
        sDescription = pszNetworkDescription;

    // check Spatial reference
    const char* pszSRS = CSLFetchNameValue(papszOptions, GNM_MD_SRS);
    if( NULL == pszSRS )
    {
        CPLError( CE_Failure, CPLE_IllegalArg,
                  "The network spatial reference should be present" );
        return CE_Failure;
    }
    else
    {
        OGRSpatialReference spatialRef;
        if (spatialRef.SetFromUserInput(pszSRS) != OGRERR_NONE)
        {
            CPLError( CE_Failure, CPLE_IllegalArg,
                      "The network spatial reference should be present" );
            return CE_Failure;
        }

        char *wktSrs = NULL;
        if (spatialRef.exportToWkt(&wktSrs) != OGRERR_NONE)
        {
            CPLError( CE_Failure, CPLE_IllegalArg,
                      "The network spatial reference should be present" );
            return CE_Failure;
        }
        m_soSRS = wktSrs;

        CPLFree(wktSrs);
    }

    int nResult = CheckNetworkExist(pszFilename, papszOptions);

    if(TRUE == nResult)
    {
        CPLError( CE_Failure, CPLE_IllegalArg, "The network already exist" );
        return CE_Failure;
    }

    // Create the necessary system layers and fields

    // Create meta layer

    CPLErr eResult = CreateMetadataLayer(m_poDS, GNM_VERSION_NUM);

    if(CE_None != eResult)
    {
        //an error message should come from function
        return CE_Failure;    }

    // Create graph layer

    eResult = CreateGraphLayer(m_poDS);

    if(CE_None != eResult)
    {
        DeleteMetadataLayer();
        return CE_Failure;
    }

    // Create features layer

    eResult = CreateFeaturesLayer(m_poDS);

    if(CE_None != eResult)
    {
        DeleteMetadataLayer();
        DeleteGraphLayer();
        return CE_Failure;
    }

    return CE_None;
}