1

I converted a csv file to projected SpatialPointsDataFrame in R, input it to bkde2D, converted the result to raster, saved the raster to a TIFF, and input that raster into the GME Isopleth tool.

Here is my R code:

    data = read.csv("_PolarBearData.csv", na.strings = "NA", header = T)
    oldproj = "+proj=longlat +ellps=WGS84 +datum=WGS84"
    myproj = "+proj=stere +lat_0=90 +lon_0=-55 +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +towgs84=0,0,0"
    coords = cbind(data$longitude, data$latitude)
    spdata = SpatialPointsDataFrame(coords, data, proj4string=CRS(oldproj))
    # ensure it's projected
    spdata = spTransform(spdata, CRS(myproj))

    # KDE parameters
    xy = cbind(coordinates(spdata)[,1], coordinates(spdata[,2])
    bandwidth = 34390
    grid_x = 130
    grid_y = 288

    # Run KDE and save to raster TIFF
    datakernel = bkde2D(xy, bandwidth, gridsize=c(grid_x, grid_y))
    ras = raster(list(x=datakernel$x1, y=datakernel$x2, z=datakernel$fhat))
    writeraster(ras, paste("mydata", '.tif', sep=''), "GTiff", overwrite=T)

Next I ran this GME code to produce 95% volume contours:

isopleth(in="I:\Data\mydata.tif", 
         out="I:\Data\Contours.gdb!mylines", 
         quantiles=c(.95), 
         poly="I:\Data\Contours.gdb!mypoly");

Here is an image of my output: Bad GME Isopleth

Black-to-white raster (background) represents a KDE generated in R with "bkde2D" from the KernSmooth package. The yellow points were the input to the KDE. The red line shows the 95% isopleth generated in GME. GME is stretching the contours south when the input is an untampered TIFF from R, but otherwise, if the raster is from Arc for instance, GME produces correct contours. Why does this happen?

UPDATE: I should also mention that I added the raster from R directly into ArcMap, and it had an unknown CRS even though I specified it in R (at least, for the input). I tried using Define Projection to fix this, but GME still produces the same output. The raster itself has coordinates that make sense (it matches the point clusters in the image), but GME is not producing good isopleths from it.

1

1 Answer 1

1

No idea as to where GME may be failing. The software is opaque, with no source code to examine. As such, there is no way to know what method has been implemented or what the source of the problem may be.

Here is a solution for deriving percent volume in R. It may be good for you to compare results to ensure that there are no issues with your data.

2
  • Thank you so much! I will look into this. Earlier today I tried to use quantile with rasterToPolygons, passing in clump(ras>=quantile), but it produced these strange, not very smooth, small contours around my data. Not even sure if clump would produce what I want in theory.
    – Wassadamo
    Commented Sep 16, 2015 at 0:26
  • That raster.vol function, along with rasterToPolygons(x=p95, fun=function(x) {x==1}, dissolve=T) does the trick. Thanks!
    – Wassadamo
    Commented Sep 21, 2015 at 16:57

Your Answer

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

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