joelgombin / concaveman

A very fast 2D concave hull algorithm
https://joelgombin.github.io/concaveman/
66 stars 7 forks source link

Help #7

Closed rafmarcondes closed 5 years ago

rafmarcondes commented 6 years ago

Dear Joel,

I am writing to request some guidance with the use of concaveman in R. I need to calculate and plot a simple concave polygon for a set of XY points. My understanding from the concaveman help file was that it would be enough to give it either a sf multipoints or a simple two-column matrix, but neither of those are working as I wanted:

polygon=concaveman(as.matrix(famdata[,2:3])) plot(polygon)

But the plot that this gives me is a simple scatterplot of the points, while I expected the polygon itself. So I tried converting to an sf object first, but that gives me an error:

fampoints=st_multipoint(as.matrix(famdata[,2:3])) #convert family data into multipoint sf polygon=concaveman(fampoints) Error in UseMethod("concaveman", points) : no applicable method for 'concaveman' applied to an object of class "c('XY', 'MULTIPOINT', 'sfg')"

Here's the file to reproduce my code: famdata.rds.zip

What am I misunderstanding/doing wrong? Any help will be much appreciated.

Thank you,

joelgombin commented 5 years ago

The documentation for the function concaveman states that its result is:

an object of the same class as points: a matrix of coordinates, an sf object or a SpatialPoints* object. Therefore, if you give concaveman a matrix of coordinates, it gives you back a matrix of coordinates. Nothing wrong therefore with the first exemple you give. Try

plot(st_polygon(list(polygon)))

and you'll see the polygon.

With regards to your second attempt, at the moment concaveman doesn't handle multipoints. But it does handle sf's points, so:

famdata$S1R <- famdata$S1R * 100 # to get more even coordinates
fampoints=st_as_sf(famdata, coords = c("B2", "S1R")) 
polygon=concaveman(fampoints)
plot(polygon)

does work.

Hope this helps?

rafmarcondes commented 5 years ago

Perfect! I've been able to make it work now. Thank you so much for your quick response.

-- Rafael Sobral Marcondes PhD Candidate (Systematics, Ecology and Evolution/Ornithology)

Museum of Natural Science http://www.lsu.edu/mns/ Louisiana State University 119 Foster Hall Baton Rouge, LA 70803, USA

Twitter: @brown_birds https://twitter.com/brown_birds

On Wed, Jan 9, 2019 at 11:03 AM Joel Gombin notifications@github.com wrote:

The documentation for the function concaveman states that its result is:

an object of the same class as points: a matrix of coordinates, an sf object or a SpatialPoints* object. Therefore, if you give concaveman a matrix of coordinates, it gives you back a matrix of coordinates. Nothing wrong therefore with the first exemple you give. Try

plot(st_polygon(list(polygon)))

and you'll see the polygon.

With regards to your second attempt, at the moment concaveman doesn't handle multipoints. But it does handle sf's points, so:

famdata$S1R <- famdata$S1R * 100 # to get more even coordinatesfampoints=st_as_sf(famdata, coords = c("B2", "S1R")) polygon=concaveman(fampoints) plot(polygon)

does work.

Hope this helps?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/joelgombin/concaveman/issues/7#issuecomment-452762572, or mute the thread https://github.com/notifications/unsubscribe-auth/AKD7UtnS7y-U8JmVrPC-UOpLsAaSNXmYks5vBiD1gaJpZM4V6_h3 .