I am trying to import an KML map of CCG boundaries in England (Available here, 200Kb) into R using readOGR
function from package rgdal
. My end-goal is to create a heat-map by colouring CCGs according to some associated value. I have a list with those values next to CCG names in one data frame. I need to match CCG names in that data frame with CCG names in the imported map object, and assign colours based on the value. However, I cannot see any CCG names imported in the map object, although they are present in the KML file. This is what I am doing:
library(sp) library(rgdal) library(maps) library(maptools)
Assuming the KML file is in the working directory. Listing layers:
ogrListLayers("Clinical_Commissioning_Groups_April_2016_Ultra_Generalised_Clipped_Boundaries_in_England.KML")
Reading OGRGeoJSON
layer:
ccg_boundaries <- ReadOGR("Clinical_Commissioning_Groups_April_2016_Ultra_Generalised_Clipped_Boundaries_in_England.KML","OGRGeoJSON")
R Studio shows there are two sections (right word?) in the object.
polygons
, which contains data for each polygon, e.g. for the first one:
> ccg_boundaries@polygons[1] [[1]] An object of class "Polygons" Slot "Polygons": [[1]] An object of class "Polygon" Slot "labpt": [1] -2.104671 54.040320 Slot "area": [1] 0.168067 ...
And data
, with two variables (Name
and Description
) which I would expect to contain CCG names, but it is empty:
> ccg_boundaries@data Name Description 0 1 2 3 4 5
However, the CCG names are there in the KML file, which can be seen if opened with a Word editor, e.g. the first one in the alphabetic order is "NHS Airedale, Wharfedale and Craven".
<PolyStyle><fill>0</fill></PolyStyle></Style> <ExtendedData><SchemaData schemaUrl="#OGRGeoJSON"> <SimpleData name="objectid">1</SimpleData> <SimpleData name="ccg16cd">E38000001</SimpleData> <SimpleData name="ccg16nm">NHS Airedale, Wharfedale and Craven CCG</SimpleData>
Is there maybe an option to readOGR or some other option to extract them and include in the object?