本文整理汇总了C++中OGRFeatureDefn::GetGeomType方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRFeatureDefn::GetGeomType方法的具体用法?C++ OGRFeatureDefn::GetGeomType怎么用?C++ OGRFeatureDefn::GetGeomType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRFeatureDefn
的用法示例。
在下文中一共展示了OGRFeatureDefn::GetGeomType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
JNIEXPORT jint JNICALL Java_es_gva_cit_jogr_OGRFeatureDefn_getGeomTypeNat
(JNIEnv *env, jobject obj, jlong cPtr){
OGRFeatureDefn *fd = (OGRFeatureDefn *) 0 ;
fd = *(OGRFeatureDefn **)&cPtr;
OGRwkbGeometryType tipo = fd->GetGeomType();
if(tipo==wkbUnknown)return 0;
if(tipo==wkbPoint)return 1;
if(tipo==wkbLineString)return 2;
if(tipo==wkbPolygon)return 3;
if(tipo==wkbMultiPoint)return 4;
if(tipo==wkbMultiLineString)return 5;
if(tipo==wkbMultiPolygon)return 6;
if(tipo==wkbGeometryCollection)return 7;
if(tipo==wkbNone)return 8;
if(tipo==wkbLinearRing)return 9;
if(tipo==wkbPoint25D)return 10;
if(tipo==wkbLineString25D)return 11;
if(tipo==wkbPolygon25D)return 12;
if(tipo==wkbMultiPoint25D)return 13;
if(tipo==wkbMultiLineString25D)return 14;
if(tipo==wkbMultiPolygon25D)return 15;
if(tipo==wkbGeometryCollection25D)return 16;
return -1;
}
示例2: VectorMetaDataInfo
void ShpReader::VectorMetaDataInfo(OGRDataSource* OGRDataset, StudyControllerPtr studyController, VectorMapControllerPtr vectorMapController)
{
vFileMetaData* vHeader = vectorMapController->GetVectorMapModel()->GetVectorMetaData();
OGRLayer *poLayer = OGRDataset->GetLayer( 0 );
char *originalWkt = NULL;
char *destinationWkt = NULL;
OGREnvelope psEnvelope;
poLayer->GetExtent( &psEnvelope );
vHeader->originalExtents.x = psEnvelope.MinX;
vHeader->originalExtents.dx = psEnvelope.MaxX;
vHeader->originalExtents.y = psEnvelope.MinY;
vHeader->originalExtents.dy = psEnvelope.MaxY;
Log::Inst().Write("Original Extents: ");
Log::Inst().Write(_T("Lower, Left (x,y): ") +wxString(StringTools::ToStringW(vHeader->originalExtents.x, 2).c_str()) + _T(", ")
+ wxString(StringTools::ToStringW(vHeader->originalExtents.y, 2).c_str()));
Log::Inst().Write(_T("Upper, Right (x,y): ") +wxString(StringTools::ToStringW(vHeader->originalExtents.dx, 2).c_str()) + _T(", ")
+ wxString(StringTools::ToStringW(vHeader->originalExtents.dy, 2).c_str()));
vHeader->numFeatures= poLayer->GetFeatureCount();
Log::Inst().Write("Number of Features: " + StringTools::ToString(vHeader->numFeatures));
std::string type;
OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
if ( wkbFlatten( poFDefn->GetGeomType() ) == wkbPoint || wkbFlatten( poFDefn->GetGeomType() ) == wkbMultiPoint )
type="Point";
else if ( wkbFlatten(poFDefn->GetGeomType() ) == wkbLineString || wkbFlatten(poFDefn->GetGeomType() ) == wkbMultiLineString )
type="Polyline";
else if ( wkbFlatten( poFDefn->GetGeomType() ) == wkbPolygon || wkbFlatten( poFDefn->GetGeomType() ) == wkbMultiPolygon )
type="Polygon";
else
type="Unknown";
vHeader->geometryType=type;
Log::Inst().Write("Geometry Type: "+ type);
OGRSpatialReference* originalShpSR = poLayer->GetSpatialRef();
if (originalShpSR != NULL)
{
originalShpSR->exportToWkt(&originalWkt);
vHeader->originalProjection = std::string(originalWkt);
}
Log::Inst().Write("Original Projection: " + vHeader->originalProjection);
Log::Inst().Write("");
ProjectionToolPtr projTool = studyController->GetProjectionTool();
if (projTool != NULL)
{
OGRSpatialReference *destinationCS= projTool->GetTargetCS ();
destinationCS->exportToWkt(&destinationWkt);
vHeader->destinationProjection = std::string(destinationWkt);
}
vHeader->currentExtents.x = vectorMapController->GetVectorMapModel()->GetVectorBoundary_MinX();
vHeader->currentExtents.y = vectorMapController->GetVectorMapModel()->GetVectorBoundary_MinY();
vHeader->currentExtents.dx = vectorMapController->GetVectorMapModel()->GetVectorBoundary_MaxX();
vHeader->currentExtents.dy = vectorMapController->GetVectorMapModel()->GetVectorBoundary_MaxY();
//Log::Inst().Write("Upper, Right (x,y): " +
// StringTools::ToString(vHeader->currentExtents.dx) + ", " +
//StringTools::ToString(vHeader->currentExtents.dy));
}
示例3: if
int ILI1Reader::ReadTable(const char *layername) {
char **tokens = NULL;
const char *firsttok = NULL;
int ret = TRUE;
int warned = FALSE;
int fIndex;
int geomIdx;
// curLayer is NULL if we have more than one
// point geometry column
if(curLayer == NULL) {
OGRFeature *metaFeature = NULL;
metaLayer->ResetReading();
while((metaFeature = metaLayer->GetNextFeature()) != NULL ) {
if(EQUAL(layername, metaFeature->GetFieldAsString(0))) {
const char *geomlayername = metaFeature->GetFieldAsString(2);
curLayer = GetLayerByName(geomlayername);
break;
}
}
}
OGRFeatureDefn *featureDef = curLayer->GetLayerDefn();
OGRFeature *feature = NULL;
// get the geometry index of the current layer
// only if the model is read
if(featureDef->GetFieldCount() != 0) {
OGRFeature *metaFeature = NULL;
metaLayer->ResetReading();
while((metaFeature = metaLayer->GetNextFeature()) != NULL ) {
if(EQUAL(curLayer->GetLayerDefn()->GetName(), metaFeature->GetFieldAsString(2))) {
geomIdx = metaFeature->GetFieldAsInteger(1);
}
}
}
long fpos = VSIFTell(fpItf);
while (ret && (tokens = ReadParseLine()))
{
firsttok = CSLGetField(tokens, 0);
if (EQUAL(firsttok, "OBJE"))
{
//Check for features spread over multiple objects
if (featureDef->GetGeomType() == wkbPolygon)
{
//Multiple polygon rings
feature = curLayer->GetFeatureRef(atol(CSLGetField(tokens, 2)));
}
else if (featureDef->GetGeomType() == wkbGeometryCollection)
{
//AREA lines spread over mutltiple objects
}
else
{
feature = NULL;
}
if (feature == NULL)
{
if (featureDef->GetFieldCount() == 0)
{
CPLDebug( "OGR_ILI", "No field definition found for table: %s", featureDef->GetName() );
//Model not read - use heuristics
for (fIndex=1; fIndex<CSLCount(tokens); fIndex++)
{
char szFieldName[32];
sprintf(szFieldName, "Field%02d", fIndex);
OGRFieldDefn oFieldDefn(szFieldName, OFTString);
featureDef->AddFieldDefn(&oFieldDefn);
}
}
//start new feature
feature = new OGRFeature(featureDef);
int fieldno = 0;
for (fIndex=1; fIndex<CSLCount(tokens) && fieldno < featureDef->GetFieldCount(); fIndex++, fieldno++)
{
if (!EQUAL(tokens[fIndex], "@")) {
//CPLDebug( "READ TABLE OGR_ILI", "Adding Field %d: %s", fieldno, tokens[fIndex]);
feature->SetField(fieldno, tokens[fIndex]);
if (featureDef->GetFieldDefn(fieldno)->GetType() == OFTReal
&& fieldno > 0
&& featureDef->GetFieldDefn(fieldno-1)->GetType() == OFTReal
&& featureDef->GetGeomType() == wkbPoint
/*
// if there is no ili model read,
// we have no chance to detect the
// geometry column!!
*/
&& (fieldno-2) == geomIdx) {
//add Point geometry
OGRPoint *ogrPoint = new OGRPoint(atof(tokens[fIndex-1]), atof(tokens[fIndex]));
feature->SetGeometryDirectly(ogrPoint);
}
}
}
if (!warned && featureDef->GetFieldCount() != CSLCount(tokens)-1 && !(featureDef->GetFieldCount() == CSLCount(tokens) && EQUAL(featureDef->GetFieldDefn(featureDef->GetFieldCount()-1)->GetNameRef(), "ILI_Geometry"))) {
//.........这里部分代码省略.........
示例4: ReportOnLayer
static void ReportOnLayer( OGRLayer * poLayer, const char *pszWHERE,
OGRGeometry *poSpatialFilter )
{
OGRFeatureDefn *poDefn = poLayer->GetLayerDefn();
/* -------------------------------------------------------------------- */
/* Set filters if provided. */
/* -------------------------------------------------------------------- */
if( pszWHERE != NULL )
poLayer->SetAttributeFilter( pszWHERE );
if( poSpatialFilter != NULL )
poLayer->SetSpatialFilter( poSpatialFilter );
/* -------------------------------------------------------------------- */
/* Report various overall information. */
/* -------------------------------------------------------------------- */
printf( "\n" );
printf( "Layer name: %s\n", poDefn->GetName() );
if( bVerbose )
{
printf( "Geometry: %s\n",
OGRGeometryTypeToName( poDefn->GetGeomType() ) );
printf( "Feature Count: %d\n", poLayer->GetFeatureCount() );
OGREnvelope oExt;
if (poLayer->GetExtent(&oExt, TRUE) == OGRERR_NONE)
{
printf("Extent: (%f, %f) - (%f, %f)\n",
oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
}
char *pszWKT;
if( poLayer->GetSpatialRef() == NULL )
pszWKT = CPLStrdup( "(unknown)" );
else
{
poLayer->GetSpatialRef()->exportToPrettyWkt( &pszWKT );
}
printf( "Layer SRS WKT:\n%s\n", pszWKT );
CPLFree( pszWKT );
if( strlen(poLayer->GetFIDColumn()) > 0 )
printf( "FID Column = %s\n",
poLayer->GetFIDColumn() );
if( strlen(poLayer->GetGeometryColumn()) > 0 )
printf( "Geometry Column = %s\n",
poLayer->GetGeometryColumn() );
for( int iAttr = 0; iAttr < poDefn->GetFieldCount(); iAttr++ )
{
OGRFieldDefn *poField = poDefn->GetFieldDefn( iAttr );
printf( "%s: %s (%d.%d)\n",
poField->GetNameRef(),
poField->GetFieldTypeName( poField->GetType() ),
poField->GetWidth(),
poField->GetPrecision() );
}
}
/* -------------------------------------------------------------------- */
/* Read, and dump features. */
/* -------------------------------------------------------------------- */
OGRFeature *poFeature = NULL;
if( nFetchFID == OGRNullFID && !bSummaryOnly )
{
while( (poFeature = poLayer->GetNextFeature()) != NULL )
{
poFeature->DumpReadable( NULL, papszOptions );
OGRFeature::DestroyFeature( poFeature );
}
}
else if( nFetchFID != OGRNullFID )
{
poFeature = poLayer->GetFeature( nFetchFID );
if( poFeature == NULL )
{
printf( "Unable to locate feature id %d on this layer.\n",
nFetchFID );
}
else
{
poFeature->DumpReadable( NULL, papszOptions );
OGRFeature::DestroyFeature( poFeature );
}
}
}
示例5: ReportOnLayer
static void ReportOnLayer( OGRLayer * poLayer, const char *pszWHERE,
OGRGeometry *poSpatialFilter )
{
OGRFeatureDefn *poDefn = poLayer->GetLayerDefn();
/* -------------------------------------------------------------------- */
/* Set filters if provided. */
/* -------------------------------------------------------------------- */
if( pszWHERE != NULL )
poLayer->SetAttributeFilter( pszWHERE );
if( poSpatialFilter != NULL )
poLayer->SetSpatialFilter( poSpatialFilter );
/* -------------------------------------------------------------------- */
/* Report various overall information. */
/* -------------------------------------------------------------------- */
printf( "\n" );
printf( "Layer name: %s\n", poDefn->GetName() );
printf( "Geometry: %s\n",
OGRGeometryTypeToName( poDefn->GetGeomType() ) );
printf( "Feature Count: %d\n", poLayer->GetFeatureCount() );
OGREnvelope oExt;
if (poLayer->GetExtent(&oExt, TRUE) == OGRERR_NONE)
{
printf("Extent: (%f, %f) - (%f, %f)\n",
oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
}
if( bVerbose )
{
char *pszWKT;
if( poLayer->GetSpatialRef() == NULL )
pszWKT = CPLStrdup( "(NULL)" );
else
poLayer->GetSpatialRef()->exportToWkt( &pszWKT );
printf( "Layer SRS WKT: %s\n", pszWKT );
CPLFree( pszWKT );
}
for( int iAttr = 0; iAttr < poDefn->GetFieldCount(); iAttr++ )
{
OGRFieldDefn *poField = poDefn->GetFieldDefn( iAttr );
printf( "%s: %s (%d.%d)\n",
poField->GetNameRef(),
poField->GetFieldTypeName( poField->GetType() ),
poField->GetWidth(),
poField->GetPrecision() );
}
/* -------------------------------------------------------------------- */
/* Read, and dump features. */
/* -------------------------------------------------------------------- */
OGRFeature *poFeature;
while( (poFeature = poLayer->GetNextFeature()) != NULL )
{
poFeature->DumpReadable( stdout );
delete poFeature;
}
/* -------------------------------------------------------------------- */
/* Read, and dump features. */
/* -------------------------------------------------------------------- */
#ifdef notdef
OGRFeature *poFeature;
int nId = -1;
while( (nId = poTF->GetNextFeatureId_Spatial(nId)) != -1 )
{
poFeature = poTF->GetFeatureRef( nId );
}
#endif
}
示例6: CPLError
OGRLayer *OGRDataSource::CopyLayer( OGRLayer *poSrcLayer,
const char *pszNewName,
char **papszOptions )
{
OGRFeatureDefn *poSrcDefn = poSrcLayer->GetLayerDefn();
OGRLayer *poDstLayer = NULL;
/* -------------------------------------------------------------------- */
/* Create the layer. */
/* -------------------------------------------------------------------- */
if( !TestCapability( ODsCCreateLayer ) )
{
CPLError( CE_Failure, CPLE_NotSupported,
"This datasource does not support creation of layers." );
return NULL;
}
CPLErrorReset();
poDstLayer = CreateLayer( pszNewName, poSrcLayer->GetSpatialRef(),
poSrcDefn->GetGeomType(), papszOptions );
if( poDstLayer == NULL )
return NULL;
/* -------------------------------------------------------------------- */
/* Add fields. Default to copy all field. */
/* If only a subset of all fields requested, then output only */
/* the selected fields, and in the order that they were */
/* selected. */
/* -------------------------------------------------------------------- */
int iField;
for( iField = 0; iField < poSrcDefn->GetFieldCount(); iField++ )
poDstLayer->CreateField( poSrcDefn->GetFieldDefn(iField) );
/* -------------------------------------------------------------------- */
/* Transfer features. */
/* -------------------------------------------------------------------- */
OGRFeature *poFeature;
poSrcLayer->ResetReading();
while( TRUE )
{
OGRFeature *poDstFeature = NULL;
poFeature = poSrcLayer->GetNextFeature();
if( poFeature == NULL )
break;
CPLErrorReset();
poDstFeature = OGRFeature::CreateFeature( poDstLayer->GetLayerDefn() );
if( poDstFeature->SetFrom( poFeature, TRUE ) != OGRERR_NONE )
{
delete poFeature;
CPLError( CE_Failure, CPLE_AppDefined,
"Unable to translate feature %d from layer %s.\n",
poFeature->GetFID(), poSrcDefn->GetName() );
return poDstLayer;
}
poDstFeature->SetFID( poFeature->GetFID() );
OGRFeature::DestroyFeature( poFeature );
CPLErrorReset();
if( poDstLayer->CreateFeature( poDstFeature ) != OGRERR_NONE )
{
OGRFeature::DestroyFeature( poDstFeature );
return poDstLayer;
}
OGRFeature::DestroyFeature( poDstFeature );
}
return poDstLayer;
}
示例7: CPLError
OGRLayer *OGRDataSource::CopyLayer( OGRLayer *poSrcLayer,
const char *pszNewName,
char **papszOptions )
{
OGRFeatureDefn *poSrcDefn = poSrcLayer->GetLayerDefn();
OGRLayer *poDstLayer = NULL;
/* -------------------------------------------------------------------- */
/* Create the layer. */
/* -------------------------------------------------------------------- */
if( !TestCapability( ODsCCreateLayer ) )
{
CPLError( CE_Failure, CPLE_NotSupported,
"This datasource does not support creation of layers." );
return NULL;
}
CPLErrorReset();
poDstLayer = CreateLayer( pszNewName, poSrcLayer->GetSpatialRef(),
poSrcDefn->GetGeomType(), papszOptions );
if( poDstLayer == NULL )
return NULL;
/* -------------------------------------------------------------------- */
/* Add fields. Default to copy all field. */
/* If only a subset of all fields requested, then output only */
/* the selected fields, and in the order that they were */
/* selected. */
/* -------------------------------------------------------------------- */
int iField;
for( iField = 0; iField < poSrcDefn->GetFieldCount(); iField++ )
poDstLayer->CreateField( poSrcDefn->GetFieldDefn(iField) );
/* -------------------------------------------------------------------- */
/* Check if the destination layer supports transactions and set a */
/* default number of features in a single transaction. */
/* -------------------------------------------------------------------- */
int nGroupTransactions = 0;
if( poDstLayer->TestCapability( OLCTransactions ) )
nGroupTransactions = 128;
/* -------------------------------------------------------------------- */
/* Transfer features. */
/* -------------------------------------------------------------------- */
OGRFeature *poFeature;
poSrcLayer->ResetReading();
if( nGroupTransactions <= 0 )
{
while( TRUE )
{
OGRFeature *poDstFeature = NULL;
poFeature = poSrcLayer->GetNextFeature();
if( poFeature == NULL )
break;
CPLErrorReset();
poDstFeature = OGRFeature::CreateFeature( poDstLayer->GetLayerDefn() );
if( poDstFeature->SetFrom( poFeature, TRUE ) != OGRERR_NONE )
{
delete poFeature;
CPLError( CE_Failure, CPLE_AppDefined,
"Unable to translate feature %ld from layer %s.\n",
poFeature->GetFID(), poSrcDefn->GetName() );
return poDstLayer;
}
poDstFeature->SetFID( poFeature->GetFID() );
OGRFeature::DestroyFeature( poFeature );
CPLErrorReset();
if( poDstLayer->CreateFeature( poDstFeature ) != OGRERR_NONE )
{
OGRFeature::DestroyFeature( poDstFeature );
return poDstLayer;
}
OGRFeature::DestroyFeature( poDstFeature );
}
}
else
{
int i, bStopTransfer = FALSE, bStopTransaction = FALSE;
int nFeatCount = 0; // Number of features in the temporary array
int nFeaturesToAdd = 0;
while( !bStopTransfer )
{
OGRFeature **papoDstFeature =
(OGRFeature **)CPLCalloc(sizeof(OGRFeature *), nGroupTransactions);
/* -------------------------------------------------------------------- */
/* Fill the array with features */
//.........这里部分代码省略.........
示例8: readFromDataset
FBErr FBProjectGdal::readFromDataset (QString datasetPath)
{
// Firstly try to open dataset and check its correctness.
QByteArray ba;
ba = datasetPath.toUtf8();
GDALDataset *dataset;
dataset = (GDALDataset*) GDALOpenEx(ba.data(), GDAL_OF_VECTOR,
NULL, NULL, NULL);
if (dataset == NULL)
{
FBProject::CUR_ERR_INFO = QObject::tr("Unable to open dataset via GDAL");
return FBErrIncorrectGdalDataset;
}
// Check layer's count.
int layerCount = dataset->GetLayerCount();
if (layerCount == 0 || layerCount > 1)
{
GDALClose(dataset);
FBProject::CUR_ERR_INFO = QObject::tr("Selected GDAL dataset must contain 1"
"layer, while it contains ") + QString::number(layerCount);
return FBErrIncorrectGdalDataset;
}
OGRLayer *layer = dataset->GetLayer(0);
if (layer == NULL)
{
GDALClose(dataset);
FBProject::CUR_ERR_INFO = QObject::tr("Unable to read layer in selected GDAL"
"dataset");
return FBErrIncorrectGdalDataset;
}
OGRFeatureDefn *layerDefn = layer->GetLayerDefn();
if (layerDefn->GetFieldCount() == 0)
{
GDALClose(dataset);
FBProject::CUR_ERR_INFO = QObject::tr("Selected GDAL dataset's layer must"
" contain at least one field, while it contains no fields");
return FBErrIncorrectGdalDataset_NotForNgw;
}
OGRSpatialReference *layerSpaRef = layer->GetSpatialRef();
if (layerSpaRef == NULL)
{
GDALClose(dataset);
FBProject::CUR_ERR_INFO = QObject::tr("Selected GDAL dataset does not contain"
" its spatial reference system description");
return FBErrIncorrectGdalDataset;
}
// All checks were made and we can fill the rest metadata of the project, which
// can be read via GDAL.
OGRwkbGeometryType geomType = layerDefn->GetGeomType();
FbGeomType *gt = FBProject::findGeomTypeByGdal(geomType);
if (gt == NULL)
{
// No default value for geometry type. NextGIS Mobile will not be able
// to read "undefined" geometry. So rise error here.
// TODO: do not rise error for GDAL types which can be translated, such as
// wkbPolygon25D to simple Polygon.
GDALClose(dataset);
FBProject::CUR_ERR_INFO = QObject::tr("Selected GDAL dataset has unsupported"
" geometry type: ") + OGRGeometryTypeToName(geomType);
return FBErrIncorrectGdalDataset_NotForNgw;
}
geometry_type = gt;
for (int i=0; i<layerDefn->GetFieldCount(); i++)
{
FBField descr;
OGRFieldDefn *fieldDefn = layerDefn->GetFieldDefn(i);
OGRFieldType fieldType = fieldDefn->GetType();
FbDataType *dt = FBProject::findDataTypeByGdal(fieldType);
if (dt == NULL)
{
// Default datatype.
// Data will be converted to string during the writing into JSON file.
descr.datataype = DATA_TYPES[FB_TYPEINDEX_DATA_STRING];
}
else
{
descr.datataype = dt;
}
descr.display_name = QString::fromUtf8(fieldDefn->GetNameRef());
fields.insert(QString::fromUtf8(fieldDefn->GetNameRef()), descr);
}
GDALClose(dataset);
return FBErrNone;
}
示例9: CacheLayer
bool GdaCache::CacheLayer(std::string ext_ds_name,
OGRLayerProxy* ext_layer_proxy)
{
OGRLayer* poSrcLayer = ext_layer_proxy->layer;
// get information from current layer: geomtype, layer_name
// (NOTE: we don't consider coodinator system and translation here)
OGRFeatureDefn *poSrcFDefn = poSrcLayer->GetLayerDefn();
int eGType = poSrcFDefn->GetGeomType();
const char* pszNewLayerName = poSrcLayer->GetName();
int bForceToPolygon = FALSE;
int bForceToMultiPolygon = FALSE;
int bForceToMultiLineString = FALSE;
if( wkbFlatten(eGType) == wkbPolygon )
bForceToPolygon = TRUE;
else if( wkbFlatten(eGType) == wkbMultiPolygon )
bForceToMultiPolygon = TRUE;
else if( wkbFlatten(eGType) == wkbMultiLineString )
bForceToMultiLineString = TRUE;
//Setup coordinate transformation if we need it.
OGRCoordinateTransformation *poCT = NULL;
bool bTransform = FALSE;
OGRSpatialReference *poSourceSRS = NULL;
// todo
OGRSpatialReference *poOutputSRS = new OGRSpatialReference("EPSG:4326");
// Cache
char *papszLCO[] = {"OVERWRITE=yes","FORMAT=Spatialite"};
std::string cache_layer_name = ext_ds_name + "_"+ext_layer_proxy->name;
OGRDataSource *poDstDS = cach_ds_proxy->ds;
OGRLayer *poDstLayer = poDstDS->CreateLayer(cache_layer_name.c_str(),
poOutputSRS,
(OGRwkbGeometryType)eGType,
papszLCO);
if (poDstLayer == NULL) {
// raise create cache failed.
return false;
}
// Process Layer style table
poDstLayer->SetStyleTable( poSrcLayer->GetStyleTable () );
// Add fields. here to copy all field.
int nSrcFieldCount = poSrcFDefn->GetFieldCount();
int iField;
OGRFeatureDefn *poDstFDefn = poDstLayer->GetLayerDefn();
for( iField = 0; iField < nSrcFieldCount; iField++ )
{
OGRFieldDefn* poSrcFieldDefn = poSrcFDefn->GetFieldDefn(iField);
OGRFieldDefn oFieldDefn( poSrcFieldDefn );
// The field may have been already created at layer creation
if (poDstLayer->CreateField( &oFieldDefn ) == OGRERR_NONE)
{
// now that we've created a field, GetLayerDefn() won't return NULL
if (poDstFDefn == NULL)
poDstFDefn = poDstLayer->GetLayerDefn();
}
}
// Transfer feature from Source Layer to Dest Layer
OGRFeature *poFeature;
GIntBig nFeaturesWritten = 0;
poSrcLayer->ResetReading();
while (poFeature = poSrcLayer->GetNextFeature())
{
OGRFeature *poDstFeature = OGRFeature::CreateFeature(
poDstLayer->GetLayerDefn() );
poDstFeature->SetFrom(poFeature);
OGRGeometry *poDstGeometry = poDstFeature->GetGeometryRef();
if (poDstGeometry != NULL)
{
if( bForceToPolygon )
{
poDstFeature->SetGeometryDirectly(
OGRGeometryFactory::forceToPolygon(
poDstFeature->StealGeometry()));
}
else if( bForceToMultiPolygon )
{
poDstFeature->SetGeometryDirectly(
OGRGeometryFactory::forceToMultiPolygon(
poDstFeature->StealGeometry() ) );
}
else if ( bForceToMultiLineString )
{
poDstFeature->SetGeometryDirectly(
OGRGeometryFactory::forceToMultiLineString(
poDstFeature->StealGeometry() ) );
}
}
if( poDstLayer->CreateFeature( poDstFeature ) == OGRERR_NONE )
{
nFeaturesWritten ++;
}
OGRFeature::DestroyFeature( poDstFeature );
//.........这里部分代码省略.........