Polygon made from a raster extent does not display exactly the same as the raster in google earth pro.

Does anyone else have this problem?

 new_crs<-crs(dem_10)#get latlon
 r2<-projectRaster(r1, crs=new_crs)# project to latlon
 p <- as((extent(r2)), 'SpatialPolygons')# get extent polygon
 KML(r2, file="example_data.kml")# write raster to kml
 KML(p, file="example_data_extent.kml")#write polyogn to kml

raster extent polygon not matching raster extent


It looks like your original raster, r1, wasn't in lat-long (you don't tell us anything about it, so its a guess). When you project this into lat-long for r2, your original raster gets rotated slightly, and padded out with missing values (NA).

This makes the extent in lat-long not be the same as the extent in the original CRS - which is what you are seeing. The red box in the image is aligned to the lat-long axes, and you can see it touching the non-NA pixels at four points.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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