0

I am trying to get an altitude raster to coincide with a working spatial polygon dataframe that shapes the region with data from an .nc file. The .nc file, and thus the derived spatial polygon dataframe, came with no crs. Instead, I gave it one that coincides with location data I will later use.

My problem is that I do not get to correctly overlap the altitude raster and the polygon, despite following what seems to be the required approach.

Here is the data: alt=https:https://www.dropbox.com/t/DmdmofDGvPPsP3uF r=https://www.dropbox.com/sh/uen3y3vig9jh1ij/AACqvB9bNC7VLcEHmjoKOcPga?dl=0

alt=raster("/Users/agus/Dropbox/geo resources/rasters/alt.grd")
polys <- as(r, "SpatialPolygonsDataFrame")
r1=rasterize(polys,pCTMAXe)
alt=crop(alt,r1)
altr=projectRaster(from=alt,to=r1,res=res(r1))
plot(r1)
plot(altr,add=T)

The objects have similar extent, resolution and projection, but plots do not overlap,why?!

I have tried options in: How to rasterize an object of class SpatialPolygonsDataframe in R https://www.rdocumentation.org/packages/raster/versions/2.5-8/topics/projectRaster Handling raster data in a "rotated pole projection" with R? Plotting spatial data when two spatial objects have different CRS using R

8
  • Your altitude raster is not actually a grid but sth that looks like a summary of your grid created by raster package? Check the content with e.g. Notepad++, just 1 KB in size.
    – dimfalk
    Commented Oct 21, 2022 at 21:51
  • Thank you, I changed that. Now both the .grd and .gri files are in the link Commented Oct 24, 2022 at 8:09
  • Your alitude is fine, but your polygon seems to be stretched in all dimensions, so you should try to attribute the crs properly... Where you got this nc file from? Would you mind sharing also? If spatial reference is not provided in the file, is there some documentation available?
    – dimfalk
    Commented Oct 24, 2022 at 8:46
  • What about the other questions? :)
    – dimfalk
    Commented Oct 25, 2022 at 10:40
  • 1
    Unfortunately, I'm not really familiar with reference systems in this area. I tried several proposed ones by projfinder.com, but was not able to align your shape with the actual coastline. My guess is your data also requires a transformation, not only a crs assignment. However, you do not need to reproject your altitude raster data; you need to properly georeference your vector data.
    – dimfalk
    Commented Oct 27, 2022 at 9:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.