[R-sig-Geo] extract the projected coordinates after reading a shapefie?

Roger Bivand Roger.Bivand at nhh.no
Mon Mar 12 15:01:32 CET 2007


On Mon, 12 Mar 2007, zhijie zhang wrote:

> Dear friends,
>   I use the function read.shape(maptools) to read a projected shapefile
> successfully, but  i need extract the coordinates after projected.

read.shape() is a low-level function that is not well suited to this. For 
a one-liner, please try:

coordinates(readShapePoints("d:/Export_Out2put.shp"))

which reads the shapefile into a SpatialPointsDataFrame, and then uses the 
coordinates() method to extract a 2 or 3 column matrix of coordinates, 
depending on whether a Z column was given in the shapefile.

Hope this helps,

Roger

> Programs:  x<-read.shape("d:/Export_Out2put.shp")   #read the projected
> shapefile
> Part of the Resutls:
> Shapefile type: Point, (1), # of Shapes: 83
> > x
> $Shapes
> [[1]]
> [[1]]$Pstart
> integer(0)
> 
> *[[1]]$verts
>          [,1]    [,2]
> [1,] 542250.9 3392404*
> 
> [[1]]$shp.type
> [1] 1
> 
> [[1]]$nVerts
> [1] 1
> 
> [[1]]$nParts
> [1] 0
> 
> [[1]]$bbox
> [1]  542250.9 3392404.1  542250.9 3392404.1
> 
> [[1]]$shpID
> [1] 0
> 
> attr(,"nVerts")
> [1] 1
> attr(,"nParts")
> [1] 0
> attr(,"shp.type")
> [1] 1
> attr(,"bbox")
> [1]  542250.9 3392404.1  542250.9 3392404.1
> 
> [[2]]
> [[2]]$Pstart
> integer(0)
> 
> *[[2]]$verts
>          [,1]    [,2]
> [1,] 542250.9 3392404*
> 
> [[2]]$shp.type
> [1] 1
> 
> [[2]]$nVerts
> [1] 1
> 
> [[2]]$nParts
> [1] 0
> 
> [[2]]$bbox
> [1]  542250.9 3392404.1  542250.9 3392404.1
> 
> [[2]]$shpID
> [1] 1
> 
> attr(,"nVerts")
> [1] 1
> attr(,"nParts")
> [1] 0
> attr(,"shp.type")
> [1] 1
> attr(,"bbox")
> [1]  542250.9 3392404.1  542250.9 3392404.1
> 
> [[3]]
> [[3]]$Pstart
> integer(0)
> 
> *[[3]]$verts
>          [,1]    [,2]
> [1,] 542250.9 3392404*
> 
> [[3]]$shp.type
> [1] 1
> 
> [[3]]$nVerts
> [1] 1
> 
> [[3]]$nParts
> [1] 0
> 
> [[3]]$bbox
> [1]  542250.9 3392404.1  542250.9 3392404.1
> 
> [[3]]$shpID
> [1] 2
> 
> attr(,"nVerts")
> [1] 1
> attr(,"nParts")
> [1] 0
> attr(,"shp.type")
> [1] 1
> attr(,"bbox")
> [1]  542250.9 3392404.1  542250.9 3392404.1
> 
> ...................................
> attr(,"class")
> [1] "ShapeList"
> 
> $att.data
>       id    lat          long     renkou year month monthnum
> 1   1 30.65134 117.4408   3270 2004     8      535
> 2   2 30.65134 117.4408   3270 2004    10      537
> 3   3 30.65134 117.4408   3270 2001     9      500
> 4   4 30.61479 117.4048   2201 2002     9      512
> 5   5 30.61479 117.4048   2201 2002     9      512
> 
> -----------------------------------------------------
>  *From the above results, i think the following data should be the
> coordinates after projected, how to extract all of them?
> *[[1]]$verts
>          [,1]    [,2]
> [1,] 542250.9 3392404
> 
> [[2]]$verts
>          [,1]    [,2]
> [1,] 542250.9 3392404
> 
> [[3]]$verts
>          [,1]    [,2]
> [1,] 542250.9 3392404
> 
> 
> I have tried several methods, but failed. The best results that i want are
> like:
> 
>    id    lat         long    renkou year month monthnum      * proj.lat
> proj.long*
> 1   1 30.65134 117.4408   3270 2004     8      535
> 2   2 30.65134 117.4408   3270 2004    10      537
> 3   3 30.65134 117.4408   3270 2001     9      500
> 
> Thanks for your information.
> 
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list