[Qgis-user] lines with arrowheads
Tim Sutton
tim at linfiniti.com
Mon Jun 2 23:32:45 PDT 2008
Hi
Yes if others are agreeable, I can add an option to vector props to
enable / disable the arrows (default off).
Regards
Tim
2008/6/3 Hugentobler Marco <marco.hugentobler at karto.baug.ethz.ch>:
> Hi Tim,
>
>>Marco what is the plan / status of that for 1.0?
>
> Prior 1.0, there will be no major redesign of vector rendering mechanism. Post 1.0, I think it is absolutely necessary to do so and to let renderer subclasses decide what shapes to draw.
>
> I think the patch only makes sense if, as you suggested in February (see below), the arrow heads can be enabled/disabled via vector layer props and the state is saved to the project file.
>
>>If anyone vigorously disagrees let me know,
>>otherwise I'll incorporate your patch in 0.9.3 with some additions
>>from myself to enabled or disable line arrows via the layer props
>>dialog, the vector api and the layer properties serialisation
>>mechanism.
>
> Regards,
> Marco
>
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: Tim Sutton [mailto:tim at linfiniti.com]
> Gesendet: Mo 02.06.2008 22:10
> An: Stefanie Tellex
> Cc: qgis-user at lists.osgeo.org; Hugentobler Marco
> Betreff: Re: [Qgis-user] lines with arrowheads
>
> Hi
>
> Yes I was for accepting the patch, but I believe others wanted to
> wait under we had rendering stuff revised. Marco what is the plan /
> status of that for 1.0? My feeling is we should reconsider the patch
> if we wont have the render modules in place for 1.0....
>
> Regards
>
> Tim
>
> 2008/6/2 Stefanie Tellex <stefie10 at media.mit.edu>:
>> I submitted a patch to do this a while back, but I don't think it was
>> accepted. I thought it was because it was decided to wait until a more
>> modular rendering pipeline was added, but I can't find the messages about
>> that in the thread. In fact the thread implies it would be accepted, but
>> if it made it into svn, I never noticed it.
>> (http://lists.osgeo.org/pipermail/qgis-developer/2008-February/003248.html)
>>
>> The patches are attached. (arrows_in_linestrings draws arrows;
>> draw_start_and_stop draws a green dot at the start and a red dot at the
>> end.)
>>
>> This message suggests an alternative solution that doesn't require compiling
>> qgis yourself:
>> http://lists.osgeo.org/pipermail/qgis-developer/2008-February/003250.html
>>
>> Stefanie
>>
>>
>>
>>
>>
>> M S wrote:
>>>
>>> One of the outputs from r.flow in GRASS is downslope flow lines. Without
>>> arrowheads (or some similar symbol like that) at the end of lines pointing
>>> which way is downhill, the lines become ambiguous.
>>>
>>> Is there a way to draw these lines with arrowheads? Or some other
>>> approach that might achieve this?
>>>
>>> Mark
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> Qgis-user mailing list
>>> Qgis-user at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/qgis-user
>>
>>
>> Index: qgis/qgis_unstable/src/core/qgsvectorlayer.cpp
>> ===================================================================
>> --- qgis.orig/qgis_unstable/src/core/qgsvectorlayer.cpp 2008-06-02
>> 12:17:11.000000000 -0400
>> +++ qgis/qgis_unstable/src/core/qgsvectorlayer.cpp 2008-06-02
>> 12:34:47.000000000 -0400
>> @@ -360,7 +360,8 @@
>> QPainter* p,
>> const QgsMapToPixel* mtp,
>> const QgsCoordinateTransform* ct,
>> - bool drawingToEditingCanvas)
>> + bool drawingToEditingCanvas,
>> + bool drawArrows)
>> {
>> unsigned char *ptr = feature + 5;
>> unsigned int wkbType = *((int*)(feature+1));
>> @@ -432,6 +433,7 @@
>> // 255 = opaque
>> //
>> QPen myTransparentPen = p->pen(); // store current pen
>> + QBrush brush = p->brush(); //to be kept as original
>> QColor myColor = myTransparentPen.color();
>> //only set transparency from layer level if renderer does not provide
>> //transparency on class level
>> @@ -459,8 +461,45 @@
>> }
>> }
>>
>> + // draw arrows
>> + if (drawArrows) {
>> +#define PI 3.14159
>> + p->setBrush(QBrush(myColor, Qt::SolidPattern));
>> +
>> + for (int i = 0; i < pa.size(); ++i)
>> + {
>> + if (i > 0)
>> + {
>> + QPointF p1 = pa[i];
>> + QPointF p2 = pa[i-1];
>> +
>> + QLineF line = QLineF(p1, p2);
>> + double angle = ::acos(line.dx() / line.length());
>> + if (line.dy() >= 0)
>> + {
>> + angle = (PI * 2) - angle;
>> + }
>> +
>> + float arrowSize = 5;
>> + QPointF arrowP1 =
>> + line.p1() + QPointF(sin(angle + PI / 3) * arrowSize,
>> + cos(angle + PI / 3) * arrowSize);
>> + QPointF arrowP2 =
>> + line.p1() + QPointF(sin(angle + PI - PI / 3) * arrowSize,
>> + cos(angle + PI - PI / 3) * arrowSize);
>> + QPolygonF arrowHead;
>> + arrowHead << line.p1() << arrowP1 << arrowP2;
>> + if (i % 2 == 0) {
>> + p->drawPolygon(arrowHead);
>> + }
>> +
>> +
>> + }
>> + }
>> + }
>> //restore the pen
>> p->setPen(pen);
>> + p->setBrush(brush);
>>
>> return ptr;
>> }
>> @@ -3057,7 +3096,7 @@
>> p,
>> theMapToPixelTransform,
>> ct,
>> - drawingToEditingCanvas);
>> + drawingToEditingCanvas, TRUE);
>> break;
>> }
>> case QGis::WKBMultiLineString:
>> Index: qgis/qgis_unstable/src/core/qgsvectorlayer.h
>> ===================================================================
>> --- qgis.orig/qgis_unstable/src/core/qgsvectorlayer.h 2008-06-02
>> 12:17:11.000000000 -0400
>> +++ qgis/qgis_unstable/src/core/qgsvectorlayer.h 2008-06-02
>> 12:35:13.000000000 -0400
>> @@ -451,7 +451,8 @@
>> QPainter* p,
>> const QgsMapToPixel* mtp,
>> const QgsCoordinateTransform* ct,
>> - bool drawingToEditingCanvas);
>> + bool drawingToEditingCanvas,
>> + bool drawArrows=FALSE);
>>
>> /** Draw the polygon as given in the WKB format. Returns a pointer to
>> * the byte after the end of the polygon binary data stream (WKB).
>>
>> Index: qgis/qgis_unstable/src/core/qgsvectorlayer.cpp
>> ===================================================================
>> --- qgis.orig/qgis_unstable/src/core/qgsvectorlayer.cpp 2008-06-02
>> 12:48:56.000000000 -0400
>> +++ qgis/qgis_unstable/src/core/qgsvectorlayer.cpp 2008-06-02
>> 12:49:22.000000000 -0400
>> @@ -361,7 +361,8 @@
>> const QgsMapToPixel* mtp,
>> const QgsCoordinateTransform* ct,
>> bool drawingToEditingCanvas,
>> - bool drawArrows)
>> + bool drawArrows,
>> + bool drawEndPoints)
>> {
>> unsigned char *ptr = feature + 5;
>> unsigned int wkbType = *((int*)(feature+1));
>> @@ -470,6 +471,8 @@
>> {
>> if (i > 0)
>> {
>> + p->setBrush(QBrush(myColor, Qt::SolidPattern));
>> +
>> QPointF p1 = pa[i];
>> QPointF p2 = pa[i-1];
>>
>> @@ -494,9 +497,17 @@
>> }
>>
>>
>> + } else {
>> +
>> }
>> }
>> }
>> + if (drawEndPoints) {
>> + p->setBrush(QBrush(Qt::green, Qt::SolidPattern));
>> + p->drawEllipse(pa[0].x(), pa[0].y(), 5, 5);
>> + p->setBrush(QBrush(Qt::red, Qt::SolidPattern));
>> + p->drawEllipse(pa[pa.size() - 1].x(), pa[pa.size() - 1].y(), 5, 5);
>> + }
>> //restore the pen
>> p->setPen(pen);
>> p->setBrush(brush);
>> @@ -3104,7 +3115,7 @@
>> p,
>> theMapToPixelTransform,
>> ct,
>> - drawingToEditingCanvas, TRUE);
>> + drawingToEditingCanvas, TRUE, TRUE);
>> break;
>> }
>> case QGis::WKBMultiLineString:
>> Index: qgis/qgis_unstable/src/core/qgsvectorlayer.h
>> ===================================================================
>> --- qgis.orig/qgis_unstable/src/core/qgsvectorlayer.h 2008-06-02
>> 12:35:13.000000000 -0400
>> +++ qgis/qgis_unstable/src/core/qgsvectorlayer.h 2008-06-02
>> 12:49:22.000000000 -0400
>> @@ -452,7 +452,8 @@
>> const QgsMapToPixel* mtp,
>> const QgsCoordinateTransform* ct,
>> bool drawingToEditingCanvas,
>> - bool drawArrows=FALSE);
>> + bool drawArrows=FALSE,
>> + bool drawEndPoints=FALSE);
>>
>> /** Draw the polygon as given in the WKB format. Returns a pointer to
>> * the byte after the end of the polygon binary data stream (WKB).
>>
>> _______________________________________________
>> Qgis-user mailing list
>> Qgis-user at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/qgis-user
>>
>>
>
>
>
> --
> Tim Sutton
> QGIS Project Steering Committee Member - Release Manager
> Visit http://qgis.org for a great open source GIS
> openModeller Desktop Developer
> Visit http://openModeller.sf.net for a great open source ecological
> niche modelling tool
> Home Page: http://tim.linfiniti.com
> Skype: timlinux
> Irc: timlinux on #qgis at freenode.net
>
>
--
Tim Sutton
QGIS Project Steering Committee Member - Release Manager
Visit http://qgis.org for a great open source GIS
openModeller Desktop Developer
Visit http://openModeller.sf.net for a great open source ecological
niche modelling tool
Home Page: http://tim.linfiniti.com
Skype: timlinux
Irc: timlinux on #qgis at freenode.net
More information about the Qgis-user
mailing list