Skip to Content

RGEOS Utility Functions {rgeos}

RGEOS Utility Functions
Package: 
rgeos
Version: 
0.3-3

Description

Utility functions for the RGEOS package

Usage

    getScale()
    setScale(scale=100000000)
    translate(spgeom)
    checkP4S(p4s)
        version_GEOS()
        version_GEOS0()

Arguments

scale
Numeric value determining the precision of translated geometries
spgeom
sp object as defined in package sp
p4s
Either a character string or an object of class CRS

Details

getScale and setScale are used to get and set the scale option in the rgeos environment. This option is used to determine the precision of coordinates when translating to and from GEOS C objects. Precision is defined as 1 / scale. The final example is a use case reported by Mao-Gui Hu, who has also made the objects available, where the default scale defeats an intended line intersection operation; changing the scale temporarily resoves the issue.

translate is a testing function which translates the sp object into a GEOS C object and then back into an sp object and is used extensively in the translation unit tests. In all cases it is expected that spgeom and translate(spgeom) should be identical.

checkP4S is a validation function for proj4strings and is used in testing.

version_GEOS returns the full runtime version string, and version_GEOS0 only the GEOS version number.

Examples

    readWKT("POINT(1.5 1.5)")
 
    # With scale set to 1, the following point will be rounded
    setScale(1)
    readWKT("POINT(1.5 1.5)")
 
    setScale(10)
    readWKT("POINT(1.5 1.5)")
 
    getScale()
    # Set scale option back to default
    setScale()
 
 
 
    # scale option only affect objects when they are translated through rgeos
    setScale(1)
    library(sp)
    SpatialPoints(data.frame(x=1.5,y=1.5))
    translate( SpatialPoints(data.frame(x=1.5,y=1.5)) )
 
    setScale()
 
        # added example of scale impact on intersection 120905
sline1 <- readWKT(readLines(system.file("wkts/sline1.wkt", package="rgeos")))
sline2 <- readWKT(readLines(system.file("wkts/sline2.wkt", package="rgeos")))
rslt <- gIntersection(sline1, sline2)
class(rslt)
getScale()
setScale(1e+6)
rslt <- gIntersection(sline1, sline2)
class(rslt)
sapply(slot(rslt, "lines"), function(x) length(slot(x, "Lines")))
rslt <- gLineMerge(rslt, byid=TRUE)
sapply(slot(rslt, "lines"), function(x) length(slot(x, "Lines")))
setScale()

Author(s)

Roger Bivand & Colin Rundel

Documentation reproduced from package rgeos, version 0.3-3. License: GPL (>= 2)