[Qgis-user] Update field based on a value from another layer

Bernd Vogelgesang bernd.vogelgesang at gmx.de
Wed Jun 24 05:10:26 PDT 2020


On 24.06.20 10:45, Ben Hur Pintor wrote:
> Hi,
>
>     aggregate ( layer:='yourpolygonlayername',
>     aggregate:='concatenate', expression:="yourfieldtoextract",
>     filter:=contains($geometry, geometry(@parent)))
>
> +1 for Harissou's answer. I'm gonna copy this one in my future
> workflows. Thanks!


Hi,

things are already even better nowadays,

Instead of manually putting those functions in the field calculator, you
can just put it in the attributes fields settings as "default value" and
check update on edit, so you won't have to run it ever again on changes
of the layer.
Don't know how this affects performance, but I just recently found out
about it, and for my small scale projects, it works nicely. As a long
time user, you easily oversee those possibilities when you have been
used to work around missing things. Actually, I regard this feature as a
killer feature for those not working with views on databases etc.

Cheers,

Bernd

>
> You can also try the Point Sampling Tool
> <https://plugins.qgis.org/plugins/pointsamplingtool/> plugin. It
> allows for multiple vectors and raster to be sampled. It creates a 3rd
> layer + it results in 1 column/attribute per sampled attribute of the
> layers. If your purpose is to have a single column/attribute hold the
> values sampled from a series of vector layers (layer 1, layer 2, layer
> 3, etc.), you might need to merge your layers to sample first.
>
> You can also try the v.what.vect or v.what.rast GRASS modules within
> QGIS for sampling vectors and rasters respectively. This option does
> not create a third layer but simply updates the point layer with
> values from the sampled layer although it only allows for one layer to
> be sampled at one time resulting again in multiple columns if you want
> to sample multiple layers.
>
> In both cases, if you have multiple layers that you want to sample
> (with similar attributes + no overlap), you can merge these layers
> first before sampling them. If they have similar attributes/fields,
> you can then sample the resulting layer. Of course this adds another
> step to your workflow.
>
> All the best,
> Ben Hur
>
> On Wed, Jun 24, 2020 at 2:01 PM Harrissou <delazj at gmail.com
> <mailto:delazj at gmail.com>> wrote:
>
>     Hi Tony,
>
>     You can use functions from the aggregate group in the field
>     calculator of the point layer. No need to create a third layer.
>     (Somehow) Picked from the QGIS function help panel
>
>     aggregate ( layer:='yourpolygonlayername',
>     aggregate:='concatenate', expression:="yourfieldtoextract",
>     filter:=contains($geometry, geometry(@parent)))
>
>     This will populate the point layer field with values of whatever
>     polygon covers the point.
>     You can also use the direct functions concatenate,
>     concatenate_unique, minimum, maximum... depending on how your data
>     are shaped and what you actually need.
>
>     Hope that helps,
>     Harrissou
>
>     Le 24 juin 2020 05:29:58 GMT+02:00, "Tony Shepherd (FarmMaps NZ)"
>     <tony at farmmaps.nz <mailto:tony at farmmaps.nz>> a écrit :
>
>         Hi All
>
>         Am I missing something?  Is there a simple point and click
>         tool in QGIS to update an existing field in a QGIS layer based
>         on a value in another using a geographic join?  For example a
>         series of points and a series polygons.  I want to update a
>         field in points from a value in a field in polygons based on
>         which polygon the point falls in. Simple stuff.
>
>         In a previous life using MapInfo we simply used query editor and
>
>         update point_layer set col1 = colx from polygon_layer where
>         obj within any
>
>         To me, this seems like a very simple everyday thing to do to
>         an existing table.  I can, of course, use vector -> Join
>         Attributes by Column but why in this case would I needlessly
>         complicate things by having to create a third layer?  I don’t
>         need an extra layer, I just need to update the one I have already.
>
>         I can see that the internet is littered with similar questions
>         dating back as long as QGIS has been around.  Perhaps I have
>         missed something obvious, and if so apologies for wasting the
>         time of others, but can you point me to the tool?
>
>         Cheers
>
>         Tony
>
>         *Tony Shepherd**|*  GeoSpatial / Mapping Manager
>
>         Ph 027 435 6193 *|*E tony at farmmaps.nz <mailto:tony at farmmaps.nz>
>
>         FarmMaps NZ, 3 Kerwood Place, Gore 9740
>
>         FM_logo1_small (Custom)
>
>         **
>
>         ** <http://tonyshepherd8.wixsite.com/home>**
>         <https://www.wunderground.com/personal-weather-station/dashboard?ID=ISTLGORE2>**
>
>
>     --
>     Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez
>     excuser ma brièveté.
>     _______________________________________________
>     Qgis-user mailing list
>     Qgis-user at lists.osgeo.org <mailto:Qgis-user at lists.osgeo.org>
>     List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
>     Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>
>
>
> --
> ---
> *Ben Hur S. Pintor*
> bnhr.xyz <https://bnhr.xyz/>
> hi at bnhr.xyz <mailto:hi at bnhr.xyz>
>
>
> open spatial & data solutions
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20200624/674ef96d/attachment-0001.html>


More information about the Qgis-user mailing list