Loading...
Searching...
No Matches
plot.c File Reference

GIS Library - Plotting functions. More...

`#include <stdlib.h>`
`#include <math.h>`
`#include <grass/gis.h>`
Include dependency graph for plot.c:

Go to the source code of this file.

## Macros

#define | POINT struct point
#define | OK 0
#define | TOO_FEW_EDGES 2
#define | NO_MEMORY 1
#define | OUT_OF_SYNC -1
#define | X(e)
#define | Y(n)
#define | EAST(x)
#define | NORTH(y)

## Functions

void | G_setup_plot (double t, double b, double l, double r, int(*Move)(int, int), int(*Cont)(int, int))
| Initialize plotting routines.
void | G_setup_fill (int gap)
| Set row_fill routine to row_solid_fill or row_dotted_fill.
void | G_plot_where_xy (double east, double north, int *x, int *y)
| Converts east,north to x,y.
void | G_plot_where_en (int x, int y, double *east, double *north)
| Converts x,y to east,north.
void | G_plot_point (double east, double north)
| Plot point.
void | G_plot_line (double east1, double north1, double east2, double north2)
| Plot line between latlon coordinates (fastline).
void | G_plot_line2 (double east1, double north1, double east2, double north2)
| Plot line between latlon coordinates (slowline).
int | G_plot_polygon (const double *x, const double *y, int n)
| Plot filled polygon with n vertices.
int | G_plot_area (double *const *xs, double *const *ys, int *rpnts, int rings)
| Plot multiple polygons.
void | G_plot_fx (double(*f)(double), double east1, double east2)
| Plot f(east1) to f(east2).

## Detailed Description

GIS Library - Plotting functions.

Plot lines and filled polygons. Input space is current window. Output space and output functions are user defined. Converts input east,north lines and polygons to output x,y and calls user supplied line drawing routines to do the plotting.

Handles global wrap-around for lat-lon locations.

Does not perform window clipping. Clipping must be done by the line draw routines supplied by the user.

Note: Hopefully, cartographic style projection plotting will be added later.

(C) 2001-2008, 2013 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
  Original author CERL

Definition in file plot.c.

## Macro Definition Documentation

## EAST

#define EAST | ( |  | x | ) |

Value:
(st->window.west + ((x) - st->left) / st->xconv)
x
#define x

Definition at line 146 of file plot.c.

Referenced by G_plot_where_en().

## NO_MEMORY

#define NO_MEMORY 1

Definition at line 72 of file plot.c.

Referenced by G_plot_area(), and G_plot_polygon().

## NORTH

#define NORTH | ( |  | y | ) |

Value:
(st->window.north - ((y) - st->top) / st->yconv)

Definition at line 147 of file plot.c.

Referenced by G_plot_where_en().

## OK

#define OK 0

Definition at line 70 of file plot.c.

Referenced by G_plot_area(), and G_plot_polygon().

## OUT_OF_SYNC

#define OUT_OF_SYNC -1

Definition at line 73 of file plot.c.

Referenced by G_plot_area(), and G_plot_polygon().

## POINT

#define POINT struct point

Definition at line 50 of file plot.c.

Referenced by G_plot_area(), and G_plot_polygon().

## TOO_FEW_EDGES

#define TOO_FEW_EDGES 2

Definition at line 71 of file plot.c.

Referenced by G_plot_area(), and G_plot_polygon().

## X

#define X | ( |  | e | ) |

Value:
(st->left + st->xconv * ((e) - st->window.west))

Definition at line 143 of file plot.c.

Referenced by G_plot_area(), G_plot_polygon(), and G_plot_where_xy().

## Y

#define Y | ( |  | n | ) |

Value:
(st->top + st->yconv * (st->window.north - (n)))

Definition at line 144 of file plot.c.

Referenced by G_plot_area(), G_plot_polygon(), and G_plot_where_xy().

## Function Documentation

## G_plot_area()

int G_plot_area | ( | double *const * | xs,
|  | double *const * | ys,
|  | int * | rpnts,
|  | int | rings )

Plot multiple polygons.

Like G_plot_polygon(), except it takes a set of polygons, each with npts[i] vertices, where the number of polygons is specified with the rings argument. It is especially useful for plotting vector areas with interior islands.

Parameters

  xs | pointer to pointer for X's
  ys | pointer to pointer for Y's
  rpnts | array of ints w/ num points per ring
  rings | number of rings

Returns
  0 on success
  2 n < 3
  -1 weird internal error
  1 no memory

Definition at line 502 of file plot.c.

References G_free(), G_warning(), NO_MEMORY, NULL, OK, OUT_OF_SYNC, POINT, TOO_FEW_EDGES, X, x, and Y.

## G_plot_fx()

void G_plot_fx | ( | double(* | f )(double),
|  | double | east1,
|  | double | east2 )

Plot f(east1) to f(east2).

The function f(east) is plotted from east1 to east2. The function f(east) must return the map northing coordinate associated with east.

Parameters

  f | plotting function
  east1 | easting (first point)
  east2 | easting (second point)

Definition at line 780 of file plot.c.

References G_plot_line().

## G_plot_line()

void G_plot_line | ( | double | east1,
|  | double | north1,
|  | double | east2,
|  | double | north2 )

Plot line between latlon coordinates (fastline).

A line from east1,north1 to east2,north2 is plotted in output x,y coordinates (e.g. pixels for graphics.) This routine handles global wrap-around for latitude-longitude databases.

Parameters

  east1,north1 | first point (start line node)
  east2,north2 | second point (end line node)

Definition at line 208 of file plot.c.

Referenced by G_plot_fx().

## G_plot_line2()

void G_plot_line2 | ( | double | east1,
|  | double | north1,
|  | double | east2,
|  | double | north2 )

Plot line between latlon coordinates (slowline).

A line from east1,north1 to east2,north2 is plotted in output x,y coordinates (e.g. pixels for graphics.) This routine handles global wrap-around for latitude-longitude databases.

Parameters

  east1,north1 | first point (start line node)
  east2,north2 | second point (end line node)

Definition at line 223 of file plot.c.

## G_plot_point()

void G_plot_point | ( | double | east,
|  | double | north )

Plot point.

Parameters

  east | easting
  north | northing

Definition at line 189 of file plot.c.

References G_plot_where_xy(), and x.

## G_plot_polygon()

int G_plot_polygon | ( | const double * | x,
|  | const double * | y,
|  | int | n )

Plot filled polygon with n vertices.

The polygon, described by the n vertices east,north, is plotted in the output x,y space as a filled polygon.

Parameters

  x | coordinates of vertices
  y | coordinates of vertices
  n | number of vertices

Returns
  0 on success
  2 n < 3
  -1 weird internal error
  1 no memory

Definition at line 372 of file plot.c.

References G_warning(), NO_MEMORY, OK, OUT_OF_SYNC, POINT, TOO_FEW_EDGES, X, x, and Y.

## G_plot_where_en()

void G_plot_where_en | ( | int | x,
|  | int | y,
|  | double * | east,
|  | double * | north )

Converts x,y to east,north.

The pixel coordinates x,y are converted to map coordinates east,north.

Parameters

  x | x coordinate
  y | y coordinate
  east | easting
  north | northing

Definition at line 177 of file plot.c.

References EAST, G_adjust_easting(), NORTH, and x.

## G_plot_where_xy()

void G_plot_where_xy | ( | double | east,
|  | double | north,
|  | int * | x,
|  | int * | y )

Converts east,north to x,y.

The map coordinates east,north are converted to pixel coordinates x,y.

Parameters

  east | easting
  north | nothing
  x | x coordinate
  y | y coordinate

Definition at line 160 of file plot.c.

References G_adjust_easting(), X, x, and Y.

Referenced by G_plot_point().

## G_setup_fill()

void G_setup_fill | ( | int | gap | ) |

Set row_fill routine to row_solid_fill or row_dotted_fill.

After calling this function, G_plot_polygon() and G_plot_area() fill shapes with solid or dotted lines. If gap is greater than zero, this value will be used for row_dotted_fill. Otherwise, row_solid_fill is used.

Parameters

  gap |

Definition at line 133 of file plot.c.

## G_setup_plot()

void G_setup_plot | ( | double | t,
|  | double | b,
|  | double | l,
|  | double | r,
|  | int(* | Move )(int, int),
|  | int(* | Cont )(int, int) )

Initialize plotting routines.

Initializes the plotting capability. This routine must be called once before calling the G_plot_*() routines described below. The parameters t, b, l, r are the top, bottom, left, and right of the output x,y coordinate space. They are not integers, but doubles to allow for subpixel registration of the input and output coordinate spaces. The input coordinate space is assumed to be the current GRASS region, and the routines supports both planimetric and latitude-longitude coordinate systems.

Move and Cont are subroutines that will draw lines in x,y space. They will be called as follows:

- Move(x, y) move to x,y (no draw)
- Cont(x, y) draw from previous position to x,y. Cont(~) is responsible for clipping

Parameters

  t,b,l,r | top, bottom, left, right
  move | Move function
  Cont | Cont function

Definition at line 97 of file plot.c.

References b, G_get_set_window(), l, r, and t.