Skip to content

Help to improve a code to substract two columns, delete and save shape-file

2 messages · Alessandro, Paul Hiemstra

#
Thanks for All help give me.

 

I spoke with my professor and now I must do some changes. After subtract the
column Z with clomun DEM_SGRD to obtain column H. I wish to create a new
shape with only this H column. I tried and tried but when I write the shape
file there is always an error.

Sorry for all disturb.

 

I don't want to be ill-mannered, to use improperly your time, but before to
save the shape is It possible to save only all records with H value > of 2.
(the statistical analysis need this clean)

 

Thanks

 

Ale
OGR data source with driver: ESRI Shapefile 

Source: ".", layer: "prova"

with  42  rows and  2  columns
Object of class SpatialPointsDataFrame

Coordinates:

                min       max

coords.x1  267980.1  267998.1

coords.x2 4147799.4 4147818.8

Is projected: NA 

proj4string : [NA]

Number of points: 42

Data attributes:

       Z           DEM_SGRD   

 Min.   :1415   Min.   :1412  

 1st Qu.:1419   1st Qu.:1413  

 Median :1421   Median :1414  

 Mean   :1423   Mean   :1414  

 3rd Qu.:1424   3rd Qu.:1415  

 Max.   :1437   Max.   :1417
Object of class SpatialPointsDataFrame

Coordinates:

                min       max

coords.x1  267980.1  267998.1

coords.x2 4147799.4 4147818.8

Is projected: NA 

proj4string : [NA]

Number of points: 42

Data attributes:

       Z           DEM_SGRD          H         

 Min.   :1415   Min.   :1412   Min.   : 3.169  

 1st Qu.:1419   1st Qu.:1413   1st Qu.: 5.612  

 Median :1421   Median :1414   Median : 7.320  

 Mean   :1423   Mean   :1414   Mean   : 9.265  

 3rd Qu.:1424   3rd Qu.:1415   3rd Qu.:10.982  

 Max.   :1437   Max.   :1417   Max.   :21.806
Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 

  3.169   5.612   7.320   9.265  10.980  21.810
Errore in writeOGR(prova2, ".", "prova2", driver = "ESRI Shapefile") : 

  obj of wrong class

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20090224/f52ae7bf/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: prova.zip
Type: application/octet-stream
Size: 2204 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20090224/f52ae7bf/attachment.obj>
#
Ale,

Some remarks between the lines:

Alessandro schreef:
Here you extract the data from prova, not including the coordinates. 
Look at class(prova2) to see that it is no longer a 
SpatialPointsDataFrame but a data.frame. Use the following syntax to get 
the data plus the coordinates:

prova2 <- prova["H"]

Now you can export it using write OGR. To get only the values above H == 2:

prova_Hgt2 = prova2[prova2$H > 2,]

Or combining the two actions above into one command:

prova2 = prova[prova$H > 2, "H"]

cheers,
Paul