Helgasoft
Back

 

Put me on a map!

Have you seen web pages screeming for a map? One of them was French Tech Visa. There was company info and search by area, but no map.
Below is a live geocoded map for the same page which could be used for location search. (data as of Dec 2017)


Click on a map marker to see details here

Luckily, all the data was inside the page source in JSON format. To clean and use it in R, one could simply copy and assign it to a variable, then source it in RStudio to fix any errors. Then it can be converted to a data.frame.
products <- '[ { "Company_Name": "1001 Pharmacies",... } ]'
companies <- jsonlite::fromJSON(products)
Next step was to extract the addresses (companies[1:100,]$Adresse), clean them of special characters and try a batch geocode online. From the KML output file, one could extract the lon/lat coordinates and match them to the companies by address. As a result, the companies data frame gets two more columns - latitude and longitude. We saved this geocoded data in a second JSON file.
xjson <- jsonlite::toJSON(companies, pretty=T)
out <- file('french.json', encoding="UTF-8")
write(xjson, file=out)
Used Javascript next to recode the data from JSON to geojson format. You can see the file raw, or here on a map. Finally we read this same geojson file and present it on a Leaflet map with clustering - here below. Clicking on a company marker will show the details just below the map. Et voilĂ !

 


Photos on a map

Below is a demo clip of another Leaflet map. Hover mouse on (green) markers will show related images. Images could be dragged over the map, zoomed along with the map, or closed by double-click.

 


Calculate distances

GIS projects ofter require spatial measurements. In the sample below, given a set of points (Lat/Lon coordinates), the goal is to find which ones are within 5 km distance from two predefined locations. By drawing a circle (radius 5km) from each location, all points inside the intersection area meet the requirement.

 

 


Census data

Coded in R, the steps accomplished for this project were:
  1. load US census boundary and attribute data
  2. cleanup blocks outside city area
  3. build interactive map with census blocks color-coded by population