[R-sig-Geo] Help Exporting ShapeFiles

Roger Bivand Roger.Bivand at nhh.no
Mon Jan 31 20:42:54 CET 2011


On Mon, 31 Jan 2011, kapo coulibaly wrote:

>> From what I can gather with your code:
> - check the result of your Paste command and make sure it is a valid path.
> - Also make sure your object a (in writePolyShape(a,Dir)) is a
> SpatialPolygonsDataFrame object, it seems to me that it is a plain data
> frame. You can convert it with the sp package command
> SpatialPolygonsDataFrame.

In addition, you might like to check whether you have a recent version of 
maptools (use update.packages()), because the foreign package containing 
write.dbf() was changed, calling for changes in writePolyShape(). Always 
give the output of sessionInfo() when asking questions like these.

Roger

>
> Hope it helps
>
> 2011/1/31 Jaime Burbano Gir?n <jaimebg27 at gmail.com>
>
>> Hi everybody, I am new using R with vector spatial data. I want to export 1
>> or a few polygons from my shapefile which has 421 polygons with the
>> function
>> "writePolyShape" from library maptools, but I get the following error:
>>
>> *Error en write.dbf(df, paste(file, ".dbf", sep = ""), factor2char =
>> factor2char,  :  unable to open file*
>>
>> This is the code:
>> *
>> Cuencas=readShapePoly("D:/Modelamiento_Hidrol?gico/Capas
>> Adicionales/Watershed_Final.shp")
>> A.Cuencas=as(Cuencas,"data.frame")
>> a=Cuencas[Cuencas$HydroID<151838,]
>> Dir=paste("D:/Modelamiento_Hidrol?gico/Watersheds",A.Cuencas[1,2],sep="/")
>> writePolyShape(a,Dir)
>
>
>
>> *
>>
>> I?ve tried exporting just 1 polygon, 2 or more, but the error is always the
>> same. I appreciate your help.
>>
>> Thanks a lot in advance and my best regards.
>>
>> --
>> Jaime Burbano Gir?n
>> Departamento de Ecolog?a y Territorio
>> Pontificia Universidad Javeriana
>> Bogot? - Colombia
>> (571) 3208320 Ext. 4836
>>
>>        [[alternative HTML version deleted]]
>>
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>>
>
> 	[[alternative HTML version deleted]]
>
>

-- 
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