Mapping geo-spatial data

Hi,
I am not I would like to map coordinates from a KML file with with other geo-spatial data (see code below). This works well if the kml file only contains one placemark, however, I receive an error if the kml file contains multiple placemarks. Does someone have an idea how I could solve this issue? I am only starting to learn R, so apologies if the solution to this question seems obvious.

Many thanks, Dominique

This is how I tried it:
install.packages("maptools")
install.packages("prevR")
install.packages("rgeos")

library("maptools")
library("prevR")
library("rgeos")

zz <- getKMLcoordinates(file.path("/Users/chs/Downloads/KML_PL1899-2.kml"), TRUE)

zz <- SpatialPolygons(zz)

p1 = Polygon(zz)
p2 <- Polygons(list(p1))

p3 = SpatialPolygons(list(p2))

// check if a coordinate is in polygon (p3)
point.in.SpatialPolygons(104.14432742893, -2.020485348759713, p3)

Hard to make certain without having access to your data (which may not be feasible).

I suggest you consider the {sf} package for reading your object. It supports the KML file format and is the current best practice for vector spatial data.

library(sf)

yer_object <- st_read("/Users/chs/Downloads/KML_PL1899-2.kml")

plot(yer_object) # a quick visual check
1 Like

Thanks a lot for that suggestion. I will test it right away.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.