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

ex51.sh 2.8 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
  1. #!/usr/bin/env bash
  2. # GMT EXAMPLE 51
  3. #
  4. # Purpose: Illustrate usage of OpenStreetMap coastlines in GMT
  5. # GMT modules: convert, select, coast, plot
  6. # GDAL progs: ogr2ogr
  7. # First we convert the shapefile to something more GMT friendly. Here we make it
  8. # into a large ASCII file. Human-readable but not very efficient. GDAL's ogr2ogr
  9. # is used with the "-f OGR_GMT" option indicating that the output should have
  10. # the native GMT format. Input is the downloaded land_polygons.shp, and the
  11. # output is named land_polygons_osm_planet.gmt. The resulting file is very
  12. # large (>1 GB) but already usable. But wait, there is more ...
  13. ogr2ogr -f OGR_GMT land_polygons_osm_planet.gmt land_polygons.shp
  14. # Resorting to GMT's convert program we take our very large ASCII file and
  15. # reduce it to about a third of its original size by converting it to a binary
  16. # file. Lets have a closer look at -bo2f:
  17. # -bo selects native binary output
  18. # 2 makes it two data columns
  19. # f indicates 4-byte single-precision for the data
  20. gmt convert land_polygons_osm_planet.gmt -bo2f > land_polygons_osm_planet.bf2
  21. # Now the heavylifting is done and we have a reusable global coastline file
  22. # with higher precision than the GSHHG coastlines.
  23. # Again, we could use the file as is, but there are more performance gains to
  24. # collect. We extract just the area we need for our plot. Here the island of
  25. # Sao Vicente, Cape Verde. select to the rescue! -bo2f is nothing new and -bi2f
  26. # looks very similar: the -bi is indicating native binary input. -R...+r gives
  27. # the area which we are interested in.
  28. gmt select land_polygons_osm_planet.bf2 -bi2f -bo2f -R-25.14/16.75/-24.8/16.95+r > land_polygons_osm_caboverde.bf2
  29. # Finally it is time to do the thing we are here for: Plot some OSM coastlines
  30. # and compare them to the GSHHG coastlines.
  31. gmt begin ex51
  32. # To make the lines a bit nicer we set the line endcaps and the way lines are
  33. # joined to round
  34. gmt set PS_LINE_CAP round
  35. gmt set PS_LINE_JOIN round
  36. # To get an idea where the GSHHG coastlines are we lay them down first with a
  37. # thin red pen. -JL defines a Lambert conic conformal projection and -R...+r
  38. # is the area of the plot. -W defines the pen and -B the style of the plot
  39. # borders, gridlines and annotations.
  40. gmt coast -JL-24.9/16.55/16.3/16.7/15c -R-25.14/16.75/-24.8/16.95+r -Wred -Ba10mg10m
  41. # Time to use the OSM coastlines we prepared earlier. Straightforward we
  42. # supply the extracted area, tell plot about the binary format (-bi), define
  43. # pen (-W) and fill (-G)
  44. gmt plot land_polygons_osm_caboverde.bf2 -bi2f -Wthinnest,black -Ggrey
  45. # Here we plot the GSHHG coastlines a second time but now with a dashed pen
  46. # to highlight the areas where they would otherwise be hidden behind the grey
  47. # OSM landmass.
  48. gmt coast -Wred,dashed
  49. gmt end show
Tip!

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

Comments

Loading...