File: Spatial-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 (39 lines) | stat: -rw-r--r-- 1,653 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
32
33
34
35
36
37
38
39
readShapeSpatial <- function(fn, proj4string=CRS(as.character(NA)), 
	verbose=FALSE, repair=FALSE, IDvar=NULL, force_ring=FALSE, 
	delete_null_obj=FALSE, retrieve_ABS_null=FALSE) {
	shinfo <- getinfo.shape(fn)
	if (verbose) print(shinfo)
	type <- shinfo[[2]]
	types <- c("Point", NA, "PolyLine", NA, "Polygon", NA, NA, 
	    "MultiPoint", NA, NA, "PointZ", NA, "PolyLineZ", NA, 
	    "PolygonZ", NA, NA, "MultiPointZ", NA, NA, "PointM", NA, 
	    "PolyLineM", NA, "PolygonM", NA, NA, "MultiPointM", NA, NA, 
	    "MultiPatch")
	typeSh <- types[type]
	if (typeSh == "Point" || typeSh == "PointZ" || typeSh == "MultiPoint") {
	    res <- readShapePoints(fn=fn, proj4string=proj4string, 
		verbose=verbose, repair=repair)
	} else if (typeSh == "PolyLine" || typeSh == "PolyLineZ") {
	    res <- readShapeLines(fn=fn, proj4string=proj4string, 
		verbose=verbose, repair=repair)
	} else if (typeSh == "Polygon" || typeSh == "PolygonZ") {
	    res <- readShapePoly(fn=fn, IDvar=IDvar, proj4string=proj4string, 
		verbose=verbose, repair=repair, force_ring=force_ring, 
		delete_null_obj=delete_null_obj, 
		retrieve_ABS_null=retrieve_ABS_null)	    
	} else stop("File type cannot be read")
	res
}

writeSpatialShape  <- function(x, fn, factor2char = TRUE, max_nchar=254) {
	if (is(x, "SpatialPolygonsDataFrame")) {
	    writePolyShape(x=x, fn=fn, factor2char=factor2char, 
		max_nchar=max_nchar)
	} else if (is(x, "SpatialLinesDataFrame")) {
	    writeLinesShape(x=x, fn=fn, factor2char=factor2char, 
		max_nchar=max_nchar)
	} else if (is(x, "SpatialPointsDataFrame")) {
	    writePointsShape(x=x, fn=fn, factor2char=factor2char, 
		max_nchar=max_nchar)
	}
}