2

I have 5 different KML files for each subzone of Singapore map. I want to plot the KML data by subzone on a Leaflet map.

library(leaflet)
library(raster)
library(readxl)
library(rgdal)
setwd("F:\\RProjects\\monilndoshi")

#Read KML Files
northEast = readOGR("aedes-mosquito-breeding-habitats-north-east-kml.kml", "BREEDINGHABITAT_NORTHEAST_AREA")
northWest = readOGR("aedes-mosquito-breeding-habitats-north-west-kml.kml", "BREEDINGHABITAT_NORTHWEST_AREA")
southEast = readOGR("aedes-mosquito-breeding-habitats-south-east-kml.kml", "BREEDINGHABITAT_SOUTHEAST_AREA")
southWest = readOGR("aedes-mosquito-breeding-habitats-south-west-kml.kml", "BREEDINGHABITAT_SOUTHWEST_AREA")
centralRegion = readOGR("aedes-mosquito-breeding-habitats-central-kml.kml", "BREEDINGHABITAT_CENTRAL_AREA")

adm <- getData('GADM', country='SGP', level=1)
popup <- paste0("<strong>Name: </strong>", adm$NAME_1)

adm@data = northEast

leaflet() %>% 
  addTiles() %>% 
  addPolygons(data=adm, weight = 2, fillColor = "white", fillOpacity = 0.7, popup=popup)

This is how the KML file looks like:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by FME 2017.1.2.0 (Build 17722) -->
<kml xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>BreedingHabitat_Northwest_Area</name>
<visibility>1</visibility>
<Schema name="BREEDINGHABITAT_NORTHWEST_AREA" id="kml_schema_ft_BREEDINGHABITAT_NORTHWEST_AREA">
<SimpleField type="xsd:int" name="JOIN_COUNT">
<displayName>JOIN_COUNT</displayName>
</SimpleField>
<SimpleField type="xsd:string" name="AREANAME">
<displayName>AREANAME</displayName>
</SimpleField>
<SimpleField type="xsd:string" name="DETAIL">
<displayName>DETAIL</displayName>
</SimpleField>
<SimpleField type="xsd:string" name="INC_CRC">
<displayName>INC_CRC</displayName>
</SimpleField>
<SimpleField type="xsd:string" name="FMEL_UPD_D">
<displayName>FMEL_UPD_D</displayName>
</SimpleField>
</Schema>
<Folder id="kml_ft_BREEDINGHABITAT_NORTHWEST_AREA">
<name>BREEDINGHABITAT_NORTHWEST_AREA</name>
<Placemark id="kml_1">
<name>kml_1</name>
<snippet> </snippet>
<description><![CDATA[<center><table><tr><th colspan='2' align='center'><em>Attributes</em></th></tr><tr bgcolor="#E3E3F3">
<th>JOIN_COUNT</th>
<td>1</td>
</tr><tr bgcolor="">
<th>AREANAME</th>
<td>Aedes Mosquito Breeding Habitats : 1</td>
</tr><tr bgcolor="#E3E3F3">
<th>DETAIL</th>
<td>Aedes Mosquito Breeding Habitats : 1</td>
</tr><tr bgcolor="">
<th>INC_CRC</th>
<td>3C1755B195344CBF</td>
</tr><tr bgcolor="#E3E3F3">
<th>FMEL_UPD_D</th>
<td>20181105105514</td>
</tr></table></center>]]></description>
<ExtendedData>
<SchemaData schemaUrl="#kml_schema_ft_BREEDINGHABITAT_NORTHWEST_AREA">
<SimpleData name="JOIN_COUNT">1</SimpleData>
<SimpleData name="AREANAME">Aedes Mosquito Breeding Habitats : 1</SimpleData>
<SimpleData name="DETAIL">Aedes Mosquito Breeding Habitats : 1</SimpleData>
<SimpleData name="INC_CRC">3C1755B195344CBF</SimpleData>
<SimpleData name="FMEL_UPD_D">20181105105514</SimpleData>
</SchemaData>
</ExtendedData>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>103.829353037996,1.37348204302234,0.0 103.829353035002,1.37529077152328,0.0 103.8311501798,1.37529077385821,0.0 103.831150181443,1.37348204535421,0.0 103.829353037996,1.37348204302234,0.0</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
<Placemark id="kml_2">
<name>kml_2</name>
<snippet> </snippet>

.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.