Fisheries and Oceans Canada / Pêches et Océans Canada - Government of Canada / Gouvernement du Canada Fisheries and Oceans Canada / Pêches et Océans Canada - Government of Canada / Gouvernement du Canada
 
Français Contact Us Help Search Canada Site
Home What's New DFO National Site Map Media

Fisheries & Oceans
 
 
Maritimes Region
Fishing Industry
General Public
Marine & Oceans Industry
Media
Students and Teachers
Scientists and Researchers
 
AconIcon ACON       Home/Topics   |   Commands

Contouring


The contouring commands include: Blanking Distance, Blanking Points, Contour Lines, Contour Method, Data Border, Data Contour Levels, Data Contour Ramp, Data Interpolation, Data Subtriangles, Delaunay Triangles, List Contour Polygons, Greyscale Legend, Ramp Legend, Shade Contours, Voronoi Polygons Potential Map, and C_Squares.

Note: A word about continuous and discrete variables. Plotting continuous surface contours when the x and y axes represent discrete variables such as product number vs market category, will result in an inappropriate graphic. Use other graphic techniques for discrete variables.


Blanking Distance

This command is used to specify the distance limit between data points at which delaunay triangles will be removed. If a delaunay triangle has one or more sides whose length exceed this value, then the triangle will not be contoured.

Delaunay triangles are normally formed between all possible user data coordinates. This is inappropriate when data points are distant and topologically separated by barriers (such as the Nova Scotian land mass when plotting data from the Bay of Fundy and Scotian Shelf). The blanking command is used to remove data triangles which are inappropriate in the user´s contouring.


There is 1 parameter:
distance - the blanking distance in user units. 0 = no removal

Blanking_Distance(distance);

Blanking_Distance(0.5);

initial program state - no blanking distance


Blanking Points

This command is used to specify the name of a file from which the blanking data is to be read. The file is read, containing the x,y coordinates in user coordinate space (free format). During plotting, the blanking coordinates are used to "remove" any delaunay triangles which contain one or more of these blanking coordinates.

Delaunay triangles are normally formed between all possible user data coordinates. This is inappropriate when data points are distant and topologically separated by barriers (such as the Nova Scotian land mass when plotting data from the Bay of Fundy and Scotian Shelf). The blanking command is used to remove data triangles which are inappropriate.

If one or more blanking coordinates in the blanking file are found to lie inside a given delaunay triangle, the triangle will be excluded from subsequent contouring.

The LOCATOR command may be used to point to any area inside your current viewport on the graph window. The coordinates of the point will be listed on the Editor 2 window. By pointing to all triangles which should not be used for contouring, a list of blanking points will be created. This list may be edited and saved as a disc file to be use as the blanking file.

There is 1 parameter:
file name - the name of the blanking point data file to read.
Blanking_Points("file name");

Blanking_Points("Blanking point file name");

initial program state - no blanking points are defined


Contour Lines

This command draws the contour surface on the output device as contour lines without shading. The contour levels must be specified before this command is activated. The number of subtriangles specified will greatly affect the smoothness and execution time of this command. The contour lines are drawn using the current line characteristics, while the Line_Type() varies from 0 through maximum # of line types. Optionally, in lieu of varying line type, a single line type may be used, of varying colour (or greyscale) to differentiate between the lines.

Parameters:
xyz matrix - a matrix containing the x, y, and z data as 3 columns.
or
x, y, and z vectors- 3 vectors containing the data to be plotted.
use colour flag - an optional parameter to indicate that lines should be all of the same line type, coloured according to the colour or greyscale levels defined in the current Data_Contour_Levels() command.

Contour_Lines(xyz matrix);
Contour_Lines(x vector, y vector, z vector);

Contour_Lines(mat);
Contour_Lines(x, y, zv);
Contour_Lines(x,y,zv,1); /* use coloured lines */

See the example Isoline Contouring

affected by Data_Window(), Data_Viewport(), Data_Projection(), Contour_Method() Data_Subtriangles(), Data_Contour_Levels(), Data_Contour_Ramp(), Data_Interpolation(), Blanking Points() Blanking Distance(), Line_Width().


Contour Method

This command allows the user to specify the contouring method to be used when contouring the data. The current methods available are Triangular and Triangular Path.

Triangular - each subtriangle of each delaunay triangle is plotted separately (if the entire delaunay triangle is represented by a single contour level, it is not subdivided).

Note that as the number of subtriangles increases, the smoothness of the contour lines increases correspondingly. Note also however, that the execution time also increases proportionately, and the degree of extrapolation from your original data points.

Triangular Path - The contour surfaces from each subtriangle (as above) are joined into continuous paths. Bezier curves will be used to draw the path (if the Bezier_Curve_Control() parameter in effect is non-zero). The storage requirements for the resultant graphics is smaller than that required for the triangular data.

NOTE: The computing time and memory resources required for initially generating the Triangular Path method is considerably larger than the Triangular Method. It may not be possible to generate this output, depending on the hardware resources of the machine being used.

The Triangular Path method is buggy in this version.

There is 1 parameter:
method index - the contouring method; 0 = Triangular, 1 = Triangular Path

Contour_Method(method index);

Contour_Method(0);

initial program state - Triangular


Data Border

This command draws the extreme borders of the delaunay triangles on the output device. This displays the limit of the contoured surface (and perhaps, by extension, the limits of your sampling area).

Delaunay triangles are normally formed between all possible user data coordinates (the blanking commands may be used to remove data triangles which are inappropriate in the user´s contouring). The border drawing will include a border around any interior triangles which may have been removed by blanking, and exclude exterior triangles which have been removed by blanking.


Parameters:
xyz matrix - a matrix containing the x, y, and z data as 3 columns.
or
x, y, and z vectors- 3 vectors containing the data to be plotted.

Data_Border(xyz matrix);
Data_Border(x vector, y vector, z vector);

Data_Border(mat);
Data_Border(x,y,zvals);

See the example Shaded Contours


Data Contour Levels

This command is used to specify the contoured data (z axis) levels and corresponding grey scale levels, or colours. The data surface will be shaded (when the Shade_Contours or Plot_Shaded command is issued) with the corresponding grey level or colour where interpolated data values are greater than or equal to the contour value. These values will also be used when a Greyscale_Legend command is executed.

There are 1 or more parameter pairs:
data level - the z axis numeric value at which the corresponding grey level or colour will be used in shading a contour surface.
grey level - the grey level (0 - 1.0) to be used in shading a contour surface (where 1 is white and 0 is black)
or
colour name - the name of a previously defined colour [see RGB_Colour () or CMYK_Colour()] to be used in shading a contour surface.

Data_Contour_Levels(data level, grey level,[...data level, grey level...]);

Data_Contour_Levels(data level, colour name,[...data level,colour name...]);

Data_Contour_Levels(10,0.8, 20,0.6, 30,0.4, 40,0.2,50,0);
Data_Contour_Levels(10,"Red",20,"Violet",30,"Green",40,"Orange");

initial program state - there are no initial contour levels

See the example Shaded Contours


Data Contour Ramp

This command is used to specify the contoured data (z axis) levels and corresponding grey scale level, or colour. The data surface will be shaded (when the Shade_Contours or Plot_Shaded command is issued) with the corresponding grey level or colour where interpolated data values are greater than or equal to the contour value. This command, as it uses vectors and matrices, is able to specify far more data levels than the Data_Contour_Levels () command. The number of levels is limited more by the practical reality of computing power to render the surface, than available memory.

There are 2 or 3 parameters:
data level - a vector containing the z axis numeric value at which the corresponding grey level or colour will be used in shading a contour surface.
the 2nd parameter is one of:
grey level - a vector containing the grey levels [0 white - 1.0 black] to be used in shading a contour surface
or
RGB colour - a n x 3 matrix containing the RGB colour values [see RGB_Colour ()] to be used in shading a contour surface.
or
CMYK colour - a n x 4 matrix containing the CMYK colour values [see CMYK_Colour ()] to be used in shading a contour surface.
the optional 3rd parameter is:
Colour Prefix- a character string containing the prefix colour name with which each colour will be named when a colour ramp is defined (the default is "ACON").

Data_Contour_Ramp(data levels, grey levels);

Data_Contour_Ramp(data levels, RGB colours[,"Colour prefix"]);
Data_Contour_Ramp(data levels, CMYK colours[,"Colour prefix"]);

Data_Contour_Ramp(1 2 3 4 5,0.2 0.4 0.6 0.8 1.0);
Data_Contour_Ramp(seq(1,10),seq(0.1,1,0.1));
Data_Contour_Ramp(seq(1,10),65535 * shape(10 3,seq(0.1,1,0.1)));
Data_Contour_Ramp(seq(1,10),shape(10 4,seq(0.1,1,0.1)),"CMYK");

An example of a colour scale which covers the spectrum reasonably well is:

Colourscale = 0.403922 1 0.403922 0 0.498039 1 0.215686 0 0.654902 1 0.215686 0 1 1;
Colourscale = cat(0,Colourscale,0.184314 0 1 0.623529 0.184314 0 1 0.466667 0.121569 0 1 0.372549);
Colourscale = cat(0,Colourscale,0.184314 0 1 0.247059 0.372549 0 1 0.184314 0.498039 0 1 0.215686);
Colourscale = cat(0,Colourscale,0.686275 0 1 0.278431 1 0 0.560784 0.184314 1 0 0.372549 0.121569 1);
Colourscale = cat(0,Colourscale,0 0.184314 0.121569 1 0 0.247059 0.247059 1 0 0.152941 0.372549 1 0);
Colourscale = cat(0,Colourscale,0.152941 0.498039 1 0 0.152941 0.623529 1 0 0.247059 1 1 0 0.0588235);
Colourscale = shape(20 4,cat(0,Colourscale,1 1 0));

GIF_output("colourscale.gif",600,300);
Data_Contour_Ramp(seq(1,20),colourscale,"CMYK");
Ramp_Legend(mm(20),mm(100),mm(20),mm(30));
Screen_Output();

the resultant image...
colourscale
See Ramp Legend.

initial program state - there are no initial contour ramp levels


Data Interpolation

This command is used to define the type of interpolation to be used when contouring the data. The 2 current interpolation types are Inverse distance weighted gradient interpolation, and Birkoff-Mansfield rational interpolation.

Inverse distance weighted gradient interpolation.

This interpolation has an interpolation parameter p which is the relative amount of weighting applied to distant data points in contributing to the computed value at any given point. A nice value to start with is 2.

A 2nd optional parameter used with this type of interpolation is the include non-shared neighbours flag. Normally, non shared neighbours are excluded from the weighted gradients when interpolating values along a shared edge between adjacent triangles.

This method is based on the interpolant given in:

Watson, D.F. and G.M. Philip. 1985. A refinement of inverse distance weighted interpolation. Geo-Processing 2: 315-327.

The gradient at any particular point is:

Gradient

where Inclined - the inclined plane that approximates the gradient

Weights - the weights

Distance1 - the distance from to

Distance4 - an arbitrary positive real number

Birkoff-Mansfield rational interpolation.

This interpolation has no parameter (which may be indicated by a 0 value).

This method is based on the Birkoff-Mansfield (1974) nine parameter rational interpolant as given in:

McCullagh, M.J. 1981. Creation of smooth contours over irregularly distributed data using local surface patches. Geographical Analysis 13: 51-63.

There are 1 or more parameters:
interpolation type - 0 = Inverse distance weighted gradient, 1 = Birkoff-Mansfield
for Inverse distance weighted gradient
p - relative amount of weighting applied to distant data points
neighbours - optional parameter to include non-shared neighbouring points in the calculation of the gradient;
0 = exclude non-shared neighbours,
1 = include non-shared neighbours

Data_Interpolation(interpolationtype,interpolation parameter,...[parameter]);

Data_Interpolation(0,2,0);

initial program state - Inverse distance weighted gradient, p = 0, neighbours = 0

See the example Shaded Contours


Data Subtriangles

This command allows the user to specify the degree of subtriangle generation within delaunay data triangles.

The number of subtriangles created is the square of the number of chords each triangle side is subdivided into.

Note that as the number of subtriangles increases, the smoothness of the contour lines increases correspondingly. Note also however, that the execution time also increases proportionately, and the degree of extrapolation from your original data points.

There is 1 parameter:
# of subtriangles - A value of 1 (or 0) will result in 1 subtriangle (actually the original delaunay triangles themselves with no interpolation) while the maximum allowable value is 625.

Data_Subtriangles(# of subtriangles);

Data_Subtriangles(4);

initial program state - 0 subtriangles, no interpolation

See the example Shaded Contours


Delaunay Triangles

This command is used to draw the delaunay triangles which are formed to permit interpolation between the data points. Delaunay triangles are the set of triangles which subdivide the data region into the set of triangles which are as equilateral as possible. The delaunay triangles are drawn on the current output device.

Parameters:
xyz matrix - a matrix containing the x, y, and z data as 3 columns.
or
x, y, and z vectors- 3 vectors containing the data to be plotted.

Delaunay_Triangles(xyz matrix);
Delaunay_Triangles(x vector, y vector, z vector);

Delaunay_Triangles(mat);
Delaunay_Triangles(x,y,z);

See the example Shaded Contours


List_Contour_Polygons

This command returns an n x 4 matrix of x, y, polygon number, and z values matching the contours that would be generated by the Shade_Contours command. This lets you do polygon matrix manipulation with the contour lines. The number of subtriangles specified will greatly affect the smoothness and execution time of this command.


Parameters:
xyz matrix - a matrix containing the x, y, and z data as 3 columns.
or
x, y, and z vectors- 3 vectors containing the data to be plotted.

polygon = List_Contour_Polygons(xyz matrix);
polygon = List_Contour_Polygons(x vector, y vector, z vector);

Function datapath(x) { return( cat(hostpath(),"test data\",x) ) };
Matrix_Read(datapath("TestData"),"data");
data = cat(1,data, -64.204741 42.058818 10 0 0);
data = cat(1,data, -64.21 42.1 22 0 0);
data = cat(1,data, -64.15 42.1 22 0 0);
data = cat(1,data, -64.204741 42.0 22 0 0);
Data_Window(-67,-62,41,44.0);
Data_Projection("MERCATOR");
Data_Viewport(mm(00),mm(100),mm(190),mm(270));
Data_Interpolation(0,1.5); // inverse distance weighted gradient interpolation
Data_Subtriangles(9); // 9 subtriangles within the delaunay triangles
Data_Contour_Levels(15,0.8,20,0.6,25,0.4,30,0.2); // grey level for each data level
Graph_Layer("Level 20");
Data_Contour_Levels(15,"RED",20,"GREEN",25,"BLUE",30,"PURPLE"); // grey level for each data level
// get the polygons representing the contours
m = List_Contour_Polygons(data[;1 2 3]); // m[n;4] = x,y,polygon number, z
Line_Colour("BLACK");
polygon_Draw(m[bindex(m[;4] == 20);1 2 3]); // Draw the 'z=20' contour line

// subtract the 'z=30' contour from the 'z=25' contour
Graph_Layer("Level 25-30");
m25_30 = polygon_intersect(m[bindex(m[;4] == 25);1 2 3], m[bindex(m[;4] == 30);1 2 3],1);
Line_Colour("YELLOW");
polygon_Draw(m25_30);

affected by Contour_Method(), Data_Subtriangles(), Data_Contour_Levels(), Data_Contour_Ramp(), Data_Interpolation(), Blanking Points() Blanking Distance().


Greyscale Legend

This command is used to draw a legend on the output device showing the correspondence between the grey levels used in shading the contours and the data z axis values they represent. This command is really a misnomer at this point, as the legend will contain colour bars if the Data_Contour_Levels() command was defined using colour names.

The legend labels are those values specified in the Data_Contour_Levels() command. The labels are rounded to show only significant digits. The size of the legend is determined by the number of contour levels, and the character height of the labels.

If the optional legend type is 1, then a 2D graph of the linearity between the grey level and the corresponding data values is plotted (see below). This style of legend is useful for highlighting the possible non-linearity between your grey values and the matching data values.

This legend command is appropriate for a small number of contour levels. For a larger number of levels (as produced by the Data_Contour_Ramp command), use Ramp_Legend() to draw a colour bar.

There are 2 or more parameters:
x position - the x axis position of the upper left hand corner of the legend in NDC´s.
y position - the y axis position of the upper left hand corner of the legend in NDC´s.
legend type - the optional type of legend to plot; 0 = simple bar, 1 = 2D graph.
optional background colour name - the name of a previously defined colour used to fill in the background under the legend. (default "WHITE")
optional text colour name - the name of a previously defined colour used to draw the text labels (default "BLACK")

Greyscale_Legend(x position NDC´s, y position NDC´s [, legend type[, "background colour"[, ["text colour"]]]);

Data_Contour_Levels(15,0.75,20,0.5,25,0.2,30,0);
Greyscale_Legend(mm(150), mm(250), 0, "White", "Blue");

Legend0

Data_Contour_Levels(15,0.75,20,0.5,25,0.2,30,0);
Greyscale_Legend(mm(150),mm(250),1);

Legend1

See the example Shaded Contours

affected by Data_Contour_Levels(), Data_Contour_Ramp(), Font(), Character_Height(), Decimal_Digits(), Line_Width().


Ramp Legend

This command is used to draw a legend on the output device showing the correspondence between the grey levels or colour used in shading the contours and the data z axis values they represent. The position of the left, right, bottom, and top margins of the ramp (excluding labels) and optionally, the values to use in labeling the ramp are specified.

If the position defines a rectangle that is wider than tall, a horizontal legend will be drawn, with the labels underneath the colour ramp, rather than a vertical legend.

If no labels are specified, the labels are chosen from those values specified in the Data_Contour_Ramp() command, such that no overlapping labels will be printed. The labels are rounded to show only significant digits (controlled by Decimal_Digits()).

When labels are specified, any values may be given (within the range of the original Data_Contour_Ramp). If a label value falls between the values of the original Data_Contour_Ramp, linear interpolation (between the Data_Contour_Ramp values) will be used to locate the position of the label. This may therefore be an approximate position when the original Data_Contour_Ramp scale is non-linear.

There are 4 or more parameters:
left- the x axis position of the left corner of the legend in NDC´s.
right- the x axis position of the right corner of the legend in NDC´s.
bottom- the y axis position of the bottom corner of the legend in NDC´s.
top- the y axis position of the top corner of the legend in NDC´s.
labels - the data value labels to annotate the ramp.

Ramp_Legend(left, right, bottom, top [, labels]);

Ramp_Legend(mm(150),mm(250),mm(220),mm(230),5,50,500,5000);

RampLegend

The colour values for this ramp are shown in the Data_Contour_Ramp command. affected by Data_Contour_Ramp(), Font(), Character_Height(), Decimal_Digits(), Line_Width().


Shade Contours

This command draws the shaded contour surface on the output device. The contour levels must be specified before this command is used. The number of subtriangles specified will greatly affect the smoothness and execution time of this command.


Parameters:
xyz matrix - a matrix containing the x, y, and z data as 3 columns.
or
x, y, and z vectors- 3 vectors containing the data to be plotted.

Shade_Contours(xyz matrix);
Shade_Contours(x vector, y vector, z vector);

Shade_Contours(mat);
Shade_Contours(x, y, zv);

See the example Shaded Contours

affected by Data_Window(), Data_Viewport(), Data_Projection(), Contour_Method() Data_Subtriangles(), Data_Contour_Levels(), Data_Contour_Ramp(), Data_Interpolation(), Blanking Points() Blanking Distance().


Voronoi Polygons

This command is used to draw the voronoi polygons which encompass areas of influence for each data point. They are the complement of the delaunay triangles which are formed to permit interpolation between the data points. Delaunay triangles are the set of triangles which subdivide the data region into the set of triangles which are as equilateral as possible. The voronoi polygons are drawn on the current output device or returned as a matrix.

Polygons can be: drawn as lines, drawn as shaded polygons, or returned as data matrix.
Parameters:
x and y vectors- 2 vectors containing the data to be plotted as lines or
xyz matrix - a matrix containing the x, y, and z data as 3 columns or
x, y, and z vectors- 3 vectors containing the data to be plotted.

Note: To be drawn as filled polygons, you must supply 3 columns of data, and set draw_filled(1).
The z parameter is only used when shading the voronoi polygons, and otherwise ignored if given.

Voronoi_Polygons(x vector,y vector [,return as data matrix flag]);
Voronoi_Polygons(xyz matrix [,return as data matrix flag]);
Voronoi_Polygons(x vector,y vector,z vector);

Voronoi_Polygons(x,y); // polygon drawn as lines
Draw_Filled(1);
Voronoi_Polygons(mat);
Voronoi_Polygons(x,y,z); // draw as filled polygons
xy = Voronoi_Polygons(x,y,1); // return data stored in the matrix xy


Potential Map

This command is used to generate a matrix of grid cells using a potential map algorithm. Using a set of observed data points, a grid of interpolated cells are calculated, which integrates the data within a specified radius of the data points.

There are 5 or more Parameters:
xyz matrix - a matrix containing the x, y, and z data as 3 columns or
x, y, and z vectors- 3 vectors containing the data to be plotted.
cell size - size of the grid cells to generate (in user units).
sampling radius - the total radius of the area of influence of a sampling point (km).
inner radius - the radius of the inner area for which no decay function is applied (km).
decay rate - the decay function which lessens the influence of observed points on distant cells.
max neighbours - the maximum number of neighbours that contribute to a averaged value.

Potential_Map(x vector,y vector,z vector,cell_size,sampling_radius,inner_radius,decay_rate,max_neighbours);
Potential_Map(xyz matrix,cell_size,sampling_radius,inner_radius,decay_rate,max_neighbours);

Function get_CMYK_ColourScale() {
// return a 20x4 matrix of value CMYK colour values
$colourscale = 0.403922 1 0.403922 0 0.498039 1 0.215686 0 0.654902 1 0.215686 0 1 1
0.184314 0 1 0.623529 0.184314 0 1 0.466667 0.121569 0 1 0.372549
0.184314 0 1 0.247059 0.372549 0 1 0.184314 0.498039 0 1 0.215686
0.686275 0 1 0.278431 1 0 0.560784 0.184314 1 0 0.372549 0.121569 1
0 0.184314 0.121569 1 0 0.247059 0.247059 1 0 0.152941 0.372549 1 0
0.152941 0.498039 1 0 0.152941 0.623529 1 0 0.247059 1 1 0 0.0588235 1 1 0;
$colourscale = shape(20 4,$colourscale);
return($colourscale);
};
Data_Projection("MERCATOR")
Data_Window(-68,-59,43,48);
Data_Viewport(mm(50),mm(110),mm(20),mm(130));
// Create random lon, lat, and val data vectors
lon = -68. + shape(100,5.0);
lat = 43 + shape(100,3.);
val = rand(shape(100,100.))
datapos = cat(2,lon,lat,val)[bindex(val > 0);];
scale = 2.26;
pixelsPerInch = 72.
cellsize = 1/((getview(2 1)*279.4)/(getwind(2) - getwind(1))*(pixelsPerInch/25.4*scale));
samplingRadius = 50;
innerRadius = 50.0;
decayRate = 0.2;
maxNeighbours = 10;
PotModel = 0;
potProjected = 0;
mat3 = potential_Map(dataPos,cellsize,samplingRadius,InnerRadius,decayRate,maxNeighbours,potModel,potprojected,0);
Colourscale = get_CMYK_ColourScale();
minval = min(mat3[;3]); maxval = max(mat3[;3]);
range = maxval - minval;
Data_Contour_Ramp(seq(minval,maxval,range/(20.- 0.001)),Colourscale);
// Draw data legend
Fill_Colour("BLACK");Line_colour("BLACK");
leftTop = GetView(1 4) + mm(5 0);
Ramp_Legend(LeftTop[1],LeftTop[1]+mm(30),LeftTop[2]-mm(5),LeftTop[2]-mm(0),distinct(rmin(0.03 .33 .66 .97*(range)+minval)));
maxvaln = max(select(val < NAN(),val));
maxval = sprintf("max = %.1f",maxvaln);
Fill_Colour(text_colour);
LeftTop[2]-= @character_Height*1.1 + mm(10)
Draw_Text(LeftTop[1],LeftTop[2],maxval);
}
Draw_Filled(1);
shade_rectangles(mat3[;4],mat3[;5],mat3);
Overlay_RANGS(-1,1,1,1,"BLACK","LIGHT_YELLOW2","LIGHT_BLUE");// Use RANGS file to cover the entire area


C_Squares

This command is used to generate a matrix of lontitude latitudes values from C Square text. The left, right, bottom and top corners of each square are returned as a matrix.

The home of C-Squares can be found at: http://www.marine.csiro.au/csquares/

From the author's web site:
"What is c-squares? C-squares is a system for storage, querying, display, and exchange of "spatial data" locations and extents in a simple, text-based, human- and machine- readable format. It uses numbered (coded) squares on the earth's surface measured in degrees (or fractions of degrees) of latitude and longitude as fundamental units of spatial information, which can then be quoted as single squares (similar to a "global postcode") in which one or more data points are located, or be built up into strings of codes to represent a wide variety of shapes and sizes of spatial data "footprints".

"Spatial data" (short for "geospatial data") in this context means any data which relate to a particular position on the earth's surface - and thus, for example, could be plotted on a map.

There is 1 Parameter:
C Square character matrix - a matrix containing the C Square values or
C Square character string - a single string containing a C Square value.

nx4matrix = C_Squares(CSquareMatrix);
vector = C_Squares(string);

c_squares("3414:227:383")
147.3 147.4 -42.9 -42.8

// The following example interprets C Squares from a string of html
// and plots the squares on a world map

Function Test_C_Squares_Window() {
// example script to test C_Squares function
// Use hard-coded OBIS output for Sebastes marinus as the test data
// source - the quote characters have been re-encoded as Tilde characters
source = "
<form action = ~http://www.marine.csiro.au/cgi-bin/cs_map.pl~ method=~post~ target=~_blank~><tr>
<td width=~200~ valign=~middle~>
<font size=-1 face=~geneva, lucida, arial~ color=~#FFFFFF~>
<b>Melanogrammus aeglefinus</b></font></td><td width=~120~
valign=~middle~><font size=-1 face=~geneva, lucida, arial~ color=~#FFFF00~>
Haddock </font></td>
<td width=~150~ valign=~middle~><font size=-1 face=~geneva, lucida, arial~ color=~#FFFFFF~>a fish</font></td>
<td width=~70~ align=~center~ valign=~middle~>
<INPUT TYPE=~hidden~ NAME=~csq~ VALUE=~1500:114:3|1500:140:4|1500:141:1|
1500:352:2|1500:360:4|1500:381:4|1500:383:1|1500:393:3|1500:465:2|
1500:466:4|1500:467:1|1500:477:2|1501:352:4|1501:354:4|1501:362:3|
1501:381:1| 1502:370:1|1502:374:1|1600:103:3|1601:130:4|1702:215:2|
1703:205:2|3600:103:3|7400:373:4|7405:131:1|7405:238:4|7405:239:3|
7405:239:4|7405:247:1|7405:247:2|7405:247:3|7405:247:4|7405:248:1|
7405:248:2|7405:248:3|7405:248:4|7405:249:1|7405:249:2|7405:249:3|
7405:249:4|7405:457:2|7405:458:1|7405:458:2|7405:458:3|7405:458:4|
7405:459:1|7405:459:2|7405:459:3|7405:459:4|7405:468:2|7405:469:1|
7405:469:2|7405:469:3|7405:469:4|7406:121:4|7406:122:3|7406:122:4|
7406:123:3|7406:123:4|7406:124:2|7406:124:3|7406:124:4|7406:130:1|
7406:130:2|7406:130:3|7406:130:4|7406:131:1|7406:131:2|7406:131:3|
7406:131:4|7406:132:1|7406:132:2|7406:132:3|7406:132:4|7406:133:1|
7406:133:2|7406:133:3|7406:133:4|7406:134:1|7406:134:2|7406:134:3|
7406:134:4|7406:140:1|7406:140:2|7406:140:3|7406:140:4|7406:141:1|
7406:141:2|7406:141:3|7406:141:4|7406:142:1|7406:142:2|7406:142:3|
7406:142:4|7406:143:1|7406:143:2|7406:144:1|7406:144:4|7406:207:3|
7406:208:3|7406:215:4|7406:216:1|7406:216:2|7406:216:3|7406:216:4|
7406:217:1|7406:218:1|7406:219:1|7406:225:1|7406:225:2|7406:225:3|
7406:225:4|7406:226:1|7406:226:2|7406:226:3|7406:226:4|7406:227:1|
7406:227:3|7406:227:4|7406:235:1|7406:235:2|7406:235:3|7406:236:1|
7406:236:2|7406:236:3|7406:236:4|7406:237:1|7406:237:2|7406:237:3|
7406:237:4|7406:245:3|7406:245:4|7406:246:1|7406:246:2|7406:246:3|
7406:246:4|7406:247:1|7406:247:3|7406:350:1|7406:350:2|7406:350:3|
7406:351:1|7406:351:2|7406:353:1|7406:354:2|7406:360:1|7406:360:3|
7406:360:4|7406:370:1|7406:455:1|7406:455:2|7406:456:1|7406:456:2|
7406:457:1|7407:103:2|7407:103:4|7407:111:1|7407:120:1|7500:219:2|
7500:457:1|7500:458:1|7500:479:1|7500:487:4|7501:248:3|7501:364:1|
7501:478:3|7504:495:4|7505:216:1|7600:226:3|7604:216:1|7605:110:1|
7605:120:2|7605:121:4|7605:132:2~>
<INPUT TYPE=~hidden~ NAME=~title~ VALUE=~OBIS stored distribution - <i>Melanogrammus aeglefinus </i><br>
<font size=3>(data sourced from DFO Scotian Summer Research Trawl Survey, FishBase,
History of Marine Animals (HMAP), NODC WOD01 Plankton Database (NODC), Taxonomic Information System for the Belgian coastal area)</font>~>
<INPUT TYPE=~hidden~ NAME=~legend~ VALUE=~This is a clickable map, click on any point to retrieve source data within the surrounding 5 x 5 degree square.~>
<INPUT TYPE=~hidden~ NAME=~redirect~ VALUE=~http://www.iobis.org/obisData/get_obis_data?genus=Melanogrammus&species=aeglefinus~>
<INPUT TYPE=~image~ border=~0~ NAME=~submit~ src=~http://www.iobis.org/images/mapbut2.gif~ width=~64~ height=~23~ alt=~Global Map~></td>
<td width=~100~ align=~center~ valign=~middle~><font size=-2 face=~geneva, lucida, arial~ color=~#FFFFFF~>
<a href=~http://www.iobis.org/obisData/get_obis_data?genus=Melanogrammus&species=aeglefinus
&n_lat=50.0&w_long=-70.0&s_lat=40&e_long=-060&resolution=10~ target=~_blank~>Get OBIS data</a>
</font></td>
<td width=~30~ align=~center~ valign=~middle~><font size=-1 face=~geneva, lucida, arial~ color=~#FFFF00~>
Y</font></td><td width=~150~ valign=~middle~><font size=-2 face=~geneva, lucida, arial~ color=~#FFFF00~>
Catalogue of Life; FishBase <br>
<a href=~http://checklist.spice.sp2000europa.org:8080/SP2003/process.php?genus=Melanogrammus
&species=aeglefinus~ target=~_blank~><i>query Cat. of Life</i></a>
</font></td>
</tr></form>";
//
// use the example text to extract the csq text
src = strregexp(source,".*csq~ VALUE=~([^~]*).*","\1"); // extract the c square coordinate text
srcmat = strfold(src,"|"); // convert to a character matrix
mat = C_Squares(srcmat); // create an n x 4 matrix of left, right, bottom, top coordinates for the Squares
nmat = len(mat)[1]; // number of rows of input
$id = seq(1,nmat); // sequence of unique polygon IDs
mat3 = shape(nmat*5,3,cat(2,mat[;1 3],$id,mat[;1 4],$id,mat[;2 4],$id,mat[;2 3],$id,mat[;1 3],$id)); // create polygon matrix n*5 x 3
//
// draw the base map
Data_Projection("proj=mill lon_0=63.5w ellps=clrk66 R_A +over");
Data_Projection("proj=eqc lon_0=0w lat_ts=0 ellps=clrk66 R_A +over");
left = mm(15); bot = mm(15); right = mm(185); top = mm(100);
Data_Viewport(left,right,bot,top);
Draw_Filled(1); Fill_Colour("CADET_BLUE3");Line_Colour("BLACK");
Draw(shape(5 2,getview(1 3 1 4 2 4 2 3 1 3))); // Fill in the background of the map in blue
Line_Width(pts(0.5))
Line_Grey(0.5); Grid(20,20);
Overlay_RANGS(-1,1,1,1,"BROWN","BEIGE","GREY"); // draw the shaded coastline
//
// draw the C-Squares
//Draw_filled(1);Fill_Col
our("RED");
//polygon_draw(mat3);
Line_Colour("RED"); Line_Width(pts(1));Draw_filled(0);
polygon_draw(mat3); // draw the C-Squares
// draw the axis and label
Fill_Colour("BLACK"); Line_Colour("BLACK");
Axis(50.000000,25.000000,5.000000,5.000000,1,0,1,0,0); // draw an axis
};

Data_window(-180 180 -90 90.);
starttime = clock();
test_c_squares_Window();
//Screen_Output();
print("elapsed time ",clock()-starttime);


AconIcon ACON       Home/Topics   |   Commands



Last Modified : 2005-11-13