Skip to content

Augment gmtspatial with -N+i#7747

Merged
PaulWessel merged 3 commits intomasterfrom
spatial-individual
Aug 21, 2023
Merged

Augment gmtspatial with -N+i#7747
PaulWessel merged 3 commits intomasterfrom
spatial-individual

Conversation

@PaulWessel
Copy link
Member

The -N+i setting will treat each input point individually and determine which polygon it falls into (if any). If a polygon ID is found then we write that point's full record out and add a final column with the ID.

Test example with some fake points and polygons::

cat << EOF > cloud.txt
138 15
139 15
140 15
141 15
142 15
143 15
138 12
139 12
141 18
142 18
150 20
EOF
cat << EOF > pols.txt
> -Z999
140 10
140 20
150 20
150 10
140 10
> -Z888
130 10
130 20
140 20
140 10
130 10
EOF

Then running the command:

gmt spatial test_points.txt -Npols.txt+i
141	15	999
142	15	999
143	15	999
141	18	999
142	18	999
138	15	888
139	15	888
138	15	888
138	12	888
139	12	888

So 5 points each in polygon IDs 888 and 999, plus one point outside all and hence skipped.
Note: I have labelled it WIP and would appreciate some more testing before we approve/merge.

The -N+i setting will treat each input point individually and determine which polygon it falls into (if any).  If a polygon ID is found then we write that point's full record out and add a final column with the ID.
@PaulWessel PaulWessel added maintenance Boring but important stuff for the core devs new core module feature PR that implements a new core module feature labels Aug 20, 2023
@PaulWessel PaulWessel added this to the 6.5.0 milestone Aug 20, 2023
@PaulWessel PaulWessel self-assigned this Aug 20, 2023
Copy link
Member

@joa-quim joa-quim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gave the same result as my (very) simple test for the GMT.jl inwhichpolygon() function.

@PaulWessel PaulWessel changed the title WIP Augment gmtspatial with -N+i Augment gmtspatial with -N+i Aug 21, 2023
@PaulWessel PaulWessel merged commit 501cd66 into master Aug 21, 2023
@PaulWessel PaulWessel deleted the spatial-individual branch August 21, 2023 12:02
@joa-quim
Copy link
Member

Wait, BUG. If headers have no -Z or -L

gmt spatial cloud.txt -Npols.txt+i
gmtspatial [ERROR]: No polygon ID found; ID set to NaN
141     15      -1
142     15      -1
143     15      -1
141     18      -1
142     18      -1
gmtspatial [ERROR]: No polygon ID found; ID set to NaN
138     15      -1
139     15      -1
138     12      -1
139     12      -1
138     15      -1

And I would really love to have a way to get ID's start counting at 1, not 0.

@PaulWessel
Copy link
Member Author

Well, see +p which we then need to allow

@PaulWessel
Copy link
Member Author

On bus so hard to check

@joa-quim
Copy link
Member

Yes, +p can be the solution.

@maxrjones maxrjones added the add-changelog Add PR to the changelog label Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add-changelog Add PR to the changelog maintenance Boring but important stuff for the core devs new core module feature PR that implements a new core module feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants