-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_lines_from_python.R
More file actions
37 lines (25 loc) · 1.07 KB
/
Copy pathcreate_lines_from_python.R
File metadata and controls
37 lines (25 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
options(warn=-1)
# Load libraries
packages <- c('rgdal', 'raster', 'sp')
lapply(packages, require, character.only = TRUE)
# setwd
#setwd('D:/Sugarcane_Project/201601_Sugar_Bacolod_sugarcanfields_zone_1/orthomosaics/')
# Fetch command line arguments
myArgs <- commandArgs(trailingOnly = TRUE)
## LOAD PYTHON RESULTS ##
ras <- raster(paste(myArgs,'/ndvi_f6.tif', sep = ''))
epsg <- crs(ras)
linecoords <- read.table(paste(myArgs,'/rotatedlines.txt', sep = ''))
## EXTRACT LINES ##
begin.coord <- data.frame(lon=c(linecoords[,1]), lat=c(linecoords[,2]))
end.coord <- data.frame(lon=c(linecoords[,3]), lat=c(linecoords[,4]))
## raw list to store Lines objects
rawlist <- vector("list", nrow(begin.coord))
for (i in seq_along(rawlist)) {
rawlist[[i]] <- Lines(list(Line(rbind(begin.coord[i,], end.coord[i,]))), as.character(i))
}
splines <- SpatialLines(rawlist, proj4string = epsg)
splinesdf <- SpatialLinesDataFrame(splines, linecoords, match.ID = FALSE)
# write a shapefile
writeOGR(splinesdf, (paste(myArgs, sep = '')), '/croprows', driver="ESRI Shapefile")
cat('Shapefile created')