[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Length of a PolyLine



Chris Burkert wrote:
Hi List,

at first I would like to thank all of you developers of dia.

I'm using dia for drawing maps where I take some raster data like a .png, put some lines and labels on it and export this as a .png again. I have an example at [1].

Now I would like to measure the length of the red PolyLine at the seaside in a defined unit. My first idea was to use pythagoras in the python console and I wrote this little script which I load with execfile("script.py"):

#!/usr/bin/env python
from math import sqrt
points = dia.active_display().diagram.layers[0].objects[1].properties['poly_points']
distance = 0
size = len(points.value)
for i in range(size):
a = points.value[i]
if i < size-1:
b = points.value[i+1]
distance += sqrt(pow(2,a.x-b.x) + pow(2,a.y-b.y))
Shouldn't the parameters to pow() be the other way around?

print distance

The problem is that the tuple points.value seems not to be ordered thus points.value[42] is not always the same.
What do you mean with "not always the same"? Looking just at the
Python bindings plug-ins/python/pydia-property.c(PyDia_get_PointArray)
you'll get the points in the same order as stored internally. And
that needs to be ordered to get the drawing right.

So what can I do to mesasure the length of this PolyLine correct? Except parsing the .dia xml by hand :-)

After fixing the bug from above it should work ;-)

	Hans

-------- Hans "at" Breuer "dot" Org -----------
Tell me what you need, and I'll tell you how to
get along without it.                -- Dilbert


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] Mail converted by Mofo Magic and the Flying D

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

GuideSMACK