[Qgis-user] Easiest way to get get feature field values from one layer to be able to copy to another layer

chris hermansen clhermansen at gmail.com
Sun Jan 31 10:40:51 PST 2021

Cory and list;

On Sun, Jan 31, 2021 at 9:48 AM Cory Albrecht <osgeo at cory.albrecht.name>

> > Not completely following you here but the normal thing is to do a
> "join" between two tables on a common attribute.
> No, I don't want to do a join. In any case, a join still requires that
> there be that common value in the one table to point to the other table to
> do the join with in the first place.
> > It would help if you would post some examples with real "numbers".
> Borders separate two places. I want my border features to have foreign
> keys to the places they separate.

"borders separate two places" - well, depending on their specific
geometry.  The eastern border of France separates that country from
Belgium, Luxembourg, Germany, Switzerland and Italy.

Of course, you might have France's eastern border split up into the
segments that separate it from its neighbours.  But then again, you might

> layer countries:
> feature_a: feature_uuid = '24910f94-5721-4b97-b7f7-1b209b34687b', name =
> 'Lower Canada'
> feature_b: feature_uuid = 'd60ac5b7-d1e0-421d-b77e-c215882f5857', name =
> 'United States of America'
> layer borders:
> feature_1: north_east_name = NULL, north_east_feature = NULL,
> south_west_name = NULL, south_west_feature = NULL
> Select those three features and take the values from countries.feature_a
> and place them into the borders.feature_1.north_east_{name|feature}
> attributes. Then do the same with feature_b's values in the south_west_*
> attributes.

Perhaps I'm missing something here but separating the geographical
relationship between two countries as either north & east or south & west
seems too... approximate.

For example if you look at the border between Washington and British
Columbia, you will see that the great majority of BC is north and/or east
of Washington; but a small chunk to the west is south and west of the north
west part of Washington.

Another example, France and Switzerland.  Another, US and México (think the
Texas panhandle).


Assuming your countries layer is formed of polygons and the polygons are
snapped together along their borders (not always a great assumption), you
can generate a list of polygon pairs that touch each other.  I'm not
exactly certain how to do this in QGIS, but it's dead simple in PostGIS
with for example the "TOUCHES" function in an SQL query

Then if you generate polygon centroids from your countries layer, you can
join them to the "touches" table.  I know you said you didn't want to do
joins, but maybe you could rethink that.

At this point you should have something more or less like this:

(Canada centroid lat-lon),(Canada attributes),(USA attributes),(USA
centroid lat-lon)
(USA centroid lat-lon),(USA attributes),(México attributes),(México
centroid lat-lon)


Having said all of this, note that it's possible that country centroids
don't end up inside the country (I bet Malaysia's centroid is in the South
China Sea).

Having that table, you can then come up with a calculate rule to assign
your north-east and south-west attribute values based on the relation of
the centroids.  Since you will have "bi directional pairs" in this table, ie

(Canada centroid lat-lon),(Canada attributes),(USA attributes),(USA
centroid lat-lon)
(USA centroid lat-lon),(USA attributes),(Canada attributes),(Canada
centroid lat-lon)

At this point you can delete all the pairs where the first country's
centroid isn't north or east of the second country's centroid.

Then you can add the
attributes north_east_name,north_east_feature,south_west_name,south_west_feature
to the remaining pairs.

Then you can set:

north_east_name = first country name
north_east_feature = first country feature
south_west_name = second country name
south_west_feature = second country feature

At this point, you'll have your table EXCEPT it won't be spatial.  I
couldn't tell if this is important or not.

Does this help?

If you need the border layer to be spatial, then you have some geometry
work to do.  You'll have to make sure that the lines are segmented into
pieces that only separate two countries.  If you have borders that are
coastlines or out in the water, you're going to have to figure out what to
do with them (since they don't - probably - touch two countries).

You could try buffering the border lines you have, then unioning those
buffers with the country polygons, then looking at the attributes in the
union to find buffer parts with a country on each side.  Of course where
borders are wind-y you could end up with some odd results and it's likely
you'll have countries showing up as both north and south of each other.  It
might be best at this point just to record that country A and country B are
adjacent within this buffer and therefore along the original segment.

Or you could try using the "TOUCHES" feature between lines and polygons in
your two layers.  I've never done that but it could be a worthwhile

The point in any of these is that the unique ID of the border segments you
have (or have created) is connected up to the countries separated.  Once
you have that, you could start up in the above directions with the part
about generating centroids.

Does this help?

[stuff deleted]

Chris Hermansen · clhermansen "at" gmail "dot" com

C'est ma façon de parler.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20210131/dae7aeff/attachment.html>

More information about the Qgis-user mailing list