本文整理汇总了C++中OGRDataSource::GetLayer方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRDataSource::GetLayer方法的具体用法?C++ OGRDataSource::GetLayer怎么用?C++ OGRDataSource::GetLayer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRDataSource
的用法示例。
在下文中一共展示了OGRDataSource::GetLayer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例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: 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;
}
示例4: ProcessError
int
NBHeightMapper::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
}
示例5: GetSummaryRefCount
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;
}
示例6:
JNIEXPORT jlong JNICALL Java_es_gva_cit_jogr_OGRDataSource_getLayerNat
(JNIEnv *env, jobject obj, jlong cPtr, jint iLayer){
OGRDataSource *ds = (OGRDataSource *) 0 ;
OGRLayer *capa;
long layer=-1;
ds = *(OGRDataSource **)&cPtr;
if(ds!=NULL){
capa = ds->GetLayer(iLayer);
if(capa!=NULL)layer = (long)&(*capa);
}
return (jlong)layer;
}
示例7: import_shapefile
OGRLayer* import_shapefile(string shapefile_name, int layer_number) {
OGRRegisterAll();
OGRDataSource *poDS;
poDS = OGRSFDriverRegistrar::Open( shapefile_name.c_str(), FALSE );
if( poDS == NULL ) { cerr << "Failed to open shapefile" << endl; exit( 1 ); }
OGRLayer* poLayer = poDS->GetLayer(layer_number);
cerr << "Shapefile layer name: " << poLayer->GetName() << endl;
// char* proj[255];
// poLayer->GetSpatialRef()->exportToWkt(proj);
// cerr << "Shapefile projection: " << *proj << endl;
return poLayer;
}
示例8: getAvailShapes
/** @brief Get list of shapes from file, optional search by name
*
* read in shape file, extract shapes return as list
* optional string argument returns only matching shapes (by string.find)
* (!case sensitive!)
*/
void getAvailShapes(vector<OGRFeature*>* availShapes_p, const string selected = "")
{
OGRRegisterAll();
OGRDataSource * poDS;
string path = "../admin_level_6/shape_al6/admin_level_6.shp";
if (exists(path))
{
poDS = OGRSFDriverRegistrar::Open(path.c_str());
if (poDS == NULL)
{
cout << "Data read error" << endl;
exit (1);
}
}
else
{
cout << "File not found" << endl;
exit(1);
}
// cout << "Found " << poDS->GetLayerCount() << "Layers in File" << endl;
OGRLayer *poLayer;
OGRFeature *poFeature;
poLayer = poDS->GetLayer(0);
poLayer->ResetReading();
while ( (poFeature = poLayer->GetNextFeature()) != NULL)
{
if (selected.empty())
{
availShapes_p->push_back(poFeature);
}
else
{
if (string(poFeature->GetFieldAsString(1)).find(selected) != string::npos)
availShapes_p->push_back(poFeature);
else
OGRFeature::DestroyFeature(poFeature);
}
}
OGRDataSource::DestroyDataSource(poDS);
}
示例9: VectortoRaster
int Raster::VectortoRaster(const char * sVectorSourcePath,
const char * sRasterOutputPath,
double dCellWidth,
const char * psFieldName){
OGRRegisterAll();
OGRDataSource * pDSVectorInput;
pDSVectorInput = OGRSFDriverRegistrar::Open( sVectorSourcePath, FALSE );
if (pDSVectorInput == NULL)
return INPUT_FILE_ERROR;
// Get the extents of the file before passing it off to the function that actually burns
// the geometries
// -------------------------------------------------------
// Note: we're just grabbing the first layer here. If we get into needing multiple layers
// Then we'll need to re-think this.
OGRLayer * poLayer = pDSVectorInput->GetLayer(0);
if (poLayer == NULL)
return VECTOR_LAYER_NOT_FOUND;
OGREnvelope psExtent;
poLayer->GetExtent(&psExtent, TRUE);
double dMaxY, dMaxX, dMinY, dMinX;
double cellWidth = fabs(dCellWidth);
dMaxY = ceil(psExtent.MaxY / cellWidth) * cellWidth;
dMaxX = ceil(psExtent.MaxX / cellWidth) * cellWidth;
dMinY = floor(psExtent.MinY / cellWidth) * cellWidth;
dMinX = floor(psExtent.MinX / cellWidth) * cellWidth;
int nRows = (int)((dMaxY - dMinY) / cellWidth);
int nCols = (int)((dMaxX - dMinX) / cellWidth);
\
// We're going to create them without projections. The projections get set later.
double fNoDataValue = (double) -std::numeric_limits<float>::max();
GDALDataType nDType = GDT_Float32;
double dCellHeight = -dCellWidth;
RasterMeta TemplateRaster(psExtent.MaxY, psExtent.MinX, nRows, nCols, &dCellHeight, &dCellWidth, &fNoDataValue, "GTiff", &nDType, "");
pDSVectorInput->Release();
return VectortoRaster(sVectorSourcePath, sRasterOutputPath, psFieldName, &TemplateRaster);
}
示例10: OGRMultiPolygon
MapExtruder::MapExtruder(const char* map2dFile,double height)
{
_map2dFile = map2dFile;
_height = height;
OGRRegisterAll();
OGRDataSource *poDS = OGRSFDriverRegistrar::Open(_map2dFile,FALSE);
if( poDS == NULL)
{
printf("Open failed.\n");
exit(1);
}
_map2d = new OGRMultiPolygon();
OGRLayer *poLayer;
poLayer = poDS->GetLayer(0);
OGRFeature *poFeature;
poLayer->ResetReading();
while((poFeature = poLayer->GetNextFeature())!=NULL)
{
OGRGeometry *poGeometry;
poGeometry = poFeature ->GetGeometryRef();
if(poGeometry!=NULL)
{
if(poGeometry ->getGeometryType()==wkbPolygon)
_map2d->addGeometry((OGRPolygon*) poGeometry);
if(poGeometry ->getGeometryType()==wkbMultiPolygon)
{
int nPolygons = ((OGRMultiPolygon*)poGeometry)->getNumGeometries();
for(int i=0;i<nPolygons;i++)
_map2d->addGeometry((OGRPolygon*)(((OGRMultiPolygon*)poGeometry)->getGeometryRef(i)));
}
}
}
extrusion();
}
示例11: OGR2SQLITE_ogr_datasource_load_layers
static
void OGR2SQLITE_ogr_datasource_load_layers(sqlite3_context* pContext,
int argc, sqlite3_value** argv)
{
sqlite3* hDB = (sqlite3*) sqlite3_user_data(pContext);
if( (argc < 1 || argc > 3) || sqlite3_value_type (argv[0]) != SQLITE_TEXT )
{
sqlite3_result_int (pContext, 0);
return;
}
const char* pszDataSource = (const char*) sqlite3_value_text(argv[0]);
int bUpdate = FALSE;
if( argc >= 2 )
{
if( sqlite3_value_type(argv[1]) != SQLITE_INTEGER )
{
sqlite3_result_int (pContext, 0);
return;
}
bUpdate = sqlite3_value_int(argv[1]);
}
const char* pszPrefix = NULL;
if( argc >= 3 )
{
if( sqlite3_value_type(argv[2]) != SQLITE_TEXT )
{
sqlite3_result_int (pContext, 0);
return;
}
pszPrefix = (const char*) sqlite3_value_text(argv[2]);
}
OGRDataSource* poDS = (OGRDataSource*)OGROpenShared(pszDataSource, bUpdate, NULL);
if( poDS == NULL )
{
CPLError(CE_Failure, CPLE_AppDefined, "Cannot open %s", pszDataSource);
sqlite3_result_int (pContext, 0);
return;
}
CPLString osEscapedDataSource = OGRSQLiteEscape(pszDataSource);
for(int i=0; i<poDS->GetLayerCount(); i++)
{
const char* pszLayerName = poDS->GetLayer(i)->GetName();
CPLString osEscapedLayerName = OGRSQLiteEscape(pszLayerName);
CPLString osTableName;
if( pszPrefix != NULL )
{
osTableName = pszPrefix;
osTableName += "_";
osTableName += OGRSQLiteEscapeName(pszLayerName);
}
else
{
osTableName = OGRSQLiteEscapeName(pszLayerName);
}
char* pszErrMsg = NULL;
if( sqlite3_exec(hDB, CPLSPrintf(
"CREATE VIRTUAL TABLE \"%s\" USING VirtualOGR('%s', %d, '%s')",
osTableName.c_str(),
osEscapedDataSource.c_str(),
bUpdate,
osEscapedLayerName.c_str()),
NULL, NULL, &pszErrMsg) != SQLITE_OK )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Cannot create table \"%s\" : %s",
osTableName.c_str(), pszErrMsg);
sqlite3_free(pszErrMsg);
}
}
poDS->Release();
sqlite3_result_int (pContext, 1);
}
示例12: main
//.........这里部分代码省略.........
/* Search for SRS */
/* temporarily supress error messages we may get from xOpen() */
bDebug = CSLTestBoolean(CPLGetConfigOption("CPL_DEBUG", "OFF"));
if ( ! bDebug )
oErrorHandler = CPLSetErrorHandler ( CPLQuietErrorHandler );
/* If argument is a file, try to open it with GDALOpen() and get the projection */
fp = VSIFOpenL( pszInput, "r" );
if ( fp ) {
bIsFile = TRUE;
VSIFCloseL( fp );
/* try to open with GDAL */
CPLDebug( "gdalsrsinfo", "trying to open with GDAL" );
poGDALDS = (GDALDataset *) GDALOpen( pszInput, GA_ReadOnly );
if ( poGDALDS != NULL && poGDALDS->GetProjectionRef( ) != NULL ) {
pszProjection = (char *) poGDALDS->GetProjectionRef( );
if( oSRS.importFromWkt( &pszProjection ) == CE_None ) {
CPLDebug( "gdalsrsinfo", "got SRS from GDAL" );
bGotSRS = TRUE;
}
GDALClose( (GDALDatasetH) poGDALDS );
}
if ( ! bGotSRS )
CPLDebug( "gdalsrsinfo", "did not open with GDAL" );
/* if unsuccessful, try to open with OGR */
if ( ! bGotSRS ) {
CPLDebug( "gdalsrsinfo", "trying to open with OGR" );
poOGRDS = OGRSFDriverRegistrar::Open( pszInput, FALSE, NULL );
if( poOGRDS != NULL ) {
poLayer = poOGRDS->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 );
}
}
OGRDataSource::DestroyDataSource( poOGRDS );
poOGRDS = NULL;
}
if ( ! bGotSRS )
CPLDebug( "gdalsrsinfo", "did not open with OGR" );
/* OGR_DS_Destroy( hOGRDS ); */
}
}
/* If didn't get the projection from the file, try OSRSetFromUserInput() */
/* File might not be a dataset, but contain projection info (e.g. .prf files) */
if ( ! bGotSRS ) {
CPLDebug( "gdalsrsinfo",
"trying to get SRS from user input [%s]", pszInput );
if( oSRS.SetFromUserInput( pszInput ) != OGRERR_NONE ) {
CPLDebug( "gdalsrsinfo", "did not get SRS from user input" );
}
else {
CPLDebug( "gdalsrsinfo", "got SRS from user input" );
bGotSRS = TRUE;
示例13: main
//.........这里部分代码省略.........
if( bVerbose && !EQUAL(pszDataSource,poDS->GetName()) )
{
printf( "INFO: Internal data source name `%s'\n"
" different from user name `%s'.\n",
poDS->GetName(), pszDataSource );
}
/* -------------------------------------------------------------------- */
/* Special case for -sql clause. No source layers required. */
/* -------------------------------------------------------------------- */
if( pszSQLStatement != NULL )
{
OGRLayer *poResultSet = NULL;
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->GetLayerDefn()->GetName() );
if( poLayer->GetLayerDefn()->GetGeomType() != wkbUnknown )
printf( " (%s)",
OGRGeometryTypeToName(
poLayer->GetLayerDefn()->GetGeomType() ) );
printf( "\n" );
}
示例14: LoadGeometry
static OGRGeometryCollection* LoadGeometry( const char* pszDS,
const char* pszSQL,
const char* pszLyr,
const char* pszWhere )
{
OGRDataSource *poDS;
OGRLayer *poLyr;
OGRFeature *poFeat;
OGRGeometryCollection *poGeom = NULL;
poDS = OGRSFDriverRegistrar::Open( pszDS, FALSE );
if ( poDS == NULL )
return NULL;
if ( pszSQL != NULL )
poLyr = poDS->ExecuteSQL( pszSQL, NULL, NULL );
else if ( pszLyr != NULL )
poLyr = poDS->GetLayerByName( pszLyr );
else
poLyr = poDS->GetLayer(0);
if ( poLyr == NULL )
{
fprintf( stderr,
"FAILURE: Failed to identify source layer from datasource.\n" );
OGRDataSource::DestroyDataSource( poDS );
return NULL;
}
if ( pszWhere )
poLyr->SetAttributeFilter( pszWhere );
while ( (poFeat = poLyr->GetNextFeature()) != NULL )
{
OGRGeometry* poSrcGeom = poFeat->GetGeometryRef();
if ( poSrcGeom )
{
OGRwkbGeometryType eType =
wkbFlatten( poSrcGeom->getGeometryType() );
if ( poGeom == NULL )
poGeom = new OGRMultiPolygon();
if ( eType == wkbPolygon )
poGeom->addGeometry( poSrcGeom );
else if ( eType == wkbMultiPolygon )
{
int iGeom;
int nGeomCount =
((OGRMultiPolygon *)poSrcGeom)->getNumGeometries();
for ( iGeom = 0; iGeom < nGeomCount; iGeom++ )
{
poGeom->addGeometry(
((OGRMultiPolygon *)poSrcGeom)->getGeometryRef(iGeom) );
}
}
else
{
fprintf( stderr, "FAILURE: Geometry not of polygon type.\n" );
OGRGeometryFactory::destroyGeometry( poGeom );
OGRFeature::DestroyFeature( poFeat );
if ( pszSQL != NULL )
poDS->ReleaseResultSet( poLyr );
OGRDataSource::DestroyDataSource( poDS );
return NULL;
}
}
OGRFeature::DestroyFeature( poFeat );
}
if( pszSQL != NULL )
poDS->ReleaseResultSet( poLyr );
OGRDataSource::DestroyDataSource( poDS );
return poGeom;
}
示例15: ProcessError
void
PCLoaderArcView::load(const std::string& file, OptionsCont& oc, PCPolyContainer& toFill,
PCTypeMap&) {
#ifdef HAVE_GDAL
GeoConvHelper& geoConvHelper = GeoConvHelper::getProcessing();
// get defaults
std::string prefix = oc.getString("prefix");
std::string type = oc.getString("type");
RGBColor color = RGBColor::parseColor(oc.getString("color"));
int layer = oc.getInt("layer");
std::string idField = oc.getString("shapefile.id-column");
bool useRunningID = oc.getBool("shapefile.use-running-id");
// start parsing
std::string shpName = file + ".shp";
OGRRegisterAll();
OGRDataSource* poDS = OGRSFDriverRegistrar::Open(shpName.c_str(), FALSE);
if (poDS == NULL) {
throw ProcessError("Could not open shape description '" + shpName + "'.");
}
// begin file parsing
OGRLayer* poLayer = poDS->GetLayer(0);
poLayer->ResetReading();
// build coordinate transformation
OGRSpatialReference* origTransf = poLayer->GetSpatialRef();
OGRSpatialReference destTransf;
// use wgs84 as destination
destTransf.SetWellKnownGeogCS("WGS84");
OGRCoordinateTransformation* poCT = OGRCreateCoordinateTransformation(origTransf, &destTransf);
if (poCT == NULL) {
if (oc.isSet("shapefile.guess-projection")) {
OGRSpatialReference origTransf2;
origTransf2.SetWellKnownGeogCS("WGS84");
poCT = OGRCreateCoordinateTransformation(&origTransf2, &destTransf);
}
if (poCT == 0) {
WRITE_WARNING("Could not create geocoordinates converter; check whether proj.4 is installed.");
}
}
OGRFeature* poFeature;
poLayer->ResetReading();
unsigned int runningID = 0;
while ((poFeature = poLayer->GetNextFeature()) != NULL) {
// read in edge attributes
std::string id = useRunningID ? toString(runningID) : poFeature->GetFieldAsString(idField.c_str());
++runningID;
id = StringUtils::prune(id);
if (id == "") {
throw ProcessError("Missing id under '" + idField + "'");
}
id = prefix + id;
// read in the geometry
OGRGeometry* poGeometry = poFeature->GetGeometryRef();
if (poGeometry == 0) {
OGRFeature::DestroyFeature(poFeature);
continue;
}
// try transform to wgs84
poGeometry->transform(poCT);
OGRwkbGeometryType gtype = poGeometry->getGeometryType();
switch (gtype) {
case wkbPoint: {
OGRPoint* cgeom = (OGRPoint*) poGeometry;
Position pos((SUMOReal) cgeom->getX(), (SUMOReal) cgeom->getY());
if (!geoConvHelper.x2cartesian(pos)) {
WRITE_ERROR("Unable to project coordinates for POI '" + id + "'.");
}
PointOfInterest* poi = new PointOfInterest(id, type, color, pos, (SUMOReal)layer);
if (!toFill.insert(id, poi, layer)) {
WRITE_ERROR("POI '" + id + "' could not be added.");
delete poi;
}
}
break;
case wkbLineString: {
OGRLineString* cgeom = (OGRLineString*) poGeometry;
PositionVector shape;
for (int j = 0; j < cgeom->getNumPoints(); j++) {
Position pos((SUMOReal) cgeom->getX(j), (SUMOReal) cgeom->getY(j));
if (!geoConvHelper.x2cartesian(pos)) {
WRITE_ERROR("Unable to project coordinates for polygon '" + id + "'.");
}
shape.push_back_noDoublePos(pos);
}
Polygon* poly = new Polygon(id, type, color, shape, false, (SUMOReal)layer);
if (!toFill.insert(id, poly, layer)) {
WRITE_ERROR("Polygon '" + id + "' could not be added.");
delete poly;
}
}
break;
case wkbPolygon: {
OGRLinearRing* cgeom = ((OGRPolygon*) poGeometry)->getExteriorRing();
PositionVector shape;
for (int j = 0; j < cgeom->getNumPoints(); j++) {
Position pos((SUMOReal) cgeom->getX(j), (SUMOReal) cgeom->getY(j));
if (!geoConvHelper.x2cartesian(pos)) {
WRITE_ERROR("Unable to project coordinates for polygon '" + id + "'.");
//.........这里部分代码省略.........