<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Having trouble with rbind() and SpatialLinesDataFrame in Data Management Questions</title>
    <link>https://community.esri.com/t5/data-management-questions/having-trouble-with-rbind-and/m-p/278219#M16024</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am using R for some spatial data management and have the following problem:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am getting the following error when trying to rbind several SpatialLinesDataFrames. I have been having a lot of trouble with ID's, in general, and have created a few workarounds further up in the code, but I am stuck here. Any info would be great!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Error in SpatialLinesDataFrame(ll, df) : &lt;/P&gt;&lt;P&gt;&amp;nbsp; row.names of data and Lines IDs do not match&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sample code up to the point of throwing the error:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;library(sp)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;library(maptools)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;library(raster)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;library(rgdal)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;library(rgeos)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;sites=cbind(rnorm(10), rnorm(10))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;plot(sites)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;points=SpatialPoints(sites) #make points spatial&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;plot(points)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;#create dataframe to store SLDF&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data=data.frame(1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;colnames(data)="ID"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;#creates many SpatialLine objects and stores at list&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;all.lines=list()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;for (i in 1:length(points)){&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; l1 &amp;lt;- apply(points[-i]@coords, 1, function(x) Line(rbind(x, points&lt;I&gt;@coords)))&lt;/I&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; l1 &amp;lt;- lapply(l1, FUN = function(x) {SpatialLines(LinesList = list(Lines(x, ID = paste( "ID", rnorm(1), sep=""))))})&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; l1=lapply(l1, FUN=function(x) {SpatialLinesDataFrame(x, data, match.ID=FALSE)})&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; all.lines &amp;lt;- c(all.lines, l1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;site.lines=all.lines[1:(length(all.lines)/2)] #grab only one path between&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;plot(points) #create plot space with points&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;#loop through to plot all SpatialLinesDF&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;for (i in 1:length(site.lines)) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;plot(site.lines[&lt;I&gt;], add=TRUE)&lt;/I&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;do.call("rbind",site.lines) #need to figure out how to get unique ID's for each object&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;Travis Gallo&lt;/P&gt;&lt;P&gt;Postdoctoral Researcher&lt;/P&gt;&lt;P&gt;Lincoln Park Zoo - Urban Wildlife Institute&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 05 Aug 2016 16:43:20 GMT</pubDate>
    <dc:creator>TravisGallo</dc:creator>
    <dc:date>2016-08-05T16:43:20Z</dc:date>
    <item>
      <title>Having trouble with rbind() and SpatialLinesDataFrame</title>
      <link>https://community.esri.com/t5/data-management-questions/having-trouble-with-rbind-and/m-p/278219#M16024</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am using R for some spatial data management and have the following problem:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am getting the following error when trying to rbind several SpatialLinesDataFrames. I have been having a lot of trouble with ID's, in general, and have created a few workarounds further up in the code, but I am stuck here. Any info would be great!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Error in SpatialLinesDataFrame(ll, df) : &lt;/P&gt;&lt;P&gt;&amp;nbsp; row.names of data and Lines IDs do not match&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sample code up to the point of throwing the error:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;library(sp)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;library(maptools)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;library(raster)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;library(rgdal)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;library(rgeos)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;sites=cbind(rnorm(10), rnorm(10))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;plot(sites)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;points=SpatialPoints(sites) #make points spatial&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;plot(points)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;#create dataframe to store SLDF&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data=data.frame(1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;colnames(data)="ID"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;#creates many SpatialLine objects and stores at list&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;all.lines=list()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;for (i in 1:length(points)){&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; l1 &amp;lt;- apply(points[-i]@coords, 1, function(x) Line(rbind(x, points&lt;I&gt;@coords)))&lt;/I&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; l1 &amp;lt;- lapply(l1, FUN = function(x) {SpatialLines(LinesList = list(Lines(x, ID = paste( "ID", rnorm(1), sep=""))))})&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; l1=lapply(l1, FUN=function(x) {SpatialLinesDataFrame(x, data, match.ID=FALSE)})&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; all.lines &amp;lt;- c(all.lines, l1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;site.lines=all.lines[1:(length(all.lines)/2)] #grab only one path between&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;plot(points) #create plot space with points&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;#loop through to plot all SpatialLinesDF&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;for (i in 1:length(site.lines)) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;plot(site.lines[&lt;I&gt;], add=TRUE)&lt;/I&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;do.call("rbind",site.lines) #need to figure out how to get unique ID's for each object&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;Travis Gallo&lt;/P&gt;&lt;P&gt;Postdoctoral Researcher&lt;/P&gt;&lt;P&gt;Lincoln Park Zoo - Urban Wildlife Institute&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Aug 2016 16:43:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/having-trouble-with-rbind-and/m-p/278219#M16024</guid>
      <dc:creator>TravisGallo</dc:creator>
      <dc:date>2016-08-05T16:43:20Z</dc:date>
    </item>
  </channel>
</rss>

