Have a look at ?contour3d in the misc3d package. I found the code used by
plot(UD) by following this trail:

str(UD)
ks:::plot.kde
ks:::plotkde.3d

In there you find this, where "fhat" is your "UD":

 contour3d(fhat$estimate, level = hts[nc - i + 1], x =
fhat$eval.points[[1]],
            y = fhat$eval.points[[2]], z = fhat$eval.points[[3]],
            add = TRUE, color = colors[i], alpha = alphavec[i],
            box = FALSE, axes = FALSE, ...)

So, that will return the triangulation if we ask for it:

tri <_ contour3d(UD$estimate, level = quantile(UD$estimate, 0.95), x =
UD$eval.points[[1]], y = UD$eval.points[[2]], z = UD$eval.points[[3]])

plot(tri)

Still though, getting that into a GIS is not trivial - it's not going to
work as an ESRI TIN. I wonder if what you really want is to get 2D slices
out of the 3d array?




On Sat, Apr 13, 2013 at 3:31 PM, Andrew Duff <andrewaduff@gmail.com> wrote:

> Thanks a lot Michael that was very helpful.  It seems like you might be
> able
> to make a TIN from one of the contour levels, say 75% or something.  I'm
> not
> really sure how to get to those isosurface vertex coordinates for a given
> contour level.  Is that possible in R.
>
> -----Original Message-----
> From: r-sig-geo-bounces@r-project.org
> [mailto:r-sig-geo-bounces@r-project.org] On Behalf Of Michael Sumner
> Sent: Friday, April 12, 2013 2:06 PM
> To: Duff, Andrew A (DFW)
> Cc: r-sig-geo@r-project.org
> Subject: Re: [R-sig-Geo] 3D KDE to Triangular Irregular Network
>
> A TIN cannot represent that data structure, the plot shows multiple
> surfaces
> that wrap around in 3D. (A TIN cannot do that). The plot is made by
> "contouring" (isosurfaces) from a 3D array.
>
> You can represent the array in NetCDF, and maybe your GIS can read that.
> Otherwise you could do the same as here but create a 2D raster for every
> slice in the 3rd dimension and reconstruct over there.
>
> Bare bones using raster to NetCDF:
>
> library(raster)
> r <- brick(UD$estimate, xmn = min(UD$eval.points[[1]]), xmx =
> max(UD$eval.points[[1]]),
>   ymn = min(UD$eval.points[[2]]), ymx = max(UD$eval.points[[2]]))
>
> ## Plot each 3D slice
> plot(r)
>
> ## write to NetCDF, you need ncdf or ncdf4 package writeRaster(r, "file.nc
> ")
>
> See ?writeRaster for further options to add descriptors to the file, and
> you
> will likely need to worry about the orientation when making the raster
> object.
>
>
>
> On Sat, Apr 13, 2013 at 4:29 AM, Duff, Andrew A (DFW) <
> Andrew.Duff@dfw.wa.gov> wrote:
>
> > I am interested in being able to export the results of a 3 dimensional
> > kernel density estimate from the ks package in R to a format that
> > could be viewed in 3D GIS application such as ESRI's ArcScene or
> > ArcGlobe.  I want to example the use of airspace in relation to
> > terrain features.  A TIN seems to be the most logical geospatial data
> > structure that would support taking the 3D kde output into GIS.  Does
> > anybody have any ideas on how to get from a 3D kde output in ks to a
> > tin.  A self-contained sample of generating the kde is below.
> >
> > ###sample
> > library(ks)
> > df <- data.frame("x"=sample(1:200, 10), "y"=sample(1:200, 10),
> > "z"=sample(1:500, 10))
> > Hpi1 <- Hpi(x = df)
> > UD <- kde(x=df, H=Hpi1)
> > plot(UD)
> >
> > Thanks in advance.
> >
> >         [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
>
>
>
> --
> Michael Sumner
> Hobart, Australia
> e-mail: mdsumner@gmail.com
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>


-- 
Michael Sumner
Hobart, Australia
e-mail: mdsumner@gmail.com

	[[alternative HTML version deleted]]

