I have a PostGIS database, with 2 layers: a point and a line. I import these layers into QGIS (set snap to 10 pixels), draw a line, then I draw a point on that line. Then i select the point and verify if the point geometry intersect line geometry and it is false.

The question is why? Below is the piece of code that I'm using:

for lyr in QgsMapLayerRegistry.instance().mapLayers().values():
  if lyr.name() == 'line':
    l_layer = lyr
  elif lyr.name() == 'point':
    p_layer = lyr
  print 'ok'

featSelected = p_layer.selectedFeatures()

for l in l_layer.getFeatures():
  if featSelected[0].geometry().intersects(l.geometry()):
    print 'ok'

for line in l_layer.getFeatures():
  if featSelected[0].geometry().intersects(line.geometry()):
     value = line["guidCON"]
     idSelected = featSelected[0].id()
     fieldIndex = p_layer.dataProvider().fieldNameIndex("guidCON")
  • When you drew the line, did you save the layer? – Joseph Jan 10 '17 at 10:05
  • Yes, i drew the line, save and after that i made a point on it. – G3orge Jan 10 '17 at 10:08

enter image description here

It is a problem related to geometry accuracy. A punt stored has an accuracy in its coordinates with a large decimal number, but a vector line is the union between 2 points. When qgis calculates the intersection in the line i gues there is always a very small distance between point and line due to the diferent accuracy.

To solve this, first i must to create a new node into the line, then you are able to insert, in the new node, a feature point. In the image above a spatial query "intersects" 3 red points in a line, only nodes line intersects with points, the green dots . In the following image is shown a JTS TestBuilder capture. A line and a point intersects, in predicates we see a True in Intersects.

enter image description here

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.