Re: [R] Plotting gps coordinates on Shapefile

2013-06-13 Thread Barry Rowlingson
On Thu, Jun 13, 2013 at 6:26 AM, L S losedag...@gmail.com wrote:

 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?

 You really need to know the coordinate reference system that your
points are in.

 What you call traditional GPS coordinates is formally known as
EPSG:4326. I suspect your points are in some small-region plane
coordinate system. In the UK, for example, we have a square metric
grid system that is EPSG:27700. The units of this system are metres
from a point origin off the south-west of the UK, which is great for
small areas in the UK but not applicable to India, because it assumes
a flat earth. If your data is in the USA, then it might be one of the
state plane systems. There and elsewhere, it might be one of the
global UTM zones (but you have to know which one).

There are thousands of possible coordinate systems:
http://www.epsg-registry.org/ or you can make your own using PROJ4
strings...

 To convert from one coordinate system to another, I normally use
spTransform from the rgdal package since I mostly work with sp-class
objects. I think there's a 'project' function that can work with raw
x-y coordinates in vectors or matrices.

 You can also try asking on the R-sig-geo mailing list where the map
people hang out.

Barry

__
R-help@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.


Re: [R] Plotting gps coordinates on Shapefile

2013-06-13 Thread MacQueen, Don
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 losedag...@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@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.

__
R-help@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.