-1

I have the following code to re-project my raster data. My problem is that when I change the projection, it seems that the resolution as well as pixel values change. I want to maintain the original file resolution and values.

NOTE THAT: Since some pixels have high values (indicating non-vegetated areas), changing resolution causes somehow to resample the pixels and creating messy pixel values.

library(raster)

# Create RasterLayer object
r <- raster('C:/test/1.tif')

# Define spatial reference 
sr <- "+proj=utm +zone=16  +datum=WGS84 +units=m " 

# Project Raster
projected_raster <- projectRaster(r, crs = sr)

# Write the RasterLayer to disk 
writeRaster(projected_raster, filename="C:/test/5.tif")

closed as unclear what you're asking by Spacedman, whyzar, BERA, Andre Silva, xunilk Jun 8 '18 at 4:21

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • What's the original coordinate reference system? Is it also in meters? – mkennedy Jun 6 '18 at 23:20
  • The original coordinate ref system is sinusoidal (hdf convertet to GeoTIFF from MODIS). – Seji Jun 7 '18 at 2:03
  • You really cant go from an orbital projection to a different projection in R, at least not reliably. There is a NASA software utility for this purpose. – Jeffrey Evans Jun 7 '18 at 3:44
  • we really need to see what your source raster looks like, and ideally get a copy of it or something of the same form. – Spacedman Jun 7 '18 at 14:56
2

Since you are not using a reference raster you can use the res argument in the function to control the output resolution of the raster. Just make sure that you define the correct resampling method for your data. With integer (nominal) data you want method="ngb" (nearest neighbor) and with floating point (continuous) data you want method="bilinear", which is the default. This is all detailed in the functions help, accessed using ?projectRaster.

  • I used res argument as follow but I get error also: projected_raster <- projectRaster(r, crs = sr, res="463.62 463.62") Error in (bb@xmax - bb@xmin)/xr : non-numeric argument to binary operator – Seji Jun 7 '18 at 1:59
  • 1
    You just provide a single value for a square grid cell. If you want different sizes for the x,y dimensions the you provide two values in a c() statement. The values has to be consistent with the output projection, eg., can't define meters for a geographic projection. – Jeffrey Evans Jun 7 '18 at 2:06
  • 1
    Instead of res="463.62,463.62" you do: res=c(463.62,463.62) - numbers, not a quoted string. – Spacedman Jun 7 '18 at 6:40
  • 1
    That's what method="ngb" fixes - it uses the nearest neighbour value, so it will always pick one of the values from the raster it is projecting, and never interpolate between values. Did you miss that from Jeffrey's answer? – Spacedman Jun 7 '18 at 15:05
  • 2
    @Seji, you really need to read up on the basics of GIS and spatial analysis. Resampling is a necessary part of reprojecting data. As mentioned in a previous comment, you need to use the NASA MRT utility to reproject from the MODIS sinsusodial project. You can download the utility from the LP DAAC site: lpdaac.usgs.gov/tools/modis_reprojection_tool We are trying to help you here but you need to listen! We would not be bringing up these issues if they were irrelevant. – Jeffrey Evans Jun 8 '18 at 17:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.