0

I am trying to find the shortest distance from a point to a polygon. I have a point on the shoreline of a map I made and I need the distance from this point to a polygon outside the shoreline. The polygon is an irregular shape (contaminant location on the surface of the water on a particular day). Both the point and the polygon are in longitude/latitude coordinates, and I can overlay the polygon onto the map. I tried to use (geosphere package)

dist2Line(-88.1253, 30.2564, may.17.10A, distfun=distHaversine)

but I get an error message that says 'Error in dist2Line(-88.1253, 30.2564, may.17.10A, distfun = distHaversine) : unused argument (may.17.10A)'

I tried to add brackets around the point coordinates but got another error message. The coordinates for the point on the shoreline are -88.1253, 30.2564 and the polygon is may.17.10A. The function states that I can use a SpatialPolygons* object as a variable and I thought

may.17.10A

would be one?

The code for the polygon is from a directory with .dbf, .prj, .sbn, .sbx, .sph, and .shx files:

may.17.10 <- readOGR("directory/20100517_Composite", "20100517_Composite")
may.17.10A<- spTransform(may.17.10, CRS("+proj=longlat +datum=WGS84"))

As I have mentioned in my previous questions I am new to R and have no prior coding experience so I very much appreciate any help I can get. Thank you for any advice!

user3281487
  • 97
  • 1
  • 1
  • 9

1 Answers1

0

The way you are calling dist2Line right now makes it look like it has 4 parameters but the signature only has three. The first parameter according to the documentation should be

longitude/latitude of point(s). Can be a vector of two numbers, a matrix of 2 columns (first one is longitude, second is latitude) or a SpatialPoints* object.

So try

dist2Line(c(-88.1253, 30.2564), may.17.10A, distfun=distHaversine).
MrFlick
  • 195,160
  • 17
  • 277
  • 295