geoshape: Calculates distances between a shape file and a set of...

Description Usage Arguments Details Value See Also Examples

View source: R/geoshape.R

Description

Calculates distances in miles between a shape file and a set of geographic coordinates.

Usage

1
geoshape(longvar,latvar,linefile=NULL,pointfile=NULL,coormatrix=NULL)

Arguments

longvar

Longitude variable, in degrees.

latvar

Latitude variable, in degrees.

linefile

A shape file with lines. In this case, geoshape calculates the distance between each observation and the nearest line in the shape file. Default: linefile=NULL.

pointfile

A shape file with points. In this case, geoshape calculates the distance between each observation and the nearest point in the shape file. Also used for polygon files, in which case the centroids are considered points. Default: shapefile=NULL.

coormatrix

A matrix of geographic coordinates. The first column must be the longitude and the second column the latitude, both in degrees. In this case, geoshape calculates the distance between each observation and the nearest point in the matrix. The class of the object sent to coormatrix must actually be matrix. Default: coormatrix=NULL.

Details

Uses the nncross command from the spatstat package to calculate distances between the set of points given by (longvar, latvar) and the shape file provided by one of the linefile, pointfile, or coormatrix options. Only one of the three shape file options should be specified, and it is critical that the appropriate option is matched to the shape file. A polygon file is considered a point file for purposes of the geoshape command; in this case, nncross calculates distances to the polygon centroids. For the coormatrix option, it is critical that the object is of class matrix, the first column is longitude, and the second is latitude.

Value

Returns the calculated distances, in miles.

See Also

geodistance

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
data(matchdata)
cmap <- readShapePoly(system.file("maps/CookCensusTracts.shp",
  package="McSpatial"))
cmap <- cmap[cmap$CHICAGO==1,]
lmat <- coordinates(cmap)
# Calculate distance between homes in matchdata and the census tract centroids
matchdata$dist1 <- geoshape(matchdata$longitude,matchdata$latitude,pointfile=cmap)
# Alternative method using coormatrix option
matchdata$dist2 <- geoshape(matchdata$longitude,matchdata$latitude,
  coormatrix=coordinates(cmap))

# measure distance from census tract centroids to Chicago city center
longitude <- lmat[,1]
latitude  <- lmat[,2]
cmat <- t(as.matrix(c(-87.627800, 41.881998)))
dcbd <- geoshape(longitude, latitude, coormatrix=cmat)
summary(dcbd)

McSpatial documentation built on May 2, 2019, 9:32 a.m.