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

2021-01-31 Thread chris hermansen
Cory and list;

On Sun, Jan 31, 2021 at 9:48 AM Cory Albrecht 
wrote:

> > 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
not.


>
> 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).

Aaaanyway.

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
https://postgis.net/docs/ST_Touches.html

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)

etc.

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
experiment.


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

2021-01-30 Thread chris hermansen
Cory and list

On Sat, Jan 30, 2021, 17:09 Cory Albrecht  wrote:

> Hello,
>
> I am looking for a way to select an arbitrary number features in one layer
> and then copy the values of their id fields into fields of an arbitrary
> feature in a second layer.
>
> For example, I have one layer which is the polygons for countries with the
> field *feathure_uuid*, and a second layer that has the border lines
> between the countries with two fields *north_east_feature* and
> *south_west_feature*. I'd like to be able to select the two country
> features on the opposite sides of the border line and have
> *countries.feature_uuid* for each one placed into borders.
> *north_east_feature* and border.*south_west_feature*.
>

Not completely following you here but the normal thing is to do a "join"
between two tables on a common attribute.

Sometimes it's necessary to compute that attribute first in each table.

When you right click on a layer and click on properties you'll see the
option to define joins.

Does this help?

>
> Do I have to finally bite the bullet and learn python to do this, or is
> there some combination of existing tools I can use to do it instead?
>

This kind of thing can be precomputed with Python or awk or some other
scripting language by working on the CSV version of the attribute tables
and calculating the common attribute that way. But I'd try just using the
field calculator and then table join in QGIS first.

It would help if you would post some examples with real "numbers".

>
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user


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

2021-01-30 Thread Cory Albrecht
Hello,

I am looking for a way to select an arbitrary number features in one layer
and then copy the values of their id fields into fields of an arbitrary
feature in a second layer.

For example, I have one layer which is the polygons for countries with the
field *feathure_uuid*, and a second layer that has the border lines between
the countries with two fields *north_east_feature* and *south_west_feature*.
I'd like to be able to select the two country features on the opposite
sides of the border line and have *countries.feature_uuid* for each one
placed into borders.*north_east_feature* and border.*south_west_feature*.

Do I have to finally bite the bullet and learn python to do this, or is
there some combination of existing tools I can use to do it instead?
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user