I would like to use a .kml track file to make a set of x, y coordinates for use in R.
What I have right now is a GoogleEarth track, which I believe is a LineString. I have heard that the rgdal package is usually what people use, but it doesn't work on Mac versions of R. If possible, I'd like to do this on a Mac, where I do the rest of my analyses. If necessary, I can do the conversion on R64 with Windows, and then bring the coordinates to my Mac, but that seems...clunky.
The beginning of the .kml code looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
<name>Perimeter_Track.kml</name>
<Placemark>
<name>ACTIVE LOG</name>
<LineString>
<coordinates>
-157.80736808,21.4323436,20.324951171875
I want to convert it into x , y coordinates in kilometers from a point in my map. The finished product will be a line outline of a body of water, with species abundance data overlaid on it.
I have tried a couple of methods already:
1. Converting the .kml file into a .csv and importing it to r using read.csv
;
2. Importing coordinates using getKMLcoordinates
in the maptools
package.
The problem with (1) is that when I try to convert the .kml coords into csv, I get an error in the converter program (kmlcsv) that says it can't read the file (I'm not sure why- the error logs aren't available).
When I try (2), I get coordinates that are arranged weirdly.
spa<-getKMLcoordinates("Perimeter_Track.kml", ignoreAltitude=TRUE)
returns:
summary(spa)
Length Class Mode
[1,] 128 -none- numeric
[2,] 242 -none- numeric
[3,] 34 -none- numeric
[4,] 126 -none- numeric
I believe this is because the .kml file is actually four separate tracks, separated by small gaps (i.e., where they turned the GPS off for a short time, then started again). Do I need to import these all separately in order to get the whole shape? If so, how do I do this?
I would like, eventually, to get this shape on a grid that is x by y km, where the coordinates are in km instead of GPS coords. If anyone has any insight into how to do this, I would love to hear from you!
Thanks very much in advance.