Skip to content

Commit c37e61d

Browse files
committedJun 16, 2014
assign WGS84 to output layer, save length and time information (fix #8696)
1 parent d616bf4 commit c37e61d

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed
 

‎src/plugins/roadgraph/exportdlg.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,20 @@ QgsVectorLayer* RgExportDlg::mapLayer() const
7676
if ( layerId == QString( "-1" ) )
7777
{
7878
// create a temporary layer
79-
myLayer = new QgsVectorLayer( "LineString", "shortest path", "memory" );
79+
myLayer = new QgsVectorLayer( "LineString?crs=epsg:4326", "shortest path", "memory" );
8080

8181
QgsVectorDataProvider *prov = myLayer->dataProvider();
8282
if ( prov == NULL )
8383
return NULL;
8484

8585
QList<QgsField> attrList;
86-
attrList.append( QgsField( "id", QVariant::Int ) );
86+
attrList.append( QgsField( "lenght", QVariant::Double, "", 20, 8 ) );
87+
attrList.append( QgsField( "time", QVariant::Double, "", 20, 8 ) );
8788
prov->addAttributes( attrList );
89+
myLayer->updateFields();
8890
QList<QgsMapLayer *> myList;
8991
myList << myLayer;
9092
QgsMapLayerRegistry::instance()->addMapLayers( myList );
91-
9293
}
9394
else
9495
{

‎src/plugins/roadgraph/shortestpathwidget.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,21 +389,34 @@ void RgShortestPathWidget::exportPath()
389389
int startVertexIdx = path->findVertex( p1 );
390390
int stopVertexIdx = path->findVertex( p2 );
391391

392+
double time = 0.0;
393+
double cost = 0.0;
394+
395+
Unit timeUnit = Unit::byName( mPlugin->timeUnitName() );
396+
Unit distanceUnit = Unit::byName( mPlugin->distanceUnitName() );
397+
392398
QgsPolyline p;
393399
while ( startVertexIdx != stopVertexIdx )
394400
{
395401
QgsGraphArcIdList l = path->vertex( stopVertexIdx ).inArc();
396402
if ( l.empty() )
397403
break;
398404
const QgsGraphArc& e = path->arc( l.front() );
405+
406+
cost += e.property( 0 ).toDouble();
407+
time += e.property( 1 ).toDouble();
408+
399409
p.push_front( ct.transform( path->vertex( e.inVertex() ).point() ) );
400410
stopVertexIdx = e.outVertex();
401411
}
402412
p.push_front( ct.transform( p1 ) );
403413

404414
QgsFeature f;
405-
QgsFeatureList features;
415+
f.initAttributes( vl->pendingFields().count() );
406416
f.setGeometry( QgsGeometry::fromPolyline( p ) );
417+
f.setAttribute( 0, cost / distanceUnit.multipler() );
418+
f.setAttribute( 1, time / timeUnit.multipler() );
419+
QgsFeatureList features;
407420
features << f;
408421
vl->dataProvider()->addFeatures( features );
409422
vl->updateExtents();

0 commit comments

Comments
 (0)
Please sign in to comment.