System::System() { // setup GDAL GDALAllRegister(); _trimOldestTiles = true; _numUnusedDatasetsToTrimFromCache = 10; _maxNumDatasets = (unsigned int)(double(vpb::getdtablesize()) * 0.8); _logDirectory = "logs"; _taskDirectory = "tasks"; _maxNumberOfFilesPerDirectory = 1000; readEnvironmentVariables(); // preload the .osg plugin so its available in case we need to output source files containing core osg nodes osgDB::Registry::instance()->loadLibrary(osgDB::Registry::instance()->createLibraryNameForExtension("osg")); GDALDriverManager *driverManager = GetGDALDriverManager(); if (driverManager) { for (int i = 0; i < driverManager->GetDriverCount(); ++i) { GDALDriver *driver = driverManager->GetDriver(i); if (driver) { const char *ext = driver->GetMetadataItem("DMD_EXTENSION"); if (ext && strlen(ext) != 0) { addSupportedExtension(ext, Source::IMAGE | Source::HEIGHT_FIELD, driver->GetMetadataItem(GDAL_DMD_LONGNAME)); } } } } // add entries that GDAL doesn't list via it's DMD_EXTENSIONS but is known to support addSupportedExtension("jpeg", Source::IMAGE | Source::HEIGHT_FIELD, "JPEG"); addSupportedExtension("tiff", Source::IMAGE | Source::HEIGHT_FIELD, "GeoTiff"); addSupportedExtension("pgm", Source::IMAGE | Source::HEIGHT_FIELD, "Netpbm"); addSupportedExtension("ppm", Source::IMAGE | Source::HEIGHT_FIELD, "Netpbm"); addSupportedExtension("shp", Source::SHAPEFILE, "Shape file loader"); addSupportedExtension("osgb", Source::MODEL, "OpenSceneGraph binary format"); addSupportedExtension("osgx", Source::MODEL, "OpenSceneGraph xml format"); addSupportedExtension("osgt", Source::MODEL, "OpenSceneGraph text/ascii format"); addSupportedExtension("osg", Source::MODEL, "OpenSceneGraph .osg ascii format"); addSupportedExtension("ive", Source::MODEL, "OpenSceneGraph .ive binary format"); }
GDALDriver *OGRSFDriverRegistrar::GetDriverByName( const char * pszName ) { GDALDriverManager* poDriverManager = GetGDALDriverManager(); GDALDriver* poGDALDriver = poDriverManager->GetDriverByName(CPLSPrintf("OGR_%s", pszName)); if( poGDALDriver == NULL ) poGDALDriver = poDriverManager->GetDriverByName(pszName); if( poGDALDriver == NULL || poGDALDriver->GetMetadataItem(GDAL_DCAP_VECTOR) == NULL ) return NULL; return poGDALDriver; }
GDALDataset* CreateGDALRaster(TeRasterParams& params) { // Gets the appropriate GDAL driver std::string path = params.fileName_; if(path.empty()) return 0; std::string extension = TeGetExtension(path.c_str()); std::string driverName = TeGDALDecoder::getGDALDriverName(extension); if(driverName.empty()) return 0; GDALDriverManager* driverManager = GetGDALDriverManager(); GDALDriver* driver = driverManager->GetDriverByName(driverName.c_str()); if(driver == 0) return 0; // Converts the raster data type GDALDataType gDataType = Convert2GDAL(params.dataType_[0]); // Creates the raster GDAL GDALDataset* ds = driver->Create(path.c_str(), params.ncols_, params.nlines_, params.nBands(), gDataType, 0); if(ds == 0) return 0; // Sets the geometric transformations double gt[6]; Convert2GDAL(gt, params); ds->SetGeoTransform(gt); // Sets the raster projection TeProjection* proj = params.projection(); if(proj) { int epsg = proj->epsgCode(); OGRSpatialReference oSRS; oSRS.importFromEPSG(epsg); char* projWKT = 0; if(oSRS.exportToWkt(&projWKT) == OGRERR_NONE) { ds->SetProjection(projWKT); OGRFree(projWKT); } } return ds; }
int OGRSFDriverRegistrar::GetDriverCount() { /* We must be careful only to return drivers that are actual OGRSFDriver* */ GDALDriverManager* poDriverManager = GetGDALDriverManager(); int nTotal = poDriverManager->GetDriverCount(); int nOGRDriverCount = 0; for(int i=0;i<nTotal;i++) { GDALDriver* poDriver = poDriverManager->GetDriver(i); if( poDriver->GetMetadataItem(GDAL_DCAP_VECTOR) != NULL ) nOGRDriverCount ++; } return nOGRDriverCount; }
GDALDataset* CreateOutputDataset(char* fileName, int width, int height, int bands) { GDALDriverManager *gdm = GetGDALDriverManager(); if(gdm == NULL) error("GetGDALDriverManager() failed!"); GDALDriver *gd = gdm->GetDriverByName("GTiff"); if(gd == NULL) error("Get GTiff Driver failed!"); char* options[2]; options[0] = "INTERLEAVE=BAND"; options[1] = NULL; GDALDataset *dstDS = gd->Create(fileName, width, height, bands, GDT_Byte, options); return dstDS; }
MAIN_START(argc, argv) { /* Check strict compilation and runtime library version as we use C++ API */ if (! GDAL_CHECK_VERSION(argv[0])) exit(1); EarlySetConfigOptions(argc, argv); /* -------------------------------------------------------------------- */ /* Generic arg processing. */ /* -------------------------------------------------------------------- */ GDALAllRegister(); argc = GDALGeneralCmdLineProcessor(argc, &argv, 0); if( argc < 1 ) exit( -argc ); for( int i = 0; i < argc; i++ ) { if( EQUAL(argv[i], "--utility_version") ) { printf("%s was compiled against GDAL %s and " "is running against GDAL %s\n", argv[0], GDAL_RELEASE_NAME, GDALVersionInfo("RELEASE_NAME")); CSLDestroy(argv); return 0; } else if( EQUAL(argv[i], "--help") ) { Usage(); } } GDALRasterizeOptionsForBinary* psOptionsForBinary = GDALRasterizeOptionsForBinaryNew(); // coverity[tainted_data] GDALRasterizeOptions *psOptions = GDALRasterizeOptionsNew(argv + 1, psOptionsForBinary); CSLDestroy(argv); if( psOptions == nullptr ) { Usage(); } if( !(psOptionsForBinary->bQuiet) ) { GDALRasterizeOptionsSetProgress(psOptions, GDALTermProgress, nullptr); } if( psOptionsForBinary->pszSource == nullptr ) Usage("No input file specified."); if( psOptionsForBinary->pszDest == nullptr ) Usage("No output file specified."); /* -------------------------------------------------------------------- */ /* Open input file. */ /* -------------------------------------------------------------------- */ GDALDatasetH hInDS = GDALOpenEx( psOptionsForBinary->pszSource, GDAL_OF_VECTOR | GDAL_OF_VERBOSE_ERROR, nullptr, nullptr, nullptr); if( hInDS == nullptr ) exit(1); /* -------------------------------------------------------------------- */ /* Open output file if it exists. */ /* -------------------------------------------------------------------- */ GDALDatasetH hDstDS = nullptr; if( !(psOptionsForBinary->bCreateOutput) ) { CPLPushErrorHandler(CPLQuietErrorHandler); hDstDS = GDALOpenEx( psOptionsForBinary->pszDest, GDAL_OF_RASTER | GDAL_OF_VERBOSE_ERROR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr ); CPLPopErrorHandler(); } if( psOptionsForBinary->pszFormat != nullptr && (psOptionsForBinary->bCreateOutput || hDstDS == nullptr) ) { GDALDriverManager *poDM = GetGDALDriverManager(); GDALDriver *poDriver = poDM->GetDriverByName(psOptionsForBinary->pszFormat); char** papszDriverMD = (poDriver) ? poDriver->GetMetadata(): nullptr; if( poDriver == nullptr || !CPLTestBool(CSLFetchNameValueDef(papszDriverMD, GDAL_DCAP_RASTER, "FALSE")) || !CPLTestBool(CSLFetchNameValueDef(papszDriverMD, GDAL_DCAP_CREATE, "FALSE")) ) { fprintf(stderr, "Output driver `%s' not recognised or does not support " "direct output file creation.\n", psOptionsForBinary->pszFormat); fprintf(stderr, "The following format drivers are configured and " "support direct output:\n" ); for( int iDriver = 0; iDriver < poDM->GetDriverCount(); iDriver++ ) { GDALDriver* poIter = poDM->GetDriver(iDriver); papszDriverMD = poIter->GetMetadata(); if( CPLTestBool( CSLFetchNameValueDef(papszDriverMD, GDAL_DCAP_RASTER, "FALSE")) && CPLTestBool( CSLFetchNameValueDef(papszDriverMD, GDAL_DCAP_CREATE, "FALSE")) ) { fprintf(stderr, " -> `%s'\n", poIter->GetDescription()); } } exit(1); } } int bUsageError = FALSE; GDALDatasetH hRetDS = GDALRasterize(psOptionsForBinary->pszDest, hDstDS, hInDS, psOptions, &bUsageError); if(bUsageError == TRUE) Usage(); const int nRetCode = hRetDS ? 0 : 1; GDALClose(hInDS); GDALClose(hRetDS); GDALRasterizeOptionsFree(psOptions); GDALRasterizeOptionsForBinaryFree(psOptionsForBinary); GDALDestroyDriverManager(); return nRetCode; }