Optimale manier om hoogte data op te halen?

Van alles en nog wat geprobeerd. Zeer onduidelijk wat er nu precies mis gaat.

**Error in read.table(“C:\Users\Admin\Documents\_R_studio\coordinaten.csv”, : **
more columns than column names

(??)

Onderstaande de files.
Voor jouw wellicht misschien duidelijk?
@mluijben hoe werkt het bij jouw?

library(sp)
library(raster)
library(rAHNextract)
punten <- read.table("C:\\Users\\Admin\\Documents\\_R_studio\\coordinaten.csv", header = TRUE, sep=",")
alle_hoogtes <- mapply(ahn_point, name = punten$ID, X = punten$X, Y = punten$Y, dem = "DTM")
#C:\\Users\\Admin\\Documents\\_R Studio\\coordinaten.csv

#voeg resultaten samen met coordinaten in een tabel en maak kolom namen
alle_hoogtes_tabel_ruw <- data.frame("DTM", punten, alle_hoogtes)
colnames(alle_hoogtes_tabel_ruw) <- c("DEM", "ID", "X", "Y", "hoogte")
#View(alle_hoogtes_tabel_ruw)

#rond af alles af naar 2 decimalen
alle_hoogtes_tabel <- alle_hoogtes_tabel_ruw
is.num <- sapply(alle_hoogtes_tabel, is.numeric)
alle_hoogtes_tabel[is.num] <- lapply(alle_hoogtes_tabel[is.num], round, 2)


#sla hoogtes op als .csv bestand. Bestand word opgelsagen in je working directory (die je hierboven hebt ingesteld met setwd())
write.table(alle_hoogtes_tabel, "tests/heights/coordinaten_hoogtes.csv", sep=",", col.names = TRUE, row.names = FALSE)

Sample input

DEM,"ID","X","Y","hoogte"
DTM,1,113219.34,472445,0
DTM,2,113219.53,472445,0
DTM,3,113219.73,472445.82,0
DTM,4,113219.93,472445.86,0
DTM,5,113220.13,472445.91,0
DTM,6,113220.32,472445.9,0
DTM,7,113220.52,472445.99,0
DTM,8,113220.72,472446.03,0
DTM,9,113220.91,472446.07,0
DTM,10,113221.11,472446.11,0

Ik heb je sample input gebruikt en bij werkt het gewoon. Waneeer krijg je read table error?

Let trouwens wel op dat je van te voren niet al de DEM en hoogte kolom invult. Deze worden - als je mijn opgestuurde script gebruikt - automatisch toegevoegd. Als ze er al zijn, dan worden ze voor een tweede keer toegevoegd en verschuift alles.

Ik druk op het knopje ‘run script’ …
?

@halam: Volgens mij moet je rgdal ook aanzetten: > library(rgdal)

nee. Laden van rgdal en sp is niet meer nodig met de versie die jullie nu gebruiken. Dat zit nu allemaal in de package. Laden van library(raster) is wel nodig als je de ouput wilt plotten via plot().

@halam je probleem lijkt echt op dat je .csv niet goed wordt ingeladen. Dit zou kunnen komen doordat de .csv niet goed is samengesteld.

Jelle, verder met spoorzoeken.
Geprobeerd: als.txt
als csv MS-dos,
zonder dubbele “” “” …
je raadt het misschien wel. Het werkt nog niet. Maar heb jij niet een dataset waarvan jij weetdat het werkt (directory veranderem en viola)? Dat zou fijn zijn.

probeer eens dit bestand in te laden: https://www.dropbox.com/s/7lqhyf75uucr89n/sample.csv?dl=0

Een deel gaat al goed Jelle, maar het draait nog niet 100%
Ik krijg het niet voor elkaar dat het data wegschrijft naar een csv bestand.
Gebruik sample_out.csv in dezelfde directory, Bestand heb ik niet open staan

> write.table(alle_hoogtes_tabel, "\\sample_out.csv", sep=",", col.names = TRUE, row.names = FALSE)
Error in file(file, ifelse(append, "a", "w")) : 
  cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
  **cannot open file '\sample_out.csv': Permission denied**




[1] "Download raster image succeeded."
[1] "Intersecting raster. Getting elevation..."
[1] "Elevation of 5: -4.37 m."
AHN3 0.5 resolution DTM (maaiveld) selected.
trying URL 'https://geodata.nationaalgeoregister.nl/ahn3/wcs?SERVICE=WCS&VERSION=1.0.0&REQUEST=GetCoverage&COVERAGE=ahn3_05m_DTM&BBOX=113219.5,472445,113221,472446.5&CRS=EPSG:28992&RESPONSE_CRS=EPSG:28992&FORMAT=GEOTIFF_FLOAT32&WIDTH=3&HEIGHT=3'
Content type 'image/tiff' length 562 bytes
downloaded 562 bytes

etc.

There were 27 warnings (use warnings() to see them)

warnigs()

Warning messages:
1: In download_wcs_raster(wcsUrl = my_url, name = name_trim,  ... :
  Cropped WCS raster for 1  already exists and was overwritten.
2: In .local(x, y, ...) : Transforming SpatialPoints to the CRS of the Raster
3: In (function (name = "AHNelevation", X, Y, AHN = "AHN3",  ... :
  NAs introduced by coercion
4: In download_wcs_raster(wcsUrl = my_url, name = name_trim,  ... :
  Cropped WCS raster for 2  already exists and was overwritten.
5: In .local(x, y, ...) : Transforming SpatialPoints to the CRS of the Raster
6: In (function (name = "AHNelevation", X, Y, AHN = "AHN3",  ... :
  NAs introduced by coercion
7: In download_wcs_raster(wcsUrl = my_url, name = name_trim,  ... :
  Cropped WCS raster for 3  already exists and was overwritten.
8: In .local(x, y, ...) : Transforming SpatialPoints to the CRS of the Raster
9: In download_wcs_raster(wcsUrl = my_url, name = name_trim,  ... :
  Cropped WCS raster for 4  already exists and was overwritten.
10: In .local(x, y, ...) : Transforming SpatialPoints to the CRS of the Raster
11: In download_wcs_raster(wcsUrl = my_url, name = name_trim,  ... :
  Cropped WCS raster for 5  already exists and was overwritten.
12: In .local(x, y, ...) : Transforming SpatialPoints to the CRS of the Raster
13: In download_wcs_raster(wcsUrl = my_url, name = name_trim,  ... :
  Cropped WCS raster for 6  already exists and was overwritten.
14: In .local(x, y, ...) : Transforming SpatialPoints to the CRS of the Raster
15: In (function (name = "AHNelevation", X, Y, AHN = "AHN3",  ... :
  NAs introduced by coercion
16: In download_wcs_raster(wcsUrl = my_url, name = name_trim,  ... :
  Cropped WCS raster for 7  already exists and was overwritten.
17: In .local(x, y, ...) : Transforming SpatialPoints to the CRS of the Raster
18: In (function (name = "AHNelevation", X, Y, AHN = "AHN3",  ... :
  NAs introduced by coercion
19: In download_wcs_raster(wcsUrl = my_url, name = name_trim,  ... :
  Cropped WCS raster for 8  already exists and was overwritten.
20: In .local(x, y, ...) : Transforming SpatialPoints to the CRS of the Raster
21: In (function (name = "AHNelevation", X, Y, AHN = "AHN3",  ... :
  NAs introduced by coercion
22: In download_wcs_raster(wcsUrl = my_url, name = name_trim,  ... :
  Cropped WCS raster for 9  already exists and was overwritten.
23: In .local(x, y, ...) : Transforming SpatialPoints to the CRS of the Raster
24: In (function (name = "AHNelevation", X, Y, AHN = "AHN3",  ... :
  NAs introduced by coercion
25: In download_wcs_raster(wcsUrl = my_url, name = name_trim,  ... :
  Cropped WCS raster for 10  already exists and was overwritten.
26: In .local(x, y, ...) : Transforming SpatialPoints to the CRS of the Raster
27: In (function (name = "AHNelevation", X, Y, AHN = "AHN3",  ... :
  NAs introduced by coercion

Een ‘friendly reminder’ gezien de titel van het topic is: “Optimale manier om hoogte data op te halen?” het lijkt nu meer het: “Grote debug topic”. Er is dus een mismatch tussen wat de titel en de daadwerkelijke content van dit topic, wat voor andere bezoekers/lezers verwarrend kan zijn.

Misschien goed om deze discussie in een ander topic (met passende titel) te verplaatsten en/of naar github.com?

3 likes

Sorry, ik heb nog niet eerder gewerkt met Github en wil dit gedoe oplost verlaten. De hints zijn : warnings kunnen worden genegeerd en de manier waarop de output wordt aangeroepen.

Eureka. De oplossing die nu wel werkt : schrijf het path voluit!
Super handig Jelle!

C:\Users\Admin\Documents\_R_studio\sample_out.csv

Mee eens. Topic zal ik sluiten. Bij aanvullende vragen kan een nieuw topic worden gemaakt.