Package 'gris'

Title: A Flexible Geometry and Topology Model for Spatial Data in R
Description: A flexible geometry data model for R.
Authors: Michael D. Sumner
Maintainer: Michael D. Sumner <[email protected]>
License: GPL-3
Version: 0.1.0
Built: 2026-10-15 00:49:03 UTC
Source: https://github.com/hypertidy/gris

Help Index


gris: A flexible geometry data model for R.

Description

The gris package provides a relational table model for spatial vector data in R. Spatial vector data are topology-based discrete spatial units such as areas (including polygons), lines and points.

Details

These kinds of data are defined in many different ways in various R packages, but the sp package has provided the most comprehensive and standard model to match the traditional GIS layer forms.

Gris features

  • provide a clear decoupling of topology from geometry (see section "Gris topology" below)

  • transcend the X/Y-only limitation for vertex attributes

  • allow multiple topological types in individual layers (i.e. Manifold or MapInfo drawings)

  • provide a flexible basis for conversion between other formats and domain-specific structures

I. Creation

gris.Spatial create from Spatial*DataFrame
grisFromRasterGeom create from geom format
grisFromFortify create from fortify format
as.gris.triangulation create from triangulation

II. Plotting

plot.gris plot a gris object as polypath, lines, points, or triangles
plot3d.gris plot a gris object in 3d

III. Manipulation

[.gris extract a subset of a gris object
pointInTriangle identify which triangle points fall in

IV. Conversion to other types

as.SpatialPolygonsDataFrame.gris coerce to SpatialPolygonsDataFrame, SpatialLinesDataFrame, SpatialPointsDataFrame, SpatialMultiPointsDataFrame
triangulate.gris add triangle primitives to a gris object

V. Miscellaneous

brick2col create hex value colours from an RGB RasterBrick

Gris topology

Topology defines the way that space is filled by 0D (points), 1D (lines), 2D (areas - or polygons) objects. (Higher dimensional topologies are possible but not explored yet.)

Geometry defines an actual instantiation of an object in a given coordinate system.

Examples of the difference are

  • polygons defining continental outlines on the Earth, these shapes are 2D topologically, but geometrically can be plotted in the plane (in long-lat, or projected coordinates) or "draped" around a curve, such as the Earth as a globe or across a topographic landscape

  • lines defining animal tracks in space time, these 1D shapes can have geometric vertex attributes such as X, Y, Z, time, temperature, etc.

Topology dimension may be 0D, 1D, 2D, or higher and geometry dimension is not necessarily coupled to this, or restricted to 2D.

Note that certain degeneracies are possible and may be important. A time series of point estimates in space may not have any sensible geometric values at all, but the topological description provided by that time series is a real structure.


as.gris

Description

as.gris

Usage

## S3 method for class 'triangulation'
as.gris(x, ...)

Arguments

x

triangulation (package RTriangle)

type

mesh, triangle polygons, or triangle edges


Return a list of Polygon, Line or matrix from gris

Description

Return a list of Polygon, Line or matrix from gris

Spatial classes are defined in the sp package.

Usage

as.SpatialPolygonsDataFrame(x, ...)

## S3 method for class 'gris'
as.SpatialPolygonsDataFrame(x, ...)

Arguments

x

gris object

...

ignored

type

return type: pp-oly, l-ine, p-oints

x

gris object


Title

Description

Title

Usage

brick2col(x)

Arguments

x

RasterBrick

Value

hex colour character vector


Geocentric coordinates.

Description

Transform to geocentric coordinates.

Usage

geocentric(x, crs = "+proj=geocent +ellps=WGS84")

Arguments

x

table of long, lat, and optionally "height"

crs
exag

exaggeration to apply to height values (added to radius)

Value

tibble


convert from spbabel sptable to gris

Description

convert from spbabel sptable to gris

Usage

grasp(dat1, map1)

gris

Description

gris

Usage

gris(x, ...)

## S3 method for class 'gris'
x[i, j, drop = FALSE]

## S3 method for class 'gris'
print(x, ..., n = NULL, width = NULL)

## S3 method for class 'gris'
plot(x, y, triangles = FALSE, ...)

as.gris(x, ...)

Arguments

x

Spatial* object

...

unused

i

indices for extract

j

indices for extract

drop

ignored

n

n

width

width

y

y

Value

gris

Methods

gris implements these base methods:

plot

Plots the object according to its topology type, or by a chosen type. This method follows base plotting with types "p" points, "l" lines, and adds "pp" for polygons

print

Prints the object and vertices tables with a summary of the topology linkages

[

Subset as an object table on attributes, propagates down through the geometry links to return a subsetted gris object


Convert Spatial*DataFrame objects to gris

Description

All availables Spatial*DataFrame types are supported, and are interpreted via the Branch model. The gris function can ingest SpatialPolygonsDataFrame, SpatialLinesDataFrame, SpatialPointsDataFrame, and SpatialMultiPointsDataFrame objects.

Usage

## S3 method for class 'Spatial'
gris(x, ...)

Arguments

x

Spatial* object

...

not used

Details

See vignette("branch-vs-primitives")

Value

gris


Not yet implemented

Description

Not yet implemented

Usage

grisFromFortify(x)

Arguments

x

Value

gris

Examples

## Not run: 
 data(cmu)
 
 
 sp <- as.SpatialPolygonsDataFrame(cmu)
 gm <- raster::geom(sp)

## End(Not run)

Not yet implemented

Description

Not yet implemented

Usage

grisFromRasterGeom(x)

Arguments

x

Value

gris


Point in triangle test.

Description

Point in triangle test.

Usage

pointInTriangle(x, pt)

pointBary(x, pt)

Arguments

x

gris object with triangulation

pt

matrix of xy coordinates

Value

for PointInTriangle, the index of triangle for each point, in vertex_ form for PointBary, the table of barycentric coordinates and vertex_ index


Template quad 3d object

Description

Template quad 3d object

Usage

q3d

Format

see rgl oh3d


Template triangle 3d object

Description

Template triangle 3d object

Usage

t3d

Format

see rgl tetrahedron3d


Add triangle primitives

Description

Add triangle primitives

Usage

triangulate(x, ...)

Arguments

x

gris object

...

passed on to triangulate, as arguments after the input pslg

Details

only a has been extensively explored, this is the minimum triangle area in the units of the coordinates

Examples

## Not run: 
library(gris)
library(maptools)
data(wrld_simpl)
gall <- gris(wrld_simpl)
g <- gall[gall$o$NAME %in% c("Australia", "New Zealand"), ]
g$v <- g$v %>% mutate(x = ifelse(x < 0, x + 360, x))

gT <- gris::triangulate(g)
plot(g)
plot(gT, triangles = TRUE, add = TRUE)

## End(Not run)