[R-sig-Geo] find in which polygon each point-coordinate belongs to

dimitrisr drdr8080 at gmail.com
Tue Feb 7 20:38:55 CET 2012


hi i am new to these stuff so bear with me  ,
i have a shapefile of Europe and a dataset of point coordinates that has 
way too many mistakes(a csv file of 10.000 lines/point coordinates written
in this way)

country,longitude,latitude
Italy,213,4353
Italy,234,3463
Italy,234,43643
Germany,325,453
Germany,344,234
etc..

but coordinates with country-name Germany are actually plotted in
Italy,Spain,Sweden .etc...
to make it clearer,if i do

plot(europe)
points(myPoints$longitude[myPoints$country=="Italy"],myPoints$latitude[myPoints$country=="Italy"])
the majority of points are drawn in Italy but there are many points
scattered around Europe.This happens for every country!

i want to write a file (preferable in the same format as points.csv) that
contains each polygon-country and the points/coordinates corrected(i.e
points with country-name Germany plotted only in Germany)

this is what i have tried so far:
europe<-readShapeSpatial("/europe/europe.shp",proj4string=CRS("+proj=longlat")
myPoints<-read.csv("points.csv",header=T)  #3 columns,10.000 rows
xy<-cbind(myPoints$longitude,myPoints$latitude)
dimnames(xy)[[1]]<-myPoints$country ---->if try to add the country-column i
get an error that the over function does not accept duplicates 
pts<-SpatialPoints(xy,proj4string=CRS("+proj=longlat")
over(pts,europe) 

how can continue from here?(if this is not the correct way to do it,please
let me know)
help is much appreciated. :)

(put differently ,if the csv file didn`t have country-names but just
coordinates,how would you write a  csv file that contains in which
polygon-country each point belongs to, but save both the country-name *and*
the coordinate)

--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/find-in-which-polygon-each-point-coordinate-belongs-to-tp7263478p7263478.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list