[R] How to write a shapefile with projection
Monica Pisica
pisicandru at hotmail.com
Fri Nov 4 15:51:41 CET 2011
Hi,
I am trying to write a shapefile with projection. I have
my data in a data.frame called try and consists in xy coordinates and a
numerical attribute value z1.
Libraries loaded are: sp, rgdal, raster, maptools
head(try)
x y z1
1 610237.1 3375751
8.221
2 610236.1 3375750
8.153
3 610236.1 3375749
8.275
4 610236.1 3375748
8.251
5 610236.1 3375747
8.217
6 610236.1 3375746
8.196
#Get the projection from a raster named llev I have loaded before:
crs <- projection(llev)
# get a spatial point data frame from my data
crest.sp <- SpatialPointsDataFrame(try[,1:2], try,
proj4string=CRS(crs))
summary(crest.sp)
Object of class SpatialPointsDataFrame
Coordinates:
min max
x 610235.1 610354.1
y 3374862.4 3375751.4
Is projected: TRUE
proj4string :
[+proj=utm +zone=15 +ellps=GRS80 +datum=NAD83 +units=m
+no_defs +towgs84=0,0,0]
Number of points: 890
Data attributes:
x y z1
Min. : 610235 Min. : 3374862 Min.: 6.966
1st
Qu.:610269 1st Qu.:3375085 1st Qu.:7.570
Median
:610298 Median :3375307 Median :7.901
Mean :610300
Mean :3375307
Mean :7.882
3rd
Qu.:610334 3rd Qu.:3375529 3rd Qu.:8.180
Max. :610354
Max. :3375751 Max.
:8.756
#write the shapefile
writePointsShape(crest.sp, "I:/LA_levee/Shape/llev_crest_pts6")
If I load this shapefile in ArcGIS is has no projection.
I also looked at the write.shapefile command from shapefiles library and again I
get a file without projection. Is there any way to write the projection for the
shapefile in R? Probably I can do something in ArcGIS, but I would like to have
my shapefile from R complete.
Thanks,
Monica
More information about the R-help
mailing list