<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
I'd start by building the array of values using just the rounded x,
y, and complex value, not storing a QgsPointXY. Something like<br>
<br>
<blockquote><font face="Courier New, Courier, monospace">triplets =
[]<br>
for point in points:<br>
# point consists of a QgsPointXY and a complex value -
[QgsPointXy, complex_value]<br>
triplets += [(round(point[0].x(), 3), round(point[0].y(),
3), point[1])]<br>
<br>
#sort points by y value<br>
triplets.sort(key = lambda point: point[1])<br>
# sort points by x value. Sort is stable, so now we have sorted
by x as primary, y as secondary<br>
<br>
#walk the list of points looking for points with same rounded
value, summing complex value, outputting a new point when x or y
doesn't match<br>
complex_sum = 0<br>
last_x = triples[0][0]<br>
last_y = triples[0][1]<br>
output = []<br>
for t in triplets:<br>
if ((t[0] == last_x AND t[1] == last_y)):<br>
complex_sum += t[2]<br>
else:<br>
output += [(last_x, last_y, complex_sum)]<br>
last_x = t[0]<br>
last_y = t[1]<br>
complex_sum = t[2]</font><br>
</blockquote>
<br>
at the end of the loop the var output is a list of triplets (x, y,
complex) with the third element equal to the sum of the the complex
value for all points with the same rounded coordinates. <br>
I haven't actually tested, this so there could be errors. But the
idea is there.<br>
There's probably a more pythonic way to do this, but possibly harder
to read. <br>
<br>
<br>
On 2/20/2022 7:07 AM, Asim al-sofi wrote:
<blockquote type="cite">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">Thank you for your reply
<div>The issue I have is that I have an array of values. each
value consists of xy coordinates of a point and a complex
value.</div>
<div>What I want is that the points that have the same xy
coordinates to be added together(i.e,, their complex values
need to be summed up)</div>
<div>Because of the high number of decimals of each point,
sometimes a point like QgsPointXY(6500.1149100000002363<b>2</b>
0), 0.25+0.25j] and a point like
QgsPointXY(6500.1149100000002363<b>1</b> 0), 0.25+0.25j] would
be considered as two different points.</div>
<div>Thanks in advance</div>
<div>Asim</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Sun, Feb 20, 2022 at 5:21
AM David Strip <<a href="mailto:qgis-user@stripfamily.net"
class="moz-txt-link-freetext">qgis-user@stripfamily.net</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div>On 2/19/2022 6:03 PM, Asim al-sofi wrote:<br>
</div>
<blockquote type="cite">Hi everyone
<div>I have a problem rounding off the QgsPointXY to say 3
decimals? How can I do that?</div>
<div>If I use the numpy.round(point,decimals) then I get
an np.array back as a type and not a QgsPointXY.</div>
<div>Can someone help?<br>
Kind regards</div>
<div>Asim</div>
</blockquote>
<br>
what are you trying to achieve? Keep in mind that in general
decimal fractions do not have exact representations in
floating point, so if you round a coordinate to 3 decimals,
store it somewhere, then print it, there will almost
certainly be more than three numbers past the decimal point.
If it's the printed representation of the number that
matters, deal with it in the formatting of the printed
representation.<br>
<br>
That said, you set() method of QgsPointXY to set the values
to their rounded values. If my_pt is a QgsPointXY, then<br>
<br>
my_pt.set(round(my_pt.x(), 3), round(my_pt.y(), 3))<br>
<br>
<br>
</div>
</blockquote>
</div>
</blockquote>
<br>
</body>
</html>