[R-sig-Geo] Finding the county shapefile polygon closest to along-lat position
Roger Bivand
Roger.Bivand at nhh.no
Fri May 22 10:44:38 CEST 2009
On Thu, 21 May 2009, Pilar Tugores Ferra wrote:
>
>
> Dear Joe,
> Maybe you could use a similar process that Marcelino suggested to me
> yesterday in order to compute the shortest distance from points to a
> polyline. You need to 1)convert your point data to ppp object in
> spatstat, 2)coerce your polygon data to a psp object in spatstat.
> 3)nncross between the two.
> You'll get "dist" - the nearest neighbour distance between the two
> patterns and "which" the nearest neighbour index of the second pattern.
> Maybe it won't be so straightforward to know which ids of the coerced
> polyline correspond to each polygon but I am not sure about this point.
Thanks, Pilar!
The only possible weakness in this might be that the input points and
polygon boundaries are in geographical, not projected (planar)
coordinates, so if there are differences in distances on the plane and
great circle distances, they might lead to the "outside" points being
assigned to the wrong county.
Depending on how many there are, you might consider two alternatives, one
visual inspection in Google Earth or similar (export the "outside" points
with IDs as one KML, and the county boundaries you are using with
writeOGR() in rgdal (or use those built into GE)); the other would be to
use the closeness to the label points of the counties of the "outside"
points - coordinates() of the SpatialPolygons* object retrieves these, so
looping over the "outside" points in spDistsN1() in sp with longlat=TRUE
would give the great circle distances.
Of course, the underlying issue is why they are outside - is this a datum
shift problem (counties in NAD27 and points in NAD83/WGS84)? If you fixed
that, they would match better.
Hope this helps,
Roger
> Best regards,
> Pilar
>
>
> -----Mensaje original-----
> De: r-sig-geo-bounces at stat.math.ethz.ch en nombre de BRWIN338 at aol.com
> Enviado el: jue 21/05/2009 21:14
> Para: r-sig-geo at stat.math.ethz.ch
> Asunto: [R-sig-Geo] Finding the county shapefile polygon closest to along-lat position
>
> Greetings
> I have a large number of long-lat locations dispersed over the US and need
>
> to identify which US county that each point is located in (or nearest to).
>
> After reading the past posts and Roger's book, I have been able to use the
> overlay function
> to identify the appropriate counties for the set of locations
> with long-lats lying within or on a polygon boundary. However, due to
> longlat precision errors (I am assuming), some of the points lie outside
> all of
> my shapefile's county polygon boundaries.
>
> Is there an R function similar to "overlay" that I could use to find which
>
> county polygon is closest to each of my longlat points that do not lie
> within the shapefile's polygons? I have spent quite a bit of time
> searching
> and browsing past list discussions and can seem to find my answer.
>
> My apologies if I have missed an obvious answer.
>
> Joe
>
>
> **************Huge savings on HDTVs from Dell.com!
> (http://pr.atwola.com/promoclk/100126575x1221836042x1201399880/aol?redir=http:%2F%2Fad.doubleclick.ne
> t%2Fclk%3B215073686%3B37034322%3Bb)
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>
> La informaci?n contenida en este e-mail y sus ficheros adjuntos es totalmente confidencial y no deber?a ser usado si no fuera usted alguno de los destinatarios. Si ha recibido este e-mail por error, por favor avise al remitente y b?rrelo de su buz?n o de cualquier otro medio de almacenamiento. This email is confidential and should not be used by anyone who is not the original intended recipient. If you have received this e-mail in error please inform the sender and delete it from your mailbox or any other storage mechanism.
> [[alternative HTML version deleted]]
>
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list