Skip to content

Commit

Permalink
assign WGS84 to output layer, save length and time information (fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Jun 16, 2014
1 parent d616bf4 commit c37e61d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/plugins/roadgraph/exportdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,20 @@ QgsVectorLayer* RgExportDlg::mapLayer() const
if ( layerId == QString( "-1" ) )
{
// create a temporary layer
myLayer = new QgsVectorLayer( "LineString", "shortest path", "memory" );
myLayer = new QgsVectorLayer( "LineString?crs=epsg:4326", "shortest path", "memory" );

QgsVectorDataProvider *prov = myLayer->dataProvider();
if ( prov == NULL )
return NULL;

QList<QgsField> attrList;
attrList.append( QgsField( "id", QVariant::Int ) );
attrList.append( QgsField( "lenght", QVariant::Double, "", 20, 8 ) );
attrList.append( QgsField( "time", QVariant::Double, "", 20, 8 ) );
prov->addAttributes( attrList );
myLayer->updateFields();
QList<QgsMapLayer *> myList;
myList << myLayer;
QgsMapLayerRegistry::instance()->addMapLayers( myList );

}
else
{
Expand Down
15 changes: 14 additions & 1 deletion src/plugins/roadgraph/shortestpathwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,21 +389,34 @@ void RgShortestPathWidget::exportPath()
int startVertexIdx = path->findVertex( p1 );
int stopVertexIdx = path->findVertex( p2 );

double time = 0.0;
double cost = 0.0;

Unit timeUnit = Unit::byName( mPlugin->timeUnitName() );
Unit distanceUnit = Unit::byName( mPlugin->distanceUnitName() );

QgsPolyline p;
while ( startVertexIdx != stopVertexIdx )
{
QgsGraphArcIdList l = path->vertex( stopVertexIdx ).inArc();
if ( l.empty() )
break;
const QgsGraphArc& e = path->arc( l.front() );

cost += e.property( 0 ).toDouble();
time += e.property( 1 ).toDouble();

p.push_front( ct.transform( path->vertex( e.inVertex() ).point() ) );
stopVertexIdx = e.outVertex();
}
p.push_front( ct.transform( p1 ) );

QgsFeature f;
QgsFeatureList features;
f.initAttributes( vl->pendingFields().count() );
f.setGeometry( QgsGeometry::fromPolyline( p ) );
f.setAttribute( 0, cost / distanceUnit.multipler() );
f.setAttribute( 1, time / timeUnit.multipler() );
QgsFeatureList features;
features << f;
vl->dataProvider()->addFeatures( features );
vl->updateExtents();
Expand Down

0 comments on commit c37e61d

Please sign in to comment.