Skip to content

Generating a polygon around points

15 messages · Bob O'Hara, Clint Bowman, Tsjerk Wassenaar +5 more

#
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
#
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:
#
Unfortunately my region isn't convex, and I don't want to end up predicting
the distribution of a forest-dwelling bird in the Atlantic ocean...

Bob
On 15 August 2014 17:15, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:

            

  
    
#
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:

            
#
Hi Bob,

You probably want to have a look at the package alphahull.

Cheers,

Tsjerk
On Fri, Aug 15, 2014 at 5:25 PM, Clint Bowman <clint at ecy.wa.gov> wrote:

            

  
    
#
On Aug 15, 2014, at 8:15 AM, Jeff Newmiller wrote:

            
RSiteSearch has really been broken for some time now. (You get the headers but the links are all broken. A more effective way of searching the existing CRAN package base (but I think r-forge and github will be missed) is:

install.packages("sos")
library(sos)
findFn("convex hull ")

I use Markmail to search the archives, but one can also use Gmane or Rseek.org. 

Both markmail and gmane have the defect that copied code comes to my console or editor without line-ends. If anyone has a hint on how to avoid that annoyance, I'll be in your debt.

http://markmail.org/search/?q=list%3Aorg.r-project.r-help
#
No wonder I didn't understand your constraints... you didn't state them. In fact, I think you still haven't stated them. Perhaps you need a map outline? Or, you could just create a polygon manually? Isocline of a two-D kernel density estimate or kriging fit? Manually partition your data into regions which are convex? There might be precedents in the literature on your topic. Appropriate selection of of algorithms is not really on topic here, though.
---------------------------------------------------------------------------
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 8:22:55 AM PDT, Bob O'Hara <rni.boh at gmail.com> wrote:
#
I use RSiteSearch regularly with no problems. Perhaps I have just had a lucky streak? I wonder what the odds are... :-)
---------------------------------------------------------------------------
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 8:55:40 AM PDT, David Winsemius <dwinsemius at comcast.net> wrote:
#
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
#
On 16/08/14 02:51, Bob O'Hara wrote:
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
#
On 16/08/14 05:10, Jeff Newmiller wrote:
<SNIP>
<SNIP>

I tried RSiteSearch("convex hull") just now, as an experiment, and it 
seemed to work just fine.  I think that the Universe is picking on Dave
(instead of on me, for once!). :-)

cheers,

Rolf
#
On Aug 15, 2014, at 3:11 PM, Rolf Turner wrote:

            
RSiteSearch("convex hull") does produce a page on my web-browser, but have you tried to follow links on the page? I got 404's about a third of the time , although admittedly I was earlier generalizing on the basis of 3 404's in a row. And I was further generalizing from earlier experience when support for searching the rhelp archive was abandoned.
#
On 16/08/14 11:01, David Winsemius wrote:
<SNIP>
Well, I tried a couple of links and the pages opened without any 
reluctance.  I didn't try them *all* ....

cheers,

Rolf
#
On Fri, Aug 15, 2014 at 4:06 PM, Rolf Turner <r.turner at auckland.ac.nz> wrote:

            
We can try the (very pre-alpha) esp package:
[1] "piccalilli crawlspace mole swarthy thunderhead forever"

Somehow I doubt that that is *exactly* what the original poster wants.

I guess it still needs work.
#
On 17/08/14 01:57, Greg Snow wrote:
ROFL!!!  (As contrasted with "ROLF". :-) )