<div dir="ltr">Another approach would be to use 'Snap points to Grid' algorithm. This allows you to snap the points to a regular grid. Choose 0.01 as the grid spacing and you'll get points rounded off to 2 decimal points (As David mentioned, floating-point precision means the printed values won't be exact 2 decimals). Sample PyQGIS code below<div><br></div><div>layer = iface.activeLayer()<br><br>output = processing.run("native:snappointstogrid",<br>    {'INPUT':layer,<br>    'HSPACING':0.01,<br>    'VSPACING':0.01,<br>    'OUTPUT': 'TEMPORARY_OUTPUT'})<br><br>for f in output['OUTPUT'].getFeatures():<br>    geom = f.geometry().asPoint()<br>    print(geom) <br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div></div><div><table cellpadding="0" cellspacing="0" style="border-spacing:0px;border-collapse:collapse;color:rgb(68,68,68);width:480px;font-size:10pt;font-family:Arial,sans-serif;line-height:normal"><tbody><tr><td valign="top" style="padding:10px 0px 12px;width:160px;vertical-align:top"><a href="https://spatialthoughts.com/" style="background-color:transparent;color:rgb(51,122,183)" target="_blank"><img border="0" alt="Logo" width="141" src="https://spatialthoughts685850346.files.wordpress.com/2019/12/spatial_thoughts_logo.png" style="border:0px;vertical-align:middle;width:141px;height:auto"></a></td><td style="padding:6px 0px;width:320px"><table cellpadding="0" cellspacing="0" style="border-spacing:0px;border-collapse:collapse;background-color:transparent"><tbody><tr><td style="padding:0px;font-size:12pt;font-family:Arial,sans-serif;font-weight:bold;color:rgb(61,60,63)"><span style="color:rgb(0,175,239)">Ujaval Gandhi</span></td></tr><tr><td style="padding:0px 0px 11px;font-size:10pt;font-family:Arial,sans-serif;color:rgb(61,60,63)"><span style="color:rgb(0,175,239)">Spatial Thoughts</span></td></tr><tr><td style="padding:0px;font-size:10pt;font-family:Arial,sans-serif;color:rgb(155,155,155)"><span>mobile: +91-8095684687</span></td></tr><tr><td style="padding:0px;font-size:10pt;font-family:Arial,sans-serif;color:rgb(155,155,155)"><span>email: </span><span style="color:rgb(23,147,210)"><a href="mailto:ujaval@spatialthoughts.com" target="_blank">ujaval@spatialthoughts.com</a></span></td></tr><tr><td style="padding:6px 0px 0px"><span style="display:inline-block;height:22px"><span><a href="https://www.linkedin.com/in/spatialthoughts/" style="background-color:transparent;color:rgb(51,122,183)" target="_blank"><img alt="LinkedIn icon" border="0" width="23" height="23" src="https://codetwocdn.azureedge.net/images/mail-signatures/generator/elegant-logo/ln.png" style="border:0px;vertical-align:middle;height:20px;width:20px"></a>  </span><span><a href="https://twitter.com/spatialthoughts" style="background-color:transparent;color:rgb(51,122,183)" target="_blank"><img alt="Twitter icon" border="0" width="23" height="23" src="https://codetwocdn.azureedge.net/images/mail-signatures/generator/elegant-logo/tt.png" style="border:0px;vertical-align:middle;height:20px;width:20px"></a>  </span></span></td></tr></tbody></table></td></tr><tr><td colspan="2" style="padding:8px 0px 0px;border-top:1px solid rgb(23,147,210);width:480px;font-family:Arial,sans-serif;color:rgb(155,155,155);text-align:justify"></td></tr></tbody></table><br></div></div></div></div></div></div></div></div></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Feb 20, 2022 at 11:03 PM David Strip <<a href="mailto:qgis-user@stripfamily.net">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>
    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">
      
      <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" target="_blank">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>
  </div>

_______________________________________________<br>
Qgis-user mailing list<br>
<a href="mailto:Qgis-user@lists.osgeo.org" target="_blank">Qgis-user@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><br>
</blockquote></div>