Gmtspatial issue

I’ve resurrected some old (GMT ver5) code that simply tested if a point (or points) was inside a polygon (poly.txt). The point gets written to a file (test.txt) and then:
gmtspatial <test.txt -Npoly.text+z
This produces zero output.

If I try:
gmtspatial <test.txt -Npoly.text+r
The response is:
Middle point from table 0 segment 0 is inside polygon # 999
even though there are six test points in the file (five of which are in the polygon).

What does it mean by “middle point”?
How can I get it to simply output the point plus the Z value?
The code worked previously but something has changed somewhere.


GMT 5 is deprecated - see GMT 6.4.0 as latest release. In the documentation for gmt select there is no +r or +z modifier to -N. Even GMT4 does not have that. In 6 I only find

Option -N...o is deprecated; use -E instead

but that is not your case.

Sorry Paul. I headed the post “gmtspatial” and then proceeded to type “gmtselect”.
I meant the former.

Can you post a MWE (reproducible example)?

Hi Joaquim.
Made up two files. One (test_poly.txt) a simple rectangular polygon and one (test_points.txt) a line of points crossing boundary of polygon.

> -Z999
140 10
140 20
150 20
150 10

138 15
139 15
140 15
141 15
142 15
143 15

gmtspatial <test_points.txt -Ntest_poly.txt+z
? (no response)

gmtspatial <test_points.txt -Ntest_poly.txt+r
gmtspatial: Processing input table data
Middle point from table 0 segment 0 is inside polygon # 999
gmtspatial: 1 segments found to be inside polygons, 0 were outside and skipped

I have since separated each point in “test_points.txt” with “>”. I get the same message (as above) for each point that is within the polygon, but still cannot get the -N+z option to produce any output.

It replies to me

C:\v>gmtspatial <test_points.txt -Ntest_poly.txt+z
138     15      999
139     15      999
140     15      999
141     15      999
142     15      999
143     15      999
138     15      999

but please don´t tell us that you are using GMT5

OK, I won’t tell you :slight_smile:

In the example, shouldn’t the 138/15 and 139/15 points be ignored (as outside)?

It used to work, but not anymore. Not sure why. I’ll klutz a workaround.

Thanks for your help.

I didn’t pay attention to the numbers (only if the replied). But indeed, on a quick check with the manual something does not look right.
For in-out tests like these I use gmtselect, and the result is different.

C:\v>gmtselect test_points.txt -Ftest_poly.txt
140     15
141     15
142     15
143     15

Thanks Joaquim,
Yeah, that worked for me as well, but I need to know which polygon the point is in so I can get a -Z value.

Does seem to have a bug. Will try to fix.

Fixed in master; see GitHub.

Are you following
Some more testing would be good.

Hi Joaquim,
Sorry for delay. Only work part-time so intermittent with web access.
Also, not computer literate enough to be able to compile and implement new code. Using windows executables.

You can try with this build that I just made

1 Like