I've been struggling for half a day on what should be a simple problem... I have a data frame of lat/long coordinates that describe a region, and I want to draw a polygon around them so I can use that as a boundary (to be thrown at INLA, but those details aren't important). The coordinates are almost on a regular grid: there is some variation in latitude (because we're on a globe). If the coordinates were on a regular grid, I could use as.owin() to create a mask, and go on from there (I have code that will work). But as.owin() doesn't like unevenly spaced points. Can anyone suggest a way to sort this out? Preferable without having to mess around transforming the coordinates. Bob -- Bob O'Hara Biodiversity and Climate Research Centre Senckenberganlage 25 D-60325 Frankfurt am Main, Germany Tel: +49 69 798 40226 Mobile: +49 1515 888 5440 WWW: http://www.bik-f.de/root/index.php?page_id=219 Blog: http://occamstypewriter.org/boboh/ Journal of Negative Results - EEB: www.jnr-eeb.org [[alternative HTML version deleted]]
Not really sure I understand your constraints, but perhaps RSiteSearch("convex hull ") might help? --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. On August 15, 2014 7:51:37 AM PDT, Bob O'Hara <rni.boh at gmail.com> wrote:>I've been struggling for half a day on what should be a simple >problem... > >I have a data frame of lat/long coordinates that describe a region, and >I >want to draw a polygon around them so I can use that as a boundary (to >be >thrown at INLA, but those details aren't important). The coordinates >are >almost on a regular grid: there is some variation in latitude (because >we're on a globe). > >If the coordinates were on a regular grid, I could use as.owin() to >create >a mask, and go on from there (I have code that will work). But >as.owin() >doesn't like unevenly spaced points. > >Can anyone suggest a way to sort this out? Preferable without having to >mess around transforming the coordinates. > >Bob
Your question seems to need an answer to, "How do you find a convex hull on a sphere?" Google has many references. Clint Bowman INTERNET: clint at ecy.wa.gov Air Quality Modeler INTERNET: clint at math.utah.edu Department of Ecology VOICE: (360) 407-6815 PO Box 47600 FAX: (360) 407-7534 Olympia, WA 98504-7600 USPS: PO Box 47600, Olympia, WA 98504-7600 Parcels: 300 Desmond Drive, Lacey, WA 98503-1274 On Fri, 15 Aug 2014, Bob O'Hara wrote:> I've been struggling for half a day on what should be a simple problem... > > I have a data frame of lat/long coordinates that describe a region, and I > want to draw a polygon around them so I can use that as a boundary (to be > thrown at INLA, but those details aren't important). The coordinates are > almost on a regular grid: there is some variation in latitude (because > we're on a globe). > > If the coordinates were on a regular grid, I could use as.owin() to create > a mask, and go on from there (I have code that will work). But as.owin() > doesn't like unevenly spaced points. > > Can anyone suggest a way to sort this out? Preferable without having to > mess around transforming the coordinates. > > Bob > > -- > Bob O'Hara > > Biodiversity and Climate Research Centre > Senckenberganlage 25 > D-60325 Frankfurt am Main, > Germany > > Tel: +49 69 798 40226 > Mobile: +49 1515 888 5440 > WWW: http://www.bik-f.de/root/index.php?page_id=219 > Blog: http://occamstypewriter.org/boboh/ > Journal of Negative Results - EEB: www.jnr-eeb.org > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
I have been using a process like the following to create polygons that (closely) surround a non-convex set of points. buf1 <- gBuffer(tmpb.ne, width=bstart, byid=TRUE) buf2 <- gUnaryUnion(buf1) buf <- gBuffer(buf2, width=bshrink) These functions are from the rgeos package. In my case, tmpb.ne is a SpatialPointsDataFrame (sp package) whose coordinates slot has the coordinates of interest. You would have to tinker with the values for the two width arguments. The first gBuffer() puts a buffer (a circle) around each individual point. The gUnaryUnion() joins those circles into one or more polygons, depending on how they overlap. The second gBuffer() shrinks the polygons to make the polygon(s) surround the points more closely. It will even respect holes, for example if all your points are on land, but there?s a lake in the middle somewhere. I use it with projected coordinates, and the width parameters are in the same units as the projection. I have never tried it with lat/long. R-sig-geo would be a good place to follow-up. I think that was where I found the above solution (I didn?t figure out by myself!) -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 8/15/14, 7:51 AM, "Bob O'Hara" <rni.boh at gmail.com> wrote:>I've been struggling for half a day on what should be a simple problem... > >I have a data frame of lat/long coordinates that describe a region, and I >want to draw a polygon around them so I can use that as a boundary (to be >thrown at INLA, but those details aren't important). The coordinates are >almost on a regular grid: there is some variation in latitude (because >we're on a globe). > >If the coordinates were on a regular grid, I could use as.owin() to create >a mask, and go on from there (I have code that will work). But as.owin() >doesn't like unevenly spaced points. > >Can anyone suggest a way to sort this out? Preferable without having to >mess around transforming the coordinates. > >Bob > >-- >Bob O'Hara > >Biodiversity and Climate Research Centre >Senckenberganlage 25 >D-60325 Frankfurt am Main, >Germany > >Tel: +49 69 798 40226 >Mobile: +49 1515 888 5440 >WWW: http://www.bik-f.de/root/index.php?page_id=219 >Blog: http://occamstypewriter.org/boboh/ >Journal of Negative Results - EEB: www.jnr-eeb.org > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.
On 16/08/14 02:51, Bob O'Hara wrote:> I've been struggling for half a day on what should be a simple problem... > > I have a data frame of lat/long coordinates that describe a region, and I > want to draw a polygon around them so I can use that as a boundary (to be > thrown at INLA, but those details aren't important). The coordinates are > almost on a regular grid: there is some variation in latitude (because > we're on a globe). > > If the coordinates were on a regular grid, I could use as.owin() to create > a mask, and go on from there (I have code that will work). But as.owin() > doesn't like unevenly spaced points. > > Can anyone suggest a way to sort this out? Preferable without having to > mess around transforming the coordinates.You need to be able to tell owin() the vertices of the polygon that you want to use as your window. It is possible that alphahull, as someone suggested, might give what you want; I don't know, I am not familiar with this function. OTOH R is still lacking a mind_read() function so it probably would NOT give you *exactly* what you want. If you want to get "exactly the right polygon" you probably will have to select out the vertices of the polygon (in the appropriate order) in some "by hand" manner. It's possible that clickpoly() might be of help to you. cheers, Rolf Turner -- Rolf Turner Technical Editor ANZJS