'Replace coordinates in API data character string Using for loop in R
I am trying to run a for loop on the following Gage Data
nfgages<-read.csv("C:\\Users\\Jay_Oliver\\Documents\\Texas EFlow Spatial\\Missing Watersheds.csv", colClasses = c("SOURCE_FEA" = "character"))
lnfgages<-as.list(nfgages$Gage.Number)
head(nfgages)
FID REACHCODE SOURCE_FEA Gage.Number POINT_Y POINT_X
1 1 1.11302e+13 7315600 7315600 33.88263 -97.65270
2 2 1.11401e+13 7331700 7331700 33.80217 -96.58093
3 6 1.11302e+13 7311622 7311622 33.86995 -99.94693
4 7 1.11302e+13 7316200 7316200 33.70243 -96.84774
5 9 1.11401e+13 7335390 7335390 33.84773 -95.55042
6 10 1.11201e+13 7299200 7299200 34.57315 -100.74567
What I am trying to do is set up an API connection using the following coordinates, but I am running into issues when trying to replace the coordinates through the for loop. I tried placing Point_Y[i], Point_X[i] but as its a character string, it is not replacing the values but rather copying the original input over and over again producing an error.
for (i in 1:length(lnfgages)) {
data = '{ "location": [Point_Y[i], Point_x[i]],
"snappingOn": true, "simplify": 0.0001, "dataSource": "nhd"}'
}
headers = c(
`accept` = 'application/json',
`Authorization` = 'Token {Your API Token Here}',
`Content-Type` = 'application/json',
`X-CSRFToken` = '9P7k41yjWNqVtysnv8iv2KfeW4vadHih1wKZWkN41Mln249QxEZVZHwfvKcufvBO',
'Accept-Encoding' = 'gzip'
)
# Location can be substituted with any location
data = '{ "location": [Point_Y[i], Point_x[i]],
"snappingOn": true, "simplify": 0.0001, "dataSource": "nhd"}'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
