本文整理汇总了C++中OGRLayer::GetGeomType方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRLayer::GetGeomType方法的具体用法?C++ OGRLayer::GetGeomType怎么用?C++ OGRLayer::GetGeomType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRLayer
的用法示例。
在下文中一共展示了OGRLayer::GetGeomType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getLayerInfo
bool NgwGdalIo::getLayerInfo (NgwLayerInfo &layer_info, QString base_url, int resource_id)
{
GDALDatasetPtr dataset_p;
u_openDataset(dataset_p, base_url, resource_id, true);
if (dataset_p.data() == NULL)
{
error = QObject::tr("Unable to open NGW dataset via GDAL");
return false;
}
OGRLayer *layer = dataset_p.data()->GetLayer(0);
if (layer == NULL)
{
error = QObject::tr("Unable to open [0] layer of NGW dataset via GDAL");
return false;
}
OGRFeatureDefn *layer_defn = layer->GetLayerDefn();
layer_info.name = layer->GetName();
layer_info.geom_type = Core::g_findGeomTypeNgw(layer->GetGeomType());
for (int i = 0; i < layer_defn->GetFieldCount(); i++)
{
QString s_field_alias = QString("FIELD_%1_ALIAS").arg(i);
QString alias = layer->GetMetadataItem(s_field_alias.toUtf8().data());
OGRFieldDefn *field_defn = layer_defn->GetFieldDefn(i);
layer_info.fields.append({field_defn->GetNameRef(), alias,
Core::g_findFieldTypeNgw(field_defn->GetType())});
}
return true;
}
示例2: 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");
}
}
示例3: ConnectPointsByLines
CPLErr GNMGenericNetwork::ConnectPointsByLines(char **papszLayerList,
double dfTolerance, double dfCost,
double dfInvCost, GNMDirection eDir)
{
if( CSLCount(papszLayerList) < 2 )
{
CPLError( CE_Failure, CPLE_IllegalArg, "Minimum 2 layers needed to connect" );
return CE_Failure;
}
std::vector<OGRLayer*> paLineLayers;
std::vector<OGRLayer*> paPointLayers;
int eType;
int iLayer;
OGRLayer* poLayer;
for(iLayer = 0; papszLayerList[iLayer] != NULL; ++iLayer)
{
poLayer = GetLayerByName(papszLayerList[iLayer]);
if(NULL == poLayer)
continue;
eType = wkbFlatten(poLayer->GetGeomType());
if(eType == wkbLineString || eType == wkbMultiLineString)
{
paLineLayers.push_back(poLayer);
}
else if(eType == wkbPoint)
{
paPointLayers.push_back(poLayer);
}
}
if (paLineLayers.empty() || paPointLayers.empty() )
{
CPLError( CE_Failure, CPLE_IllegalArg, "Need at least one line (or "
"multiline) layer and one point layer to connect" );
return CE_Failure;
}
// now walk through all lines and find nearest points for line start and end
OGRFeature* poFeature;
for(size_t i = 0; i < paLineLayers.size(); ++i)
{
poLayer = paLineLayers[i];
eType = wkbFlatten(poLayer->GetGeomType());
poLayer->ResetReading();
while((poFeature = poLayer->GetNextFeature()) != NULL)
{
const OGRGeometry* poGeom = poFeature->GetGeometryRef();
if(NULL != poGeom)
{
if(eType == wkbLineString)
{
const OGRLineString* poLineString =
(const OGRLineString*) poGeom;
ConnectPointsByLine(poFeature->GetFID(), poLineString,
paPointLayers, dfTolerance, dfCost,
dfInvCost, eDir);
}
else if( eType == wkbMultiLineString)
{
const OGRMultiLineString* poMultiLineString =
(const OGRMultiLineString*) poGeom;
ConnectPointsByMultiline(poFeature->GetFID(), poMultiLineString,
paPointLayers, dfTolerance, dfCost,
dfInvCost, eDir);
}
}
OGRFeature::DestroyFeature(poFeature);
}
}
return CE_None;
}
示例4: switch
boost::optional<mapnik::datasource_geometry_t> ogr_datasource::get_geometry_type() const
{
boost::optional<mapnik::datasource_geometry_t> result;
if (dataset_ && layer_.is_valid())
{
OGRLayer* layer = layer_.layer();
// NOTE: wkbFlatten macro in ogr flattens 2.5d types into base 2d type
#if GDAL_VERSION_NUM < 1800
switch (wkbFlatten(layer->GetLayerDefn()->GetGeomType()))
#else
switch (wkbFlatten(layer->GetGeomType()))
#endif
{
case wkbPoint:
case wkbMultiPoint:
result.reset(mapnik::datasource_geometry_t::Point);
break;
case wkbLinearRing:
case wkbLineString:
case wkbMultiLineString:
result.reset(mapnik::datasource_geometry_t::LineString);
break;
case wkbPolygon:
case wkbMultiPolygon:
result.reset(mapnik::datasource_geometry_t::Polygon);
break;
case wkbGeometryCollection:
result.reset(mapnik::datasource_geometry_t::Collection);
break;
case wkbNone:
case wkbUnknown:
{
// fallback to inspecting first actual geometry
// TODO - csv and shapefile inspect first 4 features
if (dataset_ && layer_.is_valid())
{
layer = layer_.layer();
// only new either reset of setNext
//layer->ResetReading();
layer->SetNextByIndex(0);
OGRFeature *poFeature;
while ((poFeature = layer->GetNextFeature()) != nullptr)
{
OGRGeometry* geom = poFeature->GetGeometryRef();
if (geom && ! geom->IsEmpty())
{
switch (wkbFlatten(geom->getGeometryType()))
{
case wkbPoint:
case wkbMultiPoint:
result.reset(mapnik::datasource_geometry_t::Point);
break;
case wkbLinearRing:
case wkbLineString:
case wkbMultiLineString:
result.reset(mapnik::datasource_geometry_t::LineString);
break;
case wkbPolygon:
case wkbMultiPolygon:
result.reset(mapnik::datasource_geometry_t::Polygon);
break;
case wkbGeometryCollection:
result.reset(mapnik::datasource_geometry_t::Collection);
break;
default:
break;
}
}
OGRFeature::DestroyFeature( poFeature );
break;
}
}
break;
}
default:
break;
}
}
return result;
}
示例5: lasclip
void lasclip(std::string &outfile, std::string &shapefile,
std::string &layername, std::vector<std::string> &files,
std::set<int> &classes, bool quiet) {
if (outfile.empty())
g_argerr("An output file is required.");
if (shapefile.empty())
g_argerr("A shape file is required.");
if (files.size() == 0)
g_argerr("At least one input file is required.");
if (classes.size() == 0)
g_warn("No classes specified, matching all classes.");
/* Attempt to open and load geometries from the shape file. */
OGRRegisterAll();
OGRLayer *layer;
OGRFeature *feat;
OGRGeometry *og;
OGRwkbGeometryType type;
gg::GeometryCollection *geomColl;
gg::Geometry *geom;
OGRDataSource *ds = OGRSFDriverRegistrar::Open(shapefile.c_str(), FALSE);
if (ds == nullptr)
g_runerr("Couldn't open shapefile.");
if (layername.empty()) {
layer = ds->GetLayer(0);
} else {
layer = ds->GetLayerByName(layername.c_str());
}
if (layer == nullptr)
g_runerr("Couldn't get layer.");
type = layer->GetGeomType();
if (type != wkbPolygon && type != wkbMultiPolygon)
g_runerr("Geometry must be polygon or multipolygon.");
const GEOSContextHandle_t gctx = OGRGeometry::createGEOSContext();
const gg::GeometryFactory *gf = gg::GeometryFactory::getDefaultInstance();
const gg::CoordinateSequenceFactory *cf =
gf->getCoordinateSequenceFactory();
std::vector<gg::Geometry *> geoms;
while ((feat = layer->GetNextFeature()) != NULL) {
og = feat->GetGeometryRef();
geom = (gg::Geometry *) og->exportToGEOS(gctx);
geoms.push_back(geom);
}
GDALClose(ds);
if (geoms.size() == 0)
g_runerr("No geometries were found.");
/* The geometry collection is used for checking whether a las file intersects
the region of interest. */
geomColl = gf->createGeometryCollection(geoms);
const gg::Envelope *env = geomColl->getEnvelopeInternal();
Bounds cbounds(env->getMinX(), env->getMinY(), env->getMaxX(),
env->getMaxY());
/* Loop over files and figure out which ones are relevant. */
liblas::ReaderFactory rf;
liblas::Header *dsth = nullptr;
std::vector<unsigned int> indices;
for (unsigned int i = 0; i < files.size(); ++i) {
std::ifstream in(files[i].c_str(), std::ios::in | std::ios::binary);
liblas::Reader r = rf.CreateWithStream(in);
liblas::Header h = r.GetHeader();
if (i == 0)
dsth = new liblas::Header(h);
std::vector<gg::Coordinate> coords;
coords.push_back(gg::Coordinate(h.GetMinX(), h.GetMinY()));
coords.push_back(gg::Coordinate(h.GetMaxX(), h.GetMinY()));
coords.push_back(gg::Coordinate(h.GetMaxX(), h.GetMaxY()));
coords.push_back(gg::Coordinate(h.GetMinX(), h.GetMaxY()));
coords.push_back(gg::Coordinate(h.GetMinX(), h.GetMinY()));
gg::CoordinateSequence *cs = cf->create(&coords);
gg::LinearRing *lr = gf->createLinearRing(cs);
gg::Polygon *bounds = gf->createPolygon(lr, NULL);
if (bounds->intersects(geomColl))
indices.push_back(i);
in.close();
}
if (indices.size() == 0)
g_runerr("No files matched the given bounds.");
std::ofstream out(outfile, std::ios::out | std::ios::binary);
liblas::WriterFactory wf;
liblas::Writer w(out, *dsth);
liblas::Header::RecordsByReturnArray recs;
int count = 0;
//.........这里部分代码省略.........
示例6: if
//.........这里部分代码省略.........
{
OGRLayer *poLayer = poDS->GetLayer(iLayer);
if( poLayer == nullptr )
{
printf("FAILURE: Couldn't fetch advertised layer %d!\n",
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 )
{
示例7: main
//.........这里部分代码省略.........
nRepeatCount = 0; // skip layer reporting.
if( CSLCount(papszLayers) > 0 )
printf( "layer names ignored in combination with -sql.\n" );
poResultSet = poDS->ExecuteSQL( pszSQLStatement, poSpatialFilter,
pszDialect );
if( poResultSet != NULL )
{
if( pszWHERE != NULL )
poResultSet->SetAttributeFilter( pszWHERE );
ReportOnLayer( poResultSet, NULL, NULL );
poDS->ReleaseResultSet( poResultSet );
}
}
CPLDebug( "OGR", "GetLayerCount() = %d\n", poDS->GetLayerCount() );
for( int iRepeat = 0; iRepeat < nRepeatCount; iRepeat++ )
{
if ( CSLCount(papszLayers) == 0 )
{
/* -------------------------------------------------------------------- */
/* Process each data source layer. */
/* -------------------------------------------------------------------- */
for( int iLayer = 0; iLayer < poDS->GetLayerCount(); iLayer++ )
{
OGRLayer *poLayer = poDS->GetLayer(iLayer);
if( poLayer == NULL )
{
printf( "FAILURE: Couldn't fetch advertised layer %d!\n",
iLayer );
exit( 1 );
}
if (!bAllLayers)
{
printf( "%d: %s",
iLayer+1,
poLayer->GetName() );
if( poLayer->GetGeomType() != wkbUnknown )
printf( " (%s)",
OGRGeometryTypeToName(
poLayer->GetGeomType() ) );
printf( "\n" );
}
else
{
if( iRepeat != 0 )
poLayer->ResetReading();
ReportOnLayer( poLayer, pszWHERE, poSpatialFilter );
}
}
}
else
{
/* -------------------------------------------------------------------- */
/* Process specified data source layers. */
/* -------------------------------------------------------------------- */
char** papszIter = papszLayers;
for( ; *papszIter != NULL; papszIter++ )
{
OGRLayer *poLayer = poDS->GetLayerByName(*papszIter);
if( poLayer == NULL )
{
printf( "FAILURE: Couldn't fetch requested layer %s!\n",
*papszIter );
exit( 1 );
}
if( iRepeat != 0 )
poLayer->ResetReading();
ReportOnLayer( poLayer, pszWHERE, poSpatialFilter );
}
}
}
/* -------------------------------------------------------------------- */
/* Close down. */
/* -------------------------------------------------------------------- */
end:
CSLDestroy( papszArgv );
CSLDestroy( papszLayers );
CSLDestroy( papszOptions );
OGRDataSource::DestroyDataSource( poDS );
if (poSpatialFilter)
OGRGeometryFactory::destroyGeometry( poSpatialFilter );
OGRCleanupAll();
return nRet;
}
示例8: oMutexHolder
//.........这里部分代码省略.........
"Cannot find layer '%s' in '%s'",
oLayerDesc.osLayerName.c_str(),
oLayerDesc.osDSName.c_str() );
delete poOtherDS;
delete poSQLiteDS;
VSIUnlink(pszTmpDBName);
CPLFree(pszTmpDBName);
return NULL;
}
osTableName = oLayerDesc.osSubstitutedName;
nExtraDS = OGR2SQLITE_AddExtraDS(poModule, poOtherDS);
osSQL.Printf("CREATE VIRTUAL TABLE \"%s\" USING VirtualOGR(%d,'%s',%d)",
OGRSQLiteEscapeName(osTableName).c_str(),
nExtraDS,
OGRSQLiteEscape(oLayerDesc.osLayerName).c_str(),
bFoundOGRStyle);
}
char* pszErrMsg = NULL;
int rc = sqlite3_exec( hDB, osSQL.c_str(),
NULL, NULL, &pszErrMsg );
if( rc != SQLITE_OK )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Cannot create virtual table for layer '%s' : %s",
osTableName.c_str(), pszErrMsg);
sqlite3_free(pszErrMsg);
continue;
}
if( poLayer->GetGeomType() == wkbNone )
continue;
CPLString osGeomColRaw(OGR2SQLITE_GetNameForGeometryColumn(poLayer));
const char* pszGeomColRaw = osGeomColRaw.c_str();
CPLString osGeomColEscaped(OGRSQLiteEscape(pszGeomColRaw));
const char* pszGeomColEscaped = osGeomColEscaped.c_str();
CPLString osLayerNameEscaped(OGRSQLiteEscape(osTableName));
const char* pszLayerNameEscaped = osLayerNameEscaped.c_str();
CPLString osIdxNameRaw(CPLSPrintf("idx_%s_%s",
oLayerDesc.osLayerName.c_str(), pszGeomColRaw));
CPLString osIdxNameEscaped(OGRSQLiteEscapeName(osIdxNameRaw));
/* Make sure that the SRS is injected in spatial_ref_sys */
OGRSpatialReference* poSRS = poLayer->GetSpatialRef();
int nSRSId = poSQLiteDS->GetUndefinedSRID();
if( poSRS != NULL )
nSRSId = poSQLiteDS->FetchSRSId(poSRS);
int bCreateSpatialIndex = FALSE;
if( !bSpatialiteDB )
{
osSQL.Printf("INSERT INTO geometry_columns (f_table_name, "
"f_geometry_column, geometry_format, geometry_type, "
"coord_dimension, srid) "
"VALUES ('%s','%s','SpatiaLite',%d,%d,%d)",
pszLayerNameEscaped,
pszGeomColEscaped,
(int) wkbFlatten(poLayer->GetGeomType()),
( poLayer->GetGeomType() & wkb25DBit ) ? 3 : 2,
示例9: load
bool Shape::load(const std::string& filename) {
GDALAllRegister();
GDALDataset* poDS;
poDS = (GDALDataset*)GDALOpenEx(filename.c_str(), GDAL_OF_VECTOR, NULL, NULL, NULL);
if (poDS == NULL) return false;
// 初期化
shapeObjects.clear();
minBound.x = std::numeric_limits<float>::max();
minBound.y = std::numeric_limits<float>::max();
minBound.z = std::numeric_limits<float>::max();
maxBound.x = -std::numeric_limits<float>::max();
maxBound.y = -std::numeric_limits<float>::max();
maxBound.z = -std::numeric_limits<float>::max();
int nLayers = poDS->GetLayerCount();
int i = 0;
for (int n = 0; n < nLayers; ++n) {
OGRLayer* poLayer = poDS->GetLayer(n);
shapeType = poLayer->GetGeomType();
shapeObjects.resize(shapeObjects.size() + poLayer->GetFeatureCount());
OGRFeature* poFeature;
poLayer->ResetReading();
while ((poFeature = poLayer->GetNextFeature()) != NULL) {
// 属性の名前を読み込む
std::vector<std::string> fieldNames;
for (int j = 0; j < poFeature->GetFieldCount(); ++j) {
OGRFieldDefn* poFieldDefn = poFeature->GetFieldDefnRef(j);
fieldNames.push_back(poFieldDefn->GetNameRef());
}
// 属性の値を読み込む
OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
for (int j = 0; j < poFDefn->GetFieldCount(); ++j) {
OGRFieldDefn* poFieldDefn = poFDefn->GetFieldDefn(j);
if (poFieldDefn->GetType() == OFTInteger) {
shapeObjects[i].attributes[fieldNames[j]] = Variant(poFeature->GetFieldAsInteger(j));
}
else if (poFieldDefn->GetType() == OFTInteger64) {
shapeObjects[i].attributes[fieldNames[j]] = Variant(poFeature->GetFieldAsInteger(j));
}
else if (poFieldDefn->GetType() == OFTReal) {
shapeObjects[i].attributes[fieldNames[j]] = Variant(poFeature->GetFieldAsDouble(j));
}
else if (poFieldDefn->GetType() == OFTString) {
shapeObjects[i].attributes[fieldNames[j]] = Variant(poFeature->GetFieldAsString(j));
}
else {
shapeObjects[i].attributes[fieldNames[j]] = Variant(poFeature->GetFieldAsString(j));
}
}
// このshapeのベクトルデータを読み込む
OGRGeometry* poGeometry = poFeature->GetGeometryRef();
if (poGeometry != NULL) {
if (wkbFlatten(poGeometry->getGeometryType()) == wkbPoint) {
shapeObjects[i].parts.resize(1);
shapeObjects[i].parts[0].points.resize(1);
OGRPoint* poPoint = (OGRPoint*)poGeometry;
shapeObjects[i].parts[0].points[0].x = poPoint->getX();
shapeObjects[i].parts[0].points[0].y = poPoint->getY();
updateBounds(poPoint);
}
else if (wkbFlatten(poGeometry->getGeometryType()) == wkbLineString) {
OGRLineString* poLineString = (OGRLineString*)poGeometry;
readLineString(poLineString, shapeObjects[i]);
}
else if (wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon) {
OGRPolygon* poPolygon = (OGRPolygon*)poGeometry;
readPolygon(poPolygon, shapeObjects[i]);
}
else if (wkbFlatten(poGeometry->getGeometryType()) == wkbMultiPolygon) {
OGRMultiPolygon* poMultiPolygon = (OGRMultiPolygon*)poGeometry;
readMultiPolygon(poMultiPolygon, shapeObjects[i]);
}
else {
// not supported
}
}
// shapeObjectsのインデックスをインクリメント
i++;
// OGRが取得したメモリを開放
OGRFeature::DestroyFeature(poFeature);
}
}
GDALClose(poDS);
return true;
}