Linear referencing in R

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Linear referencing in R

Rubem Dornas
Hi, people! I hope I'll be not to speculative in my question and that you
can comprehend my problem.

Well, I have a railroad shapefile and I have two csv files corresponding to
the topography in each side of the railroad. The csv are organized in this
way:

ID_topo, from_km, to_km, height
1, 0, 1.91, 15
2, 1.91, 2.23, -3

I created a point shapefile for each meter of the railroad and then I
proceeded with a join (not spatial) between the from_km of the topography
data frame and the km mark (km_calc) from the point railroad.

My goal is to create shapefiles for each of the railroadside topography.
The issue is that when I try to make a new line shapefile from topography
based on the points of the railroad, what I get is a line that has doesn't
follow the curvature of the railroad. Using the example of the csv above,
what I get are several straight lines linked by the from_km to to_km. (Here
is a link to a print screen from QGIS:
https://www.dropbox.com/s/erfsst8pasoqj64/Captura%20de%20tela%202018-09-28%2019.49.47.png?dl=0
<http://Image>)

Maybe it is a little bit difficult to me to explain exactly the problem,
but any doubts, please ask. The files and the script I'm using are on the
following github: https://github.com/rdornas/raileco

Thank you very much indeed in advance!

*Rubem A. P. Dornas*
Celular: (31) 99642-5102
PPG Análise e Modelagem de Sistemas Ambientais
Instituto de Geociências - Universidade Federal de Minas Gerais
Currículo Lattes: http://lattes.cnpq.br/7197154832267712

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Linear referencing in R

Kent Johnson
You need to snip out the sections of the railroad file rather than
connecting the endpoints. Maybe this is closer to what you want?

segments = topoESQ_comp %>%
  filter(to_km <= 871) %>%
  purrr::pmap(function(from_km, to_km, ...) {
    st_linestring(do.call(rbind,
Estacas_1m$geometry[((1000*from_km):(1000*to_km))+1]))
}) %>%
  st_sfc

Kent Johnson


> Date: Fri, 28 Sep 2018 19:52:03 -0300
> From: Rubem Dornas <[hidden email]>
> To: [hidden email]
> Subject: [R-sig-Geo] Linear referencing in R
> Hi, people! I hope I'll be not to speculative in my question and that you
> can comprehend my problem.
>
> Well, I have a railroad shapefile and I have two csv files corresponding to
> the topography in each side of the railroad. The csv are organized in this
> way:
>
> ID_topo, from_km, to_km, height
> 1, 0, 1.91, 15
> 2, 1.91, 2.23, -3
>
> I created a point shapefile for each meter of the railroad and then I
> proceeded with a join (not spatial) between the from_km of the topography
> data frame and the km mark (km_calc) from the point railroad.
>
> My goal is to create shapefiles for each of the railroadside topography.
> The issue is that when I try to make a new line shapefile from topography
> based on the points of the railroad, what I get is a line that has doesn't
> follow the curvature of the railroad. Using the example of the csv above,
> what I get are several straight lines linked by the from_km to to_km. (Here
> is a link to a print screen from QGIS:
>
> https://www.dropbox.com/s/erfsst8pasoqj64/Captura%20de%20tela%202018-09-28%2019.49.47.png?dl=0
> <http://Image>)
>
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Linear referencing in R

Rubem Dornas
Thank you very much, Kent! This is pretty much what I was looking for. The
only problem is that the new shapefile didn't come with the attributes from
the topoESQ data frame. I made some adjustments, that probably are not the
best ones, but I still made it work.

topoESQ_comp <- read.csv("Files/Topo_estacas_E.csv") %>%
  select(-1) %>%
  rename(height = Altura,
         side = Lado) %>%
  filter(to_km <= 871)

Estacas_1m <- st_read("Files/ESTACAS_1m_EFC_0-871_Policonic_SIRGAS.shp")

topoESQ_comp %>%
  purrr::pmap(function(from_km, to_km, ...) {
    st_linestring(do.call(rbind,
Estacas_1m$geometry[((1000*from_km):(1000*to_km))+1]))
  }) %>%
  st_sfc(., crs = 5880) %>%
  cbind(topoESQ_comp, .) %>%
  st_as_sf(.) %>%
  st_write(., dsn = "Files/Topo_esq.shp", delete_dsn = T)

Best regards,

Rubem Dornas.


Em sáb, 29 de set de 2018 às 22:17, Kent Johnson <[hidden email]>
escreveu:

> You need to snip out the sections of the railroad file rather than
> connecting the endpoints. Maybe this is closer to what you want?
>
> segments = topoESQ_comp %>%
>   filter(to_km <= 871) %>%
>   purrr::pmap(function(from_km, to_km, ...) {
>     st_linestring(do.call(rbind,
> Estacas_1m$geometry[((1000*from_km):(1000*to_km))+1]))
> }) %>%
>   st_sfc
>
> Kent Johnson
>
>
>> Date: Fri, 28 Sep 2018 19:52:03 -0300
>> From: Rubem Dornas <[hidden email]>
>> To: [hidden email]
>> Subject: [R-sig-Geo] Linear referencing in R
>> Hi, people! I hope I'll be not to speculative in my question and that you
>> can comprehend my problem.
>>
>> Well, I have a railroad shapefile and I have two csv files corresponding
>> to
>> the topography in each side of the railroad. The csv are organized in this
>> way:
>>
>> ID_topo, from_km, to_km, height
>> 1, 0, 1.91, 15
>> 2, 1.91, 2.23, -3
>>
>> I created a point shapefile for each meter of the railroad and then I
>> proceeded with a join (not spatial) between the from_km of the topography
>> data frame and the km mark (km_calc) from the point railroad.
>>
>> My goal is to create shapefiles for each of the railroadside topography.
>> The issue is that when I try to make a new line shapefile from topography
>> based on the points of the railroad, what I get is a line that has doesn't
>> follow the curvature of the railroad. Using the example of the csv above,
>> what I get are several straight lines linked by the from_km to to_km.
>> (Here
>> is a link to a print screen from QGIS:
>>
>> https://www.dropbox.com/s/erfsst8pasoqj64/Captura%20de%20tela%202018-09-28%2019.49.47.png?dl=0
>> <http://Image>)
>>
>>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo