1

In a QField project, I have two layers:

  1. MEASUREMENT POINT
  2. PARCEL

When an agent wishes to record a point on a parcel in the field, if the agent's geographical position does not correspond to the location of the parcel where he is, the entry will not be executed.

1
  • Are they always using "Cursor locked at position" to create the points? (They dont place the point manually by "clicking")
    – BERA
    Aug 10 at 12:10

1 Answer 1

0

Unfortunately, QGIS does not treat geometry like any other attribute of a feature class - it should, but it doesn't.

A possible workaround is to create a field, e.g. a uuid field. Do not use the UUID generator widget type, use a text edit. Make the widget uneditable. Set constraints of the field to NOT NULL and 'enforce constraint'.

Under default value use overlay_intersects() expression or similar to check the current point feature is within your target polygon. Be aware that depending on how you use overlay_intersects() it may return a boolean or an array. (Check out the syntax and options for overlay_intersects() in the manual). Assuming your point can be within any polygon of your target layer, you can simply use overlay_intersects('myTargetLayer'), which returns a boolean: true if it is inside a polygon, false if not. You can then put this in a case statement something like

case
     when overlay_intersects('myTargetLayer') then uuid()
     else null
end

If the expression returns null, then you will not be able to save the feature.

EDIT: Screenshots of it working. In this case I am using tree_pt as my point layer and tgtnote_ar as my polygon layer. For 'tree_pt' I have a text field with default set to

case
     when overlay_intersects('tgtnote_ar') then uuid
     else null
end

(Note: the 'when' clause, could be written as when overlay_intersects('tgtnote_ar') = True then uuid, but the '= True' is implicit.)

I have constraints set to 'Not null' and 'Enforce not null constraint' checked.

enter image description here

Here is a short GIF of it working. First two attempts at plotting a point are outside of a polygon: the feature form opens but can't be saved. Third attempt is inside a polygon. The feature form opens and the save button is enabled - I save the feature.

enter image description here

12
  • Hello ,@Oisine your method seems to answer my problem. When I enter the expression: overlay_intersect ('TagetLayer'), it returns TRUE or FALSE. I'd like it to be impossible to type when the expression returns False.
    – Donovan93
    Aug 17 at 15:42
  • Add '=False' no quotes after overlay_intersects('TagetLayer').
    – Oisin
    Aug 17 at 21:18
  • Hi @Oisin, Thanks for your feedback. Unfortunately, the expression: overlay_intersects('TagetLayer', false), still doesn't make it possible to disable input when the false condition is checked.
    – Donovan93
    Aug 22 at 15:19
  • It worked for me. The feature form opens but cannot be saved, so user must cancel.
    – Oisin
    Aug 22 at 15:21
  • what is your full expression please? Did you use only overlay_intersects('TagetLayer', false) or did you add the declaration with CASE?
    – Donovan93
    Aug 22 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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