Creating a polygon border from binary grid

I have an xyz geographical file file1.xyz where x is lon,y is lat and z values are 1 and 0. I turned it into a grid file1.nc using xyz2grd.

The areas where z=1 are my interest areas. I would like to extract points from file.xyz to have polygon files that contain only the points on the border of each interest area. So not all the points where values z=1 (not sites inside the interest area), only those that are on the edge of the areas. Is it possible to do that?

I would look into psmask -D for this. You would have to feed it an xyz table consisting of only the nodes with z = 1. Something like this, perhaps:

gmt grdmath file1.nc 0 NAN = tmp.nc
grd2xyz -s tmp.nc | gmt psmask -Rfile1.nc -Dpolygons.txt
1 Like

It creates a lot of small polygons, not a big one surrounding the entire area, but it works for my purpose, thank you!