Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

gmtspatial.rst 11 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
  1. .. index:: ! gmtspatial
  2. .. include:: module_core_purpose.rst_
  3. **********
  4. gmtspatial
  5. **********
  6. |gmtspatial_purpose|
  7. Synopsis
  8. --------
  9. .. include:: common_SYN_OPTs.rst_
  10. **gmt spatial** [ *table* ] [ |-A|\ [**a**\ *min_dist*][*unit*]]
  11. [ |-C| ]
  12. [ |-D|\ [**+f**\ *file*][**+a**\ *amax*][**+d**\ *dmax*][**+c\|C**\ *cmax*][**+s**\ *fact*] ]
  13. [ |-E|\ **+p**\|\ **n** ]
  14. [ |-F|\ [**l**] ]
  15. [ |-I|\ [**e**\|\ **i**] ]
  16. [ |-N|\ *pfile*\ [**+a**][**+p**\ *start*][**+r**][**+z**] ]
  17. [ |-Q|\ [*unit*][**+c**\ *min*\ [/*max*]][**+h**][**+l**][**+p**][**+s**\ [**a**\|\ **d**]] ]
  18. [ |SYN_OPT-R| ]
  19. [ |-S|\ **b**\ *width*\|\ **h**\|\ **i**\|\ **u**\|\ **s**\|\ **j** ]
  20. [ |-T|\ [*clippolygon*] ]
  21. [ |SYN_OPT-V| ]
  22. [ |SYN_OPT-b| ]
  23. [ |SYN_OPT-d| ]
  24. [ |SYN_OPT-e| ]
  25. [ |SYN_OPT-f| ]
  26. [ |SYN_OPT-g| ]
  27. [ |SYN_OPT-h| ]
  28. [ |SYN_OPT-i| ]
  29. [ |SYN_OPT-j| ]
  30. [ |SYN_OPT-o| ]
  31. [ |SYN_OPT-q| ]
  32. [ |SYN_OPT-:| ]
  33. [ |SYN_OPT--| ]
  34. |No-spaces|
  35. Description
  36. -----------
  37. **spatial** reads one or more data files (which may be multisegment
  38. files) that contains closed polygons and operates of these polygons in
  39. the specified way. Operations include area calculation, handedness
  40. reversals, and polygon intersections.
  41. Required Arguments
  42. ------------------
  43. None.
  44. Optional Arguments
  45. ------------------
  46. .. |Add_intables| unicode:: 0x20 .. just an invisible code
  47. .. include:: explain_intables.rst_
  48. .. _-A:
  49. **-A**\ [**a**\ *min_dist*][*unit*]
  50. Perform spatial nearest neighbor (NN) analysis: Determine the nearest
  51. neighbor of each point and report the NN distances and the point IDs
  52. involved in each pair (IDs are the input record numbers starting at 0).
  53. Use **-Aa** to decimate a data set so that no NN distance is lower than
  54. the threshold *min_dist*. In this case we write out the (possibly
  55. averaged) coordinates and the updated NN distances and point IDs. A
  56. negative point number means the original point was replaced by a weighted
  57. average (the absolute ID value gives the ID of the first original point
  58. ID to be included in the average.). **Note**: The input data are assumed to
  59. contain (*lon, lat*) or (*x, y*), optionally followed by a *z* and a *weight* [1] column.
  60. We compute a weighted average of the location and *z* (if present).
  61. .. _-C:
  62. **-C**
  63. Clips polygons to the map region, including map boundary to the
  64. polygon as needed. The result is a closed polygon (see **-T** for
  65. truncation instead). Requires **-R**.
  66. .. _-D:
  67. **-D**\ [**+f**\ *file*][**+a**\ *amax*][**+d**\ *dmax*][**+c\|C**\ *cmax*][**+s**\ *fact*]
  68. Check for duplicates among the input lines or polygons, or, if
  69. *file* is given via **+f**, check if the input features already
  70. exist among the features in *file*. We consider the cases of exact
  71. (same number and coordinates) and approximate matches (average
  72. distance between nearest points of two features is less than a
  73. threshold). We also consider that some features may have been
  74. reversed. Features are considered approximate matches if their
  75. minimum distance is less than *dmax* [0] (see `Units`_) and their
  76. closeness (defined as the ratio between the average distance between
  77. the features divided by their average length) is less than *cmax*
  78. [0.01]. For each duplicate found, the output record begins with the
  79. single letter Y (exact match) or ~ (approximate match). If the two
  80. matching segments differ in length by more than a factor of 2 then
  81. we consider the duplicate to be either a subset (-) or a superset
  82. (+). Finally, we also note if two lines are the result of splitting
  83. a continuous line across the Dateline (|).
  84. For polygons we also consider the fractional difference in
  85. areas; duplicates must differ by less than *amax* [0.01]. By
  86. default, we compute the mean line separation. Use **+C**\ *cmin* to
  87. instead compute the median line separation and therefore a robust
  88. closeness value. Also by default we consider all distances between
  89. points on one line and another. Append **+p** to limit the
  90. comparison to points that project perpendicularly to points on the
  91. other line (and not its extension).
  92. .. _-E:
  93. **-E**\ **+p**\|\ **n**
  94. Reset the handedness of all polygons to match the given **+p**
  95. (counter-clockwise; positive) or **+n** (clockwise; negative). Implies **-Q+**.
  96. .. _-F:
  97. **-F**\ [**l**]
  98. Force input data to become polygons on output, i.e., close them explicitly if not
  99. already closed. Optionally, append **l** to force line geometry.
  100. .. _-I:
  101. **-I**\ [**e**\|\ **i**]
  102. Determine the intersection locations between all pairs of polygons.
  103. Append **i** to only compute internal (i.e., self-intersecting
  104. polygons) crossovers or **e** to only compute external (i.e.,
  105. between pairs of polygons) crossovers [Default is both].
  106. .. _-N:
  107. **-N**\ *pfile*\ [**+a**][**+p**\ *start*][**+r**][**+z**]
  108. Determine if one (or all, with **+a**) points of each feature in the
  109. input data are inside any of the polygons given in the *pfile*. If
  110. inside, then report which polygon it is; the polygon ID is either
  111. taken from the aspatial value assigned to Z, the segment header
  112. (first **-Z**, then **-L** are scanned), or it is assigned the
  113. running number that is initialized to *start* [0]. By default the
  114. input segment that are found to be inside a polygon are written to
  115. stdout with the polygon ID encoded in the segment header as
  116. **-Z**\ *ID*. Alternatively, append **+r** to just report which
  117. polygon contains a feature or **+z** to have the IDs added as an
  118. extra data column on output. Segments that fail to be inside a
  119. polygon are not written out. If more than one polygon contains the
  120. same segment we skip the second (and further) scenario.
  121. .. _-Q:
  122. **-Q**\ [*unit*][**+c**\ *min*\ [/*max*]][**+h**][**+l**][**+p**][**+s**\ [**a**\|\ **d**]]
  123. Measure the area of all polygons or length of line segments. Use
  124. **-Q+h** to append the area to each polygons segment header [Default
  125. simply writes the area to stdout]. For polygons we also compute the
  126. centroid location while for line data we compute the mid-point
  127. (half-length) position. Append a distance unit to select the unit
  128. used (see `Units`_). Note that the area will depend on the current
  129. setting of :term:`PROJ_ELLIPSOID`; this should be a
  130. recent ellipsoid to get accurate results. The centroid is computed
  131. using the mean of the 3-D Cartesian vectors making up the polygon
  132. vertices, while the area is obtained via an equal-area projection.
  133. Normally, all input segments
  134. will be be reflected on output. Use **+c** to restrict processing to
  135. those whose length (or area for polygons) fall inside the specified
  136. range set by *min* and *max*. If *max* is not set it defaults to infinity.
  137. To sort the segments based on their lengths or area, use **+s** and
  138. append **a** for ascending and **d** for descending order [ascending].
  139. By default, we consider open polygons as lines.
  140. Append **+p** to close open polygons and thus consider all input
  141. as polygons, or append **+l** to consider all input as lines, even
  142. if closed.
  143. .. _-R:
  144. .. |Add_-Rgeo| replace:: Clips polygons to the map
  145. region, including map boundary to the polygon as needed. The result
  146. is a closed polygon.
  147. .. include:: explain_-Rgeo.rst_
  148. .. _-S:
  149. **-S**\ **b**\ *width*\|\ **h**\|\ **i**\|\ **j**\|\ **s**\|\ **u**
  150. Spatial processing of polygons. Choose from **-Sb**\ *width* which computes a buffer polygon around lines,
  151. **-Sh** which identifies perimeter and hole polygons (and flags/reverses them), **-Si** which returns
  152. the intersection of polygons (closed), **-Su** which returns the
  153. union of polygons (closed), **-Ss** which will split polygons that
  154. straddle the Dateline, and **-Sj** which will join polygons that
  155. were split by the Dateline. **Note**: Only **-Sb**, **-Sh** and **-Ss** have been implemented.
  156. .. _-T:
  157. **-T**\ [*clippolygon*]
  158. Truncate polygons against the specified polygon given, possibly
  159. resulting in open polygons. If no argument is given to **-T** we
  160. create a clipping polygon from **-R** which then is required. Note
  161. that when the **-R** clipping is in effect we will also look for
  162. polygons of length 4 or 5 that exactly match the **-R** clipping polygon.
  163. .. _-V:
  164. .. |Add_-V| unicode:: 0x20 .. just an invisible code
  165. .. include:: explain_-V.rst_
  166. .. |Add_-bi| replace:: [Default is 2 input columns].
  167. .. include:: explain_-bi.rst_
  168. .. |Add_-bo| replace:: [Default is same as input].
  169. .. include:: explain_-bo.rst_
  170. .. |Add_-d| unicode:: 0x20 .. just an invisible code
  171. .. include:: explain_-d.rst_
  172. .. |Add_-e| unicode:: 0x20 .. just an invisible code
  173. .. include:: explain_-e.rst_
  174. .. |Add_-f| unicode:: 0x20 .. just an invisible code
  175. .. include:: explain_-f.rst_
  176. .. |Add_-g| unicode:: 0x20 .. just an invisible code
  177. .. include:: explain_-g.rst_
  178. .. |Add_-h| unicode:: 0x20 .. just an invisible code
  179. .. include:: explain_-h.rst_
  180. .. include:: explain_-icols.rst_
  181. .. include:: explain_distcalc.rst_
  182. .. include:: explain_-ocols.rst_
  183. .. include:: explain_-q.rst_
  184. .. include:: explain_colon.rst_
  185. .. include:: explain_help.rst_
  186. .. include:: explain_distunits.rst_
  187. .. include:: explain_inside.rst_
  188. .. include:: explain_precision.rst_
  189. Examples
  190. --------
  191. To determine the centroid of the remote GSHHH high-resolution polygon for Australia,
  192. as well as the land area in km squared, try::
  193. gmt spatial @GSHHS_h_Australia.txt -fg -Qk
  194. To turn all lines in the multisegment file lines.txt into closed polygons,
  195. run
  196. ::
  197. gmt spatial lines.txt -F > polygons.txt
  198. To compute the area of all geographic polygons in the multisegment file
  199. polygons.txt, run
  200. ::
  201. gmt spatial polygons.txt -Q > areas.txt
  202. Same data, but now orient all polygons to go counter-clockwise and write
  203. their areas to the segment headers, run
  204. ::
  205. gmt spatial polygons.txt -Q+h -E+p > areas.txt
  206. To determine the areas of all the polygon segments in the file janmayen_land_full.txt,
  207. add this information to the segment headers, sort the segments from largest
  208. to smallest in area but only keep polygons with area larger than 1000 sq. meters, run
  209. ::
  210. gmt spatial -Qe+h+p+c1000+sd -V janmayen_land_full.txt > largest_pols.txt
  211. To determine the intersections between the polygons A.txt and B.txt, run
  212. ::
  213. gmt spatial A.txt B.txt -Ie > crossovers.txt
  214. To truncate polygons A.txt against polygon B.txt, resulting in an open line segment, run
  215. ::
  216. gmt spatial A.txt -TB.txt > line.txt
  217. Notes
  218. -----
  219. OGR/GMT files are considered complete datasets and thus you cannot specify more than one
  220. at a given time. This causes problems if you want to examine the intersections of
  221. two OGR/GMT files. The solution is to convert them to regular datasets via
  222. :doc:`gmtconvert` and then run **gmt spatial** on the converted files.
  223. See Also
  224. --------
  225. :doc:`gmt`,
  226. :doc:`gmtconvert`,
  227. :doc:`gmtselect`,
  228. :doc:`gmtsimplify`
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...