Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

Add polygon search #12

Closed
AugustT opened this issue Oct 1, 2015 · 2 comments
Closed

Add polygon search #12

AugustT opened this issue Oct 1, 2015 · 2 comments

Comments

@AugustT
Copy link

AugustT commented Oct 1, 2015

The API has a polygon field that I don't currently make use of. I cannot remember why but I should look into it again.

First the user should be able to submit the polygon as a WKT string

"POLYGON ((-0.11450148172820968 54.130864525842412, -0.11446068409490597 54.131762784280212, -0.11293115900887428 54.131738814327306, -0.11297198969343905 54.130840556676205, -0.11450148172820968 54.130864525842412))"

Second the user should be able to give a point and buffer, something like:

dt1 <- getOccurrences(tvks = "NBNSYS0000002987",
    datasets = "GA000373", 
    startYear = "1990",
    endYear = "1991",
    latlong = c(-0.1145, 54.1308),
    radius = 5000)

This can use this code internally:

createWKT <- function(latitude, longitude, radius = 5000) {

  library(sp)
  library(rgdal)
  library(rgeos)

  p <- SpatialPointsDataFrame(coords = data.frame(lon = longitude, lat = latitude),
                              data.frame(ID = 1),
                              proj4string = CRS("+proj=longlat +ellps=WGS84 +datum=WGS84"))
  stopifnot(length(p) == 1)
  cust <- sprintf("+proj=tmerc +lat_0=%s +lon_0=%s +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs", 
                  p@coords[[2]], p@coords[[1]])
  projected <- spTransform(p, CRS(cust))
  buffered <- gBuffer(projected, width = radius, byid = TRUE)
  bufferedOrg <- spTransform(buffered, p@proj4string)
  writeWKT(bufferedOrg)

}
@AugustT
Copy link
Author

AugustT commented Oct 1, 2015

The URL should look like this:

https://data.nbn.org.uk/api/taxonObservations/?polygon=POLYGON%20((-0.11450148172820968%2054.130864525842412,
%20-0.11446068409490597%2054.131762784280212,
%20-0.11293115900887428%2054.131738814327306,
%20-0.11297198969343905%2054.130840556676205,
%20-0.11450148172820968%2054.130864525842412))

Remember to use gsub to convert ' ' to a '%20'

@AugustT
Copy link
Author

AugustT commented Nov 4, 2015

#14

@AugustT AugustT closed this as completed Nov 4, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant