Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Laboratory Week 2 <96>
- ## Sample of Programming Structures and Batch Processing:
- ## Created by: Forrest R. Stevens
- ## Modified by: Matthew Marsik
- ## September 4, 2014
- ## The strPath variable will need to change based on where you
- ## unzipped your lab folders for this week:
- strPath <- "H:/tmp/"
- booWriteHeader <- FALSE
- vecTiles <- c("one", "two")
- intTileCount <- length(vecTiles)
- for (intTile in 1:intTileCount) {
- outFileName <- paste(strPath, "output/tile-", vecTiles[intTile], ".txt", sep="")
- outFile <- file(outFileName, "w")
- print(outFileName)
- if (booWriteHeader == TRUE) {
- strHeader <- "ncols 10\n"
- strHeader <- paste(strHeader, "nrows 10\n", sep="")
- strHeader <- paste(strHeader, "xllcorner ", (intTile * 10), "\n", sep="")
- strHeader <- paste(strHeader, "yllcorner ", (intTile * 10), "\n", sep="")
- strHeader <- paste(strHeader, "cellsize 1\n", sep="")
- strHeader <- paste(strHeader, "NODATA_VALUE -9999\n", sep="")
- cat(strHeader, file=outFile)
- } else {
- print("WARNING: No header included!")
- }
- matTile <- matrix(NA, nrow=10, ncol=10)
- for (intRow in 1:10) {
- for (intColumn in 1:10) {
- strInFileName <- paste(strPath, "data/tile-", vecTiles[intTile], "_r", intRow, "_c", intColumn, ".txt", sep="")
- inFile <- file(strInFileName, "r")
- strValue <- readLines(inFile)
- cat(paste(strValue, " ", sep=""), file=outFile)
- matTile[intRow, intColumn] = as.numeric(strValue)
- close(inFile)
- }
- cat("\n", file=outFile)
- }
- close(outFile)
- print(matTile)
- }
- print("Data preparation finished!")
- #print("Convert data to images:")
- ### The following command invokes a Python script that will convert
- ### our raw ASCII files into images for viewing in ArcGIS. You
- ### should never run source code without looking at it first.
- ### There may be things you need to edit in order for it to run
- ### correctly (hint, hint)!
- ### NOTE: You may need to change the path to locate the Python
- ### executable for your particular version of ArcGIS/Python:
- #system(paste("C:/Python27/ArcGIS10.1/python.exe ", strPath, "src/data_convert.py", sep=""))
- #print("Data processing finished!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement