[Qgis-user] Problem with R script in Sextante, I can't write the output

Agustin Diez-Castillo gvsig.mac at gmail.com
Wed Jan 9 06:28:35 PST 2013


Hi,
Maybe, I'm doing some silly mistake but I don't know where.
With [1] everything works fine, but when I try to write the output to a
shape [2] I got an error (Can't convert columns of class: AsIs; column
names: i_ID,j_ID). Finally, if I write the output with writeLinesShape [3]
I get the shape I'm looking for, before the algorithm crash.
AFAICT "lines" is an object of class SpatialLinesDataFrame
Any ideas?
Thanks
[1]------------------------------------------------

##[datagistips]=group

##points=vector

##neighbours=number 3

##showplots

library("spdep")

mur_coords <- coordinates(points)

mur.knn <- knearneigh(points, k=neighbours)

plot(points)

plot(knn2nb(mur.knn), mur_coords, add=TRUE,col='red',lwd='2')
title(main=paste("Distance based neighbours (",neighbours,")"))
[2]___________

##[datagistips]=group

##points=vector

##neighbours=number 3

##output=output vector

library("spdep")

coords <- coordinates(points)

knn <- knearneigh(points, k=neighbours)

output <- listw2lines(nb2listw(knn2nb(knn)), coords)


The log error

Algorithm vecinos shape starting...

R execution commands

options("repos"="http://cran.us.r-project.org")

tryCatch(find.package("rgdal"), error=function(e) install.packages("rgdal",
lib="/Users/adiez/.qgis//sextante/rlibs"))

library("rgdal")

points = readOGR("/Users/adiez/Dropbox/tests",layer="turton_rand")

neighbours=3

library("spdep")

coords

knn

lines

writeLinesShape(lines,
paste('/Users/adiez/Dropbox/mursilandia/mapas_finales/k_neig_51',neighbours))

output=lines

writeOGR(output,"/var/folders/sm/1djysrdj1clbzvn35gv8vqq40000gn/T/sextante/rvecinosshapeb87dccb5ed70455683e8ad4e4a5139b5.shp","rvecinosshapeb87dccb5ed70455683e8ad4e4a5139b5",
driver="ESRI Shapefile")

R execution console output


R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"

Copyright (C) 2012 The R Foundation for Statistical Computing

ISBN 3-900051-07-0

Platform: i386-apple-darwin9.8.0/i386 (32-bit)


R is free software and comes with ABSOLUTELY NO WARRANTY.

You are welcome to redistribute it under certain conditions.

Type 'license()' or 'licence()' for distribution details.


Natural language support but running in an English locale


R is a collaborative project with many contributors.

Type 'contributors()' for more information and

'citation()' on how to cite R or R packages in publications.


Type 'demo()' for some demos, 'help()' for on-line help, or

'help.start()' for an HTML browser interface to help.

Type 'q()' to quit R.


options("repos"="http://cran.us.r-project.org")

tryCatch(find.package("rgdal"), error=function(e) install.packages("rgdal",
lib="/Users/adiez/.qgis//sextante/rlibs"))

[1] "/Users/adiez/Library/R/2.15/library/rgdal"

library("rgdal")

Loading required package: sp

Geospatial Data Abstraction Library extensions to R successfully loaded

Loaded GDAL runtime: GDAL 1.9.0, released 2011/12/29

Path to GDAL shared files: /Users/adiez/Library/R/2.15/library/rgdal/gdal

Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]

Path to PROJ.4 shared files: /Users/adiez/Library/R/2.15/library/rgdal/proj

points = readOGR("/Users/adiez/Dropbox/tests",layer="turton_rand")

OGR data source with driver: ESRI Shapefile

Source: "/Users/adiez/Dropbox/tests", layer: "turton_rand"

with 24 features and 2 fields

Feature type: wkbPoint with 2 dimensions

neighbours=3

library("spdep")

Loading required package: boot

Loading required package: Matrix

Loading required package: lattice


Attaching package: 'lattice'


The following object(s) are masked from 'package:boot':


melanoma


Loading required package: MASS

Loading required package: nlme

Loading required package: maptools

Loading required package: foreign

Checking rgeos availability: TRUE

Loading required package: deldir

deldir 0.0-19


PLEASE NOTE: The components "delsgs" and "summary" of the

object returned by deldir() are now DATA FRAMES rather than

matrices (as they were prior to release 0.0-18).

See help("deldir").


PLEASE NOTE: The process for determining duplicated points

has changed from that used in version 0.0-9 (and previously).


Loading required package: coda

coords

knn

lines

writeLinesShape(lines,
paste('/Users/adiez/Dropbox/mursilandia/mapas_finales/k_neig_51',neighbours))

output=lines

writeOGR(output,"/var/folders/sm/1djysrdj1clbzvn35gv8vqq40000gn/T/sextante/rvecinosshapeb87dccb5ed70455683e8ad4e4a5139b5.shp","rvecinosshapeb87dccb5ed70455683e8ad4e4a5139b5",
driver="ESRI Shapefile")

Error in writeOGR(output,
"/var/folders/sm/1djysrdj1clbzvn35gv8vqq40000gn/T/sextante/rvecinosshapeb87dccb5ed70455683e8ad4e4a5139b5.shp",
:

Can't convert columns of class: AsIs; column names: i_ID,j_ID

Execution halted

Algorithm vecinos shape finished

[3]----------------------------------------

##[datagistips]=group

##points=vector

##neighbours=number 3

##output=output vector

library("spdep")

coords <- coordinates(points)

knn <- knearneigh(points, k=neighbours)

lines <- listw2lines(nb2listw(knn2nb(knn)), coords)

writeLinesShape(lines,
paste('/Users/adiez/Dropbox/mursilandia/mapas_finales/k_neig_51',neighbours))

output=lines

---------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20130109/6521c950/attachment.html>


More information about the Qgis-user mailing list