[R] Plotting gps coordinates on Shapefile

MacQueen, Don macqueen1 at llnl.gov
Thu Jun 13 19:20:02 CEST 2013


Your shapefile should include specifications for its coordinate system.
Look for a file names maryland.prj in the same directory as maryland.shp.
And that coordinate system should be included in your 'border' object. You
might need to change to using readOGR() to load the shapefile into R. Use

  str(border)

to find out.

If your border object does in fact include its projection, then you can
use spTransform(), as Barry suggested, to transform it to lat/long. Then
your overlay should succeed.

And I second Barry's recommendation to ask this kind of question on
r-sig-geo.


You will need to learn how to specify coordinate systems; a starting point
is
  ?proj4string
(from the sp package). r-sig-geo is definitely a good place to get help
for that.
I myself have used QGIS (Quantum GIS) to look up projection specs, as it
has a nice listing which you can search by name; in your case I'd search
for 'Maryland'. 

-Don


-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 6/12/13 10:26 PM, "L S" <losedaghat at gmail.com> wrote:

>Hi,
>
>I am new to doing spatial analysis.  I am interested in trying many things
>in R, but one of the first things I would like to do is plot all of my
>lat,
>lon points in a csv file within a window defined by a shapefile.
>
>I have read in the shape file by doing the following:
>border <-readShapePoly("shapefiles/maryland.shp")
>plot(border, border="red", las=1)  # plot confirms correct shape
>border <-as(border, "owin")
>
>However, once I try to do:
>data_ppp <-ppp(data$Latitude, data$Longitude, window=border)
>
>I get the error that:
>In ppp(data$Latitude, data$Longitude, window = border) :
>  523461 points were rejected as lying outside the specified window
>
>I realized that the coordinates are completely different.  The coordinates
>in my data file (i.e. my csv file) are traditional GPS coordinates (e.g.
>39.17
>or 76.37).  The shapefile however has x,y values such as 1416813.54262877
>or 561125.546602725. I am not familiar with what type of coordinate system
>those values use.
>
>How can I change the coordinates in my csv file to match the same system
>as
>my shapefile or the other way around--i.e. to get my shapefile to have
>similar coordinates as my csv file?
>
>Any help would be appreciated.
>
>Thank you.
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list