Skip to content

Commit

Permalink
Handle different vector field types
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Nov 1, 2011
1 parent cc91d14 commit 59545f1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/core/symbology-ng-core.sip
Expand Up @@ -711,7 +711,7 @@ public:
//! delete layer at specified index and set a new one
bool changeSymbolLayer(int index, QgsSymbolLayerV2* layer /Transfer/);

void startRender( QgsRenderContext& context, const QgsVectorLayer* layer );
void startRender( QgsRenderContext& context, const QgsVectorLayer* layer = 0 );
void stopRender(QgsRenderContext& context);

void setColor(const QColor& color);
Expand Down
31 changes: 31 additions & 0 deletions src/core/symbology-ng/qgsvectorfieldsymbollayer.cpp
Expand Up @@ -105,6 +105,13 @@ void QgsVectorFieldSymbolLayer::renderPoint( const QPointF& point, QgsSymbolV2Re
xComponent = context.outputLineWidth( xVal );
yComponent = context.outputLineWidth( yVal );
break;
case Polar:
convertPolarToCartesian( xVal, yVal, xComponent, yComponent );
xComponent = context.outputLineWidth( xComponent );
yComponent = context.outputLineWidth( yComponent );
case Height:
xComponent = 0;
yComponent = context.outputLineWidth( yVal );
default:
break;
}
Expand Down Expand Up @@ -189,3 +196,27 @@ QSet<QString> QgsVectorFieldSymbolLayer::usedAttributes() const
}
return attributes;
}

void QgsVectorFieldSymbolLayer::convertPolarToCartesian( double length, double angle, double& x, double& y ) const
{
//convert angle to degree and to north orientation
if ( mAngleOrientation == CounterclockwiseFromEast )
{
if ( angle <= 90 )
{
angle = 90 - angle;
}
else
{
angle = 360 - angle + 90;
}
}

if ( mAngleUnits == Degrees )
{
angle = angle * M_PI / 180.0;
}

x = length * sin( angle );
y = length * cos( angle );
}
3 changes: 3 additions & 0 deletions src/core/symbology-ng/qgsvectorfieldsymbollayer.h
Expand Up @@ -91,6 +91,9 @@ class CORE_EXPORT QgsVectorFieldSymbolLayer: public QgsMarkerSymbolLayerV2
//Attribute indices are resolved in startRender method
int mXIndex;
int mYIndex;

//Converts length/angle to cartesian x/y
void convertPolarToCartesian( double length, double angle, double& x, double& y ) const;
};

#endif // QGSVECTORFIELDSYMBOLLAYER_H

0 comments on commit 59545f1

Please sign in to comment.