这篇教程C++ GDALClose函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中GDALClose函数的典型用法代码示例。如果您正苦于以下问题:C++ GDALClose函数的具体用法?C++ GDALClose怎么用?C++ GDALClose使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了GDALClose函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: GDALComputeProximity//.........这里部分代码省略......... pdfSrcNoData, nTargetValues, panTargetValues ); // Write out results. eErr = GDALRasterIO( hWorkProximityBand, GF_Write, 0, iLine, nXSize, 1, pafProximity, nXSize, 1, GDT_Float32, 0, 0 ); if( eErr != CE_None ) break; if( !pfnProgress( 0.5 * (iLine+1) / (double) nYSize, "", pProgressArg ) ) { CPLError( CE_Failure, CPLE_UserInterrupt, "User terminated" ); eErr = CE_Failure; } }/* -------------------------------------------------------------------- *//* Loop from bottom to top of the image. *//* -------------------------------------------------------------------- */ for( i = 0; i < nXSize; i++ ) panNearX[i] = panNearY[i] = -1; for( iLine = nYSize-1; eErr == CE_None && iLine >= 0; iLine-- ) { // Read first pass proximity eErr = GDALRasterIO( hWorkProximityBand, GF_Read, 0, iLine, nXSize, 1, pafProximity, nXSize, 1, GDT_Float32, 0, 0 ); if( eErr != CE_None ) break; // Read pixel values. eErr = GDALRasterIO( hSrcBand, GF_Read, 0, iLine, nXSize, 1, panSrcScanline, nXSize, 1, GDT_Int32, 0, 0 ); if( eErr != CE_None ) break; // Right to left ProcessProximityLine( panSrcScanline, panNearX, panNearY, FALSE, iLine, nXSize, dfMaxDist, pafProximity, pdfSrcNoData, nTargetValues, panTargetValues ); // Left to right ProcessProximityLine( panSrcScanline, panNearX, panNearY, TRUE, iLine, nXSize, dfMaxDist, pafProximity, pdfSrcNoData, nTargetValues, panTargetValues ); // Final post processing of distances. for( i = 0; i < nXSize; i++ ) { if( pafProximity[i] < 0.0 ) pafProximity[i] = fNoDataValue; else if( pafProximity[i] > 0.0 ) { if( bFixedBufVal ) pafProximity[i] = (float) dfFixedBufVal; else pafProximity[i] = (float)(pafProximity[i] * dfDistMult); } } // Write out results. eErr = GDALRasterIO( hProximityBand, GF_Write, 0, iLine, nXSize, 1, pafProximity, nXSize, 1, GDT_Float32, 0, 0 ); if( eErr != CE_None ) break; if( !pfnProgress( 0.5 + 0.5 * (nYSize-iLine) / (double) nYSize, "", pProgressArg ) ) { CPLError( CE_Failure, CPLE_UserInterrupt, "User terminated" ); eErr = CE_Failure; } }/* -------------------------------------------------------------------- *//* Cleanup *//* -------------------------------------------------------------------- */end: CPLFree( panNearX ); CPLFree( panNearY ); CPLFree( panSrcScanline ); CPLFree( pafProximity ); CPLFree(panTargetValues); if( hWorkProximityDS != NULL ) { CPLString osProxFile = GDALGetDescription( hWorkProximityDS ); GDALClose( hWorkProximityDS ); GDALDeleteDataset( GDALGetDriverByName( "GTiff" ), osProxFile ); } return eErr;}
开发者ID:drownedout,项目名称:datamap,代码行数:101,
示例2: main//.........这里部分代码省略......... } } CSLDestroy( argv ); CSLDestroy( papszExtraMDDomains ); GDALDumpOpenDatasets( stderr ); GDALDestroyDriverManager(); CPLDumpSharedList( NULL ); exit( 1 ); } /* -------------------------------------------------------------------- *//* Read specified subdataset if requested. *//* -------------------------------------------------------------------- */ if ( nSubdataset > 0 ) { char **papszSubdatasets = GDALGetMetadata( hDataset, "SUBDATASETS" ); int nSubdatasets = CSLCount( papszSubdatasets ); if ( nSubdatasets > 0 && nSubdataset <= nSubdatasets ) { char szKeyName[1024]; char *pszSubdatasetName; snprintf( szKeyName, sizeof(szKeyName), "SUBDATASET_%d_NAME", nSubdataset ); szKeyName[sizeof(szKeyName) - 1] = '/0'; pszSubdatasetName = CPLStrdup( CSLFetchNameValue( papszSubdatasets, szKeyName ) ); GDALClose( hDataset ); hDataset = GDALOpen( pszSubdatasetName, GA_ReadOnly ); CPLFree( pszSubdatasetName ); } else { fprintf( stderr, "gdalinfo warning: subdataset %d of %d requested. " "Reading the main dataset./n", nSubdataset, nSubdatasets ); } }/* -------------------------------------------------------------------- *//* Report general info. *//* -------------------------------------------------------------------- */ hDriver = GDALGetDatasetDriver( hDataset ); printf( "Driver: %s/%s/n", GDALGetDriverShortName( hDriver ), GDALGetDriverLongName( hDriver ) ); papszFileList = GDALGetFileList( hDataset ); if( CSLCount(papszFileList) == 0 ) { printf( "Files: none associated/n" ); } else { printf( "Files: %s/n", papszFileList[0] ); if( bShowFileList ) { for( i = 1; papszFileList[i] != NULL; i++ )
开发者ID:TUW-GEO,项目名称:OGRSpatialRef3D,代码行数:67,
示例3: msTransformToGeospatialPDFstatic void msTransformToGeospatialPDF(imageObj *img, mapObj *map, cairo_renderer *r){ /* We need a GDAL 1.10 PDF driver at runtime, but as far as the C API is concerned, GDAL 1.9 is */ /* largely sufficient. */#if defined(USE_GDAL) && defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1900 GDALDatasetH hDS = NULL; const char* pszGEO_ENCODING = NULL; GDALDriverH hPDFDriver = NULL; const char* pszVirtualIO = NULL; int bVirtualIO = FALSE; char* pszTmpFilename = NULL; VSILFILE* fp = NULL; if (map == NULL) return; pszGEO_ENCODING = msGetOutputFormatOption(img->format, "GEO_ENCODING", NULL); if (pszGEO_ENCODING == NULL) return; msGDALInitialize(); hPDFDriver = GDALGetDriverByName("PDF"); if (hPDFDriver == NULL) return; /* When compiled against libpoppler, the PDF driver is VirtualIO capable */ /* but not, when it is compiled against libpodofo. */ pszVirtualIO = GDALGetMetadataItem( hPDFDriver, GDAL_DCAP_VIRTUALIO, NULL ); if (pszVirtualIO) bVirtualIO = CSLTestBoolean(pszVirtualIO); if (bVirtualIO) pszTmpFilename = msTmpFile(map, NULL, "/vsimem/mscairopdf/", "pdf"); else pszTmpFilename = msTmpFile(map, map->mappath, NULL, "pdf"); /* Copy content of outputStream buffer into file */ fp = VSIFOpenL(pszTmpFilename, "wb"); if (fp == NULL) { msFree(pszTmpFilename); return; } VSIFWriteL(r->outputStream->data, 1, r->outputStream->size, fp); VSIFCloseL(fp); fp = NULL; hDS = GDALOpen(pszTmpFilename, GA_Update); if ( hDS != NULL ) { char* pszWKT = msProjectionObj2OGCWKT( &(map->projection) ); if( pszWKT != NULL ) { double adfGeoTransform[6]; int i; /* Add user-specified options */ for( i = 0; i < img->format->numformatoptions; i++ ) { const char* pszOption = img->format->formatoptions[i]; if( strncasecmp(pszOption,"METADATA_ITEM:",14) == 0 ) { char* pszKey = NULL; const char* pszValue = CPLParseNameValue(pszOption + 14, &pszKey); if( pszKey != NULL ) { GDALSetMetadataItem(hDS, pszKey, pszValue, NULL); CPLFree(pszKey); } } } /* We need to rescale the geotransform because GDAL will not necessary */ /* open the PDF with the DPI that was used to generate it */ memcpy(adfGeoTransform, map->gt.geotransform, 6 * sizeof(double)); adfGeoTransform[1] = adfGeoTransform[1] * map->width / GDALGetRasterXSize(hDS); adfGeoTransform[5] = adfGeoTransform[5] * map->height / GDALGetRasterYSize(hDS); GDALSetGeoTransform(hDS, adfGeoTransform); GDALSetProjection(hDS, pszWKT); msFree( pszWKT ); pszWKT = NULL; CPLSetThreadLocalConfigOption("GDAL_PDF_GEO_ENCODING", pszGEO_ENCODING); GDALClose(hDS); hDS = NULL; CPLSetThreadLocalConfigOption("GDAL_PDF_GEO_ENCODING", NULL); /* We need to replace the buffer with the content of the GDAL file */ fp = VSIFOpenL(pszTmpFilename, "rb"); if( fp != NULL ) { int nFileSize; VSIFSeekL(fp, 0, SEEK_END); nFileSize = (int)VSIFTellL(fp); msBufferResize(r->outputStream, nFileSize); VSIFSeekL(fp, 0, SEEK_SET); r->outputStream->size = VSIFReadL(r->outputStream->data, 1, nFileSize, fp); VSIFCloseL(fp);//.........这里部分代码省略.........
开发者ID:KaiJancke,项目名称:mapserver,代码行数:101,
示例4: MAIN_START//.........这里部分代码省略......... iLayer); exit(1); } if( !bAllLayers ) { printf("%d: %s", iLayer + 1, poLayer->GetName()); const int nGeomFieldCount = poLayer->GetLayerDefn()->GetGeomFieldCount(); if( nGeomFieldCount > 1 ) { printf(" ("); for( int iGeom = 0; iGeom < nGeomFieldCount; iGeom++ ) { if( iGeom > 0 ) printf(", "); OGRGeomFieldDefn* poGFldDefn = poLayer->GetLayerDefn()-> GetGeomFieldDefn(iGeom); printf( "%s", OGRGeometryTypeToName( poGFldDefn->GetType())); } printf(")"); } else if( poLayer->GetGeomType() != wkbUnknown ) printf(" (%s)", OGRGeometryTypeToName( poLayer->GetGeomType())); printf("/n"); } else { if( iRepeat != 0 ) poLayer->ResetReading(); ReportOnLayer(poLayer, pszWHERE, pszGeomField, poSpatialFilter, bListMDD, bShowMetadata, papszExtraMDDomains, bFeatureCount, bExtent, pszWKTFormat); } } } else {/* -------------------------------------------------------------------- *//* Process specified data source layers. *//* -------------------------------------------------------------------- */ for( char** papszIter = papszLayers; *papszIter != nullptr; ++papszIter ) { OGRLayer *poLayer = poDS->GetLayerByName(*papszIter); if( poLayer == nullptr ) { printf("FAILURE: Couldn't fetch requested layer %s!/n", *papszIter); exit(1); } if( iRepeat != 0 ) poLayer->ResetReading(); ReportOnLayer(poLayer, pszWHERE, pszGeomField, poSpatialFilter, bListMDD, bShowMetadata, papszExtraMDDomains, bFeatureCount, bExtent, pszWKTFormat); } } }/* -------------------------------------------------------------------- *//* Close down. *//* -------------------------------------------------------------------- */ GDALClose(poDS);#ifdef __AFL_HAVE_MANUAL_CONTROL }#elseend:#endif CSLDestroy(papszArgv); CSLDestroy(papszLayers); CSLDestroy(papszOptions); CSLDestroy(papszOpenOptions); CSLDestroy(papszExtraMDDomains); if( poSpatialFilter ) OGRGeometryFactory::destroyGeometry(poSpatialFilter); CPLFree(pszSQLStatement); CPLFree(pszWHERE); OGRCleanupAll(); return nRet;}
开发者ID:AsgerPetersen,项目名称:gdal,代码行数:101,
示例5: qDeleteAll//.........这里部分代码省略......... // if crs transform needed if ( it->raster->crs() != mOutputCrs ) { QgsRasterProjector proj; proj.setCrs( it->raster->crs(), mOutputCrs ); proj.setInput( it->raster->dataProvider() ); proj.setPrecision( QgsRasterProjector::Exact ); block = proj.block( it->bandNumber, mOutputRectangle, mNumOutputColumns, mNumOutputRows ); } else { block = it->raster->dataProvider()->block( it->bandNumber, mOutputRectangle, mNumOutputColumns, mNumOutputRows ); } if ( block->isEmpty() ) { delete block; delete calcNode; qDeleteAll( inputBlocks ); return static_cast<int>( MemoryError ); } inputBlocks.insert( it->ref, block ); } //open output dataset for writing GDALDriverH outputDriver = openOutputDriver(); if ( !outputDriver ) { return static_cast< int >( CreateOutputError ); } GDALDatasetH outputDataset = openOutputFile( outputDriver ); GDALSetProjection( outputDataset, mOutputCrs.toWkt().toLocal8Bit().data() ); GDALRasterBandH outputRasterBand = GDALGetRasterBand( outputDataset, 1 ); float outputNodataValue = -FLT_MAX; GDALSetRasterNoDataValue( outputRasterBand, outputNodataValue ); if ( p ) { p->setMaximum( mNumOutputRows ); } QgsRasterMatrix resultMatrix; resultMatrix.setNodataValue( outputNodataValue ); //read / write line by line for ( int i = 0; i < mNumOutputRows; ++i ) { if ( p ) { p->setValue( i ); } if ( p && p->wasCanceled() ) { break; } if ( calcNode->calculate( inputBlocks, resultMatrix, i ) ) { bool resultIsNumber = resultMatrix.isNumber(); float* calcData = new float[mNumOutputColumns]; for ( int j = 0; j < mNumOutputColumns; ++j ) { calcData[j] = ( float )( resultIsNumber ? resultMatrix.number() : resultMatrix.data()[j] ); } //write scanline to the dataset if ( GDALRasterIO( outputRasterBand, GF_Write, 0, i, mNumOutputColumns, 1, calcData, mNumOutputColumns, 1, GDT_Float32, 0, 0 ) != CE_None ) { QgsDebugMsg( "RasterIO error!" ); } delete[] calcData; } } if ( p ) { p->setValue( mNumOutputRows ); } //close datasets and release memory delete calcNode; qDeleteAll( inputBlocks ); inputBlocks.clear(); if ( p && p->wasCanceled() ) { //delete the dataset without closing (because it is faster) GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) ); return static_cast< int >( Cancelled ); } GDALClose( outputDataset ); return static_cast< int >( Success );}
开发者ID:3liz,项目名称:Quantum-GIS,代码行数:101,
示例6: d// Slot called when the menu item is triggered// If you created more menu items / toolbar buttons in initiGui, you should// create a separate handler for each action - this single run() method will// not be enoughvoid Heatmap::run(){ HeatmapGui d( mQGisIface->mainWindow(), QgisGui::ModalDialogFlags, &mSessionSettings ); if ( d.exec() == QDialog::Accepted ) { // everything runs here // Get the required data from the dialog QgsRectangle myBBox = d.bbox(); int columns = d.columns(); int rows = d.rows(); double cellsize = d.cellSizeX(); // or d.cellSizeY(); both have the same value mDecay = d.decayRatio(); int kernelShape = d.kernelShape(); // Start working on the input vector QgsVectorLayer* inputLayer = d.inputVectorLayer(); // Getting the rasterdataset in place GDALAllRegister(); GDALDataset *emptyDataset; GDALDriver *myDriver; myDriver = GetGDALDriverManager()->GetDriverByName( d.outputFormat().toUtf8() ); if ( myDriver == NULL ) { QMessageBox::information( 0, tr( "GDAL driver error" ), tr( "Cannot open the driver for the specified format" ) ); return; } double geoTransform[6] = { myBBox.xMinimum(), cellsize, 0, myBBox.yMinimum(), 0, cellsize }; emptyDataset = myDriver->Create( d.outputFilename().toUtf8(), columns, rows, 1, GDT_Float32, NULL ); emptyDataset->SetGeoTransform( geoTransform ); // Set the projection on the raster destination to match the input layer emptyDataset->SetProjection( inputLayer->crs().toWkt().toLocal8Bit().data() ); GDALRasterBand *poBand; poBand = emptyDataset->GetRasterBand( 1 ); poBand->SetNoDataValue( NO_DATA ); float* line = ( float * ) CPLMalloc( sizeof( float ) * columns ); for ( int i = 0; i < columns ; i++ ) { line[i] = NO_DATA; } // Write the empty raster for ( int i = 0; i < rows ; i++ ) { poBand->RasterIO( GF_Write, 0, i, columns, 1, line, columns, 1, GDT_Float32, 0, 0 ); } CPLFree( line ); //close the dataset GDALClose(( GDALDatasetH ) emptyDataset ); // open the raster in GA_Update mode GDALDataset *heatmapDS; heatmapDS = ( GDALDataset * ) GDALOpen( TO8F( d.outputFilename() ), GA_Update ); if ( !heatmapDS ) { QMessageBox::information( 0, tr( "Raster update error" ), tr( "Could not open the created raster for updating. The heatmap was not generated." ) ); return; } poBand = heatmapDS->GetRasterBand( 1 ); QgsAttributeList myAttrList; int rField = 0; int wField = 0; // Handle different radius options double radius; double radiusToMapUnits = 1; int myBuffer = 0; if ( d.variableRadius() ) { rField = d.radiusField(); myAttrList.append( rField ); QgsDebugMsg( QString( "Radius Field index received: %1" ).arg( rField ) ); // If not using map units, then calculate a conversion factor to convert the radii to map units if ( d.radiusUnit() == HeatmapGui::Meters ) { radiusToMapUnits = mapUnitsOf( 1, inputLayer->crs() ); } } else { radius = d.radius(); // radius returned by d.radius() is already in map units myBuffer = bufferSize( radius, cellsize ); } if ( d.weighted() ) { wField = d.weightField();//.........这里部分代码省略.........
开发者ID:AnAvidDeveloper,项目名称:QGIS,代码行数:101,
示例7: main//.........这里部分代码省略......... GDALAllRegister(); // Geotiff oeffnen printf("# IN FILE: %s/n", ifile); GDALDatasetH h_dset = GDALOpen( ifile, GA_ReadOnly); printf("# OUT FILE: %s/n", ofile); printf("# EXTENTION: %s/n", ext); // Transformation holen if( GDALGetGeoTransform( h_dset, trfm ) == CE_None ) { printf("# TRANSFORM: /n"); printf("# X = %.6f + %.6f * COL + %.6f * ROW/n", trfm[0], trfm[1], trfm[2] ); printf("# Y = %.6f + %.6f * COL + %.6f * ROW/n# EOF:/n", trfm[3], trfm[4], trfm[5] ); } else { error_exit(10, "Keine Transformation im TIFF vorhanden!/n"); } // Geotiff Fehler abfangen if( h_dset == NULL ) { error_exit(10, "Datensatz %s kann nicht geoeffnet werden!/n", ifile); } // Bilddimensionen ermitteln int img_width = GDALGetRasterXSize( h_dset ); int img_height = GDALGetRasterYSize( h_dset ); int num_bands = GDALGetRasterCount (h_dset ); // Bilddimensionen ermitteln GDALRasterBandH h_band[num_bands]; GDALDataType h_type[num_bands]; int h_tsize[num_bands]; for(int b=0 ; b<num_bands; b++) { h_band[b] = GDALGetRasterBand( h_dset, b+1 ); h_type[b] = GDALGetRasterDataType(h_band[b]); h_tsize[b] = GDALGetDataTypeSize(h_type[b]); } // Erzeuge Bildschnitte for (int c=0; c< pos_x.length; c++ ) { // Welt zu Pixeltransformation long icol = -1; long irow = -1; trfm_geo_pix(trfm, pos_x.data[c], pos_y.data[c], &icol , &irow); // Dateinamen erzeugen sprintf(cfile,"%s.%d%s",ofile, id.data[c],ext); // Test ob das Schnittfenstrer passt if (icol-size/2<=0 || irow-size/2<=0 || icol+size/2>=img_width || irow+size/2>=img_height){ printf ("IGN %d %s/n",id.data[c],ofile); continue; } // Schneiden printf ("ADD %d %s/n",id.data[c],ofile); int ioffs_col = icol-size/2; int ioffs_row = irow-size/2; // Tiff-Datei anlegen // char **options = NULL; GDALDatasetH h_dset_out = GDALCreate( h_drv, cfile, size, size, num_bands, h_type[0], NULL); // Iteration ueber alle Baender for (int b=0; b< num_bands; b++) { // IO Buffer allozieren @todo static void *io_buffer = CPLMalloc(h_tsize[0] * size * size); // Pixel lesen GDALRasterIO( h_band[b], GF_Read, ioffs_col, ioffs_row, size, size, io_buffer, size, size, h_type[b], 0, 0 ); // Pixel schreiben GDALRasterBandH h_band_out = GDALGetRasterBand(h_dset_out, b+1); GDALRasterIO( h_band_out, GF_Write, 0, 0, size, size, io_buffer, size, size, h_type[b], 0, 0 ); // IO Buffer freigeben CPLFree(io_buffer); } // resultierendes Tiff flushen und schliessen GDALClose( h_dset_out ); } // EOF Positions // Eingangsbild GDALClose( h_dset); return 0;}
开发者ID:ifaoe,项目名称:2014-10-Bird-View,代码行数:101,
示例8: main//.........这里部分代码省略......... if (pszWkt && pszWkt[0]) { hSRS = OSRNewSpatialReference(pszWkt); } if (pszLayerName == NULL) pszLayerName = CPLStrdup(CPLGetBasename(pszDstFilename)); hOGRLayer = OGR_DS_CreateLayer( hOGRDS, pszLayerName, hSRS, eType, NULL); if (hSRS) OSRDestroySpatialReference(hSRS); if (hOGRLayer == NULL) { fprintf(stderr, "Can't create layer %s/n", pszLayerName); exit(1); } if (eType != wkbPoint25D) { OGRFieldDefnH hFieldDefn = OGR_Fld_Create( "z", OFTReal ); OGR_L_CreateField(hOGRLayer, hFieldDefn, 0); OGR_Fld_Destroy( hFieldDefn ); } } padfBuffer = (double*)CPLMalloc(nXSize * sizeof(double));#define GET_X(j, i) adfGeotransform[0] + (j) * adfGeotransform[1] + (i) * adfGeotransform[2]#define GET_Y(j, i) adfGeotransform[3] + (j) * adfGeotransform[4] + (i) * adfGeotransform[5]#define GET_XY(j, i) GET_X(j, i), GET_Y(j, i)/* -------------------------------------------------------------------- *//* "Translate" the source dataset *//* -------------------------------------------------------------------- */ for(i=0;i<nYSize;i+=yStep) { GDALRasterIO( hBand, GF_Read, 0, i, nXSize, 1, padfBuffer, nXSize, 1, GDT_Float64, 0, 0); for(j=0;j<nXSize;j+=xStep) { if (fOut) { fprintf(fOut, "%f,%f,%f/n", GET_XY(j + .5, i + .5), padfBuffer[j]); } else { OGRFeatureH hFeature = OGR_F_Create(OGR_L_GetLayerDefn(hOGRLayer)); OGRGeometryH hGeometry = OGR_G_CreateGeometry(eType); if (eType == wkbPoint25D) { OGR_G_SetPoint(hGeometry, 0, GET_XY(j + .5, i + .5), padfBuffer[j]); } else if (eType == wkbPoint) { OGR_G_SetPoint_2D(hGeometry, 0, GET_XY(j + .5, i + .5)); OGR_F_SetFieldDouble(hFeature, 0, padfBuffer[j]); } else { OGRGeometryH hLinearRing = OGR_G_CreateGeometry(wkbLinearRing); OGR_G_SetPoint_2D(hLinearRing, 0, GET_XY(j + 0, i + 0)); OGR_G_SetPoint_2D(hLinearRing, 1, GET_XY(j + 1, i + 0)); OGR_G_SetPoint_2D(hLinearRing, 2, GET_XY(j + 1, i + 1)); OGR_G_SetPoint_2D(hLinearRing, 3, GET_XY(j + 0, i + 1)); OGR_G_SetPoint_2D(hLinearRing, 4, GET_XY(j + 0, i + 0)); OGR_G_AddGeometryDirectly(hGeometry, hLinearRing); OGR_F_SetFieldDouble(hFeature, 0, padfBuffer[j]); } OGR_F_SetGeometryDirectly(hFeature, hGeometry); OGR_L_CreateFeature(hOGRLayer, hFeature); OGR_F_Destroy(hFeature); } } }/* -------------------------------------------------------------------- *//* Cleanup *//* -------------------------------------------------------------------- */ if (fOut) fclose(fOut); else OGR_DS_Destroy(hOGRDS); GDALClose(hDS); CPLFree(padfBuffer); CPLFree(pszLayerName); GDALDumpOpenDatasets( stderr ); GDALDestroyDriverManager(); OGRCleanupAll(); CSLDestroy( argv ); return 0;}
开发者ID:MattLatt,项目名称:GDAL_2.0.x_VC,代码行数:101,
示例9: main//.........这里部分代码省略......... int bHasNoData;/* -------------------------------------------------------------------- *//* Identify arguments. *//* -------------------------------------------------------------------- */ for( iArg = 1; iArg < argc; iArg++ ) { if( EQUAL(argv[iArg],"-trim") ) bEnableTrim = TRUE; else if( EQUAL(argv[iArg],"-fill") ) nFillDist = atoi(argv[++iArg]); else if( EQUAL(argv[iArg],"-level") ) nOutLevel = atoi(argv[++iArg]); else { if( pszFilename != NULL ) Usage(); pszFilename = argv[iArg]; } } if( pszFilename == NULL ) Usage();/* -------------------------------------------------------------------- *//* Open input file. *//* -------------------------------------------------------------------- */ GDALAllRegister(); hSrcDS = GDALOpen( pszFilename, GA_ReadOnly ); if( hSrcDS == NULL ) exit(1); hSrcBand = GDALGetRasterBand( hSrcDS, 1 ); noDataValue = (GInt16)GDALGetRasterNoDataValue(hSrcBand, &bHasNoData); nXSize = GDALGetRasterXSize( hSrcDS ); nYSize = GDALGetRasterYSize( hSrcDS ); GDALGetGeoTransform( hSrcDS, adfGeoTransform );/* -------------------------------------------------------------------- *//* Create output stream. *//* -------------------------------------------------------------------- */ pStream = DTEDCreatePtStream( ".", nOutLevel ); if( pStream == NULL ) exit( 1 );/* -------------------------------------------------------------------- *//* Process all the profiles. *//* -------------------------------------------------------------------- */ panData = (GInt16 *) malloc(sizeof(GInt16) * nXSize); for( iY = 0; iY < nYSize; iY++ ) { GDALRasterIO( hSrcBand, GF_Read, 0, iY, nXSize, 1, panData, nXSize, 1, GDT_Int16, 0, 0 ); if (bHasNoData) { for( iX = 0; iX < nXSize; iX++ ) { if (panData[iX] == noDataValue) panData[iX] = DTED_NODATA_VALUE; } } for( iX = 0; iX < nXSize; iX++ ) { DTEDWritePt( pStream, adfGeoTransform[0] + adfGeoTransform[1] * (iX + 0.5) + adfGeoTransform[2] * (iY + 0.5), adfGeoTransform[3] + adfGeoTransform[4] * (iX + 0.5) + adfGeoTransform[5] * (iY + 0.5), panData[iX] ); } } free( panData );/* -------------------------------------------------------------------- *//* Cleanup. *//* -------------------------------------------------------------------- */ if( bEnableTrim ) DTEDPtStreamTrimEdgeOnlyTiles( pStream ); if( nFillDist > 0 ) DTEDFillPtStream( pStream, nFillDist ); DTEDClosePtStream( pStream ); GDALClose( hSrcDS ); exit( 0 );}
开发者ID:469447793,项目名称:World-Wind-Java,代码行数:101,
示例10: MAIN_START//.........这里部分代码省略......... GDALTranslateOptionsFree(psOptions); GDALTranslateOptionsForBinaryFree(psOptionsForBinary); GDALDestroyDriverManager(); exit(1); } }/* -------------------------------------------------------------------- *//* Attempt to open source file. *//* -------------------------------------------------------------------- */ GDALDatasetH hDataset = GDALOpenEx(psOptionsForBinary->pszSource, GDAL_OF_RASTER | GDAL_OF_VERBOSE_ERROR, nullptr, psOptionsForBinary->papszOpenOptions, nullptr); if( hDataset == nullptr ) { GDALDestroyDriverManager(); exit( 1 ); }/* -------------------------------------------------------------------- *//* Handle subdatasets. *//* -------------------------------------------------------------------- */ if( !psOptionsForBinary->bCopySubDatasets && GDALGetRasterCount(hDataset) == 0 && CSLCount(GDALGetMetadata( hDataset, "SUBDATASETS" )) > 0 ) { fprintf( stderr, "Input file contains subdatasets. Please, select one of them for reading./n" ); GDALClose( hDataset ); GDALDestroyDriverManager(); exit( 1 ); } int bUsageError = FALSE; GDALDatasetH hOutDS = nullptr; if( psOptionsForBinary->bCopySubDatasets && CSLCount(GDALGetMetadata( hDataset, "SUBDATASETS" )) > 0 ) { char **papszSubdatasets = GDALGetMetadata(hDataset,"SUBDATASETS"); char *pszSubDest = static_cast<char *>( CPLMalloc(strlen(psOptionsForBinary->pszDest) + 32)); CPLString osPath = CPLGetPath(psOptionsForBinary->pszDest); CPLString osBasename = CPLGetBasename(psOptionsForBinary->pszDest); CPLString osExtension = CPLGetExtension(psOptionsForBinary->pszDest); CPLString osTemp; const char* pszFormat = nullptr; if ( CSLCount(papszSubdatasets)/2 < 10 ) { pszFormat = "%s_%d"; } else if ( CSLCount(papszSubdatasets)/2 < 100 ) { pszFormat = "%s_%002d"; } else { pszFormat = "%s_%003d"; }
开发者ID:AsgerPetersen,项目名称:gdal,代码行数:66,
示例11: FindSRSint FindSRS( const char *pszInput, OGRSpatialReference &oSRS ){ int bGotSRS = FALSE; VSILFILE *fp = NULL; GDALDataset *poGDALDS = NULL; OGRLayer *poLayer = NULL; const char *pszProjection = NULL; CPLErrorHandler oErrorHandler = NULL; int bIsFile = FALSE; OGRErr eErr = OGRERR_NONE; int bDebug = FALSE; /* temporarily suppress error messages we may get from xOpen() */ bDebug = CSLTestBoolean(CPLGetConfigOption("CPL_DEBUG", "OFF")); if ( ! bDebug ) oErrorHandler = CPLSetErrorHandler ( CPLQuietErrorHandler ); /* Test if argument is a file */ fp = VSIFOpenL( pszInput, "r" ); if ( fp ) { bIsFile = TRUE; VSIFCloseL( fp ); CPLDebug( "gdalsrsinfo", "argument is a file" ); } /* try to open with GDAL */ if( strncmp(pszInput, "http://spatialreference.org/", strlen("http://spatialreference.org/")) != 0 ) { CPLDebug( "gdalsrsinfo", "trying to open with GDAL" ); poGDALDS = (GDALDataset *) GDALOpenEx( pszInput, 0, NULL, NULL, NULL ); } if ( poGDALDS != NULL ) { pszProjection = poGDALDS->GetProjectionRef( ); if( pszProjection != NULL && pszProjection[0] != '/0' ) { char* pszProjectionTmp = (char*) pszProjection; if( oSRS.importFromWkt( &pszProjectionTmp ) == OGRERR_NONE ) { CPLDebug( "gdalsrsinfo", "got SRS from GDAL" ); bGotSRS = TRUE; } } else if( poGDALDS->GetLayerCount() > 0 ) { poLayer = poGDALDS->GetLayer( 0 ); if ( poLayer != NULL ) { OGRSpatialReference *poSRS = poLayer->GetSpatialRef( ); if ( poSRS != NULL ) { CPLDebug( "gdalsrsinfo", "got SRS from OGR" ); bGotSRS = TRUE; OGRSpatialReference* poSRSClone = poSRS->Clone(); oSRS = *poSRSClone; OGRSpatialReference::DestroySpatialReference( poSRSClone ); } } } GDALClose( (GDALDatasetH) poGDALDS ); if ( ! bGotSRS ) CPLDebug( "gdalsrsinfo", "did not open with GDAL" ); } /* Try ESRI file */ if ( ! bGotSRS && bIsFile && (strstr(pszInput,".prj") != NULL) ) { CPLDebug( "gdalsrsinfo", "trying to get SRS from ESRI .prj file [%s]", pszInput ); char **pszTemp; if ( strstr(pszInput,"ESRI::") != NULL ) pszTemp = CSLLoad( pszInput+6 ); else pszTemp = CSLLoad( pszInput ); if( pszTemp ) { eErr = oSRS.importFromESRI( pszTemp ); CSLDestroy( pszTemp ); } else eErr = OGRERR_UNSUPPORTED_SRS; if( eErr != OGRERR_NONE ) { CPLDebug( "gdalsrsinfo", "did not get SRS from ESRI .prj file" ); } else { CPLDebug( "gdalsrsinfo", "got SRS from ESRI .prj file" ); bGotSRS = TRUE; } } /* Last resort, try OSRSetFromUserInput() */ if ( ! bGotSRS ) { CPLDebug( "gdalsrsinfo", "trying to get SRS from user input [%s]", pszInput ); eErr = oSRS.SetFromUserInput( pszInput ); if( eErr != OGRERR_NONE ) { CPLDebug( "gdalsrsinfo", "did not get SRS from user input" ); } else {//.........这里部分代码省略.........
开发者ID:garnertb,项目名称:gdal,代码行数:101,
示例12: ProxyMain//.........这里部分代码省略......... exit(1); } if (strcmp(pszDest, "/vsistdout/") == 0) { bQuiet = TRUE; pfnProgress = GDALDummyProgress; }/* -------------------------------------------------------------------- *//* Attempt to open source file. *//* -------------------------------------------------------------------- */ hDataset = GDALOpenShared(pszSource, GA_ReadOnly); if (hDataset == NULL) { fprintf(stderr, "GDALOpen failed - %d/n%s/n", CPLGetLastErrorNo(), CPLGetLastErrorMsg()); GDALDestroyDriverManager(); exit(1); }/* -------------------------------------------------------------------- *//* Handle subdatasets. *//* -------------------------------------------------------------------- */ if (!bCopySubDatasets && CSLCount(GDALGetMetadata(hDataset, "SUBDATASETS")) > 0 && GDALGetRasterCount(hDataset) == 0) { fprintf(stderr, "Input file contains subdatasets. Please, select one of them for reading./n"); GDALClose(hDataset); GDALDestroyDriverManager(); exit(1); } if (CSLCount(GDALGetMetadata(hDataset, "SUBDATASETS")) > 0 && bCopySubDatasets) { char **papszSubdatasets = GDALGetMetadata(hDataset, "SUBDATASETS"); char *pszSubDest = (char*) CPLMalloc(strlen(pszDest) + 32); int i; int bOldSubCall = bSubCall; char **papszDupArgv = CSLDuplicate(argv); int nRet = 0; CPLFree(papszDupArgv[iDstFileArg]); papszDupArgv[iDstFileArg] = pszSubDest; bSubCall = TRUE; for (i = 0; papszSubdatasets[i] != NULL; i += 2) { CPLFree(papszDupArgv[iSrcFileArg]); papszDupArgv[iSrcFileArg] = CPLStrdup(strstr(papszSubdatasets[i], "=") + 1); sprintf(pszSubDest, "%s%d", pszDest, i / 2 + 1); nRet = ProxyMain(argc, papszDupArgv); if (nRet != 0) break; } CSLDestroy(papszDupArgv); bSubCall = bOldSubCall; CSLDestroy(argv);
开发者ID:hyyh619,项目名称:OpenSceneGraph-3.4.0,代码行数:67,
示例13: main//.........这里部分代码省略......... ahLayers.push_back(hLayer); hDstDS = CreateOutputDataset(ahLayers, hSRS, bGotBounds, sEnvelop, hDriver, pszDstFilename, nXSize, nYSize, dfXRes, dfYRes, bTargetAlignedPixels, anBandList.size(), eOutputType, papszCreateOptions, adfInitVals, bNoDataSet, dfNoData); } ProcessLayer( hLayer, hSRS != NULL, hDstDS, anBandList, adfBurnValues, b3D, bInverse, pszBurnAttribute, papszRasterizeOptions, pfnProgress, NULL ); OGR_DS_ReleaseResultSet( hSrcDS, hLayer ); } }/* -------------------------------------------------------------------- *//* Create output file if necessary. *//* -------------------------------------------------------------------- */ int nLayerCount = CSLCount(papszLayers); if (bCreateOutput && hDstDS == NULL) { std::vector<OGRLayerH> ahLayers; for( i = 0; i < nLayerCount; i++ ) { OGRLayerH hLayer = OGR_DS_GetLayerByName( hSrcDS, papszLayers[i] ); if( hLayer == NULL ) { continue; } ahLayers.push_back(hLayer); } hDstDS = CreateOutputDataset(ahLayers, hSRS, bGotBounds, sEnvelop, hDriver, pszDstFilename, nXSize, nYSize, dfXRes, dfYRes, bTargetAlignedPixels, anBandList.size(), eOutputType, papszCreateOptions, adfInitVals, bNoDataSet, dfNoData); }/* -------------------------------------------------------------------- *//* Process each layer. *//* -------------------------------------------------------------------- */ for( i = 0; i < nLayerCount; i++ ) { OGRLayerH hLayer = OGR_DS_GetLayerByName( hSrcDS, papszLayers[i] ); if( hLayer == NULL ) { fprintf( stderr, "Unable to find layer %s, skipping./n", papszLayers[i] ); continue; } if( pszWHERE ) { if( OGR_L_SetAttributeFilter( hLayer, pszWHERE ) != OGRERR_NONE ) break; } void *pScaledProgress; pScaledProgress = GDALCreateScaledProgress( 0.0, 1.0 * (i + 1) / nLayerCount, pfnProgress, NULL ); ProcessLayer( hLayer, hSRS != NULL, hDstDS, anBandList, adfBurnValues, b3D, bInverse, pszBurnAttribute, papszRasterizeOptions, GDALScaledProgress, pScaledProgress ); GDALDestroyScaledProgress( pScaledProgress ); }/* -------------------------------------------------------------------- *//* Cleanup *//* -------------------------------------------------------------------- */ OGR_DS_Destroy( hSrcDS ); GDALClose( hDstDS ); OSRDestroySpatialReference(hSRS); CSLDestroy( argv ); CSLDestroy( papszRasterizeOptions ); CSLDestroy( papszLayers ); CSLDestroy( papszCreateOptions ); GDALDestroyDriverManager(); OGRCleanupAll(); return 0;}
开发者ID:actian-geospatial,项目名称:ogr-ingres,代码行数:101,
示例14: tindex//.........这里部分代码省略......... if (hTileIndexDS != NULL) { hLayer = OGR_DS_GetLayer(hTileIndexDS, 0); } } else { OGRSFDriverH hDriver; const char* pszDriverName = "ESRI Shapefile"; fprintf( stderr,"Creating new index file.../n" ); hDriver = OGRGetDriverByName( pszDriverName ); if( hDriver == NULL ) { char msg[1024]; sprintf( msg, "%s driver not available.", pszDriverName ); setMapInMaps(conf,"lenv","message",msg); return SERVICE_FAILED; } hTileIndexDS = OGR_Dr_CreateDataSource( hDriver, index_filename, NULL ); if (hTileIndexDS) { char* pszLayerName = CPLStrdup(CPLGetBasename(index_filename)); OGRSpatialReferenceH hSpatialRef = NULL; GDALDatasetH hDS = GDALOpen( index_filename, GA_ReadOnly ); if (hDS) { const char* pszWKT = GDALGetProjectionRef(hDS); if (pszWKT != NULL && pszWKT[0] != '/0') { hSpatialRef = OSRNewSpatialReference(pszWKT); } GDALClose(hDS); } DIR *dirp = opendir(pszDataDir); if(dirp==NULL){ char tmp1[1024]; sprintf(tmp1,_ss("The specified path %s doesn't exist."),pszDataDir); setMapInMaps(conf,"lenv","message",tmp1); return SERVICE_FAILED; } char *res=NULL; struct dirent *dp; tmpMap=getMapFromMaps(inputs,"ext","value"); char *ext; if(tmpMap!=NULL) ext=tmpMap->value; while ((dp = readdir(dirp)) != NULL){ if(strncmp(dp->d_name,".",1)!=0&&strncmp(dp->d_name,"..",2)!=0){ char* argv=(char*) malloc((strlen(dp->d_name)+strlen(pszDataDir)+2)*sizeof(char)); sprintf(argv,"%s/%s",pszDataDir,dp->d_name); GDALDatasetH hDS0 = GDALOpen( argv, GA_ReadOnly ); if (hDS0) { const char* pszWKT = GDALGetProjectionRef(hDS0); fprintf(stderr,"SRS %s /n",pszWKT); if (pszWKT != NULL && pszWKT[0] != '/0') { if (hSpatialRef) OSRRelease(hSpatialRef); hSpatialRef = OSRNewSpatialReference(pszWKT); } GDALClose(hDS); }
开发者ID:ThomasG77,项目名称:mapmint,代码行数:67,
示例15: ogrCheckExistsSEXP ogrCheckExists (SEXP ogrSource, SEXP Layer) { OGRLayer *poLayer;#ifdef GDALV2 GDALDataset *poDS; GDALDriver *poDriver;#else OGRDataSource *poDS; OGRSFDriver *poDriver;#endif SEXP ans, drv; int pc=0; PROTECT(ans=NEW_LOGICAL(1)); pc++; installErrorHandler();#ifdef GDALV2 poDS=(GDALDataset*) GDALOpenEx(CHAR(STRING_ELT(ogrSource, 0)), GDAL_OF_VECTOR, NULL, NULL, NULL); if (poDS != NULL) poDriver = poDS->GetDriver();#else poDS=OGRSFDriverRegistrar::Open(CHAR(STRING_ELT(ogrSource, 0)), FALSE, &poDriver);#endif uninstallErrorHandlerAndTriggerError(); if (poDS==NULL) {// installErrorHandler();// OGRDataSource::DestroyDataSource( poDS );// uninstallErrorHandlerAndTriggerError();// delete poDS; LOGICAL_POINTER(ans)[0] = FALSE; UNPROTECT(pc); return(ans); } installErrorHandler(); poLayer = poDS->GetLayerByName(CHAR(STRING_ELT(Layer, 0))); uninstallErrorHandlerAndTriggerError(); if (poLayer == NULL) { installErrorHandler();#ifdef GDALV2 GDALClose( poDS );#else OGRDataSource::DestroyDataSource( poDS );#endif uninstallErrorHandlerAndTriggerError();// delete poDS; LOGICAL_POINTER(ans)[0] = FALSE; UNPROTECT(pc); return(ans); } LOGICAL_POINTER(ans)[0] = TRUE; PROTECT(drv=allocVector(STRSXP,1)); pc++; installErrorHandler();#ifdef GDALV2 SET_STRING_ELT(drv, 0, mkChar(poDriver->GetDescription()));#else SET_STRING_ELT(drv, 0, mkChar(poDriver->GetName()));#endif uninstallErrorHandlerAndTriggerError(); setAttrib(ans, install("driver"), drv); installErrorHandler();#ifdef GDALV2 GDALClose( poDS );#else OGRDataSource::DestroyDataSource( poDS );#endif uninstallErrorHandlerAndTriggerError();// delete poDS; UNPROTECT(pc); return(ans);}
开发者ID:rforge,项目名称:rgdal,代码行数:76,
示例16: ogrDeleteLayerSEXP 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);}
开发者ID:rforge,项目名称:rgdal,代码行数:85,
示例17: GDALRPCTransformint GDALRPCTransform( void *pTransformArg, int bDstToSrc, int nPointCount, double *padfX, double *padfY, double *padfZ, int *panSuccess ){ VALIDATE_POINTER1( pTransformArg, "GDALRPCTransform", 0 ); GDALRPCTransformInfo *psTransform = (GDALRPCTransformInfo *) pTransformArg; GDALRPCInfo *psRPC = &(psTransform->sRPC); int i; if( psTransform->bReversed ) bDstToSrc = !bDstToSrc; int bands[1] = {1}; int nRasterXSize = 0, nRasterYSize = 0;/* -------------------------------------------------------------------- *//* Lazy opening of the optionnal DEM file. *//* -------------------------------------------------------------------- */ if(psTransform->pszDEMPath != NULL && psTransform->bHasTriedOpeningDS == FALSE) { int bIsValid = FALSE; psTransform->bHasTriedOpeningDS = TRUE; psTransform->poDS = (GDALDataset *) GDALOpen( psTransform->pszDEMPath, GA_ReadOnly ); if(psTransform->poDS != NULL && psTransform->poDS->GetRasterCount() >= 1) { const char* pszSpatialRef = psTransform->poDS->GetProjectionRef(); if (pszSpatialRef != NULL && pszSpatialRef[0] != '/0') { OGRSpatialReference* poWGSSpaRef = new OGRSpatialReference(SRS_WKT_WGS84); OGRSpatialReference* poDSSpaRef = new OGRSpatialReference(pszSpatialRef); if(!poWGSSpaRef->IsSame(poDSSpaRef)) psTransform->poCT =OGRCreateCoordinateTransformation( poWGSSpaRef, poDSSpaRef ); delete poWGSSpaRef; delete poDSSpaRef; } if (psTransform->poDS->GetGeoTransform( psTransform->adfGeoTransform) == CE_None && GDALInvGeoTransform( psTransform->adfGeoTransform, psTransform->adfReverseGeoTransform )) { bIsValid = TRUE; } } if (!bIsValid && psTransform->poDS != NULL) { GDALClose(psTransform->poDS); psTransform->poDS = NULL; } } if (psTransform->poDS) { nRasterXSize = psTransform->poDS->GetRasterXSize(); nRasterYSize = psTransform->poDS->GetRasterYSize(); }/* -------------------------------------------------------------------- *//* The simple case is transforming from lat/long to pixel/line. *//* Just apply the equations directly. *//* -------------------------------------------------------------------- */ if( bDstToSrc ) { for( i = 0; i < nPointCount; i++ ) { if(psTransform->poDS) { double dfX, dfY; //check if dem is not in WGS84 and transform points padfX[i], padfY[i] if(psTransform->poCT) { double dfXOrig = padfX[i]; double dfYOrig = padfY[i]; double dfZOrig = padfZ[i]; if (!psTransform->poCT->Transform( 1, &dfXOrig, &dfYOrig, &dfZOrig)) { panSuccess[i] = FALSE; continue; } GDALApplyGeoTransform( psTransform->adfReverseGeoTransform, dfXOrig, dfYOrig, &dfX, &dfY ); } else GDALApplyGeoTransform( psTransform->adfReverseGeoTransform, padfX[i], padfY[i], &dfX, &dfY ); int dX = int(dfX); int dY = int(dfY); if (!(dX >= 0 && dY >= 0 && dX+2 <= nRasterXSize && dY+2 <= nRasterYSize)) {//.........这里部分代码省略.........
开发者ID:afarnham,项目名称:gdal,代码行数:101,
示例18: GeoLocGenerateBackMap//.........这里部分代码省略......... if( iBMX > 0 && pabyValidFlag[iBMX-1+iBMY*nBMXSize] > nMarkedAsGood ) { dfXSum += psTransform->pafBackMapX[iBMX-1+iBMY*nBMXSize]; dfYSum += psTransform->pafBackMapY[iBMX-1+iBMY*nBMXSize]; nCount++; } // right? if( iBMX + 1 < nBMXSize && pabyValidFlag[iBMX+1+iBMY*nBMXSize] > nMarkedAsGood ) { dfXSum += psTransform->pafBackMapX[iBMX+1+iBMY*nBMXSize]; dfYSum += psTransform->pafBackMapY[iBMX+1+iBMY*nBMXSize]; nCount++; } // top? if( iBMY > 0 && pabyValidFlag[iBMX+(iBMY-1)*nBMXSize] > nMarkedAsGood ) { dfXSum += psTransform->pafBackMapX[iBMX+(iBMY-1)*nBMXSize]; dfYSum += psTransform->pafBackMapY[iBMX+(iBMY-1)*nBMXSize]; nCount++; } // bottom? if( iBMY + 1 < nBMYSize && pabyValidFlag[iBMX+(iBMY+1)*nBMXSize] > nMarkedAsGood ) { dfXSum += psTransform->pafBackMapX[iBMX+(iBMY+1)*nBMXSize]; dfYSum += psTransform->pafBackMapY[iBMX+(iBMY+1)*nBMXSize]; nCount++; } // top-left? if( iBMX > 0 && iBMY > 0 && pabyValidFlag[iBMX-1+(iBMY-1)*nBMXSize] > nMarkedAsGood ) { dfXSum += psTransform->pafBackMapX[iBMX-1+(iBMY-1)*nBMXSize]; dfYSum += psTransform->pafBackMapY[iBMX-1+(iBMY-1)*nBMXSize]; nCount++; } // top-right? if( iBMX + 1 < nBMXSize && iBMY > 0 && pabyValidFlag[iBMX+1+(iBMY-1)*nBMXSize] > nMarkedAsGood ) { dfXSum += psTransform->pafBackMapX[iBMX+1+(iBMY-1)*nBMXSize]; dfYSum += psTransform->pafBackMapY[iBMX+1+(iBMY-1)*nBMXSize]; nCount++; } // bottom-left? if( iBMX > 0 && iBMY + 1 < nBMYSize && pabyValidFlag[iBMX-1+(iBMY+1)*nBMXSize] > nMarkedAsGood ) { dfXSum += psTransform->pafBackMapX[iBMX-1+(iBMY+1)*nBMXSize]; dfYSum += psTransform->pafBackMapY[iBMX-1+(iBMY+1)*nBMXSize]; nCount++; } // bottom-right? if( iBMX + 1 < nBMXSize && iBMY + 1 < nBMYSize && pabyValidFlag[iBMX+1+(iBMY+1)*nBMXSize] > nMarkedAsGood ) { dfXSum += psTransform->pafBackMapX[iBMX+1+(iBMY+1)*nBMXSize]; dfYSum += psTransform->pafBackMapY[iBMX+1+(iBMY+1)*nBMXSize]; nCount++; } if( nCount > 0 ) { psTransform->pafBackMapX[iBMX + iBMY * nBMXSize] = (float)(dfXSum/nCount); psTransform->pafBackMapY[iBMX + iBMY * nBMXSize] = (float)(dfYSum/nCount); // genuinely valid points will have value iMaxIter+1 // On each iteration mark newly valid points with a // descending value so that it will not be used on the // current iteration only on subsequent ones. pabyValidFlag[iBMX+iBMY*nBMXSize] = (GByte) (nMaxIter - iIter); } } } if (nNumValid == nBMXSize * nBMYSize) break; }#ifdef notdef GDALDatasetH hBMDS = GDALCreate( GDALGetDriverByName( "GTiff" ), "backmap.tif", nBMXSize, nBMYSize, 2, GDT_Float32, NULL ); GDALSetGeoTransform( hBMDS, psTransform->adfBackMapGeoTransform ); GDALRasterIO( GDALGetRasterBand(hBMDS,1), GF_Write, 0, 0, nBMXSize, nBMYSize, psTransform->pafBackMapX, nBMXSize, nBMYSize, GDT_Float32, 0, 0 ); GDALRasterIO( GDALGetRasterBand(hBMDS,2), GF_Write, 0, 0, nBMXSize, nBMYSize, psTransform->pafBackMapY, nBMXSize, nBMYSize, GDT_Float32, 0, 0 ); GDALClose( hBMDS );#endif CPLFree( pabyValidFlag ); return TRUE;}
开发者ID:bbradbury,项目名称:lib_gdal,代码行数:101,
示例19: mainint main(int argc, const char * argv[]) { boost::filesystem::path p = boost::filesystem::current_path(); fprintf(stdout,"cwp := %s/n",p.c_str()); GDALAllRegister(); // for (int i = 0; i < GDALGetDriverCount(); i++) {// GDALDriver * d = (GDALDriver *)GDALGetDriver(i);// const char * desc = d->GetDescription();// fprintf(stdout, "GDAL: %s/n",desc);// } GDALDataset *poDataset = (GDALDataset *) GDALOpen(DataPath.c_str(), GA_ReadOnly ); std::string SupportedDriver = {"GTiff"}; if (poDataset != NULL) { GDALDriver * drv = poDataset->GetDriver(); assert(0 == SupportedDriver.compare(drv->GetDescription())); assert (1 == poDataset->GetRasterCount()); fprintf(stdout,"RasterXSize := %d/n",poDataset->GetRasterXSize()); fprintf(stdout,"RasterYSize := %d/n",poDataset->GetRasterYSize()); fprintf(stdout,"ProjectionRef := %s/n",poDataset->GetProjectionRef()); double adfGeoTransform[6]; if ( poDataset->GetGeoTransform(adfGeoTransform) == CE_None ) { fprintf(stdout, "Origin = (%.6f, %.6f)/n", adfGeoTransform[0],adfGeoTransform[3]); // upper left courner fprintf(stdout, "Pixel Size = (%.6f, %.6f)/n", adfGeoTransform[1],adfGeoTransform[5]); // pixel width/height } GDALRasterBand *poBand = poDataset->GetRasterBand(1); int nBlockXSize, nBlockYSize; poBand->GetBlockSize(&nBlockXSize, &nBlockYSize); std::string SupportedDataType = {"Int16"}; assert (GDT_Int16 == poBand->GetRasterDataType()); printf( "Block=%dx%d Type=%s, ColorInterp=%s/n", nBlockXSize, nBlockYSize, GDALGetDataTypeName(poBand->GetRasterDataType()), GDALGetColorInterpretationName( poBand->GetColorInterpretation()) ); FILE * patch = fopen("patch.txt","w"); for (int i = 0; i < poBand->GetYSize(); i++) { int nXSize = poBand->GetXSize(); float *pafScanline = (float *) CPLMalloc(sizeof(float)*nXSize); poBand->RasterIO( GF_Read, 0, 0, nXSize, 1, pafScanline, nXSize, 1, GDT_Float32, 0, 0); for (int j = 0; j < nXSize; j++) { fprintf(patch, "%f ", pafScanline[j]); } fprintf(patch, "/n"); CPLFree(pafScanline); } fclose(patch); GDALClose(poDataset); } DelaunayTriangulation dt; //std::srand(static_cast<unsigned int>(std::time(0))); // use current time as seed for random generator /* std::srand(static_cast<unsigned int>(3652123216145)); for (int i = 0; i < 10 ; i++) { double x = 180.0 * static_cast <float> (rand()) / static_cast <float> (RAND_MAX);; double y = 180.0 * static_cast <float> (rand()) / static_cast <float> (RAND_MAX);; dt.addPt(x, y, 0.0); } */ /* dt.addPt(-0.02222276248244826, -0.4979727817680433, 0.0); dt.addPt(-0.4285431913366012, 0.4745826469497594, 0.0); dt.addPt( 0.3105396575392593, 0.2400179190933871, 0.0); dt.addPt(-0.01883958887200765, 0.3630260628303755, 0.0); dt.addPt( 0.3790312361708201, 0.3779794437605696, 0.0); dt.addPt(-0.2994955874043476, 0.3776609263174803, 0.0); dt.addPt( 0.3471817493878135, 0.08365533089605659, 0.0); dt.addPt(-0.00485819764887746, 0.3482682405489201, 0.0); dt.addPt( 0.3443122672329771, -0.1437312230875075, 0.0); dt.addPt( 0.309330780347186, -0.07758103877080702, 0.0); dt.compute(); */ return 0;}
开发者ID:parrishmyers,项目名称:tacmap,代码行数:94,
示例20: CPLErrorGDALDataset *CALSDataset::CreateCopy( const char *pszFilename, GDALDataset *poSrcDS, int bStrict, char ** /* papszOptionsUnused */, GDALProgressFunc pfnProgress, void *pProgressData ){ if( poSrcDS->GetRasterCount() == 0 || (bStrict && poSrcDS->GetRasterCount() != 1) ) { CPLError( CE_Failure, CPLE_NotSupported, "CALS driver only supports single band raster."); return NULL; } if( poSrcDS->GetRasterBand(1)-> GetMetadataItem("NBITS", "IMAGE_STRUCTURE") == NULL || !EQUAL(poSrcDS->GetRasterBand(1)-> GetMetadataItem("NBITS", "IMAGE_STRUCTURE"), "1") ) { CPLError( bStrict ? CE_Failure : CE_Warning, CPLE_NotSupported, "CALS driver only supports 1-bit."); if( bStrict ) return NULL; } if( poSrcDS->GetRasterXSize() > 999999 || poSrcDS->GetRasterYSize() > 999999 ) { CPLError( CE_Failure, CPLE_NotSupported, "CALS driver only supports datasets with dimension <= 999999."); return NULL; } GDALDriver* poGTiffDrv = static_cast<GDALDriver *>(GDALGetDriverByName("GTiff")); if( poGTiffDrv == NULL ) { CPLError( CE_Failure, CPLE_NotSupported, "CALS driver needs GTiff driver." ); return NULL; } // Write a in-memory TIFF with just the TIFF header to figure out // how large it will be. CPLString osTmpFilename(CPLSPrintf("/vsimem/cals/tmp_%p", poSrcDS)); char** papszOptions = NULL; papszOptions = CSLSetNameValue(papszOptions, "COMPRESS", "CCITTFAX4"); papszOptions = CSLSetNameValue(papszOptions, "NBITS", "1"); papszOptions = CSLSetNameValue(papszOptions, "BLOCKYSIZE", CPLSPrintf("%d", poSrcDS->GetRasterYSize())); papszOptions = CSLSetNameValue(papszOptions, "SPARSE_OK", "YES"); GDALDataset* poDS = poGTiffDrv->Create(osTmpFilename, poSrcDS->GetRasterXSize(), poSrcDS->GetRasterYSize(), 1, GDT_Byte, papszOptions); if( poDS == NULL ) { // Should not happen normally (except if CCITTFAX4 not available). CSLDestroy(papszOptions); return NULL; } const char INITIAL_PADDING[] = "12345"; // To adjust padding. poDS->SetMetadataItem("TIFFTAG_DOCUMENTNAME", INITIAL_PADDING); GDALClose(poDS); VSIStatBufL sStat; if( VSIStatL(osTmpFilename, &sStat) != 0 ) { // Shoudln't happen really. Just to make Coverity happy. CSLDestroy(papszOptions); return NULL; } int nTIFFHeaderSize = static_cast<int>(sStat.st_size); VSIUnlink(osTmpFilename); // Redo the same thing, but this time write it to the output file // and use a variable TIFF tag (TIFFTAG_DOCUMENTNAME) to enlarge the // header + the variable TIFF tag so that they are 2048 bytes large. char szBuffer[2048+1] = {}; memset(szBuffer, 'X', 2048 - nTIFFHeaderSize + strlen(INITIAL_PADDING)); szBuffer[2048 - nTIFFHeaderSize + strlen(INITIAL_PADDING)] = 0; GDALDataset* poTmpDS = new CALSWrapperSrcDataset(poSrcDS, szBuffer); poDS = poGTiffDrv->CreateCopy(pszFilename, poTmpDS, FALSE, papszOptions, pfnProgress, pProgressData ); delete poTmpDS; CSLDestroy(papszOptions); if( poDS == NULL ) return NULL; delete poDS; // Now replace the TIFF header by the CALS header. VSILFILE* fp = VSIFOpenL(pszFilename, "rb+"); if( fp == NULL ) return NULL; // Shoudln't happen normally. memset(szBuffer, ' ', 2048); CPLString osField; osField = "srcdocid: NONE"; memcpy(szBuffer, osField, osField.size());//.........这里部分代码省略.........
开发者ID:ryandavid,项目名称:rotobox,代码行数:101,
示例21: ogrListLayersSEXP ogrListLayers (SEXP ogrSource) {#ifdef GDALV2 GDALDataset *poDS; GDALDriver *poDriver;#else OGRDataSource *poDS; OGRSFDriver *poDriver;#endif OGRLayer *poLayer; int i, nlayers; SEXP ans, debug; int pc=0; installErrorHandler();#ifdef GDALV2 poDS=(GDALDataset*) GDALOpenEx(CHAR(STRING_ELT(ogrSource, 0)), GDAL_OF_VECTOR, NULL, NULL, NULL); if(poDS==NULL) { uninstallErrorHandlerAndTriggerError(); error("Cannot open data source"); } poDriver = poDS->GetDriver();#else poDS=OGRSFDriverRegistrar::Open(CHAR(STRING_ELT(ogrSource, 0)), FALSE, &poDriver);#endif uninstallErrorHandlerAndTriggerError(); if(poDS==NULL) { error("Cannot open data source"); } debug = getAttrib(ogrSource, mkString("debug")); installErrorHandler(); nlayers = poDS->GetLayerCount(); uninstallErrorHandlerAndTriggerError(); if (LOGICAL_POINTER(debug)[0] == TRUE) Rprintf("ogrListLayers: nlayers %d/n", nlayers); PROTECT(ans=NEW_CHARACTER(nlayers+1)); pc++; for (i=0; i<nlayers; i++) { installErrorHandler(); poLayer = poDS->GetLayer(i); if(poLayer == NULL) { if (LOGICAL_POINTER(debug)[0] == TRUE) { SET_STRING_ELT(ans, i, mkChar("")); Rprintf("ogrListLayers: NULL layer %d/n", i); } else { uninstallErrorHandlerAndTriggerError(); error("Cannot open layer"); } } else { SET_STRING_ELT(ans, i, mkChar(poLayer->GetLayerDefn()->GetName())); } uninstallErrorHandlerAndTriggerError(); } installErrorHandler();#ifdef GDALV2 SET_STRING_ELT(ans, nlayers, mkChar(poDriver->GetDescription()));#else SET_STRING_ELT(ans, nlayers, mkChar(poDriver->GetName()));#endif uninstallErrorHandlerAndTriggerError(); installErrorHandler();#ifdef GDALV2 GDALClose( poDS );#else OGRDataSource::DestroyDataSource( poDS );#endif uninstallErrorHandlerAndTriggerError(); UNPROTECT(pc); return(ans);}
开发者ID:rforge,项目名称:rgdal,代码行数:79,
示例22: equalize_densityint equalize_density(char *infile, char *outfile, int fast, int accurate) { int xsize, ysize; // Size of the density grid. double *gridx, *gridy; // Array for grid double **rho; // Initial population density GDALDatasetH hDataset; // The input density raster file. GDALRasterBandH hBand; // The raster band we are going to use. FILE *outfp; // The morphing file (a text file). double adfGeoTransform[6]; // For the georeference of the raster. // Register all GDAL drivers. GDALAllRegister(); #if defined (_OPENMP) omp_set_num_threads(omp_get_num_procs());#endif hDataset = GDALOpen(infile, GA_ReadOnly); if (hDataset == NULL) { fprintf(stderr,"Error. Unable to open file `%s'/n", infile); exit(1); } outfp = fopen(outfile, "w"); if (outfp == NULL) { fprintf(stderr,"Error. Unable to open file `%s'/n", outfile); exit(1); } // Get the raster band for the dataset; we are using the first band. hBand = GDALGetRasterBand(hDataset, 1); if (hBand == NULL) { fprintf(stderr, "Error. Unable to read band 1 in file `%s'/n", infile); exit(1); } // Determine the raster size xsize = GDALGetRasterBandXSize(hBand); ysize = GDALGetRasterBandYSize(hBand); // Allocate space for the cartogram code to use cart_makews(xsize, ysize); // Read in the population data, transform it, then destroy it again rho = cart_dmalloc(xsize, ysize); if (readpop(hBand, rho, xsize, ysize)) { fprintf(stderr,"Error. Density file contains too few or incorrect data/n"); exit(1); } cart_transform(rho, xsize, ysize); cart_dfree(rho); // Create the grid of points gridx = malloc((xsize+1)*(ysize+1)*sizeof(double)); gridy = malloc((xsize+1)*(ysize+1)*sizeof(double)); creategrid(gridx, gridy, xsize, ysize); // Compute the cartogram cart_makecart(gridx, gridy, (xsize+1)*(ysize+1), xsize, ysize, 0.0); // Write out the final positions of the grid points GDALGetGeoTransform(hDataset, adfGeoTransform); writepoints(outfp, gridx, gridy, xsize, ysize, adfGeoTransform); //writepoints(outfp, gridx, gridy, (xsize+1)*(ysize+1)); // Free up the allocated memory cart_freews(xsize, ysize); free(gridx); free(gridy); // Close the input and output files GDALClose(hDataset); fclose(outfp); return 0;}
开发者ID:christiankaiser,项目名称:spatial-tools,代码行数:88,
示例23: ogrFIDs//extern "C" {SEXP ogrFIDs(SEXP filename, SEXP layer) { SEXP fids, nf, ii; int /*layerNum,*/i; int nFeatures, pc=0; OGRLayer *poLayer; OGRFeature *poFeature;#ifdef GDALV2 GDALDataset *poDS;#else OGRDataSource *poDS; OGRSFDriver *poDriver;#endif installErrorHandler();#ifdef GDALV2 poDS=(GDALDataset*) GDALOpenEx(CHAR(STRING_ELT(filename, 0)), GDAL_OF_VECTOR, NULL, NULL, NULL);#else poDS=OGRSFDriverRegistrar::Open(CHAR(STRING_ELT(filename, 0)), FALSE, &poDriver);#endif uninstallErrorHandlerAndTriggerError(); if(poDS==NULL) { error("Cannot open file"); } installErrorHandler(); poLayer = poDS->GetLayerByName(CHAR(STRING_ELT(layer, 0))); uninstallErrorHandlerAndTriggerError(); if(poLayer == NULL) { error("Cannot open layer"); } installErrorHandler();#ifdef GDALV2 GIntBig nFIDs64 = poLayer->GetFeatureCount(); nFeatures = (nFIDs64 > INT_MAX) ? INT_MAX : (nFIDs64 < INT_MIN) ? INT_MIN : (int) nFIDs64; if ((GIntBig) nFeatures != nFIDs64) { uninstallErrorHandlerAndTriggerError(); error("ogrFIDs: feature count overflow"); }#else nFeatures=poLayer->GetFeatureCount();#endif uninstallErrorHandlerAndTriggerError(); if (nFeatures == -1) { i=0; installErrorHandler(); while( ((poFeature = poLayer->GetNextFeature()) != NULL) && i <= INT_MAX) { i++; OGRFeature::DestroyFeature( poFeature );// delete poFeature; } uninstallErrorHandlerAndTriggerError(); installErrorHandler(); poLayer->ResetReading(); uninstallErrorHandlerAndTriggerError(); if (i == INT_MAX) { error("ogrFIDs: feature count overflow"); } else { nFeatures = i; } } PROTECT(fids=allocVector(INTSXP,nFeatures)); pc++; PROTECT(nf = NEW_INTEGER(1)); pc++; INTEGER_POINTER(nf)[0] = nFeatures; PROTECT(ii = NEW_INTEGER(1)); pc++; installErrorHandler(); poLayer->ResetReading(); uninstallErrorHandlerAndTriggerError(); i=0; installErrorHandler(); while( (poFeature = poLayer->GetNextFeature()) != NULL ) { INTEGER(fids)[i]= (int) poFeature->GetFID(); i++; OGRFeature::DestroyFeature( poFeature );// delete poFeature; } uninstallErrorHandlerAndTriggerError(); INTEGER_POINTER(ii)[0] = i; setAttrib(fids, install("nf"), nf); setAttrib(fids, install("i"), ii); installErrorHandler();#ifdef GDALV2 GDALClose( poDS );#else OGRDataSource::DestroyDataSource( poDS );#endif//.........这里部分代码省略.........
开发者ID:rforge,项目名称:rgdal,代码行数:101,
示例24: OGRRegisterAllintNBHeightMapper::loadShapeFile(const std::string& file) {#ifdef HAVE_GDAL#if GDAL_VERSION_MAJOR < 2 OGRRegisterAll(); OGRDataSource* ds = OGRSFDriverRegistrar::Open(file.c_str(), FALSE);#else GDALAllRegister(); GDALDataset* ds = (GDALDataset*)GDALOpenEx(file.c_str(), GDAL_OF_VECTOR | GA_ReadOnly, NULL, NULL, NULL);#endif if (ds == NULL) { throw ProcessError("Could not open shape file '" + file + "'."); } // begin file parsing OGRLayer* layer = ds->GetLayer(0); layer->ResetReading(); // triangle coordinates are stored in WGS84 and later matched with network coordinates in WGS84 // build coordinate transformation OGRSpatialReference* sr_src = layer->GetSpatialRef(); OGRSpatialReference sr_dest; sr_dest.SetWellKnownGeogCS("WGS84"); OGRCoordinateTransformation* toWGS84 = OGRCreateCoordinateTransformation(sr_src, &sr_dest); if (toWGS84 == 0) { WRITE_WARNING("Could not create geocoordinates converter; check whether proj.4 is installed."); } int numFeatures = 0; OGRFeature* feature; layer->ResetReading(); while ((feature = layer->GetNextFeature()) != NULL) { OGRGeometry* geom = feature->GetGeometryRef(); assert(geom != 0); // @todo gracefull handling of shapefiles with unexpected contents or any error handling for that matter assert(std::string(geom->getGeometryName()) == std::string("POLYGON")); // try transform to wgs84 geom->transform(toWGS84); OGRLinearRing* cgeom = ((OGRPolygon*) geom)->getExteriorRing(); // assume TIN with with 4 points and point0 == point3 assert(cgeom->getNumPoints() == 4); PositionVector corners; for (int j = 0; j < 3; j++) { Position pos((double) cgeom->getX(j), (double) cgeom->getY(j), (double) cgeom->getZ(j)); corners.push_back(pos); myBoundary.add(pos); } addTriangle(corners); numFeatures++; /* OGRwkbGeometryType gtype = geom->getGeometryType(); switch (gtype) { case wkbPolygon: { break; } case wkbPoint: { WRITE_WARNING("got wkbPoint"); break; } case wkbLineString: { WRITE_WARNING("got wkbLineString"); break; } case wkbMultiPoint: { WRITE_WARNING("got wkbMultiPoint"); break; } case wkbMultiLineString: { WRITE_WARNING("got wkbMultiLineString"); break; } case wkbMultiPolygon: { WRITE_WARNING("got wkbMultiPolygon"); break; } default: WRITE_WARNING("Unsupported shape type occurred"); break; } */ OGRFeature::DestroyFeature(feature); }#if GDAL_VERSION_MAJOR < 2 OGRDataSource::DestroyDataSource(ds);#else GDALClose(ds);#endif OCTDestroyCoordinateTransformation(toWGS84); OGRCleanupAll(); return numFeatures;#else UNUSED_PARAMETER(file); WRITE_ERROR("Cannot load shape file since SUMO was compiled without GDAL support."); return 0;#endif}
开发者ID:fieryzig,项目名称:sumo,代码行数:98,
示例25: ogrInfo// extern "C" {SEXP ogrInfo(SEXP ogrsourcename, SEXP Layer) { // return FIDs, nFields, fieldInfo SEXP ans, vec1, vec2, vec3,/*mat,*/drv, dvec; SEXP itemlist, itemnames, itemwidth, itemtype, itemTypeNames; SEXP itemlistmaxcount;#ifdef GDALV2 SEXP dFIDs;#endif /*SEXP geotype;*/ int nFIDs, nFields, iField, *nCount, pc=0;#ifdef GDALV2 GDALDriver *poDriver; GDALDataset *poDS;#else OGRDataSource *poDS; OGRSFDriver *poDriver;#endif OGRLayer *poLayer; OGRFeature *poFeature; OGRFeatureDefn *poDefn; /* OGRGeometry *poGeom;*/ installErrorHandler();#ifdef GDALV2 poDS=(GDALDataset*) GDALOpenEx(CHAR(STRING_ELT(ogrsourcename, 0)), GDAL_OF_VECTOR, NULL, NULL, NULL); if(poDS==NULL) { uninstallErrorHandlerAndTriggerError(); error("Cannot open data source"); } poDriver = poDS->GetDriver();#else poDS=OGRSFDriverRegistrar::Open(CHAR(STRING_ELT(ogrsourcename, 0)), FALSE, &poDriver);#endif uninstallErrorHandlerAndTriggerError(); if(poDS==NULL) { installErrorHandler();#ifdef GDALV2 GDALClose( poDS );#else OGRDataSource::DestroyDataSource( poDS );#endif uninstallErrorHandlerAndTriggerError();// delete poDS; error("Cannot open file"); } installErrorHandler(); poLayer = poDS->GetLayerByName(CHAR(STRING_ELT(Layer, 0))); uninstallErrorHandlerAndTriggerError(); if(poLayer == NULL) { installErrorHandler();#ifdef GDALV2 GDALClose( poDS );#else OGRDataSource::DestroyDataSource( poDS );#endif uninstallErrorHandlerAndTriggerError();// delete poDS; error("Cannot open layer"); } // allocate a list for return values PROTECT(ans=allocVector(VECSXP,6)); pc++; PROTECT(drv=allocVector(STRSXP,1)); pc++; installErrorHandler();#ifdef GDALV2 SET_STRING_ELT(drv, 0, mkChar(poDriver->GetDescription()));#else SET_STRING_ELT(drv, 0, mkChar(poDriver->GetName()));#endif uninstallErrorHandlerAndTriggerError(); SET_VECTOR_ELT(ans,3,drv); PROTECT(vec1=allocVector(INTSXP,1)); pc++; installErrorHandler();#ifdef GDALV2 GIntBig nFIDs64 = poLayer->GetFeatureCount(); nFIDs = (nFIDs64 > INT_MAX) ? INT_MAX : (nFIDs64 < INT_MIN) ? INT_MIN : (int) nFIDs64; if ((GIntBig) nFIDs != nFIDs64) { warning("ogrInfo: feature count overflow"); INTEGER(vec1)[0]=NA_INTEGER; PROTECT(dFIDs=NEW_NUMERIC(1)); pc++; NUMERIC_POINTER(dFIDs)[0] = (double) nFIDs64; setAttrib(vec1, install("dFIDs"), dFIDs); } else { // store number of FIDs INTEGER(vec1)[0]=nFIDs;//.........这里部分代码省略.........
开发者ID:rforge,项目名称:rgdal,代码行数:101,
示例26: LLVMFuzzerTestOneInput//.........这里部分代码省略......... if( papszArgv != nullptr ) { GDALTranslateOptions* psOptions = GDALTranslateOptionsNew(papszArgv, nullptr); if( psOptions ) { GDALDatasetH hSrcDS = GDALOpen( "/vsitar//vsimem/test.tar/in", GA_ReadOnly ); if( hSrcDS != nullptr ) { // Also check that reading the source doesn't involve too // much memory GDALDataset* poSrcDS = reinterpret_cast<GDALDataset*>(hSrcDS); int nBands = poSrcDS->GetRasterCount(); if( nBands < 10 ) { // Prevent excessive downsampling which might require huge // memory allocation bool bOKForResampling = true; if( bNonNearestResampling && nXDim >= 0 && nYDim >= 0 ) { if( bXDimPct && nXDim > 0 ) { nXDim = static_cast<int>( poSrcDS->GetRasterXSize() / 100.0 * nXDim); } if( bYDimPct && nYDim > 0 ) { nYDim = static_cast<int>( poSrcDS->GetRasterYSize() / 100.0 * nYDim); } if( nXDim > 0 && poSrcDS->GetRasterXSize() / nXDim > 100 ) bOKForResampling = false; if( nYDim > 0 && poSrcDS->GetRasterYSize() / nYDim > 100 ) bOKForResampling = false; } bool bOKForSrc = true; if( nBands ) { const int nDTSize = GDALGetDataTypeSizeBytes( poSrcDS->GetRasterBand(1)->GetRasterDataType() ); vsi_l_offset nSize = static_cast<vsi_l_offset>(nBands) * poSrcDS->GetRasterXSize() * poSrcDS->GetRasterYSize() * nDTSize; if( nSize > 10 * 1024 * 1024 ) { bOKForSrc = false; } int nBXSize = 0, nBYSize = 0; GDALGetBlockSize( GDALGetRasterBand(hSrcDS, 1), &nBXSize, &nBYSize ); const char* pszInterleave = GDALGetMetadataItem( hSrcDS, "INTERLEAVE", "IMAGE_STRUCTURE" ); int nSimultaneousBands = (pszInterleave && EQUAL(pszInterleave, "PIXEL")) ? nBands : 1; if( static_cast<GIntBig>(nSimultaneousBands)* nBXSize * nBYSize * nDTSize > 10 * 1024 * 1024 ) { bOKForSrc = false; } if( static_cast<GIntBig>(nBlockXSize) * nBlockYSize > 10 * 1024 * 1024 / (nBands * nDTSize) ) { bOKForSrc = false; } } bool bOKForStats = true; if( nBands && bStatsEnabled ) { // Other types might be too slow with sanitization enabled // See https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=10029 bOKForStats = poSrcDS->GetRasterBand(1)->GetRasterDataType() == GDT_Byte; } if( bOKForSrc && bOKForResampling && bOKForStats ) { GDALDatasetH hOutDS = GDALTranslate("/vsimem/out", hSrcDS, psOptions, nullptr); if( hOutDS ) GDALClose(hOutDS); } } GDALClose(hSrcDS); } GDALTranslateOptionsFree(psOptions); } } CSLDestroy(papszArgv); VSIRmdirRecursive("/vsimem/"); CPLPopErrorHandler(); return 0;}
开发者ID:OSGeo,项目名称:gdal,代码行数:101,
示例27: ogrDataFrame// extern "C" {SEXP ogrDataFrame(SEXP ogrSource, SEXP Layer, SEXP FIDs, SEXP iFields) { // query an OGR data source and return a list SEXP ans; SEXP nListFields, ListFields=R_NilValue, int64; OGRLayer *poLayer;#ifdef GDALV2 GDALDataset *poDS;#else OGRDataSource *poDS; OGRSFDriver *poDriver;#endif int iField, nflds=length(iFields), j=0, k; int pc=0; // open the data source layer or error installErrorHandler();#ifdef GDALV2 poDS=(GDALDataset*) GDALOpenEx(CHAR(STRING_ELT(ogrSource, 0)), GDAL_OF_VECTOR, NULL, NULL, NULL);#else poDS=OGRSFDriverRegistrar::Open(CHAR(STRING_ELT(ogrSource,0)), FALSE, &poDriver);#endif uninstallErrorHandlerAndTriggerError(); if(poDS==NULL) { error("Cannot open file"); } installErrorHandler(); poLayer = poDS->GetLayerByName(CHAR(STRING_ELT(Layer, 0))); uninstallErrorHandlerAndTriggerError(); if(poLayer == NULL) { error("Cannot open layer"); } int64 = getAttrib(iFields, mkString("int64")); nListFields = getAttrib(iFields, mkString("nListFields")); SEXP ENC_attr = getAttrib(iFields, mkString("ENCODING_DEBUG")); int ENC_DEBUG = LOGICAL_POINTER(ENC_attr)[0]; // reserve a list for the result if (INTEGER_POINTER(nListFields)[0] == 0) { PROTECT(ans=allocVector(VECSXP,length(iFields))); pc++; } else { nflds = INTEGER_POINTER(getAttrib(iFields, mkString("nflds")))[0]; PROTECT(ans=allocVector(VECSXP,nflds)); pc++; ListFields = getAttrib(iFields, mkString("ListFields")); } // now set each element of the list installErrorHandler(); if (INTEGER_POINTER(nListFields)[0] == 0) { for(iField=0; iField<length(iFields); iField++) { SET_VECTOR_ELT(ans,iField,ogrReadColumn(poLayer, FIDs, INTEGER(iFields)[iField], INTEGER(int64)[0], ENC_DEBUG)); } } else { j=0; for(iField=0; iField<length(iFields); iField++) { if (INTEGER_POINTER(ListFields)[iField] == 0) { SET_VECTOR_ELT(ans, j, ogrReadColumn(poLayer, FIDs, INTEGER(iFields)[iField], INTEGER(int64)[0], ENC_DEBUG)); j++; } else { for (k=0; k < INTEGER_POINTER(ListFields)[iField]; k++) { SET_VECTOR_ELT(ans, j, ogrReadListColumn(poLayer, FIDs, INTEGER(iFields)[iField], k, INTEGER(int64)[0])); j++; } } } } uninstallErrorHandlerAndTriggerError(); // clean up and return installErrorHandler();#ifdef GDALV2 GDALClose( poDS );#else OGRDataSource::DestroyDataSource( poDS );#endif// delete poDS; uninstallErrorHandlerAndTriggerError(); UNPROTECT(pc); return(ans);}
开发者ID:rforge,项目名称:rgdal,代码行数:90,
示例28: MIN//.........这里部分代码省略......... } } if (!advise_read) { for (int ib = 1; ib <= m_parent_dataset->nBands; ++ib) { if (ret == CE_None) { void *p = NULL; GDALRasterBlock *b = NULL; if ((buffer != NULL) && (ib == to_buffer_band)) { p = buffer; } else { GDALWMSRasterBand *band = static_cast<GDALWMSRasterBand *>(m_parent_dataset->GetRasterBand(ib)); if (m_overview >= 0) band = static_cast<GDALWMSRasterBand *>(band->GetOverview(m_overview)); if (!band->IsBlockInCache(x, y)) { b = band->GetLockedBlockRef(x, y, true); if (b != NULL) { p = b->GetDataRef(); if (p == NULL) { CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS: GetDataRef returned NULL."); ret = CE_Failure; } } } else { //CPLDebug("WMS", "Band %d, block (x,y)=(%d, %d) already in cache", band->GetBand(), x, y); } } if (p != NULL) { int pixel_space = GDALGetDataTypeSize(eDataType) / 8; int line_space = pixel_space * nBlockXSize; if (color_table == NULL) { if( ib <= ds->GetRasterCount()) { GDALDataType dt=eDataType; // Get the data from the PNG as stored instead of converting, if the server asks for that // TODO: This hack is from #3493 - not sure it really belongs here. if ((GDT_Int16==dt)&&(GDT_UInt16==ds->GetRasterBand(ib)->GetRasterDataType())) dt=GDT_UInt16; if (ds->RasterIO(GF_Read, 0, 0, sx, sy, p, sx, sy, dt, 1, &ib, pixel_space, line_space, 0) != CE_None) { CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS: RasterIO failed on downloaded block."); ret = CE_Failure; } } else { // parent expects 4 bands but file only has 3 so generate a all "opaque" 4th band if (accepted_as_no_alpha) { // the file had 3 bands and we are reading band 4 (Alpha) so fill with 255 (no alpha) GByte *byte_buffer = reinterpret_cast<GByte *>(p); for (int y = 0; y < sy; ++y) { for (int x = 0; x < sx; ++x) { const int offset = x + y * line_space; byte_buffer[offset] = 255; // fill with opaque } } } else { // we should never get here because this case was caught above CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS: Incorrect bands count %d in downloaded block, expected %d.", ds->GetRasterCount(), m_parent_dataset->nBands); ret = CE_Failure; } } } else if (ib <= 4) { if (ds->RasterIO(GF_Read, 0, 0, sx, sy, p, sx, sy, eDataType, 1, NULL, pixel_space, line_space, 0) != CE_None) { CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS: RasterIO failed on downloaded block."); ret = CE_Failure; } if (ret == CE_None) { GByte *band_color_table = color_table + 256 * (ib - 1); GByte *byte_buffer = reinterpret_cast<GByte *>(p); for (int y = 0; y < sy; ++y) { for (int x = 0; x < sx; ++x) { const int offset = x + y * line_space; byte_buffer[offset] = band_color_table[byte_buffer[offset]]; } } } } else { CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS: Color table supports at most 4 components."); ret = CE_Failure; } } if (b != NULL) { b->DropLock(); } } } } GDALClose(ds); } else { CPLError(CE_Failure, CPLE_AppDefined, "GDALWMS: Unable to open downloaded block."); ret = CE_Failure; } if (color_table != NULL) { delete[] color_table; } return ret;}
开发者ID:Mofangbao,项目名称:node-gdal,代码行数:101,
示例29: strlen//.........这里部分代码省略......... } /* Extract pixel spacing information */ const char *pszPixelSpacing = CPLGetXMLValue( psAnnotation, "=product.imageAnnotation.imageInformation.rangePixelSpacing", "UNK" ); poDS->SetMetadataItem( "PIXEL_SPACING", pszPixelSpacing ); const char *pszLineSpacing = CPLGetXMLValue( psAnnotation, "=product.imageAnnotation.imageInformation.azimuthPixelSpacing", "UNK" ); poDS->SetMetadataItem( "LINE_SPACING", pszLineSpacing );/* -------------------------------------------------------------------- *//* Form full filename (path of manifest.safe + measurement file). *//* -------------------------------------------------------------------- */ char *pszFullname = CPLStrdup(CPLFormFilename( osPath, pszMeasurement, NULL ));/* -------------------------------------------------------------------- *//* Try and open the file. *//* -------------------------------------------------------------------- */ GDALDataset *poBandFile = reinterpret_cast<GDALDataset *>( GDALOpen( pszFullname, GA_ReadOnly ) ); if( poBandFile == NULL ) { // NOP } else if (poBandFile->GetRasterCount() == 0) { GDALClose( (GDALRasterBandH) poBandFile ); } else { poDS->papszExtraFiles = CSLAddString( poDS->papszExtraFiles, osAnnotationFilePath ); poDS->papszExtraFiles = CSLAddString( poDS->papszExtraFiles, pszFullname );/* -------------------------------------------------------------------- *//* Create the band. *//* -------------------------------------------------------------------- */ SAFERasterBand *poBand = new SAFERasterBand( poDS, eDataType, osSwath.c_str(), osPolarisation.c_str(), poBandFile ); poDS->SetBand( poDS->GetRasterCount() + 1, poBand ); } CPLFree( pszFullname ); } } //loop through all Swath/pols to add subdatasets int iSubDS = 1; for (std::map<CPLString, std::set<CPLString> >::iterator iterSwath=oMapSwaths2Pols.begin(); iterSwath!=oMapSwaths2Pols.end(); ++iterSwath) { CPLString osSubDS1 = iterSwath->first; CPLString osSubDS2; for (std::set<CPLString>::iterator iterPol=iterSwath->second.begin();
开发者ID:Mavrx-inc,项目名称:gdal,代码行数:67,
注:本文中的GDALClose函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ GDALCreate函数代码示例 C++ GDALCheckDatasetDimensions函数代码示例 |