本文整理汇总了C++中OGRFeature::GetFieldAsDouble方法的典型用法代码示例。如果您正苦于以下问题:C++ OGRFeature::GetFieldAsDouble方法的具体用法?C++ OGRFeature::GetFieldAsDouble怎么用?C++ OGRFeature::GetFieldAsDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OGRFeature
的用法示例。
在下文中一共展示了OGRFeature::GetFieldAsDouble方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void WaterDemandModel::run()
{
initmodel();
OGRFeature * p;
this->parcels.resetReading();
//Calculate outdoor demand for standard unit (100m2 roof, 100m2 garden, 1 person)
double imp_fraction = 0.2;
calculateRunoffAndDemand(500, imp_fraction, 0.8, 1);
while(p = this->parcels.getNextFeature()) {
double persons = p->GetFieldAsDouble("persons");
double garden_area = p->GetFieldAsDouble("garden_area");
double roof_area = p->GetFieldAsDouble("roof_area");
// this->stormwater_runoff = *(flow_probe_runoff->getState<std::vector<double> >("Flow"));
// this->non_potable_demand = *(nonpot_before->getState<std::vector<double> >("Flow"));
// this->potable_demand = *(pot_before->getState<std::vector<double> >("Flow"));
// this->outdoor_demand = *(flow_probe_outdoor->getState<std::vector<double> >("Flow"));
// parcels.addAttribute("non_potable_demand_daily", DM::Attribute::DOUBLE, DM::WRITE);
// parcels.addAttribute("potable_demand_daily", DM::Attribute::DOUBLE, DM::WRITE);
// parcels.addAttribute("outdoor_demand_daily", DM::Attribute::DOUBLE, DM::WRITE);
// parcels.addAttribute("run_off_roof_daily", DM::Attribute::DOUBLEVECTOR, DM::WRITE);
DM::DMFeature::SetDoubleList( p, "potable_demand_daily", this->mutiplyVector(this->potable_demand, persons));
DM::DMFeature::SetDoubleList( p, "non_potable_demand_daily", this->mutiplyVector(this->non_potable_demand, persons));
DM::DMFeature::SetDoubleList( p, "outdoor_demand_daily", this->mutiplyVector(this->outdoor_demand,garden_area/400.));
//DM::DMFeature::SetDoubleList( p, "outdoor_demand_daily", this->outdoor_demand);
DM::DMFeature::SetDoubleList( p, "run_off_roof_daily", this->mutiplyVector(this->stormwater_runoff,roof_area/100.));
}
}
示例2: LoadGraph
CPLErr GNMGenericNetwork::LoadGraph()
{
if(m_bIsGraphLoaded)
return CE_None;
if(NULL == m_poGraphLayer)
{
CPLError( CE_Failure, CPLE_AppDefined, "Loading of graph data failed");
return CE_Failure;
}
OGRFeature *poFeature;
m_poGraphLayer->ResetReading();
GNMGFID nSrcFID, nTgtFID, nConFID;
double dfCost, dfInvCost;
while ((poFeature = m_poGraphLayer->GetNextFeature()) != NULL)
{
nSrcFID = poFeature->GetFieldAsGNMGFID(GNM_SYSFIELD_SOURCE);
nTgtFID = poFeature->GetFieldAsGNMGFID(GNM_SYSFIELD_TARGET);
nConFID = poFeature->GetFieldAsGNMGFID(GNM_SYSFIELD_CONNECTOR);
dfCost = poFeature->GetFieldAsDouble(GNM_SYSFIELD_COST);
dfInvCost = poFeature->GetFieldAsDouble(GNM_SYSFIELD_INVCOST);
GNMDirection eDir = poFeature->GetFieldAsInteger(GNM_SYSFIELD_DIRECTION);
int nBlockState = poFeature->GetFieldAsInteger(GNM_SYSFIELD_BLOCKED);
bool bIsBlock = GNM_BLOCK_NONE != nBlockState;
m_oGraph.AddEdge(nConFID, nSrcFID, nTgtFID, eDir == GNM_EDGE_DIR_BOTH,
dfCost, dfInvCost);
if(bIsBlock)
{
if(nBlockState & GNM_BLOCK_SRC)
m_oGraph.ChangeBlockState(nSrcFID, bIsBlock);
if(nBlockState & GNM_BLOCK_TGT)
m_oGraph.ChangeBlockState(nTgtFID, bIsBlock);
if(nBlockState & GNM_BLOCK_CONN)
m_oGraph.ChangeBlockState(nConFID, bIsBlock);
}
if(nConFID < m_nVirtualConnectionGID)
m_nVirtualConnectionGID = nConFID;
OGRFeature::DestroyFeature(poFeature);
}
m_bIsGraphLoaded = true;
return CE_None;
}
示例3: compareIntersectionResults
bool AoIIntersection::compareIntersectionResults( OGRDataSource *resultData, IntersectionSummary *origSummary )
{
bool success = true;
IntersectionSummary resultSummary;
OGRLayer *resultLayer;
resultSummary.numLayers = resultData->GetLayerCount();
if ( resultSummary.numLayers != origSummary->numLayers )
{
printf( "Test results: Layer count mismatch.\n" );
success = false;
}
for (int layerCt = 0; layerCt < resultSummary.numLayers; ++layerCt)
{
resultLayer = resultData->GetLayer( layerCt );
if ( resultLayer == NULL )
{
printf( "Test results: Layer count mismatch.\n" );
success = false;
}
// get field indices for the fields we wrote
int acreIndex = resultLayer->GetLayerDefn()->GetFieldIndex( "Acres in AoI" );
int areaIndex = resultLayer->GetLayerDefn()->GetFieldIndex( "Percent of AOI" );
resultLayer->ResetReading();
OGRFeature *resultFeature;
while( (resultFeature = resultLayer->GetNextFeature()) != NULL )
{
double acres = resultFeature->GetFieldAsDouble( acreIndex );
double area = resultFeature->GetFieldAsDouble( areaIndex );
resultSummary.totalPercentOfAoI += area;
resultSummary.totalIntersectionAcres += acres;
}
}
if ( resultSummary.totalPercentOfAoI != origSummary->totalPercentOfAoI )
{
printf( "Test results: Percent of AoI mismatch.\n" );
success = false;
}
if ( resultSummary.totalIntersectionAcres != origSummary->totalIntersectionAcres )
{
printf( "Test results: Acreage mismatch.\n" );
success = false;
}
return success;
}
示例4: OGRFeatureFetcher
static swq_expr_node* OGRFeatureFetcher(swq_expr_node *op, void *pFeatureIn)
{
OGRFeature *poFeature = (OGRFeature*) pFeatureIn;
swq_expr_node *poRetNode = NULL;
switch (op->field_type)
{
case SWQ_INTEGER:
case SWQ_BOOLEAN:
poRetNode = new swq_expr_node(
poFeature->GetFieldAsInteger(op->field_index));
break;
case SWQ_FLOAT:
poRetNode = new swq_expr_node(
poFeature->GetFieldAsDouble(op->field_index));
break;
default:
poRetNode = new swq_expr_node(
poFeature->GetFieldAsString(op->field_index));
break;
}
poRetNode->is_null = !(poFeature->IsFieldSet(op->field_index));
return poRetNode;
}
示例5:
//---------------------------------------------------------
CSG_Shapes * COGR_DataSource::Read_Shapes(int iLayer)
{
OGRLayer *pLayer = Get_Layer(iLayer);
//-----------------------------------------------------
if( pLayer && Get_Type(iLayer) != SHAPE_TYPE_Undefined )
{
int iField;
OGRFeature *pFeature;
OGRFeatureDefn *pDef = pLayer->GetLayerDefn();
CSG_Shapes *pShapes = SG_Create_Shapes(Get_Type(iLayer), CSG_String(pDef->GetName()));
for(iField=0; iField<pDef->GetFieldCount(); iField++)
{
OGRFieldDefn *pDefField = pDef->GetFieldDefn(iField);
pShapes->Add_Field(pDefField->GetNameRef(), COGR_Driver::Get_Type(pDefField->GetType()));
}
pLayer->ResetReading();
//-------------------------------------------------
while( (pFeature = pLayer->GetNextFeature()) != NULL && SG_UI_Process_Get_Okay(false) )
{
OGRGeometry *pGeometry = pFeature->GetGeometryRef();
if( pGeometry != NULL )
{
CSG_Shape *pShape = pShapes->Add_Shape();
for(iField=0; iField<pDef->GetFieldCount(); iField++)
{
OGRFieldDefn *pDefField = pDef->GetFieldDefn(iField);
switch( pDefField->GetType() )
{
default: pShape->Set_Value(iField, SG_STR_MBTOSG(pFeature->GetFieldAsString (iField))); break;
case OFTString: pShape->Set_Value(iField, SG_STR_MBTOSG(pFeature->GetFieldAsString (iField))); break;
case OFTInteger: pShape->Set_Value(iField, pFeature->GetFieldAsInteger(iField)); break;
case OFTReal: pShape->Set_Value(iField, pFeature->GetFieldAsDouble (iField)); break;
}
}
//-----------------------------------------
if( _Read_Geometry(pShape, pGeometry) == false )
{
pShapes->Del_Shape(pShape);
}
}
OGRFeature::DestroyFeature(pFeature);
}
return( pShapes );
}
//-----------------------------------------------------
return( NULL );
}
示例6: OGR2SQLITE_ogr_geocode_set_result
static
void OGR2SQLITE_ogr_geocode_set_result(sqlite3_context* pContext,
OGRLayerH hLayer,
const char* pszField)
{
if( hLayer == NULL )
sqlite3_result_null (pContext);
else
{
OGRLayer* poLayer = (OGRLayer*)hLayer;
OGRFeatureDefn* poFDefn = poLayer->GetLayerDefn();
OGRFeature* poFeature = poLayer->GetNextFeature();
int nIdx = -1;
if( poFeature == NULL )
sqlite3_result_null (pContext);
else if( strcmp(pszField, "geometry") == 0 &&
poFeature->GetGeometryRef() != NULL )
{
GByte* pabyGeomBLOB = NULL;
int nGeomBLOBLen = 0;
if( OGRSQLiteLayer::ExportSpatiaLiteGeometry(
poFeature->GetGeometryRef(), 4326, wkbNDR, FALSE, FALSE, FALSE,
&pabyGeomBLOB,
&nGeomBLOBLen ) != CE_None )
{
sqlite3_result_null (pContext);
}
else
{
sqlite3_result_blob (pContext, pabyGeomBLOB, nGeomBLOBLen, CPLFree);
}
}
else if( (nIdx = poFDefn->GetFieldIndex(pszField)) >= 0 &&
poFeature->IsFieldSet(nIdx) )
{
OGRFieldType eType = poFDefn->GetFieldDefn(nIdx)->GetType();
if( eType == OFTInteger )
sqlite3_result_int(pContext,
poFeature->GetFieldAsInteger(nIdx));
else if( eType == OFTInteger64 )
sqlite3_result_int64(pContext,
poFeature->GetFieldAsInteger64(nIdx));
else if( eType == OFTReal )
sqlite3_result_double(pContext,
poFeature->GetFieldAsDouble(nIdx));
else
sqlite3_result_text(pContext,
poFeature->GetFieldAsString(nIdx),
-1, SQLITE_TRANSIENT);
}
else
sqlite3_result_null (pContext);
delete poFeature;
OGRGeocodeFreeResult(hLayer);
}
}
示例7: getSpeed
SUMOReal
NIImporter_ArcView::getSpeed(OGRFeature& poFeature, const std::string& edgeid) {
if (myOptions.isSet("shapefile.type-id")) {
return myTypeCont.getSpeed(poFeature.GetFieldAsString((char*)(myOptions.getString("shapefile.type-id").c_str())));
}
// try to get definitions as to be found in SUMO-XML-definitions
// idea by John Michael Calandrino
int index = poFeature.GetDefnRef()->GetFieldIndex("speed");
if (index >= 0 && poFeature.IsFieldSet(index)) {
return (SUMOReal) poFeature.GetFieldAsDouble(index);
}
index = poFeature.GetDefnRef()->GetFieldIndex("SPEED");
if (index >= 0 && poFeature.IsFieldSet(index)) {
return (SUMOReal) poFeature.GetFieldAsDouble(index);
}
// try to get the NavTech-information
index = poFeature.GetDefnRef()->GetFieldIndex("SPEED_CAT");
if (index >= 0 && poFeature.IsFieldSet(index)) {
std::string def = poFeature.GetFieldAsString(index);
return NINavTeqHelper::getSpeed(edgeid, def);
}
return -1;
}
示例8: run
void DM_MicroClimate::run()
{
grid.resetReading();
OGRFeature * f;
while (f = grid.getNextFeature()) {
double tree = f->GetFieldAsDouble("tree_cover_fraction") > 0 ? f->GetFieldAsDouble("tree_cover_fraction") : 0;
double water = f->GetFieldAsDouble("water_fraction") > 0 ? f->GetFieldAsDouble("water_fraction") : 0;
double grass = f->GetFieldAsDouble("grass_fraction") > 0 ? f->GetFieldAsDouble("grass_fraction") : 0;
double irrGrass = f->GetFieldAsDouble("irrigated_grass_fraction") > 0 ? f->GetFieldAsDouble("irrigated_grass_fraction") : 0;
double roof = f->GetFieldAsDouble("roof_fraction") > 0 ? f->GetFieldAsDouble("roof_fraction") : 0;
double road = f->GetFieldAsDouble("road_fraction") > 0 ? f->GetFieldAsDouble("road_fraction") : 0;
double concrete = f->GetFieldAsDouble("concrete_fraction") > 0 ? f->GetFieldAsDouble("concrete_fraction") : 0;
double scale = tree + water + grass + irrGrass + roof + road + concrete;
f->SetField("temperature",
tree/scale * getTempForSurface(1,this->percentile) +
water/scale * getTempForSurface(2,this->percentile) +
grass/scale * getTempForSurface(3,this->percentile) +
irrGrass/scale * getTempForSurface(4,this->percentile) +
roof/scale * getTempForSurface(5,this->percentile) +
road/scale * getTempForSurface(6,this->percentile) +
concrete/scale * getTempForSurface(7,this->percentile) );
}
}
示例9: LoadSamples
void MSN_Helper::LoadSamples(Config &config, Matrix &mat)
{
if(config.bShapefile)
{
OGRRegisterAll();
string pLayerName = StringGetFileName(config.sSamples);
OGRDataSource* poDS = OGRSFDriverRegistrar::Open(config.sSamples.c_str(),FALSE);
OGRLayer* poLayer = poDS->GetLayerByName(pLayerName.c_str());
config.nSamples = poLayer->GetFeatureCount();
mat.Resize(config.nSamples, 4);
OGRPoint *poPoint;
OGRFeature * pFeature =poLayer->GetNextFeature();
for(unsigned long i=1; i<=config.nSamples; i++)
{
//样本取值字段名为value,double型
poPoint = (OGRPoint *)pFeature->GetGeometryRef();
mat[i][1] = poPoint->getX();
mat[i][2] = poPoint->getY();
mat[i][3] = pFeature->GetFieldAsInteger("stratum");
mat[i][4] = pFeature->GetFieldAsDouble("value");
pFeature = poLayer->GetNextFeature();
}
OGRDataSource::DestroyDataSource( poDS );
}
else
{
double x, y, v, stratum;
string sline;
ifstream infile(config.sSamples.c_str());
infile >> config.nSamples;
mat.Resize(config.nSamples, 4);
for(unsigned long i=1; i<=config.nSamples; i++)
{
infile >> x >> y >> stratum >> v;
mat[i][1] = x;
mat[i][2] = y;
mat[i][3] = stratum;
mat[i][4] = v;
}
infile.close();
}
}
示例10: switch
static swq_expr_node *OGRFeatureFetcher( swq_expr_node *op, void *pFeatureIn )
{
OGRFeature *poFeature = (OGRFeature *) pFeatureIn;
swq_expr_node *poRetNode = NULL;
if( op->field_type == SWQ_GEOMETRY )
{
int iField = op->field_index - (poFeature->GetFieldCount() + SPECIAL_FIELD_COUNT);
poRetNode = new swq_expr_node( poFeature->GetGeomFieldRef(iField) );
return poRetNode;
}
switch( op->field_type )
{
case SWQ_INTEGER:
case SWQ_BOOLEAN:
poRetNode = new swq_expr_node(
poFeature->GetFieldAsInteger(op->field_index) );
break;
case SWQ_INTEGER64:
poRetNode = new swq_expr_node(
poFeature->GetFieldAsInteger64(op->field_index) );
break;
case SWQ_FLOAT:
poRetNode = new swq_expr_node(
poFeature->GetFieldAsDouble(op->field_index) );
break;
default:
poRetNode = new swq_expr_node(
poFeature->GetFieldAsString(op->field_index) );
break;
}
poRetNode->is_null = !(poFeature->IsFieldSet(op->field_index));
return poRetNode;
}
示例11: GetAsString
wxString wxGISFeatureDataset::GetAsString(int row, int col)
{
if(m_poLayer->GetFeatureCount() <= row)
return wxString();
else
{
OGRFeature* pFeature = GetAt(row);
OGRFieldDefn* pDef = pFeature->GetFieldDefnRef(col);
switch(pDef->GetType())
{
case OFTDate:
{
int year, mon, day, hour, min, sec, flag;
pFeature->GetFieldAsDateTime(col, &year, &mon, &day, &hour, &min, &sec, &flag);
wxDateTime dt(day, wxDateTime::Month(mon - 1), year, hour, min, sec);
return dt.Format(_("%d-%m-%Y"));//wxString::Format(_("%.2u-%.2u-%.4u"), day, mon, year );
}
case OFTTime:
{
int year, mon, day, hour, min, sec, flag;
pFeature->GetFieldAsDateTime(col, &year, &mon, &day, &hour, &min, &sec, &flag);
wxDateTime dt(day, wxDateTime::Month(mon - 1), year, hour, min, sec);
return dt.Format(_("%H:%M:%S"));//wxString::Format(_("%.2u:%.2u:%.2u"), hour, min, sec);
}
case OFTDateTime:
{
int year, mon, day, hour, min, sec, flag;
pFeature->GetFieldAsDateTime(col, &year, &mon, &day, &hour, &min, &sec, &flag);
wxDateTime dt(day, wxDateTime::Month(mon - 1), year, hour, min, sec);
return dt.Format(_("%d-%m-%Y %H:%M:%S"));//wxString::Format(_("%.2u-%.2u-%.4u %.2u:%.2u:%.2u"), day, mon, year, hour, min, sec);
}
case OFTReal:
return wxString::Format(_("%.6f"), pFeature->GetFieldAsDouble(col));
default:
return wgMB2WX(pFeature->GetFieldAsString(col));
}
//return wgMB2WX(GetAt(row)->GetFieldAsString(col));
}
}
示例12: next
feature_ptr ogr_featureset::next()
{
OGRFeature *poFeature;
while ((poFeature = layer_.GetNextFeature()) != NULL)
{
// ogr feature ids start at 0, so add one to stay
// consistent with other mapnik datasources that start at 1
const int feature_id = (poFeature->GetFID() + 1);
feature_ptr feature(feature_factory::create(ctx_,feature_id));
OGRGeometry* geom = poFeature->GetGeometryRef();
if (geom && ! geom->IsEmpty())
{
ogr_converter::convert_geometry(geom, feature);
}
else
{
MAPNIK_LOG_DEBUG(ogr) << "ogr_featureset: Feature with null geometry="
<< poFeature->GetFID();
OGRFeature::DestroyFeature( poFeature );
continue;
}
++count_;
int fld_count = layerdef_->GetFieldCount();
for (int i = 0; i < fld_count; i++)
{
OGRFieldDefn* fld = layerdef_->GetFieldDefn(i);
const OGRFieldType type_oid = fld->GetType();
const std::string fld_name = fld->GetNameRef();
switch (type_oid)
{
case OFTInteger:
{
feature->put( fld_name, poFeature->GetFieldAsInteger(i));
break;
}
case OFTReal:
{
feature->put( fld_name, poFeature->GetFieldAsDouble(i));
break;
}
case OFTString:
case OFTWideString: // deprecated !
{
UnicodeString ustr = tr_->transcode(poFeature->GetFieldAsString(i));
feature->put( fld_name, ustr);
break;
}
case OFTIntegerList:
case OFTRealList:
case OFTStringList:
case OFTWideStringList: // deprecated !
{
MAPNIK_LOG_WARN(ogr) << "ogr_featureset: Unhandled type_oid=" << type_oid;
break;
}
case OFTBinary:
{
MAPNIK_LOG_WARN(ogr) << "ogr_featureset: Unhandled type_oid=" << type_oid;
//feature->put(name,feat->GetFieldAsBinary (i, size));
break;
}
case OFTDate:
case OFTTime:
case OFTDateTime: // unhandled !
{
MAPNIK_LOG_WARN(ogr) << "ogr_featureset: Unhandled type_oid=" << type_oid;
break;
}
default: // unknown
{
MAPNIK_LOG_WARN(ogr) << "ogr_featureset: Unknown type_oid=" << type_oid;
break;
}
}
}
OGRFeature::DestroyFeature( poFeature );
return feature;
}
MAPNIK_LOG_DEBUG(ogr) << "ogr_featureset: " << count_ << " features";
return feature_ptr();
}
示例13: ExportDataToCSV
void CDlg_GISDataExchange::ExportDataToCSV(CString csv_file_name)
{
#ifndef _WIN64
CString message_str;
OGRRegisterAll();
OGRDataSource *poDS;
poDS = OGRSFDriverRegistrar::Open(m_GIS_ShapeFile, FALSE );
if( poDS == NULL )
{
m_MessageList.AddString("Open file failed." );
return;
}
ofstream CSVFile;
CSVFile.open (csv_file_name, ios::out);
if(CSVFile.is_open () == false)
{
AfxMessageBox("This file cannot be found or opened.\n It might be currently used and locked by EXCEL.");
return;
}else
{
CSVFile.width(15);
CSVFile.precision(6) ;
CSVFile.setf(ios::fixed);
}
int poLayers = ((OGRDataSource*)poDS)->GetLayerCount() ;
for (int i=0; i < poLayers; i++)
{
OGRLayer *poLayer;
poLayer = ((OGRDataSource*)poDS)->GetLayer(i);
if(poLayer == NULL)
{
message_str.Format("Open layer %d failed", i+1);
m_MessageList.AddString (message_str);
return;
}
OGRFeature *poFeature;
int feature_count = 0;
poLayer->ResetReading();
while( (poFeature = poLayer->GetNextFeature()) != NULL )
{
OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
int iField;
if(feature_count == 0) // first feature point, output field name;
{
for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )
{
OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn( iField );
CString str = poFieldDefn->GetNameRef();
str.Replace(" ", NULL); // remove space
CSVFile << str << "," ;
}
CSVFile << "geometry" << endl;
}
for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )
{
OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn( iField );
CString str;
if( poFieldDefn->GetType() == OFTInteger )
CSVFile << poFeature->GetFieldAsInteger( iField ) << ",";
else if( poFieldDefn->GetType() == OFTReal )
CSVFile << poFeature->GetFieldAsDouble(iField) << ",";
else if( poFieldDefn->GetType() == OFTString )
{
str = poFeature->GetFieldAsString(iField);
if(str.Find(',') >=0)
CSVFile << "\"" << poFeature->GetFieldAsString(iField) << "\",";
else
CSVFile << poFeature->GetFieldAsString(iField) << ",";
}
else
{
str = poFeature->GetFieldAsString(iField);
if(str.Find(',') >=0)
CSVFile << "\"" << poFeature->GetFieldAsString(iField) << "\",";
else
CSVFile << poFeature->GetFieldAsString(iField) << ",";
}
}
//.........这里部分代码省略.........
示例14: GetNextRawFeature
OGRFeature* OGRPLScenesLayer::GetNextRawFeature()
{
if( bEOF ||
(!bFilterMustBeClientSideEvaluated && nFeatureCount >= 0 && nNextFID > nFeatureCount) )
return NULL;
if( poGeoJSONLayer == NULL )
{
if( !GetNextPage() )
return NULL;
}
#ifdef notdef
if( CSLTestBoolean(CPLGetConfigOption("OGR_LIMIT_TOO_MANY_FEATURES", "FALSE")) &&
nFeatureCount > nPageSize )
{
bEOF = TRUE;
OGRFeature* poFeature = new OGRFeature(poFeatureDefn);
OGRGeometry* poGeom;
const char* pszWKT = "MULTIPOLYGON(((-180 90,180 90,180 -90,-180 -90,-180 90)))";
OGRGeometryFactory::createFromWkt((char**)&pszWKT, poSRS, &poGeom);
poFeature->SetGeometryDirectly(poGeom);
return poFeature;
}
#endif
OGRFeature* poGeoJSONFeature = poGeoJSONLayer->GetNextFeature();
if( poGeoJSONFeature == NULL )
{
osRequestURL = osNextURL;
bStillInFirstPage = FALSE;
if( !GetNextPage() )
return NULL;
poGeoJSONFeature = poGeoJSONLayer->GetNextFeature();
if( poGeoJSONFeature == NULL )
{
bEOF = TRUE;
return NULL;
}
}
OGRFeature* poFeature = new OGRFeature(poFeatureDefn);
poFeature->SetFID(nNextFID++);
OGRGeometry* poGeom = poGeoJSONFeature->StealGeometry();
if( poGeom != NULL )
{
if( poGeom->getGeometryType() == wkbPolygon )
{
OGRMultiPolygon* poMP = new OGRMultiPolygon();
poMP->addGeometryDirectly(poGeom);
poGeom = poMP;
}
poGeom->assignSpatialReference(poSRS);
poFeature->SetGeometryDirectly(poGeom);
}
for(int i=0;i<poFeatureDefn->GetFieldCount();i++)
{
OGRFieldDefn* poFieldDefn = poFeatureDefn->GetFieldDefn(i);
OGRFieldType eType = poFieldDefn->GetType();
int iSrcField = poGeoJSONFeature->GetFieldIndex(poFieldDefn->GetNameRef());
if( iSrcField >= 0 && poGeoJSONFeature->IsFieldSet(iSrcField) )
{
if( eType == OFTInteger )
poFeature->SetField(i,
poGeoJSONFeature->GetFieldAsInteger(iSrcField));
else if( eType == OFTReal )
poFeature->SetField(i,
poGeoJSONFeature->GetFieldAsDouble(iSrcField));
else
poFeature->SetField(i,
poGeoJSONFeature->GetFieldAsString(iSrcField));
}
}
delete poGeoJSONFeature;
return poFeature;
}
示例15: OnBnClickedImportGpsShapeFile
void CDlg_GISDataExchange::OnBnClickedImportGpsShapeFile()
{
#ifndef _WIN64
UpdateData(1);
if(m_GIS_ShapeFile.GetLength () == 0 )
{
AfxMessageBox("Please select a file first.");
return;
}
CWaitCursor wait;
CString message_str;
OGRRegisterAll();
OGRDataSource *poDS;
bool bFindOverlappingNode = false;
poDS = OGRSFDriverRegistrar::Open(m_GIS_ShapeFile, FALSE );
if( poDS == NULL )
{
m_MessageList.AddString("Open file failed." );
return;
}
int point_index = 0;
int poLayers = ((OGRDataSource*)poDS)->GetLayerCount() ;
for (int i=0; i < poLayers; i++)
{
OGRLayer *poLayer;
poLayer = ((OGRDataSource*)poDS)->GetLayer(i);
if(poLayer == NULL)
{
message_str.Format("Open layer %d failed", i+1);
m_MessageList.AddString (message_str);
return;
}
OGRFeature *poFeature;
int feature_count = 0;
// 0.03 miles
// 0.02: shape length / miles
double threashold = 0.02*0.001;
poLayer->ResetReading();
while( (poFeature = poLayer->GetNextFeature()) != NULL )
{
OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
int id = feature_count;
OGRGeometry *poGeometry;
poGeometry = poFeature->GetGeometryRef();
if( poGeometry != NULL
&& wkbFlatten(poGeometry->getGeometryType()) == wkbPoint ) // point data
{
OGRPoint *poPoint = (OGRPoint *) poGeometry;
// Create and insert the node
DTAPoint* pDTAPoint = new DTAPoint;
pDTAPoint->pt.x = poPoint->getX();
pDTAPoint->pt.y = poPoint->getY();
pDTAPoint->m_NodeNumber = id;
pDTAPoint->m_NodeID = point_index;
pDTAPoint->m_ZoneID = 0;
pDTAPoint->m_ControlType = 0;
m_pDoc->m_DTAPointSet.push_back(pDTAPoint);
point_index++;
}
else if (wkbFlatten(poGeometry->getGeometryType()) == wkbLineString) // line data
{
// Create and insert the node
DTALine* pDTALine = new DTALine;
std::string name = poFeature->GetFieldAsString("Tmc");
pDTALine->TMC_code = name;
double Miles = poFeature->GetFieldAsDouble("Miles");
pDTALine->Miles = Miles;
OGRLineString *poLine = (OGRLineString *) poGeometry;
double shape_len = 0;
int step = 1;
// in case there are too many points
if(poLine->getNumPoints()>=900)
step = (int)(poLine->getNumPoints()/900)+1;
//.........这里部分代码省略.........