Skip to content

Instantly share code, notes, and snippets.

@marcellobenigno
Last active August 29, 2015 14:02
Show Gist options
  • Save marcellobenigno/335a9635bb0a4cf94d77 to your computer and use it in GitHub Desktop.
Save marcellobenigno/335a9635bb0a4cf94d77 to your computer and use it in GitHub Desktop.
Perfil Longitudinal de um rio utilizando o GRASS e o R
# 1) Criação de um camada de pontos, contendo os vértices do rio principal
v.to.points -i -v -t in=out_dem_filled_mainchannel out=mchannel_pts type=line dmax=1000
# 2) Exportação dos vértices para um arquivo txt
v.out.ascii mchannel_pts > coords.txt
# 3) Remoção dos pipes ("|") e da coluna cat do arquivo txt
cat coords.txt | awk -F "|" '{print $1,''$2}' > xy.txt
# 4) Substituição dos espaços por vírgulas
sed -i "s/ /,/g" xy.txt
# 5) Criação do arquivo txt contendo as distâncias e as elevações do perfil
cat xy.txt | r.profile input=dem output=profile.txt
# 6) Início da sessão do R
R
# 7) Importação do arquivo txt
profile <- read.table('profile.txt', header=F, sep=" ",col.names=c('distance','elev'))
# 8) Plotagem do gráfico
plot(profile$distance/1000, profile$elev, axes='true', xlab='Distância (km)',
ylab='Elevações (m)', main='Perfil Longitudinal do Rio Principal', type='l', col='blue')
# 9) Adição do Grid de coordenadas
grid()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment