Obtain array of Station/Elevation for a cross section in RAS Controller

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

Obtain array of Station/Elevation for a cross section in RAS Controller

Anand Kulkarni
Hi Chris,
I am looking for a method obtaining any array or string of Station values and their corresponding ground elevation for a give cross-section (of a river/reach).
I searched in the user guide of Automating HEC-RAS but could not get.

Alternatively, I tried parsing the *.g01 (Geometry file) but it can complicate things when we have 10 km long cross-sections.

I would like to know if there is any method (or can be built) in using RAS controller methods.

Thanks
Anand K  
Reply | Threaded
Open this post in threaded view
|

Re: Obtain array of Station/Elevation for a cross section in RAS Controller

Chris G.
Administrator
Hi Amanda, Unfortunately, parsing the g01 file is the only way to do this. 

Chris

Sent from my iPhone

On May 23, 2018, at 12:15 AM, Anand Kulkarni [via HEC-RAS Help] <[hidden email]> wrote:

Hi Chris,
I am looking for a method obtaining any array or string of Station values and their corresponding ground elevation for a give cross-section (of a river/reach).
I searched in the user guide of Automating HEC-RAS but could not get.

Alternatively, I tried parsing the *.g01 (Geometry file) but it can complicate things when we have 10 km long cross-sections.

I would like to know if there is any method (or can be built) in using RAS controller methods.

Thanks
Anand K  


To start a new topic under HECRAS Controller, email [hidden email]
To unsubscribe from HECRAS Controller, click here.
NAML
Chris G.
@RASModel
www.therassolution.com
Reply | Threaded
Open this post in threaded view
|

Re: Obtain array of Station/Elevation for a cross section in RAS Controller

Toby
Hi,

You can accomplish this by using the .g01.hdf or .p01.hdf file.  

Here is an R script to get you started.  This works in 5.0.3.  You would need to update a line or two to get it to work in 5.0.4.

cheers,

################################################

# To access HDF5 files in R, we will use the rhdf5 library which is part of the
#Bioconductor suite of R libraries.

#install rhdf5 package
#source("http://bioconductor.org/biocLite.R")
#biocLite("rhdf5")

# load libraries
library(raster)
library(rhdf5)
library(rgdal)
library(sp)
library(maptools)
library(rgeos)

# #####################################################################################################
# # Cross-section compairson
#
# # set working directory
# setwd("C:\\Users\\yourComp\\Documents\\myRAS")
#
# # define the file name as an object
# plan<-"model.g01.hdf"
#  
# proj 4 string - look to www.spatialreference.org
# sp.Ref<- "+proj=lcc +lat_1=38.33333333333334 +lat_2=39.83333333333334 +lat_0=37.66666666666666 +lon_0=-122
# +x_0=2000000 +y_0=500000.0000000001 +datum=NAD83 +units=us-ft +no_defs +ellps=GRS80 +towgs84=0,0,0"
#
# #####################################################################################################
# # Use of function...
#
# ras.data<-RAS_XS_to_R(plan, SP.Ref=NULL)
#
# #Unpack xs data
# xs_lines<-ras.data[[1]]
#
# #Unpack profile data
# profile<-ras.data[[2]]
#
#####################################################################################################
#function

RAS_XS_to_R<-function(plan, sp.Ref=NULL){

#####################################################################################################
  #Extract xs metadata
 
  path<-"Geometry/Cross Sections/River Names"
  riverNames <- t(h5read(plan, path))
  #trim trailing whitespace
  riverNames<-sub("\\s+$", "", riverNames)
 
  path<-"Geometry/Cross Sections/Reach Names"
  reachNames <- t(h5read(plan, path))
  #trim trailing whitespace
  reachNames<-sub("\\s+$", "", reachNames)
 
  path<-"Geometry/Cross Sections/River Stations"
  riverStations <- t(h5read(plan, path))
  #trim trailing whitespace
  riverStations<-sub("\\s+$", "", riverStations)
 
  path<-"Geometry/Cross Sections/Node Descriptions"
  nodeDesc <- t(h5read(plan, path))
  #remove \r\n
  nodeDesc<-as.character(gsub("\r\n"," ",nodeDesc))
 
  # create reach names
  xsNames<-paste0(riverNames," ",reachNames," ",riverStations)
 
  #find the River channel reach lengths
  path<-"Geometry/Cross Sections/Lengths"
  reachLengths <- t(h5read(plan, path))
 
  #####################################################################################################
  # Get geometry
 
  # get xs point count
  path<-"Geometry/Cross Sections/Polyline Parts"
  xs.parts <- h5read(plan, path)
  xs.parts.sum<-cumsum(xs.parts[2,])
 
  # get xs coords
  path<-"Geometry/Cross Sections/Polyline Points"
  xs.points <- t(h5read(plan, path))
  nrow(xs.points)
 
  #####################################################################################################
  #Create XS lines
 
  tmp<-xs.points[1:xs.parts.sum[1],]
  xs_lines<-SpatialLines(list(Lines(list(Line(tmp)), ID = "1")))
 
  for(i in 2:length(xs.parts.sum)){
   
    tmp<-xs.points[(xs.parts.sum[i-1]+1):xs.parts.sum[i],]
   
    L.tmp <- SpatialLines(list(Lines(list(Line(tmp)), ID = as.character(i))))
   
    xs_lines <- spRbind(xs_lines, L.tmp)
   
  }# close i loop
 
  #create the spatial lines
  xs_lines<-SpatialLinesDataFrame(xs_lines,
                                  data.frame(xsNames=xsNames,rivNames=t(riverNames),reaNames=t(reachNames),
                                  rivSta=t(riverStations),Desc=nodeDesc,ReachLen=reachLengths))
 
  # Assign the sp ref if provided
  if(!is.null(sp.Ref)){
    crs(xs_lines)<-sp.Ref
  }
 
  #####################################################################################################
  # get cross section station and elevation data from RAS
 
  path<-"Geometry/Cross Sections/Station Elevation Info"
  eleInfo <- t(h5read(plan, path))

  path<-"Geometry/Cross Sections/Station Elevation Values"
  eleValue <- t(h5read(plan, path))

  # convert profile values to dataframe
  profile<-data.frame(station=eleValue[,1], elev=eleValue[,2])
 
  # assign each profile an id
  profile$id<-NA
  for(i in 1:nrow(eleInfo)){
    startID<-eleInfo[i,1]
    endID<-startID + eleInfo[i,2]
    profile$id[(startID+1):endID]<-i
  }#close i loop
 
  # give profile names ids
  xsNames<-data.frame(id=1:length(xsNames), names=xsNames)
  profile$xsName<-xsNames[match(profile$id,xsNames$id),"names"]
 
  # xs stationing may not start at zero!!!
  # correct for xs which do not start at 1
  for(i in 1:length(unique(profile$id))){
   
    index<-which(profile$id==i)
   
    if(profile[index,1][1]!=0){profile[index,1]<-profile[index,1]-profile[index,1][1]}
   
  }# close i loop

  return(list(xs_lines, profile))
 
}# close function
Reply | Threaded
Open this post in threaded view
|

Re: Obtain array of Station/Elevation for a cross section in RAS Controller

PaoloP
In reply to this post by Anand Kulkarni
Hi Anand,

you can download from www.m3eweb.it/products/ the App RAS to Excel and than copy part of the program that gets stations/elevations from .gxx file.

PaoloP
Reply | Threaded
Open this post in threaded view
|

Re: Obtain array of Station/Elevation for a cross section in RAS Controller

Anand Kulkarni
In reply to this post by Anand Kulkarni
Hi all,
Thanks for the reply that is encouraging. I will try out the methods.

Regards,
Anand K