5

I have a polygon layer that shows the counties of England and a point layer of project sites. I am trying to make a new virtual field within the point layer that will reference the county that it is in. It needs to be able to stay in the attribute table of the point layer (and not creating a new joined layer) as it will be updated by adding more project sites/points in the future and am working in spatialite where this point shapefile has a join to a records table.

Does anyone know the expression I can use to do this?

9
  • If you install the refFunctions plugin which adds extra functionality to the field calculator, you could use the expression geomwithin( 'nameOfPolygonLayer', 'countyField' ) which retrieves the target field value from the target layer when source feature is within target feature.
    – Joseph
    Commented Nov 12, 2019 at 11:43
  • 1
    Thank you, I will give it a try! How do you add a plugin into the field calculator? Commented Nov 12, 2019 at 11:50
  • From the menubar at the top, go to Plugins > Manage and Install plugins. Then search for the plugin and click the Install Plugin button.
    – Joseph
    Commented Nov 12, 2019 at 11:57
  • Thank you, I have tried it and it created a new column in the attribute table but all the values are NULL? Commented Nov 12, 2019 at 12:10
  • 1
    It worked!! Thank you so much Commented Nov 12, 2019 at 12:45

1 Answer 1

6

If you install the refFunctions plugin (from the menubar: Plugins > Manage and Install plugins) which adds extra functionality to the field calculator, you could use the expression:

geomwithin( 'nameOfPolygonLayer', 'countyField' ) 

which retrieves the target field value from the target layer when source feature is within target feature. Ensure both your layers are in the same CRS.

Your Answer

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

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