Advertisement
altoidnerd

R

Sep 9th, 2014
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 2.60 KB | None | 0 0
  1. ##      Laboratory Week 2 <96>
  2. ##              Sample of Programming Structures and Batch Processing:
  3. ##      Created by: Forrest R. Stevens
  4. ##  Modified by: Matthew Marsik
  5. ##      September 4, 2014
  6.  
  7.  
  8. ##      The strPath variable will need to change based on where you
  9. ##              unzipped your lab folders for this week:
  10. strPath <- "H:/tmp/"
  11.  
  12. booWriteHeader <- FALSE
  13. vecTiles <- c("one", "two")
  14.  
  15. intTileCount <- length(vecTiles)
  16.  
  17. for (intTile in 1:intTileCount) {
  18.         outFileName <- paste(strPath, "output/tile-", vecTiles[intTile], ".txt", sep="")
  19.         outFile <- file(outFileName, "w")
  20.         print(outFileName)
  21.  
  22.         if (booWriteHeader == TRUE) {
  23.                 strHeader <- "ncols 10\n"
  24.                 strHeader <- paste(strHeader, "nrows 10\n", sep="")
  25.                 strHeader <- paste(strHeader, "xllcorner ", (intTile * 10), "\n", sep="")
  26.                 strHeader <- paste(strHeader, "yllcorner ", (intTile * 10), "\n", sep="")
  27.                 strHeader <- paste(strHeader, "cellsize 1\n", sep="")
  28.                 strHeader <- paste(strHeader, "NODATA_VALUE -9999\n", sep="")
  29.                 cat(strHeader, file=outFile)
  30.         } else {
  31.                 print("WARNING: No header included!")
  32.         }
  33.  
  34.         matTile <- matrix(NA, nrow=10, ncol=10)
  35.  
  36.         for (intRow in 1:10) {
  37.  
  38.                 for (intColumn in 1:10) {
  39.  
  40.                         strInFileName <- paste(strPath, "data/tile-", vecTiles[intTile], "_r", intRow, "_c", intColumn, ".txt", sep="")
  41.                         inFile <- file(strInFileName, "r")
  42.                         strValue <- readLines(inFile)
  43.  
  44.                         cat(paste(strValue, " ", sep=""), file=outFile)
  45.                         matTile[intRow, intColumn] = as.numeric(strValue)
  46.  
  47.                         close(inFile)
  48.                 }
  49.  
  50.                 cat("\n", file=outFile)
  51.         }
  52.  
  53.         close(outFile)
  54.         print(matTile)
  55. }
  56.  
  57. print("Data preparation finished!")
  58.  
  59.  
  60.  
  61. #print("Convert data to images:")
  62. ###     The following command invokes a Python script that will convert
  63. ###             our raw ASCII files into images for viewing in ArcGIS. You
  64. ###             should never run source code without looking at it first.
  65. ###             There may be things you need to edit in order for it to run
  66. ###             correctly (hint, hint)!
  67. ###     NOTE: You may need to change the path to locate the Python
  68. ###             executable for your particular version of ArcGIS/Python:
  69. #system(paste("C:/Python27/ArcGIS10.1/python.exe ", strPath, "src/data_convert.py", sep=""))
  70. #print("Data processing finished!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement