<div dir="ltr"><div style>Hi,</div>Maybe, I'm doing some silly mistake but I don't know where.<div style>With [1] everything works fine, but when I try to write the output to a shape [2] I got an error (<span style="color:rgb(169,169,169);font-family:'Courier New,courier'">Can't convert columns of class: AsIs; column names: i_ID,j_ID).</span> Finally, if I write the output with writeLinesShape [3] I get the shape I'm looking for, before the algorithm crash.</div>
<div style>AFAICT "lines" is an object of class SpatialLinesDataFrame</div>







<div style>Any ideas?</div><div style>Thanks</div>







<div style>[1]------------------------------------------------</div>
<p style="margin:0px">##[datagistips]=group</p>
<p style="margin:0px">##points=vector</p>
<p style="margin:0px">##neighbours=number 3</p>
<p style="margin:0px">##showplots</p>
<p style="margin:0px">library("spdep")</p>
<p style="margin:0px">mur_coords <- coordinates(points)</p>
<p style="margin:0px">mur.knn <- knearneigh(points, k=neighbours)</p>
<p style="margin:0px">plot(points)</p>
<p style="margin:0px">plot(knn2nb(mur.knn), mur_coords, add=TRUE,col='red',lwd='2')</p>
<div style>title(main=paste("Distance based neighbours (",neighbours,")"))</div><div style>[2]___________</div><div style>
<p style="margin:0px">##[datagistips]=group</p>
<p style="margin:0px">##points=vector</p>
<p style="margin:0px">##neighbours=number 3</p>
<p style="margin:0px">##output=output vector</p>
<p style="margin:0px">library("spdep")</p>
<p style="margin:0px">coords <- coordinates(points)</p>
<p style="margin:0px">knn <- knearneigh(points, k=neighbours)</p>
<p style="margin:0px">output <- listw2lines(nb2listw(knn2nb(knn)), coords)</p>
<p style="margin:0px"><br></p></div><div style>The log error</div><div style>
<p style="margin:0px"><span style="font-weight:600">Algorithm vecinos shape starting...</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier'">R execution commands</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier'">options("repos"="<a href="http://cran.us.r-project.org">http://cran.us.r-project.org</a>")</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier'">tryCatch(find.package("rgdal"), error=function(e) install.packages("rgdal", lib="/Users/adiez/.qgis//sextante/rlibs"))</span></p>

<p style="margin:0px"><span style="font-family:'Courier New,courier'">library("rgdal")</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier'">points = readOGR("/Users/adiez/Dropbox/tests",layer="turton_rand")</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier'">neighbours=3</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier'">library("spdep")</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier'">coords </span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier'">knn </span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier'">lines </span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier'">writeLinesShape(lines, paste('/Users/adiez/Dropbox/mursilandia/mapas_finales/k_neig_51',neighbours))</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier'">output=lines</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier'">writeOGR(output,"/var/folders/sm/1djysrdj1clbzvn35gv8vqq40000gn/T/sextante/rvecinosshapeb87dccb5ed70455683e8ad4e4a5139b5.shp","rvecinosshapeb87dccb5ed70455683e8ad4e4a5139b5", driver="ESRI Shapefile")</span></p>

<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">R execution console output</span></p>
<p style="margin:0px"><br></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Copyright (C) 2012 The R Foundation for Statistical Computing</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">ISBN 3-900051-07-0</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Platform: i386-apple-darwin9.8.0/i386 (32-bit)</span></p>
<p style="margin:0px"><br></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">R is free software and comes with ABSOLUTELY NO WARRANTY.</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">You are welcome to redistribute it under certain conditions.</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Type 'license()' or 'licence()' for distribution details.</span></p>
<p style="margin:0px"><br></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Natural language support but running in an English locale</span></p>
<p style="margin:0px"><br></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">R is a collaborative project with many contributors.</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Type 'contributors()' for more information and</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">'citation()' on how to cite R or R packages in publications.</span></p>
<p style="margin:0px"><br></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Type 'demo()' for some demos, 'help()' for on-line help, or</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">'help.start()' for an HTML browser interface to help.</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Type 'q()' to quit R.</span></p>
<p style="margin:0px"><br></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">options("repos"="<a href="http://cran.us.r-project.org">http://cran.us.r-project.org</a>")</span></p>

<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">tryCatch(find.package("rgdal"), error=function(e) install.packages("rgdal", lib="/Users/adiez/.qgis//sextante/rlibs"))</span></p>

<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">[1] "/Users/adiez/Library/R/2.15/library/rgdal"</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">library("rgdal")</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Loading required package: sp</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Geospatial Data Abstraction Library extensions to R successfully loaded</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Loaded GDAL runtime: GDAL 1.9.0, released 2011/12/29</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Path to GDAL shared files: /Users/adiez/Library/R/2.15/library/rgdal/gdal</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Path to PROJ.4 shared files: /Users/adiez/Library/R/2.15/library/rgdal/proj</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">points = readOGR("/Users/adiez/Dropbox/tests",layer="turton_rand")</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">OGR data source with driver: ESRI Shapefile</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Source: "/Users/adiez/Dropbox/tests", layer: "turton_rand"</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">with 24 features and 2 fields</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Feature type: wkbPoint with 2 dimensions</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">neighbours=3</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">library("spdep")</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Loading required package: boot</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Loading required package: Matrix</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Loading required package: lattice</span></p>
<p style="margin:0px"><br></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Attaching package: 'lattice'</span></p>
<p style="margin:0px"><br></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">The following object(s) are masked from 'package:boot':</span></p>
<p style="margin:0px"><br></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">melanoma</span></p>
<p style="margin:0px"><br></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Loading required package: MASS</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Loading required package: nlme</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Loading required package: maptools</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Loading required package: foreign</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Checking rgeos availability: TRUE</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Loading required package: deldir</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">deldir 0.0-19</span></p>
<p style="margin:0px"><br></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">PLEASE NOTE: The components "delsgs" and "summary" of the</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">object returned by deldir() are now DATA FRAMES rather than</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">matrices (as they were prior to release 0.0-18).</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">See help("deldir").</span></p>
<p style="margin:0px"><br></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">PLEASE NOTE: The process for determining duplicated points</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">has changed from that used in version 0.0-9 (and previously).</span></p>
<p style="margin:0px"><br></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Loading required package: coda</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">coords </span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">knn </span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">lines </span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">writeLinesShape(lines, paste('/Users/adiez/Dropbox/mursilandia/mapas_finales/k_neig_51',neighbours))</span></p>

<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">output=lines</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">writeOGR(output,"/var/folders/sm/1djysrdj1clbzvn35gv8vqq40000gn/T/sextante/rvecinosshapeb87dccb5ed70455683e8ad4e4a5139b5.shp","rvecinosshapeb87dccb5ed70455683e8ad4e4a5139b5", driver="ESRI Shapefile")</span></p>

<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Error in writeOGR(output, "/var/folders/sm/1djysrdj1clbzvn35gv8vqq40000gn/T/sextante/rvecinosshapeb87dccb5ed70455683e8ad4e4a5139b5.shp", :</span></p>

<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Can't convert columns of class: AsIs; column names: i_ID,j_ID</span></p>
<p style="margin:0px"><span style="font-family:'Courier New,courier';color:rgb(169,169,169)">Execution halted</span></p>
<p style="margin:0px">Algorithm vecinos shape finished</p><p style="margin:0px">[3]----------------------------------------</p><p style="margin:0px">
</p><p style="margin:0px">##[datagistips]=group</p>
<p style="margin:0px">##points=vector</p>
<p style="margin:0px">##neighbours=number 3</p>
<p style="margin:0px">##output=output vector</p>
<p style="margin:0px">library("spdep")</p>
<p style="margin:0px">coords <- coordinates(points)</p>
<p style="margin:0px">knn <- knearneigh(points, k=neighbours)</p>
<p style="margin:0px">lines <- listw2lines(nb2listw(knn2nb(knn)), coords)</p>
<p style="margin:0px">writeLinesShape(lines, paste('/Users/adiez/Dropbox/mursilandia/mapas_finales/k_neig_51',neighbours))</p>
<p style="margin:0px">output=lines</p><p style="margin:0px">---------------------------------------</p><p></p></div></div>