本文整理汇总了C++中OGRSFDriver::CreateDataSource方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRSFDriver::CreateDataSource方法的具体用法?C++ OGRSFDriver::CreateDataSource怎么用?C++ OGRSFDriver::CreateDataSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRSFDriver
的用法示例。
在下文中一共展示了OGRSFDriver::CreateDataSource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OGR_Dr_CreateDataSource
OGRDataSourceH OGR_Dr_CreateDataSource( OGRSFDriverH hDriver,
const char *pszName,
char ** papszOptions )
{
VALIDATE_POINTER1( hDriver, "OGR_Dr_CreateDataSource", NULL );
OGRSFDriver* poDriver = (OGRSFDriver *) hDriver;
CPLAssert( NULL != poDriver );
OGRDataSource* poDS = NULL;
poDS = poDriver->CreateDataSource( pszName, papszOptions );
/* This fix is explained in Ticket #1223 */
if( NULL != poDS )
{
poDS->SetDriver( poDriver );
CPLAssert( NULL != poDS->GetDriver() );
}
else
{
CPLDebug( "OGR", "CreateDataSource operation failed. NULL pointer returned." );
}
return (OGRDataSourceH) poDS;
}
示例2: Create
int OGRGPSBabelWriteDataSource::Create( const char * pszName,
char **papszOptions )
{
OGRSFDriver* poGPXDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName("GPX");
if (poGPXDriver == NULL)
{
CPLError(CE_Failure, CPLE_AppDefined, "GPX driver is necessary for GPSBabel write support");
return FALSE;
}
if (!EQUALN(pszName, "GPSBABEL:", 9))
{
const char* pszOptionGPSBabelDriverName =
CSLFetchNameValue(papszOptions, "GPSBABEL_DRIVER");
if (pszOptionGPSBabelDriverName != NULL)
pszGPSBabelDriverName = CPLStrdup(pszOptionGPSBabelDriverName);
else
{
CPLError(CE_Failure, CPLE_AppDefined, "GPSBABEL_DRIVER dataset creation option expected");
return FALSE;
}
pszFilename = CPLStrdup(pszName);
}
else
{
const char* pszSep = strchr(pszName + 9, ':');
if (pszSep == NULL)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Wrong syntax. Expected GPSBabel:driver_name[,options]*:file_name");
return FALSE;
}
pszGPSBabelDriverName = CPLStrdup(pszName + 9);
*(strchr(pszGPSBabelDriverName, ':')) = '\0';
pszFilename = CPLStrdup(pszSep+1);
}
/* A bit of validation to avoid command line injection */
if (!OGRGPSBabelDataSource::IsValidDriverName(pszGPSBabelDriverName))
return FALSE;
const char* pszOptionUseTempFile = CSLFetchNameValue(papszOptions, "USE_TEMPFILE");
if (pszOptionUseTempFile == NULL)
pszOptionUseTempFile = CPLGetConfigOption("USE_TEMPFILE", NULL);
if (pszOptionUseTempFile && CSLTestBoolean(pszOptionUseTempFile))
osTmpFileName = CPLGenerateTempFilename(NULL);
else
osTmpFileName.Printf("/vsimem/ogrgpsbabeldatasource_%p", this);
poGPXDS = poGPXDriver->CreateDataSource(osTmpFileName.c_str(), papszOptions);
if (poGPXDS == NULL)
return FALSE;
this->pszName = CPLStrdup(pszName);
return TRUE;
}
示例3: init_ogr
void init_ogr(const std::string& outfile) {
OGRRegisterAll();
const char* driver_name = "SQLite";
OGRSFDriver* driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(driver_name);
if (driver == NULL) {
std::cerr << driver_name << " driver not available.\n";
exit(1);
}
CPLSetConfigOption("OGR_SQLITE_SYNCHRONOUS", "FALSE");
const char* options[] = { "SPATIALITE=TRUE", NULL };
m_data_source = driver->CreateDataSource(outfile.c_str(), const_cast<char**>(options));
if (m_data_source == NULL) {
std::cerr << "Creation of output file failed.\n";
exit(1);
}
m_layer_point = init_layer("planet_osm_point", m_fields_nodes, wkbPoint);
m_layer_line = init_layer("planet_osm_line", m_fields_ways, wkbLineString);
m_layer_polygon = init_layer("planet_osm_polygon", m_fields_areas, wkbMultiPolygon);
stringv fields_roads;
fields_roads.push_back("railway");
fields_roads.push_back("highway");
fields_roads.push_back("boundary");
m_layer_roads = init_layer("planet_osm_roads", fields_roads, wkbLineString);
}
示例4: HootException
shared_ptr<OGRDataSource> OgrUtilities::createDataSource(QString url)
{
const char* driverName = NULL;
int i = 0;
while (extensions[i][0] != NULL)
{
if (url.endsWith(extensions[i][0]))
{
driverName = extensions[i][1];
}
i++;
}
i = 0;
while (beginName[i][0] != NULL)
{
if (url.startsWith(beginName[i][0]))
{
driverName = beginName[i][1];
}
i++;
}
if (driverName == NULL)
{
throw HootException("No driver found for: " + url);
}
OGRSFDriver* driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(driverName);
if (driver == 0)
{
throw HootException("Error getting driver by name: " + QString(driverName));
}
// if the user specifies a shapefile then crop off the .shp and create a directory.
if (url.toLower().endsWith(".shp"))
{
url = url.mid(0, url.length() - 4);
}
shared_ptr<OGRDataSource> result(driver->CreateDataSource(url.toAscii()));
if (result == NULL)
{
throw HootException("Unable to create data source: " + url +
" (" + QString(CPLGetLastErrorMsg()) + ")");
}
result->SetDriver(driver);
if (QString(driverName) == "FileGDB")
{
long v = GDAL_VERSION_MAJOR * 1000000 + GDAL_VERSION_MINOR * 1000 + GDAL_VERSION_REV;
long lowest = 1 * 1000000 + 10 * 1000 + 1;
if (v < lowest)
{
LOG_WARN("Writing to FileGDB with GDAL v" << GDAL_RELEASE_NAME << ". FileGDB with a GDAL "
"v1.9.0 is known to create files that can't be read by ArcMap 10.2. "
"GDAL v1.10.1 is known to work.");
}
}
return result;
}
示例5: Create
bool COGR_DataSource::Create(const CSG_String &File, const CSG_String &DriverName)
{
OGRSFDriver *pDriver;
Destroy();
if( (pDriver = g_OGR_Driver.Get_Driver(DriverName)) != NULL )
{
m_pDataSource = pDriver->CreateDataSource(SG_STR_SGTOMB(File), NULL);
}
return( m_pDataSource != NULL );
}
示例6: VectorCreate
OGRDataSource * VectorCreate( const char * pszFormat, const char * pszFilename, char ** papszOptions/*=NULL*/ )
{
OGRSFDriver * poDriver = GetVectorDriver(pszFormat);
OGRDataSource * poOGRDataSource =
poDriver->CreateDataSource(pszFilename, papszOptions);
#ifdef TRACEON
//测试时使用文件型数据库,没有图层时打开有问题,因此在这里放一个图层
//这样才能打开,不用测试可以关闭,在release中没有
poOGRDataSource->CreateLayer("TEMP", NULL, wkbUnknown, NULL);
#endif
return poOGRDataSource;
}
示例7: return
OGRDataSource *AoIIntersection::buildIntersectionDataSource ( const char *outFmt )
{
// get driver registrar
OGRSFDriverRegistrar *reg = OGRSFDriverRegistrar::GetRegistrar();
// create an OGRDataSource
OGRSFDriver *driverToUse = reg->GetDriverByName( outFmt );
if ( driverToUse )
{
return( driverToUse->CreateDataSource( "C:\\Minerva\\Data\\intersection.mem", NULL ) );
}
return 0;
}
示例8:
JNIEXPORT jlong JNICALL Java_es_gva_cit_jogr_OGRSFDriver_createDataSourceNat
(JNIEnv *env, jobject obj, jlong cPtr, jstring pszName){
OGRSFDriver *drv = (OGRSFDriver *) 0 ;
drv = *(OGRSFDriver **)&cPtr;
OGRDataSource *ds;
long ptr_ds;
const char *name = env->GetStringUTFChars( pszName, 0);
ds = drv->CreateDataSource(name);
env->ReleaseStringUTFChars( pszName, name);
if(ds==NULL)return -1;
ptr_ds = (long)&(*ds);
return (jlong)ptr_ds;
}
示例9: MyOGRHandler
MyOGRHandler(const std::string& filename) :
m_data_source(NULL),
m_layer_point(NULL),
m_filter(true),
m_tohstore() {
OGRRegisterAll();
OGRSFDriver* driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName("PostgreSQL");
if (driver == NULL) {
std::cerr << "PostgreSQL OGR driver not available.\n";
exit(1);
}
// using COPY is much faster than INSERT
CPLSetConfigOption("PG_USE_COPY", "YES");
const char* options[] = { NULL };
m_data_source = driver->CreateDataSource(filename.c_str(), const_cast<char**>(options));
if (m_data_source == NULL) {
std::cerr << "Database open failed.\n";
exit(1);
}
// OGR can't create a table with hstore column, so we do it ourselves here
OGRLayer* dummy = m_data_source->ExecuteSQL("CREATE TABLE nodes (id VARCHAR, tags hstore);", NULL, NULL);
if (dummy) {
m_data_source->ReleaseResultSet(dummy);
}
dummy = m_data_source->ExecuteSQL("SELECT AddGeometryColumn('nodes', 'geom', 4326, 'POINT', 2);", NULL, NULL);
if (dummy) {
m_data_source->ReleaseResultSet(dummy);
}
m_layer_point = m_data_source->GetLayerByName("nodes");
if (!m_layer_point) {
std::cerr << "Something went wrong setting up the 'nodes' layer.\n";
exit(1);
}
// using transactions makes this much faster than without
m_layer_point->StartTransaction();
m_filter.add(false, "created_by");
m_filter.add(false, "odbl");
}
示例10: output_ogr
void output_ogr(const std::string& filename, const std::string& driver_name, const segvec& removed_segments, const segvec& added_segments) {
OGRRegisterAll();
OGRSFDriver* driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(driver_name.c_str());
if (!driver) {
std::cerr << driver_name << " driver not available.\n";
exit(return_code_fatal);
}
//const char* options[] = { "SPATIALITE=yes", "OGR_SQLITE_SYNCHRONOUS=OFF", "INIT_WITH_EPSG=no", nullptr };
const char* options[] = { nullptr };
auto data_source = std::unique_ptr<OGRDataSource, OGRDataSourceDestroyer>(driver->CreateDataSource(filename.c_str(), const_cast<char**>(options)));
if (!data_source) {
std::cerr << "Creation of output file failed.\n";
exit(return_code_fatal);
}
SRS srs;
auto layer = data_source->CreateLayer("changes", srs.out(), wkbLineString, const_cast<char**>(options));
if (!layer) {
std::cerr << "Creating layer 'changes' failed.\n";
exit(return_code_fatal);
}
OGRFieldDefn field_change("change", OFTInteger);
field_change.SetWidth(1);
if (layer->CreateField(&field_change) != OGRERR_NONE ) {
std::cerr << "Creating field 'change' on 'changes' layer failed.\n";
exit(return_code_fatal);
}
layer->StartTransaction();
for (const auto& segment : removed_segments) {
add_segment(layer, 0, segment);
}
for (const auto& segment : added_segments) {
add_segment(layer, 1, segment);
}
layer->CommitTransaction();
}
示例11: initialize_database
OGRDataSource* initialize_database(const std::string& output_format, const std::string& output_filename) {
OGRRegisterAll();
OGRSFDriver* driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(output_format.c_str());
if (!driver) {
std::cerr << output_format << " driver not available.\n";
exit(1);
}
CPLSetConfigOption("OGR_SQLITE_SYNCHRONOUS", "FALSE");
const char* options[] = { "SPATIALITE=TRUE", nullptr };
OGRDataSource* data_source = driver->CreateDataSource(output_filename.c_str(), const_cast<char**>(options));
if (!data_source) {
std::cerr << "Creation of output file failed.\n";
exit(1);
}
return data_source;
}
示例12: main
//.........这里部分代码省略.........
edge_list.clear();
edge_list.shrink_to_fit();
SimpleLogger().Write() << "Starting SCC graph traversal";
RestrictionMap restriction_map(restriction_list);
auto tarjan = osrm::make_unique<TarjanSCC<TarjanDynamicGraph>>(graph,
restriction_map,
bollard_node_list);
tarjan->run();
SimpleLogger().Write() << "identified: " << tarjan->get_number_of_components()
<< " many components";
SimpleLogger().Write() << "identified " << tarjan->get_size_one_count() << " SCCs of size 1";
// output
TIMER_START(SCC_RUN_SETUP);
// remove files from previous run if exist
DeleteFileIfExists("component.dbf");
DeleteFileIfExists("component.shx");
DeleteFileIfExists("component.shp");
Percent p(graph->GetNumberOfNodes());
OGRRegisterAll();
const char *pszDriverName = "ESRI Shapefile";
OGRSFDriver *poDriver =
OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(pszDriverName);
if (nullptr == poDriver)
{
throw osrm::exception("ESRI Shapefile driver not available");
}
OGRDataSource *poDS = poDriver->CreateDataSource("component.shp", nullptr);
if (nullptr == poDS)
{
throw osrm::exception("Creation of output file failed");
}
OGRSpatialReference *poSRS = new OGRSpatialReference();
poSRS->importFromEPSG(4326);
OGRLayer *poLayer = poDS->CreateLayer("component", poSRS, wkbLineString, nullptr);
if (nullptr == poLayer)
{
throw osrm::exception("Layer creation failed.");
}
TIMER_STOP(SCC_RUN_SETUP);
SimpleLogger().Write() << "shapefile setup took " << TIMER_MSEC(SCC_RUN_SETUP)/1000. << "s";
uint64_t total_network_distance = 0;
p.reinit(graph->GetNumberOfNodes());
TIMER_START(SCC_OUTPUT);
for (const NodeID source : osrm::irange(0u, graph->GetNumberOfNodes()))
{
p.printIncrement();
for (const auto current_edge : graph->GetAdjacentEdgeRange(source))
{
const TarjanDynamicGraph::NodeIterator target = graph->GetTarget(current_edge);
if (source < target || graph->EndEdges(target) == graph->FindEdge(target, source))
{
total_network_distance +=
100 * FixedPointCoordinate::ApproximateEuclideanDistance(
示例13: ExportToGISFile
void CDlg_GISDataExchange::ExportToGISFile(LPCTSTR lpszCSVFileName,LPCTSTR lpszShapeFileName, CString GISTypeString )
{
#ifndef _WIN64
m_MessageList.ResetContent ();
CWaitCursor wait;
CCSVParser parser;
int i= 0;
// open csv file
if (parser.OpenCSVFile(lpszCSVFileName))
{
CString message_str;
OGRSFDriver *poDriver;
OGRRegisterAll();
poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(GISTypeString );
if( poDriver == NULL )
{
message_str.Format ( "%s driver not available.", GISTypeString );
m_MessageList.AddString (message_str);
return;
}
OGRDataSource *poDS;
poDS = poDriver->CreateDataSource(lpszShapeFileName, NULL );
if( poDS == NULL )
{
message_str.Format ( "Creation of GIS output file %s failed.\nPlease do not overwrite the exiting file and please select a new file name.",
lpszShapeFileName );
m_MessageList.AddString (message_str);
return;
}
///// export to link layer
// link layer
OGRLayer *poLayer;
poLayer = poDS->CreateLayer( "link", NULL, wkbLineString, NULL );
if( poLayer == NULL )
{
m_MessageList.AddString ("link Layer creation failed");
return;
}
vector<string> HeaderVector = parser.GetHeaderVector();
std::vector <CString> LongFieldVector;
for(unsigned int i = 0; i < HeaderVector.size(); i++)
{
if(HeaderVector[i].find ("geometry") != string::npos|| HeaderVector[i].find ("name") != string::npos || HeaderVector[i].find ("code") != string::npos)
{
OGRFieldDefn oField (HeaderVector[i].c_str (), OFTString);
CString str;
if( poLayer->CreateField( &oField ) != OGRERR_NONE )
{
str.Format("Creating field %s failed", oField.GetNameRef());
m_MessageList.AddString (str);
return;
}
}else
{
CString field_string = HeaderVector[i].c_str ();
OGRFieldDefn oField (field_string, OFTReal);
CString str;
if( poLayer->CreateField( &oField ) != OGRERR_NONE )
{
str.Format("Creating field %s failed", oField.GetNameRef());
m_MessageList.AddString (str);
return;
}
}
if(HeaderVector[i].size()>=11)
{
LongFieldVector.push_back (HeaderVector[i].c_str ());
}
}
message_str.Format ("%d fields have been created.",HeaderVector.size());
m_MessageList.AddString (message_str);
//.........这里部分代码省略.........
示例14: main
int main(int argc, char **argv)
{
// Get data from ogr
OGRRegisterAll();
std::cout << "Opening: " << argv[1] << std::endl;
OGRDataSource *shp = OGRSFDriverRegistrar::Open(argv[1], FALSE);
IsValid(shp, "Error opening file.");
std::cout << "Shape contains " << shp->GetLayerCount() << " layers." << std::endl;
OGRLayer *layer = shp->GetLayerByName(argv[2]);
IsValid(layer, "Couldn't grab layer");
OGRSpatialReference *srcSRS = NULL;
srcSRS = layer->GetSpatialRef();
// Set up writing
const char *kDriverName = "ESRI Shapefile";
OGRSFDriver *shpDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(kDriverName);
IsValid(shpDriver, "Couldn't grab the shapefile driver.");
IsValid(argv[3], "Please provide a output shp.");
std::cout << "Writing to: " << argv[3] << std::endl;
OGRDataSource *shpOut = shpDriver->CreateDataSource(argv[3], NULL);
IsValid(shpOut, "Couldn't open output file");
OGRLayer *outLayer = shpOut->CreateLayer(layer->GetName(), srcSRS, wkbMultiLineString, NULL);
IsValid(outLayer, "Couldn't create an output layer");
// copy over the fields from the source file
OGRFeatureDefn *source = layer->GetLayerDefn();
for(int i=0; i < source->GetFieldCount(); i++){
OGRFieldDefn *field = source->GetFieldDefn(i);
if(outLayer->CreateField(field) != OGRERR_NONE) {
std::cout << "Couldn't make layer" << std::endl; exit(1);
};
}
// Loop through features and grab the hull and put it into CGAL then
// skeletonize the points
OGRFeature *feature;
int count = 0;
while((feature = layer->GetNextFeature()) != NULL)
{
OGRMultiPolygon *geometry = dynamic_cast<OGRMultiPolygon *>(OGRGeometryFactory::forceToMultiPolygon(feature->GetGeometryRef()));
IsValid(geometry, "No geometry.");
OGRFeature *outFeature = OGRFeature::CreateFeature(outLayer->GetLayerDefn());
IsValid(outFeature, "Couldn't make a feature.");
for(int i=0; i < source->GetFieldCount(); i++){
OGRField *field = feature->GetRawFieldRef(i);
outFeature->SetField(i, field);
}
OGRGeometry* line = NULL;
for(int i=0; i < geometry->getNumGeometries(); i++){
OGRGeometry* segment = BuildMultiLine(geometry->getGeometryRef(i));
if(segment != NULL){
if(line == NULL) { line = new OGRLineString; }
OGRGeometry* tmp = line->Union(segment);
if(tmp != NULL){
delete line;
line = tmp;
}
delete segment;
}
}
outFeature->SetGeometry(line);
if(outLayer->CreateFeature(outFeature) != OGRERR_NONE){
std::cout << "Couldn't create feature." << std::endl;
exit(1);
}
// clean up
OGRFeature::DestroyFeature(outFeature);
std::cout << std::endl << ++count << std::endl;
}
// cleanup
OGRDataSource::DestroyDataSource(shp);
OGRDataSource::DestroyDataSource(shpOut);
return 0;
}
示例15: export_
// export
bool ImportExportGdal::export_(const QList<Feature *>& featList)
{
const char *pszDriverName = "SQLite";
OGRSFDriver *poDriver;
OGRRegisterAll();
poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(pszDriverName);
if( poDriver == NULL )
{
qDebug( "%s driver not available.", pszDriverName );
return false;
}
OGRDataSource *poDS;
QFile::remove(QString(HOMEDIR + "/test.sqlite"));
poDS = poDriver->CreateDataSource( QString(HOMEDIR + "/test.sqlite").toUtf8().constData(), NULL );
if( poDS == NULL )
{
qDebug( "Creation of output file failed." );
return false;
}
poDS->ExecuteSQL("PRAGMA synchronous = OFF", NULL, NULL);
OGRSpatialReference *poSRS;
poSRS = new OGRSpatialReference();
poSRS->importFromEPSG(4326);
char **papszOptions = NULL;
papszOptions = CSLSetNameValue( papszOptions, "SPATIALITE", "YES" );
papszOptions = CSLSetNameValue( papszOptions, "FORMAT", "SPATIALITE" );
papszOptions = CSLSetNameValue( papszOptions, "SPATIAL_INDEX", "YES" );
OGRLayer *poLayer;
poLayer = poDS->CreateLayer( "osm", poSRS, wkbUnknown, papszOptions);
CSLDestroy( papszOptions );
if( poLayer == NULL )
{
qDebug( "Layer creation failed." );
return false;
}
OGRFieldDefn oField("osm_id", OFTReal);
if( poLayer->CreateField( &oField ) != OGRERR_NONE )
{
qDebug( "Creating field failed." );
return false;
}
oField.Set("osm_version", OFTInteger );
poLayer->CreateField( &oField );
oField.Set("osm_timestamp", OFTInteger );
poLayer->CreateField( &oField );
OGRFeature *poFeature;
foreach (Feature* F, featList) {
poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );
poFeature->SetField( "osm_id", (qreal)(F->id().numId));
#ifndef FRISIUS_BUILD
poFeature->SetField( "osm_version", F->versionNumber());
poFeature->SetField( "osm_timestamp", (int)F->time().toTime_t());
#endif
if (CHECK_NODE(F)) {
Node* N = STATIC_CAST_NODE(F);
OGRPoint pt;
pt.setX(N->position().x());
pt.setY(N->position().y());
poFeature->SetGeometry( &pt );
} else if (CHECK_WAY(F)) {
Way* W = STATIC_CAST_WAY(F);
OGRLineString ls;
ls.setNumPoints(W->size());
for (int i=0; i<W->size(); ++i) {
ls.setPoint(i, W->getNode(i)->position().x(), W->getNode(i)->position().y(), 0);
}
poFeature->SetGeometry( &ls );
}
if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE )
{
qDebug( "Failed to create feature in output." );
return false;
}
OGRFeature::DestroyFeature( poFeature );
}