本文整理汇总了C++中OGRDataSource类的典型用法代码示例。如果您正苦于以下问题:C++ OGRDataSource类的具体用法?C++ OGRDataSource怎么用?C++ OGRDataSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OGRDataSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ProblemReporterOGR
explicit ProblemReporterOGR(OGRDataSource* data_source) :
m_data_source(data_source) {
OGRSpatialReference sparef;
sparef.SetWellKnownGeogCS("WGS84");
m_layer_perror = m_data_source->CreateLayer("perrors", &sparef, wkbPoint, nullptr);
if (!m_layer_perror) {
std::runtime_error("Layer creation failed for layer 'perrors'");
}
OGRFieldDefn layer_perror_field_id1("id1", OFTReal);
layer_perror_field_id1.SetWidth(10);
if (m_layer_perror->CreateField(&layer_perror_field_id1) != OGRERR_NONE) {
std::runtime_error("Creating field 'id1' failed for layer 'perrors'");
}
OGRFieldDefn layer_perror_field_id2("id2", OFTReal);
layer_perror_field_id2.SetWidth(10);
if (m_layer_perror->CreateField(&layer_perror_field_id2) != OGRERR_NONE) {
std::runtime_error("Creating field 'id2' failed for layer 'perrors'");
}
OGRFieldDefn layer_perror_field_problem_type("problem_type", OFTString);
layer_perror_field_problem_type.SetWidth(30);
if (m_layer_perror->CreateField(&layer_perror_field_problem_type) != OGRERR_NONE) {
std::runtime_error("Creating field 'problem_type' failed for layer 'perrors'");
}
/**************/
m_layer_lerror = m_data_source->CreateLayer("lerrors", &sparef, wkbLineString, nullptr);
if (!m_layer_lerror) {
std::runtime_error("Layer creation failed for layer 'lerrors'");
}
OGRFieldDefn layer_lerror_field_id1("id1", OFTReal);
layer_lerror_field_id1.SetWidth(10);
if (m_layer_lerror->CreateField(&layer_lerror_field_id1) != OGRERR_NONE) {
std::runtime_error("Creating field 'id1' failed for layer 'lerrors'");
}
OGRFieldDefn layer_lerror_field_id2("id2", OFTReal);
layer_lerror_field_id2.SetWidth(10);
if (m_layer_lerror->CreateField(&layer_lerror_field_id2) != OGRERR_NONE) {
std::runtime_error("Creating field 'id2' failed for layer 'lerrors'");
}
OGRFieldDefn layer_lerror_field_problem_type("problem_type", OFTString);
layer_lerror_field_problem_type.SetWidth(30);
if (m_layer_lerror->CreateField(&layer_lerror_field_problem_type) != OGRERR_NONE) {
std::runtime_error("Creating field 'problem_type' failed for layer 'lerrors'");
}
}
示例2: OGR_Dr_CreateDataSource
OGRDataSourceH OGR_Dr_CreateDataSource( OGRSFDriverH hDriver,
const char *pszName,
char ** papszOptions )
{
VALIDATE_POINTER1( hDriver, "OGR_Dr_CreateDataSource", NULL );
OGRSFDriver* poDriver = (OGRSFDriver *) hDriver;
CPLAssert( NULL != poDriver );
OGRDataSource* poDS = NULL;
poDS = poDriver->CreateDataSource( pszName, papszOptions );
/* This fix is explained in Ticket #1223 */
if( NULL != poDS )
{
poDS->SetDriver( poDriver );
CPLAssert( NULL != poDS->GetDriver() );
}
else
{
CPLDebug( "OGR", "CreateDataSource operation failed. NULL pointer returned." );
}
return (OGRDataSourceH) poDS;
}
示例3: CPLError
OGRDataSource *OGRSFDriver::CopyDataSource( OGRDataSource *poSrcDS,
const char *pszNewName,
char **papszOptions )
{
if( !TestCapability( ODrCCreateDataSource ) )
{
CPLError( CE_Failure, CPLE_NotSupported,
"%s driver does not support data source creation.",
GetName() );
return NULL;
}
OGRDataSource *poODS;
poODS = CreateDataSource( pszNewName, papszOptions );
if( poODS == NULL )
return NULL;
/* -------------------------------------------------------------------- */
/* Process each data source layer. */
/* -------------------------------------------------------------------- */
for( int iLayer = 0; iLayer < poSrcDS->GetLayerCount(); iLayer++ )
{
OGRLayer *poLayer = poSrcDS->GetLayer(iLayer);
if( poLayer == NULL )
continue;
poODS->CopyLayer( poLayer, poLayer->GetLayerDefn()->GetName(),
papszOptions );
}
return poODS;
}
示例4: readFile
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;
}
示例5: VectorOpen
bool V2vProj::Compute(const data::VectorBarral * barrel)
{
OGRDataSource * poSourceDs = VectorOpen(barrel->GetSrcDataSource().c_str(),
GA_ReadOnly);
ON_SCOPE_EXIT([&]() {OGRDataSource::DestroyDataSource(poSourceDs); });
OGRDataSource * poOutputDs = VectorOpen(barrel->GetDstDataSource().c_str(),
GA_Update);
ON_SCOPE_EXIT([&]() {OGRDataSource::DestroyDataSource(poOutputDs); });
OGRLayer * poSrcLayer = poSourceDs->GetLayerByName(
barrel->GetSrcLayer().c_str());
OGRLayer * poDstLayer = poOutputDs->GetLayerByName(
barrel->GetDstLayer().c_str());
OGRSpatialReference * poSourceSRS = poSrcLayer->GetSpatialRef();
OGRCoordinateTransformation * poCT = poCT = OGRCreateCoordinateTransformation(
poSourceSRS, m_ogrSr);
OGRFeatureDefn * poDstFeatureDefn = poDstLayer->GetLayerDefn();
auto features = barrel->GetFeatures();
std::for_each(begin(features), end(features)
, [&](int fid) {
poSrcLayer->GetFeature(fid);
OGRFeature * poDstFeature = OGRFeature::CreateFeature(poDstFeatureDefn);
ON_SCOPE_EXIT([&]() {OGRFeature::DestroyFeature(poDstFeature); });
poDstFeature->SetFrom(poSrcLayer->GetFeature(fid));
OGRGeometry * poDstGeometry = poDstFeature->GetGeometryRef();
OGRGeometry * poReprojectedGeom = OGRGeometryFactory::transformWithOptions(
poDstGeometry, poCT, NULL);
poDstFeature->SetGeometryDirectly(poReprojectedGeom);
poDstLayer->CreateFeature(poDstFeature);
});
return true;
}
示例6: main
//#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");
}
}
示例7: if
JNIEXPORT jlong JNICALL Java_es_gva_cit_jogr_OGRDataSource_createLayerNat
(JNIEnv *env, jobject obj, jlong cPtr, jstring pszName, jlong poSpatialRef, jstring eGType, jobjectArray papszOptions){
OGRDataSource *ds = (OGRDataSource *) 0 ;
int longitud;
char **opciones;
OGRLayer *layer_dstno;
OGRSpatialReference *spatialRef;
long ptr_dtno=-1;
OGRwkbGeometryType geomtype;
ds = *(OGRDataSource **)&cPtr;
spatialRef = *(OGRSpatialReference **)&poSpatialRef;
if(ds!=NULL){
longitud = env->GetArrayLength( papszOptions);
opciones = (char **)malloc(sizeof(char *)*longitud);
for(int i=0;i<longitud;i++){
jstring el = (jstring)env->GetObjectArrayElement(papszOptions,i);
const char *simple_option = env->GetStringUTFChars( el, 0);
opciones[i]=(char *)malloc(strlen(simple_option));
strcpy(opciones[i],simple_option);
env->ReleaseStringUTFChars( el, simple_option);
}
const char *type = env->GetStringUTFChars( eGType, 0);
const char *name = env->GetStringUTFChars( pszName, 0);
if(strcmp(type,"wkbUnknown")==0)geomtype = wkbUnknown;
else if(strcmp(type,"wkbPoint")==0)geomtype = wkbPoint;
else if(strcmp(type,"wkbLineString")==0)geomtype = wkbLineString;
else if(strcmp(type,"wkbPolygon")==0)geomtype = wkbPolygon;
else if(strcmp(type,"wkbMultiPoint")==0)geomtype = wkbMultiPoint;
else if(strcmp(type,"wkbMultiLineString")==0)geomtype = wkbMultiLineString;
else if(strcmp(type,"wkbMultiPolygon")==0)geomtype = wkbMultiPolygon;
else if(strcmp(type,"wkbGeometryCollection")==0)geomtype = wkbGeometryCollection;
else if(strcmp(type,"wkbNone")==0)geomtype = wkbNone;
else if(strcmp(type,"wkbLinearRing")==0)geomtype = wkbLinearRing;
else if(strcmp(type,"wkbPoint25D")==0)geomtype = wkbPoint25D;
else if(strcmp(type,"wkbLineString25D")==0)geomtype = wkbLineString25D;
else if(strcmp(type,"wkbPolygon25D")==0)geomtype = wkbPolygon25D;
else if(strcmp(type,"wkbMultiPoint25D")==0)geomtype = wkbMultiPoint25D;
else if(strcmp(type,"wkbMultiLineString25D")==0)geomtype = wkbMultiLineString25D;
else if(strcmp(type,"wkbMultiPolygon25D")==0)geomtype = wkbMultiPolygon25D;
else if(strcmp(type,"wkbGeometryCollection25D")==0)geomtype = wkbGeometryCollection25D;
layer_dstno = ds->CreateLayer(name, spatialRef, geomtype, opciones);
env->ReleaseStringUTFChars( eGType, type);
env->ReleaseStringUTFChars( pszName, name);
}
for(int i=0;i<longitud;i++)free(opciones[i]);
free(opciones);
if(layer_dstno==NULL)return -1;
ptr_dtno = (long)&(*layer_dstno);
return (jlong)ptr_dtno;
}
示例8: OpenWithDriverArg
GDALDataset* OGRSFDriverRegistrar::OpenWithDriverArg(GDALDriver* poDriver,
GDALOpenInfo* poOpenInfo)
{
OGRDataSource* poDS = (OGRDataSource*)
((OGRSFDriver*)poDriver)->Open(poOpenInfo->pszFilename,
poOpenInfo->eAccess == GA_Update);
if( poDS != NULL )
poDS->SetDescription( poDS->GetName() );
return poDS;
}
示例9: CreateVectorOnly
GDALDataset* OGRSFDriverRegistrar::CreateVectorOnly( GDALDriver* poDriver,
const char * pszName,
char ** papszOptions )
{
OGRDataSource* poDS = (OGRDataSource*)
((OGRSFDriver*)poDriver)->CreateDataSource(pszName, papszOptions);
if( poDS != NULL && poDS->GetName() != NULL )
poDS->SetDescription( poDS->GetName() );
return poDS;
}
示例10: GetSummaryRefCount
int OGRDataSource::GetSummaryRefCount() const
{
int nSummaryCount = m_nRefCount;
int iLayer;
OGRDataSource *poUseThis = (OGRDataSource *) this;
for( iLayer=0; iLayer < poUseThis->GetLayerCount(); iLayer++ )
nSummaryCount += poUseThis->GetLayer( iLayer )->GetRefCount();
return nSummaryCount;
}
示例11:
JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_OGRDataSource_deleteLayerNat
(JNIEnv *env, jobject obj, jlong cPtr, jint layer){
OGRDataSource *ds = (OGRDataSource *) 0 ;
int ogrerr;
ds = *(OGRDataSource **)&cPtr;
if(ds!=NULL){
ogrerr = ds->DeleteLayer(layer);
}
return ogrerr;
}
示例12: CPLMutexHolderD
int OGRDataSource::GetSummaryRefCount() const
{
CPLMutexHolderD( (void **) &m_hMutex );
int nSummaryCount = m_nRefCount;
int iLayer;
OGRDataSource *poUseThis = (OGRDataSource *) this;
for( iLayer=0; iLayer < poUseThis->GetLayerCount(); iLayer++ )
nSummaryCount += poUseThis->GetLayer( iLayer )->GetRefCount();
return nSummaryCount;
}
示例13: OGR_Dr_Open
OGRDataSourceH OGR_Dr_Open( OGRSFDriverH hDriver, const char *pszName,
int bUpdate )
{
VALIDATE_POINTER1( hDriver, "OGR_Dr_Open", NULL );
OGRDataSource *poDS = ((OGRSFDriver *)hDriver)->Open( pszName, bUpdate );
if( poDS != NULL && poDS->GetDriver() == NULL )
poDS->SetDriver( (OGRSFDriver *)hDriver );
return (OGRDataSourceH) poDS;
}
示例14: VectorCreate
OGRDataSource * VectorCreate( const char * pszFormat, const char * pszFilename, char ** papszOptions/*=NULL*/ )
{
OGRSFDriver * poDriver = GetVectorDriver(pszFormat);
OGRDataSource * poOGRDataSource =
poDriver->CreateDataSource(pszFilename, papszOptions);
#ifdef TRACEON
//测试时使用文件型数据库,没有图层时打开有问题,因此在这里放一个图层
//这样才能打开,不用测试可以关闭,在release中没有
poOGRDataSource->CreateLayer("TEMP", NULL, wkbUnknown, NULL);
#endif
return poOGRDataSource;
}
示例15: WrapLayer
OGRLayer *OGRDataSourceWithTransaction::CopyLayer( OGRLayer *poSrcLayer,
const char *pszNewName,
char **papszOptions )
{
if( !m_poBaseDataSource ) return NULL;
return WrapLayer(m_poBaseDataSource->CopyLayer(poSrcLayer, pszNewName, papszOptions ));
}