//#include "s57.h" int main(int argc, char **argv) { OGRRegisterAll(); OGRDataSource *poDS; printf("Opening %s\n",argv[1]); poDS = OGRSFDriverRegistrar::Open( argv[1], FALSE ); if( poDS == NULL ) { printf( "Open failed.\n" ); exit( 1 ); } OGRLayer *poLayer; int layers = poDS->GetLayerCount(); for (int layer =0 ; layer< layers; layer++) { poLayer = poDS->GetLayer(layer); if (poLayer == NULL) continue; printf("%d, %s, %s",layer, poLayer->GetName(), OGRGeometryTypeToName(poLayer->GetGeomType())); poLayer->ResetReading(); OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn(); int iField; for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ ) { OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn( iField ); printf(", %s",poFieldDefn->GetNameRef()); } printf("\n"); } }
bool MyApp::OnInit() { #ifdef __LINUX__ setlocale (LC_ALL,"POSIX"); #endif register_all_file_formats(); #if GILVIEWER_USE_GDAL OGRRegisterAll(); #endif // GILVIEWER_USE_GDAL try { if ( InitFrame() ) m_mainFrameDock->Show(); else exit(0); } catch( std::exception &e ) { wxString message; message << wxString(e.what(), *wxConvCurrent); wxMessageBox( message ); } catch( ... ) { wxMessageBox( _("Unhandled exception ...") ); } return true; }
void QgsNewOgrConnection::testConnection() { QString uri; uri = createDatabaseURI( cmbDatabaseTypes->currentText(), txtHost->text(), txtDatabase->text(), txtPort->text(), mAuthSettingsDatabase->configId(), mAuthSettingsDatabase->username(), mAuthSettingsDatabase->password(), true ); QgsDebugMsg( "Connecting using uri = " + uri ); OGRRegisterAll(); OGRDataSourceH poDS; OGRSFDriverH pahDriver; CPLErrorReset(); poDS = OGROpen( uri.toUtf8().constData(), false, &pahDriver ); if ( !poDS ) { QMessageBox::information( this, tr( "Test Connection" ), tr( "Connection failed - Check settings and try again.\n\nExtended error information:\n%1" ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) ); } else { QMessageBox::information( this, tr( "Test Connection" ), tr( "Connection to %1 was successful." ).arg( uri ) ); OGRReleaseDataSource( poDS ); } }
void QgsApplication::registerOgrDrivers() { if ( 0 >= OGRGetDriverCount() ) { OGRRegisterAll(); } }
SEXP RGDAL_Init(void) { // CPLSetErrorHandler((CPLErrorHandler)__errorHandler); // CPLPushErrorHandler((CPLErrorHandler)__errorHandler); #ifdef GDALV2 installErrorHandler(); GDALAllRegister(); uninstallErrorHandlerAndTriggerError(); #else installErrorHandler(); GDALAllRegister(); uninstallErrorHandlerAndTriggerError(); installErrorHandler(); OGRRegisterAll(); uninstallErrorHandlerAndTriggerError(); #endif return(R_NilValue); }
/*! \brief Open database (OGR datasource) \param handle pointer to dbHandle (db name and schema) \return DB_OK on success \return DB_FAILED on failure */ int db__driver_open_database(dbHandle * handle) { const char *name; dbConnection connection; init_error(); db_get_connection(&connection); name = db_get_handle_dbname(handle); /* if name is empty use connection.databaseName */ if (strlen(name) == 0) name = connection.databaseName; G_debug(3, "db_driver_open_database() name = '%s'", name); OGRRegisterAll(); hDs = OGROpen(name, TRUE, NULL); if (hDs == NULL) { append_error(_("Unable to open OGR data source")); report_error(); return DB_FAILED; } G_debug(3, "Datasource opened"); return DB_OK; }
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); }
bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs ) { QgsDebugMsg( "mPath = " + mPath ); OGRRegisterAll(); OGRSFDriverH hDriver; OGRDataSourceH hDataSource = OGROpen( TO8F( mPath ), true, &hDriver ); if ( !hDataSource ) return false; QString driverName = OGR_Dr_GetName( hDriver ); OGR_DS_Destroy( hDataSource ); // we are able to assign CRS only to shapefiles :-( if ( driverName == "ESRI Shapefile" ) { QString layerName = mPath.left( mPath.indexOf( ".shp", Qt::CaseInsensitive ) ); QString wkt = crs.toWkt(); // save ordinary .prj file OGRSpatialReferenceH hSRS = OSRNewSpatialReference( wkt.toLocal8Bit().data() ); OSRMorphToESRI( hSRS ); // this is the important stuff for shapefile .prj char* pszOutWkt = NULL; OSRExportToWkt( hSRS, &pszOutWkt ); QFile prjFile( layerName + ".prj" ); if ( prjFile.open( QIODevice::WriteOnly ) ) { QTextStream prjStream( &prjFile ); prjStream << pszOutWkt << endl; prjFile.close(); } else { QgsMessageLog::logMessage( tr( "Couldn't open file %1.prj" ).arg( layerName ), tr( "OGR" ) ); return false; } OSRDestroySpatialReference( hSRS ); CPLFree( pszOutWkt ); // save qgis-specific .qpj file (maybe because of better wkt compatibility?) QFile qpjFile( layerName + ".qpj" ); if ( qpjFile.open( QIODevice::WriteOnly ) ) { QTextStream qpjStream( &qpjFile ); qpjStream << wkt.toLocal8Bit().data() << endl; qpjFile.close(); } else { QgsMessageLog::logMessage( tr( "Couldn't open file %1.qpj" ).arg( layerName ), tr( "OGR" ) ); return false; } return true; } // It it is impossible to assign a crs to an existing layer // No OGR_L_SetSpatialRef : http://trac.osgeo.org/gdal/ticket/4032 return false; }
void CShapefileLayer::OpenShapefile(const std::string& filename) { m_FileName_ = filename; OGRRegisterAll(); std::string pszDriverName = "ESRI Shapefile"; //CPLSetConfigOption("SHAPE_ENCODING", ""); //支持中文 OGRSFDriver* poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(pszDriverName.c_str()); m_pDataSource_ = poDriver->Open(m_FileName_.c_str(), false); //打开shapefile文件,获取数据源 if(m_pDataSource_ == NULL) { m_bExistFile_ = false; return; } m_pLayer_ = m_pDataSource_->GetLayer(0); //获取shapefile第0层 if(m_pLayer_ == NULL) { m_bExistFile_ = false; return ; } int theFeatureCount = m_pLayer_->GetFeatureCount(); //层里面的数据数量 OGRFeature *poFeature = NULL; //读取的数据指针 m_pLayer_->ResetReading(); //重新读取 m_ShapefileType_ = m_pLayer_->GetLayerDefn()->GetGeomType(); //类型 m_bExistFile_ = true; }
/* From https://github.com/iamaleksey/iconverl/blob/master/c_src/iconverl.c */ static int load(ErlNifEnv *env, void **priv, ERL_NIF_TERM load_info) { OGRRegisterAll(); OGR_DS_RESOURCE = enif_open_resource_type( env, NULL, "ogr_ds_resource", &datasource_destroy, ERL_NIF_RT_CREATE | ERL_NIF_RT_TAKEOVER, NULL); OGR_F_RESOURCE = enif_open_resource_type( env, NULL, "ogr_f_resource", &feature_destroy, ERL_NIF_RT_CREATE | ERL_NIF_RT_TAKEOVER, NULL); OGR_FD_RESOURCE = enif_open_resource_type( env, NULL, "ogr_fd_resource", &feature_defn_destroy, ERL_NIF_RT_CREATE | ERL_NIF_RT_TAKEOVER, NULL); OGR_FLD_RESOURCE = enif_open_resource_type( env, NULL, "ogr_fld_resource", &field_defn_destroy, ERL_NIF_RT_CREATE | ERL_NIF_RT_TAKEOVER, NULL); OGR_G_RESOURCE = enif_open_resource_type( env, NULL, "ogr_g_resource", &geometry_destroy, ERL_NIF_RT_CREATE | ERL_NIF_RT_TAKEOVER, NULL); OGR_D_RESOURCE = enif_open_resource_type( env, NULL, "ogr_d_resource", NULL, ERL_NIF_RT_CREATE | ERL_NIF_RT_TAKEOVER, NULL); OGR_L_RESOURCE = enif_open_resource_type( env, NULL, "ogr_l_resource", &layer_destroy, ERL_NIF_RT_CREATE | ERL_NIF_RT_TAKEOVER, NULL); return 0; }
virtual ReadResult readFile(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { if (OGRSFDriverRegistrar::GetRegistrar()->GetDriverCount() == 0) OGRRegisterAll(); // Try to open data source OGRDataSource* file = OGRSFDriverRegistrar::Open(fileName.c_str()); if (!file) return 0; bool useRandomColorByFeature = false; bool addGroupPerFeature = false; if (options) { if (options->getOptionString().find("UseRandomColorByFeature") != std::string::npos) useRandomColorByFeature = true; if (options->getOptionString().find("useRandomColorByFeature") != std::string::npos) useRandomColorByFeature = true; if (options->getOptionString().find("addGroupPerFeature") != std::string::npos) addGroupPerFeature = true; } osg::Group* group = new osg::Group; for (int i = 0; i < file->GetLayerCount(); i++) { osg::Group* node = readLayer(file->GetLayer(i), file->GetName(), useRandomColorByFeature, addGroupPerFeature); if (node) group->addChild( node ); } OGRDataSource::DestroyDataSource( file ); return group; }
// Initialize libraries, register the atexit handler and set up error reporting. void simplet_init(){ if(initialized) return; simplet_error_init(); OGRRegisterAll(); atexit(cleanup); initialized = 1; };
GdalTestData() { GDALAllRegister(); OGRRegisterAll(); fetch = NULL; poDS = NULL; pszFilename = CPLFormFilename( NULL, CPLGenerateTempFilename( "GDAL_TEST" ), ".tif" ); }
// Initialize libraries, register the atexit handler and set up error reporting. void simplet_init() { if (initialized) return; CPLSetConfigOption("OGR_ENABLE_PARTIAL_REPROJECTION", "ON"); #ifdef DEBUG CPLSetConfigOption("CPL_DEBUG", "ON"); #endif OGRRegisterAll(); GDALAllRegister(); atexit(cleanup); initialized = 1; };
//-------------------------------------------------------------- void GeoData::setup() { #ifdef USE_OGR OGRRegisterAll(); datasource = OGRSFDriverRegistrar::Open(dataSourceName.c_str(), FALSE); #endif startThread(true, false); // blocking, non-verbose }
rspfGdalFactory* rspfGdalFactory::instance() { if(!theInstance) { theInstance = new rspfGdalFactory; CPLSetErrorHandler((CPLErrorHandler)CPLQuietErrorHandler); GDALAllRegister(); OGRRegisterAll(); } return theInstance; }
SEXP RGDAL_Init(void) { CPLSetErrorHandler((CPLErrorHandler)__errorHandler); GDALAllRegister(); OGRRegisterAll(); return(R_NilValue); }
ERMsg COGRBaseOption::ParseOption(int argc, char* argv[]) { ERMsg msg; // Must process GDAL_SKIP before GDALAllRegister(), but we can't call // GDALGeneralCmdLineProcessor before it needs the drivers to be registered // for the --format or --formats options for (int i = 1; i < argc; i++) { if (IsEqual(argv[i], "--config") && i + 2 < argc && IsEqual(argv[i + 1], "GDAL_SKIP")) { CPLSetConfigOption(argv[i + 1], argv[i + 2]); i += 2; } } // -------------------------------------------------------------------- // Register standard GDAL drivers, and process generic GDAL // command options. // -------------------------------------------------------------------- OGRRegisterAll(); argc = OGRGeneralCmdLineProcessor(argc, &argv, 0); if (argc < 1) exit(-argc); // -------------------------------------------------------------------- // Parse arguments. // -------------------------------------------------------------------- for (int i = 1; i < argc; i++) { msg += ProcessOption(i, argc, argv); } if (m_bVersion) { string error = Format("%s was compiled against GDAL %s and is running against GDAL %s\n", argv[0], GDAL_RELEASE_NAME, GDALVersionInfo("RELEASE_NAME")); msg.ajoute(error); //return msg; } if (m_bNeedHelp) { msg.ajoute(GetUsage()); msg.ajoute(GetHelp()); //return msg; } return msg; }
QgsShapeFile::QgsShapeFile(QString name){ filename = name; features = 0; OGRRegisterAll(); ogrDataSource = OGRSFDriverRegistrar::Open((const char *) filename); if (ogrDataSource != NULL){ valid = true; ogrLayer = ogrDataSource->GetLayer(0); features = ogrLayer->GetFeatureCount(); } else valid = false; setDefaultTable(); }
AddDatastoreItemDialog::AddDatastoreItemDialog(const QStringList& ExistingIDs, QWidget* Parent): openfluid::ui::common::OpenFLUIDDialog(Parent),ui(new(Ui::EditDatastoreItemDialog)), m_ExistingIDs(ExistingIDs) { ui->setupUi(this); GDALAllRegister(); OGRRegisterAll(); m_OGRFormatsStr = openfluid::utils::getOGRGDALFormatsForQFileDialogs(openfluid::utils::getOGRFilesDriversForOpenFLUID(), tr("All vector files")); m_GDALFormatsStr = openfluid::utils::getOGRGDALFormatsForQFileDialogs(openfluid::utils::getGDALFilesDriversForOpenFLUID(), tr("All raster files")); setMessage(); ui->StaticIDLabel->setVisible(false); ui->GeovectorRadioButton->setChecked(true); ui->CopyRadioButton->setChecked(true); connect(ui->IDEdit,SIGNAL(textEdited(const QString&)),this,SLOT(checkGlobal())); connect(ui->UnitsClassCheckBox,SIGNAL(toggled(bool)),this,SLOT(checkGlobal())); connect(ui->UnitsClassEdit,SIGNAL(textEdited(const QString&)),this,SLOT(checkGlobal())); connect(ui->GeovectorRadioButton,SIGNAL(toggled(bool)),this,SLOT(checkGlobal())); connect(ui->GeorasterRadioButton,SIGNAL(toggled(bool)),this,SLOT(checkGlobal())); connect(ui->CopyRadioButton,SIGNAL(toggled(bool)),this,SLOT(checkGlobal())); connect(ui->CopySubdirRadioButton,SIGNAL(toggled(bool)),this,SLOT(checkGlobal())); connect(ui->CopySubdirEdit,SIGNAL(textEdited(const QString&)),this,SLOT(checkGlobal())); connect(ui->GeovectorBrowseButton,SIGNAL(clicked()),this,SLOT(selectVectorFile())); connect(ui->GeorasterBrowseButton,SIGNAL(clicked()),this,SLOT(selectRasterFile())); // completer for units classes openfluid::ui::common::ShortcutCompleter* Completer = new openfluid::ui::common::ShortcutCompleter(ProjectCentral::instance()->unitsClassesList(),this); Completer->linkToLineEdit(ui->UnitsClassEdit); connect(Completer,SIGNAL(activated(const QString&)),this,SLOT(checkGlobal())); ui->IDEdit->setPlaceholderText(getPlaceholderRequired()); connect(ui->ButtonBox,SIGNAL(accepted()),this,SLOT(accept())); connect(ui->ButtonBox,SIGNAL(rejected()),this,SLOT(reject())); checkGlobal(); }
int S57_ogrLoadCell(const char *filename, S52_loadLayer_cb loadLayer_cb, S52_loadObject_cb loadObject_cb) { // check that geometric data type are in sync with OpenGL if (sizeof(geocoord) != sizeof(double)) { PRINTF("ERROR: sizeof(geocoord) != sizeof(double)\n"); g_assert(0); } OGRRegisterAll(); //_ogrLoadCell(filename, loadLayer_cb); _ogrLoadCell(filename, loadLayer_cb, loadObject_cb); return TRUE; }
void GlobalEnvironment::wakeGDALDrivers() { static std::once_flag flag; auto init = [this]() -> void { if (!m_gdalAwake) { GDALAllRegister(); OGRRegisterAll(); m_gdalAwake = true; } }; std::call_once(flag, init); }
int Raster::VectortoRaster(const char * sVectorSourcePath, const char * sRasterOutputPath, double dCellWidth, const char * psFieldName){ OGRRegisterAll(); OGRDataSource * pDSVectorInput; pDSVectorInput = OGRSFDriverRegistrar::Open( sVectorSourcePath, FALSE ); if (pDSVectorInput == NULL) return INPUT_FILE_ERROR; // Get the extents of the file before passing it off to the function that actually burns // the geometries // ------------------------------------------------------- // Note: we're just grabbing the first layer here. If we get into needing multiple layers // Then we'll need to re-think this. OGRLayer * poLayer = pDSVectorInput->GetLayer(0); if (poLayer == NULL) return VECTOR_LAYER_NOT_FOUND; OGREnvelope psExtent; poLayer->GetExtent(&psExtent, TRUE); double dMaxY, dMaxX, dMinY, dMinX; double cellWidth = fabs(dCellWidth); dMaxY = ceil(psExtent.MaxY / cellWidth) * cellWidth; dMaxX = ceil(psExtent.MaxX / cellWidth) * cellWidth; dMinY = floor(psExtent.MinY / cellWidth) * cellWidth; dMinX = floor(psExtent.MinX / cellWidth) * cellWidth; int nRows = (int)((dMaxY - dMinY) / cellWidth); int nCols = (int)((dMaxX - dMinX) / cellWidth); \ // We're going to create them without projections. The projections get set later. double fNoDataValue = (double) -std::numeric_limits<float>::max(); GDALDataType nDType = GDT_Float32; double dCellHeight = -dCellWidth; RasterMeta TemplateRaster(psExtent.MaxY, psExtent.MinX, nRows, nCols, &dCellHeight, &dCellWidth, &fNoDataValue, "GTiff", &nDType, ""); pDSVectorInput->Release(); return VectortoRaster(sVectorSourcePath, sRasterOutputPath, psFieldName, &TemplateRaster); }
QgsLayerItem::Capability QgsOgrLayerItem::capabilities() { QgsDebugMsg( "mPath = " + mPath ); OGRRegisterAll(); OGRSFDriverH hDriver; OGRDataSourceH hDataSource = OGROpen( TO8F( mPath ), true, &hDriver ); if ( !hDataSource ) return NoCapabilities; QString driverName = OGR_Dr_GetName( hDriver ); OGR_DS_Destroy( hDataSource ); if ( driverName == "ESRI Shapefile" ) return SetCrs; return NoCapabilities; }
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"); }
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(); }
int main(int argc, char *argv[]) { struct GModule *module; struct _options options; struct _flags flags; G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("vector")); G_add_keyword(_("export")); G_add_keyword(_("output")); G_add_keyword(_("external")); module->description = _("Defines vector output format utilizing OGR library."); OGRRegisterAll(); parse_args(argc, argv, &options, &flags); if (flags.f->answer) { list_formats(); exit(EXIT_SUCCESS); } if (flags.r->answer) { G_remove("", "OGR"); exit(EXIT_SUCCESS); } if (options.format->answer) check_format(options.format->answer); if (options.dsn->answer) make_link(options.dsn->answer, options.format->answer, options.opts->answers); if (flags.p->answer || flags.g->answer) { print_status(flags.g->answer ? 1 : 0); } exit(EXIT_SUCCESS); }
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; }
int main(int argc, char* argv[]) { fprintf(stderr, "GeoTIFF to CONSOLE PRINTER\nVersion %s.%s. Free software. GNU General Public License, version 3\n", PROG_VERSION, DATE_VERSION); fprintf(stderr, "Copyright (C) 2016 Igor Garkusha.\nUkraine, Dnipro (Dnipropetrovsk)\n\n"); if(!((argc==6)||(argc==8)||(argc==10))) { fputs("Input parameters not found!\n", stderr); printHelp(); return 1; } int headerFormat = 1; int BandNumber = 0; char separator = '\x20'; char SHPMaskFile[MAX_PATH] = ""; for(int i=1; i<argc-2; i++) { if(0 == strcmp(argv[i], "-f")) headerFormat = getHeaderFormat(argv[i], argv[i+1]); else if(0 == strcmp(argv[i], "-b")) BandNumber = getBand(argv[i], argv[i+1]); else if(0 == strcmp(argv[i], "-s")) { if(0 == strcmp(argv[i+1], "space")) separator = '\x20'; else if(0 == strcmp(argv[i+1], "tab")) separator = '\t'; else if(1 == strlen(argv[i+1])) separator = argv[i+1][0]; // else default -> '\x20' } else if(0 == strcmp(argv[i], "-m")) strcpy(SHPMaskFile, argv[i+1]); } OGRRegisterAll(); GDALAllRegister(); if((ERROR != headerFormat)&&(ERROR != BandNumber)) { doTif2Con(argv[argc-1], headerFormat, BandNumber, separator, SHPMaskFile); return 0; } else { printHelp(); return 1; } }
GDALWConnection * GDALWConnect(char * source) { GDALWConnection * conn = NULL; OGRFeatureDefnH featureDefn; int fieldCount, i; OGRRegisterAll(); conn = malloc(sizeof(GDALWConnection)); if (conn == NULL) { fprintf(stderr, "Could not allocate memory\n"); return NULL; } conn->handler = OGROpen(source, 0 , &(conn->driver)); if (conn->handler == NULL) { free(conn); return NULL; } conn->layer = OGR_DS_GetLayer(conn->handler, 0); if (conn->layer == NULL) { OGRReleaseDataSource(conn->handler); free(conn); return NULL; } conn->layername = (const char *) OGR_L_GetName(conn->layer); featureDefn = OGR_L_GetLayerDefn(conn->layer); fieldCount = OGR_FD_GetFieldCount(featureDefn); conn->numFieldDefinitions = fieldCount; conn->fieldDefinitions = malloc(fieldCount * sizeof(OGRFieldDefnH)); if (conn->fieldDefinitions == NULL) { OGRReleaseDataSource(conn->handler); free(conn); fprintf(stderr, "Could not allocate memory\n"); return NULL; } for (i=0 ; i<fieldCount ; i++) { conn->fieldDefinitions[i] = OGR_FD_GetFieldDefn(featureDefn, i); } return conn; }