1

enter image description here

I want to get the point attribute data into intersected layer. I have this code

if pt.geometry().intersects(pg.geometry()):
    intersection = pg.geometry().intersection(pt.geometry())
    intersectionLength = intersection.length()
    print pt['PLATSECID']
    fieldIndex = pointLayer.fieldNameIndex(polygonLayerColumToUpdate)
    pointLayer.startEditing()
    pointLayer.changeAttributeValue(pt.id(), fieldIndex, pg[pointLayerColumName])
    pointLayer.commitChanges()

The problem is that point intesecting with only one split fragmented layer, it is not intesecting with other split fragmented polygon. Although picture seems that point intesecting with both split feature of the layer

1

Points are infinitesimally small, they have no area.

Polygon boundaries are lines. For a point to lie exactly on a line, the geometric accuracy has to be either super high/logical or it needs to lie on one of the line's points.

So for a point to intersect a polygon it usually has to lie somewhere at least just inside the polygon.

A common workaround is using a tiny buffer around the point and testing that for intersection.

if pt.geometry().buffer(your_threshold).intersects(pg.geometry()):

Another common workaround that does not require the creation of a new geometry (such as that buffer) is measuring the nearest distance to the candidates for intersection, in your case the polygons) and considering it an intersection if the distance is below a threshold.

if pt.geometry().distance(pg.geometry()) >= your_threshold:

Another common workaround, but not always supported, would be specifying a tolerance. That really depends on the used software and approach.

| improve this answer | |
  • Thanks for valueable input! but I only know that how to code(a little bit) i dont know about qgis. Can you explain any programming workaround – Muhammad Faizan Khan Dec 7 '16 at 10:42
  • I added example code to my answer, untested though, give them a try. You do not use the actual intersection geometry later on in your code snippet, if you do, that would require additional work. – bugmenot123 Dec 7 '16 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.