本文整理汇总了C++中OGRFeatureDefn类的典型用法代码示例。如果您正苦于以下问题:C++ OGRFeatureDefn类的具体用法?C++ OGRFeatureDefn怎么用?C++ OGRFeatureDefn使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OGRFeatureDefn类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetLayerDefn
CPLString OGRKMLLayer::WriteSchema()
{
CPLString osRet;
if ( !(bSchemaWritten_) )
{
OGRFeatureDefn *featureDefinition = GetLayerDefn();
for (int j=0; j < featureDefinition->GetFieldCount(); j++)
{
OGRFieldDefn *fieldDefinition = featureDefinition->GetFieldDefn(j);
if (NULL != poDS_->GetNameField() &&
EQUAL(fieldDefinition->GetNameRef(), poDS_->GetNameField()) )
continue;
if (NULL != poDS_->GetDescriptionField() &&
EQUAL(fieldDefinition->GetNameRef(), poDS_->GetDescriptionField()) )
continue;
if( osRet.size() == 0 )
{
osRet += CPLSPrintf( "<Schema name=\"%s\" id=\"%s\">\n", pszName_, pszName_ );
}
const char* pszKMLType = NULL;
const char* pszKMLEltName = NULL;
// Match the OGR type to the GDAL type
switch (fieldDefinition->GetType())
{
case OFTInteger:
pszKMLType = "int";
pszKMLEltName = "SimpleField";
break;
case OFTIntegerList:
pszKMLType = "int";
pszKMLEltName = "SimpleArrayField";
break;
case OFTReal:
pszKMLType = "float";
pszKMLEltName = "SimpleField";
break;
case OFTRealList:
pszKMLType = "float";
pszKMLEltName = "SimpleArrayField";
break;
case OFTString:
pszKMLType = "string";
pszKMLEltName = "SimpleField";
break;
case OFTStringList:
pszKMLType = "string";
pszKMLEltName = "SimpleArrayField";
break;
//TODO: KML doesn't handle these data types yet...
case OFTDate:
case OFTTime:
case OFTDateTime:
pszKMLType = "string";
pszKMLEltName = "SimpleField";
break;
default:
pszKMLType = "string";
pszKMLEltName = "SimpleField";
break;
}
osRet += CPLSPrintf( "\t<%s name=\"%s\" type=\"%s\"></%s>\n",
pszKMLEltName, fieldDefinition->GetNameRef() ,pszKMLType, pszKMLEltName );
}
if( osRet.size() )
osRet += CPLSPrintf( "%s", "</Schema>\n" );
}
return osRet;
}
示例2: switch
void OgrWriter::_createLayer(shared_ptr<const Layer> layer)
{
OGRLayer *poLayer;
OGRwkbGeometryType gtype;
switch(layer->getGeometryType())
{
case GEOS_POINT:
gtype = wkbPoint;
break;
case GEOS_LINESTRING:
gtype = wkbLineString;
break;
case GEOS_POLYGON:
gtype = wkbPolygon;
break;
default:
throw HootException("Unexpected geometry type.");
}
OgrOptions options;
if (_ds->GetDriver())
{
// if this is a CSV file
if (_ds->GetDriver()->GetName() == QString("CSV"))
{
// if we're exporting point data, then export with x/y at the front
if (gtype == wkbPoint)
{
options["GEOMETRY"] = "AS_XY";
}
// if we're exporting other geometries then export w/ WKT at the front.
else
{
options["GEOMETRY"] = "AS_WKT";
}
options["CREATE_CSVT"] = "YES";
}
if (_ds->GetDriver()->GetName() == QString("ESRI Shapefile"))
{
options["ENCODING"] = "UTF-8";
}
// Add a Feature Dataset to a ESRI File GeoDatabase if requested
if (_ds->GetDriver()->GetName() == QString("FileGDB"))
{
if (layer->getFdName() != "")
{
options["FEATURE_DATASET"] = layer->getFdName();
// speed up bulk inserts.
options["FGDB_BULK_LOAD"] = "YES";
}
}
}
QString layerName = _prependLayerName + layer->getName();
poLayer = _getLayerByName(layerName);
// We only want to add to a layer IFF the config option "ogr.append.data" set
if (poLayer != NULL && _appendData)
{
// Layer exists
_layers[layer->getName()] = poLayer;
// Loop through the fields making sure that they exist in the output. Print a warning if
// they don't exist
OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
shared_ptr<const FeatureDefinition> fd = layer->getFeatureDefinition();
for (size_t i = 0; i < fd->getFieldCount(); i++)
{
shared_ptr<const FieldDefinition> f = fd->getFieldDefinition(i);
if (poFDefn->GetFieldIndex(f->getName().toAscii()) == -1)
{
// throw HootException(QString("Error: Unable to find output field: %1 in layer %2.").arg(f->getName()).arg(layerName));
LOG_WARN("Unable to find field: " << QString(f->getName()) << " in layer " << layerName);
}
}
}
else
{
LOG_INFO("Layer: " << layerName << " not found. Creating layer...");
// Layer does not exist
poLayer = _ds->CreateLayer(layerName.toAscii(),
MapProjector::createWgs84Projection()->Clone(), gtype, options.getCrypticOptions());
if( poLayer == NULL )
{
throw HootException(QString("Layer creation failed. %1").arg(layerName));
}
_layers[layer->getName()] = poLayer;
shared_ptr<const FeatureDefinition> fd = layer->getFeatureDefinition();
for (size_t i = 0; i < fd->getFieldCount(); i++)
{
shared_ptr<const FieldDefinition> f = fd->getFieldDefinition(i);
OGRFieldDefn oField(f->getName().toAscii(), toOgrFieldType(f->getType()));
if (f->getWidth() > 0)
{
//.........这里部分代码省略.........