Classifying point coordinates to countries or continents?
Using SAGA-GIS you can use the tool Add Polygon Attributes to Points
On the commandline (linux or windows):
$ saga_cmd shapes_points 10
library path: C:\Program Files\SAGA-GIS\Modules
library name: shapes_points
module name : Add Polygon Attributes to Points
author : O.Conrad (c) 2009
Usage: 10 -INPUT <str> [-OUTPUT <str>] -POLYGONS <str> [-FIELD <str>]
-INPUT:<str> Points
Shapes (input)
-OUTPUT:<str> Result
Shapes (optional output)
-POLYGONS:<str> Polygons
Shapes (input)
-FIELD:<str> Attribute
Table field
In R, you can use my geonames
package to access the www.geonames.org
API:
> library(geonames)
Loading required package: rjson
Warning message:
In fun(libname, pkgname) :
No geonamesUsername set. See http://geonames.wordpress.com/2010/03/16/ddos-part-ii/ and set one with options(geonamesUsername="foo") for some services to work
> GNcountryCode(lat=20,lng=0)$countryCode
[1] "ML"
> GNcountryCode(lat=30,lng=0)$countryCode
[1] "DZ"
> GNcountryCode(lat=40,lng=0)$countryCode
[1] "ES"
> GNcountryCode(lat=50,lng=0)$countryCode
Error in getJson("countryCode", list(lat = lat, lng = lng, radius = radius, :
error code 15 from server: no country code found
I think 50,0 is in the sea. You'd have to trap this error in a loop. The function is not vectorised so you can't feed it all 50,000 points without a loop anyway.
geonames
is on CRAN, so install.packages("geonames")
will get it for you.