1## Copyright (C) 1998, 1999, 2000 Joao Cardoso.
2##
3## This program is free software; you can redistribute it and/or modify it
4## under the terms of the GNU General Public License as published by the
5## Free Software Foundation; either version 2 of the License, or (at your
6## option) any later version.
7##
8## This program is distributed in the hope that it will be useful, but
9## WITHOUT ANY WARRANTY; without even the implied warranty of
10## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11## General Public License for more details.
12##
13## This file is part of plplot_octave.
14## It is based on the corresponding demo function of PLplot.
15
161;
17
18## Shows two views of the world map.
19
20function ix19c
21  ## Parse and process command line arguments
22
23  ## (void) plparseopts( &argc, argv, PL_PARSE_FULL );
24
25  ## Longitude (x) and latitude (y)
26
27  miny = -70;
28  maxy = 80;
29
30  plinit();
31
32  ## Cartesian plots
33  ## Most of world
34
35  minx = -170;
36  maxx = minx + 360;
37
38  ## Setup a custom latitude and longitude-based scaling function.
39  plslabelfunc( @geolocation_labeler, [] );
40
41  plcol0( 1 );
42  plenv( minx, maxx, miny, maxy, 1, 70 );
43  plmap( [], "usaglobe", minx, maxx, miny, maxy );
44
45  ## The Americas
46
47  minx = 190;
48  maxx = 340;
49
50  plcol0( 1 );
51  plenv( minx, maxx, miny, maxy, 1, 70 );
52  plmap( [], "usaglobe", minx, maxx, miny, maxy );
53
54  ## Clear the labeling function
55  plslabelfunc( [], [] );
56
57  ## Polar, Northern hemisphere
58
59  minx = 0;
60  maxx = 360;
61
62  plenv( -75., 75., -75., 75., 1, -1 );
63  plmap( @mapform19, "globe", minx, maxx, miny, maxy );
64
65  pllsty( 2 );
66  plmeridians( @mapform19, 10.0, 10.0, 0.0, 360.0, -10.0, 80.0 );
67
68  ## Polar, Northern hemisphere, this time with a PLplot-wide transform
69
70  minx = 0;
71  maxx = 360;
72
73  plstransform( @map_transform, [] );
74
75  pllsty( 1 );
76  plenv( -75., 75., -75., 75., 1, -1 );
77  ## No need to set the map transform here as the global transform will be
78  ## used.
79  plmap( [], "globe", minx, maxx, miny, maxy );
80
81  pllsty( 2 );
82  plmeridians( [], 10.0, 10.0, 0.0, 360.0, -10.0, 80.0 );
83
84  ## Show Baltimore, MD on the map
85  plcol0( 2 );
86  plssym( 0.0, 2.0 );
87  x = -76.6125;
88  y = 39.2902778;
89  plpoin( x, y, 18 );
90  plssym( 0.0, 1.0 );
91  plptex( -76.6125, 43.0, 0.0, 0.0, 0.0, "Baltimore, MD" );
92
93  ## For C, this is how the global transform is cleared
94  plstransform( [], [] );
95
96  ## An example using shapefiles. The shapefiles used are from Ordnance Survey, UK.
97  ## These were chosen because they provide shapefiles for small grid boxes which
98  ## are easilly manageable for this demo.
99
100  pllsty( 1 );
101
102  minx = 240570;
103  maxx = 621109;
104  miny = 87822;
105  maxy = 722770;
106  plscol0( 0, 255, 255, 255 );
107  plscol0( 1, 0, 0, 0 );
108  plscol0( 2, 150, 150, 150 );
109  plscol0( 3, 0, 50, 200 );
110  plscol0( 4, 50, 50, 50 );
111  plscol0( 5, 150, 0, 0 );
112  plscol0( 6, 100, 100, 255 );
113
114  minx = 265000;
115  maxx = 270000;
116  miny = 145000;
117  maxy = 150000;
118  plscol0( 0, 255, 255, 255 ); ##white
119  plscol0( 1, 0, 0, 0 );       ##black
120  plscol0( 2, 255, 200, 0 );   ##yelow for sand
121  plscol0( 3, 60, 230, 60 );   ## green for woodland
122  plscol0( 4, 210, 120, 60 );  ##brown for contours
123  plscol0( 5, 150, 0, 0 );     ##red for major roads
124  plscol0( 6, 180, 180, 255 ); ##pale blue for water
125  plscol0( 7, 100, 100, 100 ); ##pale grey for shingle or boulders
126  plscol0( 8, 100, 100, 100 ); ##dark grey for custom polygons - generally crags
127
128  plcol0( 1 );
129  plenv( minx, maxx, miny, maxy, 1, -1 );
130  pllab( "", "", "Martinhoe CP, Exmoor National Park, UK (shapelib only)" );
131
132  ##Beach
133  plcol0( 2 );
134  beachareas = [ 23, 24 ]';
135  plmapfill( [], "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, beachareas );
136
137  ##woodland
138  plcol0( 3 );
139  nwoodlandareas = 94;
140  woodlandareas = (0:nwoodlandareas-1)' + 218;
141  plmapfill( [], "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, woodlandareas );
142
143  ##shingle or boulders
144  plcol0( 7 );
145  shingleareas = [ 0, 1, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 217, 2424, 2425, 2426, 2427, 2428, 2491, 2577 ]';
146  plmapfill( [], "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, shingleareas );
147
148  ##crags
149  plcol0( 8 );
150  ncragareas = 2024;
151  cragareas = (0:ncragareas-1)' + 325;
152  plmapfill( [], "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, cragareas );
153
154  ##draw contours, we need to separate contours from high/low coastline
155  ##draw_contours(pls, "ss/SS64_line", 433, 20, 4, 3, minx, maxx, miny, maxy );
156  plcol0( 4 );
157  plmapline( [], "ss/ss64ne_Height_Contours", minx, maxx, miny, maxy, [] );
158
159  ##draw the sea and surface water
160  plwidth( 0.0 );
161  plcol0( 6 );
162  plmapfill( [], "ss/ss64ne_Water_Area", minx, maxx, miny, maxy, [] );
163  plwidth( 2.0 );
164  plmapline( [], "ss/ss64ne_Water_Line", minx, maxx, miny, maxy, [] );
165
166  ##draw the roads, first with black and then thinner with colour to give an
167  ##an outlined appearance
168  plwidth( 5.0 );
169  plcol0( 1 );
170  plmapline( [], "ss/ss64ne_Road_Centreline", minx, maxx, miny, maxy, [] );
171  plwidth( 3.0 );
172  plcol0( 0 );
173  plmapline( [], "ss/ss64ne_Road_Centreline", minx, maxx, miny, maxy, [] );
174  plcol0( 5 );
175  majorroads = [ 33, 48, 71, 83, 89, 90, 101, 102, 111 ]';
176  plmapline( [], "ss/ss64ne_Road_Centreline", minx, maxx, miny, maxy, majorroads );
177
178  ##draw buildings
179  plwidth( 1.0 );
180  plcol0( 1 );
181  plmapfill( [], "ss/ss64ne_Building_Area", minx, maxx, miny, maxy, [] );
182
183  ##labels
184  plsfci( 0x80000100 );
185  plschr( 0, 0.8 );
186  plmaptex( [], "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "MARTINHOE CP", minx, maxx, miny, maxy, 202 );
187  plschr( 0, 0.7 );
188  plmaptex( [], "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Heale\nDown", minx, maxx, miny, maxy, 13 );
189  plmaptex( [], "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "South\nDown", minx, maxx, miny, maxy, 34 );
190  plmaptex( [], "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Martinhoe\nCommon", minx, maxx, miny, maxy, 42 );
191  plmaptex( [], "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Woody Bay", minx, maxx, miny, maxy, 211 );
192  plschr( 0, 0.6 );
193  plmaptex( [], "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Mill Wood", minx, maxx, miny, maxy, 16 );
194  plmaptex( [], "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Heale Wood", minx, maxx, miny, maxy, 17 );
195  plmaptex( [], "ss/ss64ne_General_Text", 1.0, 0.0, 1.0, "Bodley", minx, maxx, miny, maxy, 31 );
196  plmaptex( [], "ss/ss64ne_General_Text", 1.0, 0.0, 0.0, "Martinhoe", minx, maxx, miny, maxy, 37 );
197  plmaptex( [], "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Woolhanger\nCommon", minx, maxx, miny, maxy, 60 );
198  plmaptex( [], "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "West Ilkerton\nCommon", minx, maxx, miny, maxy, 61 );
199  plmaptex( [], "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Caffyns\nHeanton\nDown", minx, maxx, miny, maxy, 62 );
200
201  plend1();
202endfunction
203
204function [xt, yt] = map_transform( x, y, data )
205    radius = 90.0 - y;
206    xt    = radius .* cos( x * pi / 180.0 );
207    yt    = radius .* sin( x * pi / 180.0 );
208endfunction
209
210##--------------------------------------------------------------------------
211## mapform19
212##
213## Defines specific coordinate transformation for example 19.
214## Not to be confused with mapform in src/plmap.c.
215## x[], y[] are the coordinates to be plotted.
216##--------------------------------------------------------------------------
217
218function [xp, yp] = mapform19( x, y )
219  [xp, yp] = map_transform( x, y, [] );
220endfunction
221
222## "Normalize" longitude values so that they always fall between -180.0 and
223## 180.0
224function norm = normalize_longitude( lon )
225  if ( lon >= -180.0 && lon <= 180.0 )
226    norm = lon;
227  else
228    times = floor( ( abs( lon ) + 180.0 ) / 360.0 );
229    if ( lon < 0.0 )
230      norm = lon + 360.0 * times;
231    else
232      norm = lon - 360.0 * times;
233    endif
234  endif
235endfunction
236
237## A custom axis labeling function for longitudes and latitudes.
238function label = geolocation_labeler( axis, value, data )
239
240  global PL_X_AXIS PL_Y_AXIS
241  if ( axis == PL_Y_AXIS )
242    label_val = value;
243    if ( label_val > 0.0 )
244      direction_label = " N";
245    elseif ( label_val < 0.0 )
246      direction_label = " S";
247    else
248      direction_label = "Eq";
249    endif
250  elseif ( axis == PL_X_AXIS )
251    label_val = normalize_longitude( value );
252    if ( label_val > 0.0 )
253      direction_label = " E";
254    elseif ( label_val < 0.0 )
255      direction_label = " W";
256    else
257      direction_label = "";
258    endif
259  endif
260  if ( axis == PL_Y_AXIS && value == 0.0 )
261    ## A special case for the equator
262    label = sprintf( "%s", direction_label );
263  else
264    label = sprintf( "%.0f%s", abs( label_val ), direction_label );
265  endif
266endfunction
267
268ix19c
269