File: SpatialPoints-methods.R

package info (click to toggle)
r-cran-maptools 1%3A0.7-34-2
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze
  • size: 2,184 kB
  • ctags: 232
  • sloc: ansic: 3,014; makefile: 3
file content (31 lines) | stat: -rw-r--r-- 940 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
readShapePoints <- function(fn, proj4string=CRS(as.character(NA)), 
	verbose=FALSE, repair=FALSE) {
	suppressWarnings(Map <- read.shape(filen=fn, verbose=verbose,
	    repair=repair))
	suppressWarnings(.Map2SPDF(Map, proj4string=proj4string))
}

.Map2SPDF <- function(Map, IDs, proj4string=CRS(as.character(NA))) {
	if (missing(IDs))
		IDs <- as.character(sapply(Map$Shapes, function(x) x$shpID))
	coords <- Map2points(Map)
	oldClass(coords) <- NULL
	rownames(coords) <- IDs
	attr(coords, "shpID") <- NULL
	attr(coords, "maplim") <- NULL

	df <- Map$att.data
	rownames(df) <- IDs
	res <- SpatialPointsDataFrame(coords=coords, data=df, 
		proj4string=proj4string, match.ID=TRUE)
	res
}

writePointsShape <- function(x, fn, factor2char = TRUE, max_nchar=254) {
	df <- as(x, "data.frame")
	coords <- coordinates(x)
	suppressWarnings(write.pointShape(coordinates=coords, df=df, file=fn,  
		factor2char = factor2char, max_nchar=max_nchar))
}