My first Map

Test mix HTML and HTML

Running your RStudio

docker run -d -p 8790:8787 --name r_workbench it4poster/geofracker

##Open your browser at your docker host IP at port 8790
# Ususally for mac or windows: http://192.168.99.100:8790
# if you are using docker machine
# For linux user, usually: http://<your ip>:8790
# or: http://127.0.0.1:8790

At you your browser you will see a login page, for login use: User: rstudio Password: rstudio

Now execute the following:

#!/usr/bin/env Rscript
install.packages("rgeos")
install.packages("rgdal")
# raster install not working
install.packages('raster',  repos='http://cran.us.r-project.org')
install.packages('ncdf4')
install.packages("xlsx")
install.packages("ggmap")
library(raster)
library(rgdal)

# installing dowload helper
## 1. install
install.packages("devtools")
library(devtools)
devtools::install_github("i40poster/geoSampaRHelper")

# using dowload helper
## 2 .Sample of use:
library(helper4geosampa)

# To conver GeoJSON
install.packages("geojsonio")
library("geojsonio")

# Exploring a sample data: Source: http://geosampa.prefeitura.sp.gov.br/

Abastecimento = downloadAndUnzipShp("http://geosampa.prefeitura.sp.gov.br/PaginasPublicas/downloadArquivoOL.aspx?orig=DownloadCamadas&arq=03_Equipamentos%5C%5CAbastecimento%5C%5CShapefile%5C%5CEQUIPAMENTOS_SHP_TEMA_ABASTECIMENTO&arqTipo=Shapefile")

Abastecimento1 <- readOGR(dsn=Abastecimento$dir[1], layer=Abastecimento$shapeclass[1])

#function to convert UTM to Degrees




#geojson_write( us.cities[1:2, ], lat = 'lat', lon = 'long',file = "/home/rstudio/sample.json")

utm2decimalSouth <- function(data,zone,datum){
    #coordinates(newData) <- c("easting","northing")
    crs <- paste0("+proj=utm+zone=",zone,"+datum=",datum)
    data@proj4string@projargs <- paste0("+proj=utm"," +south  +zone=",zone," +datum=",datum)
    spTransform(data, CRS("+proj=longlat"))}


#Converting the Coordinates from UTM to Degrees
Abastecimento1inDegrees <- utm2decimalSouth(Abastecimento1,23,"WGS84")
head(coordinates(Abastecimento1inDegrees))

Expected Result:

coords.x1 coords.x2
[1,] -46.62910 -23.55624
[2,] -46.61584 -23.53899
[3,] -46.62229 -23.57894
[4,] -46.70011 -23.52669
[5,] -46.60064 -23.55279
[6,] -46.59940 -23.54647

Exporting


# Lat, Long, Data
Abastecimento1iDF <- data.frame(coordinates(Abastecimento1inDegrees)[,2], coordinates(Abastecimento1inDegrees)[,1], Abastecimento1inDegrees$eq_nome )

#Abastecimento1iDF <- data.frame(Abastecimento1iDF_Lat, Abastecimento1iDF_Long, Abastecimento1iDF$variable )
# Renaming
# http://stackoverflow.com/questions/7531868/how-to-rename-a-single-column-in-a-data-frame-in-r
colnames(Abastecimento1iDF) = c("lat","long","data")
geojson_write(Abastecimento1iDF, lat = 'lat', lon = 'long',file = "/home/rstudio/Abastecimento1")

File Saved at: /home/rstudio/Abastecimento1 Copying it to your machine:

docker cp r_workbench:/home/rstudio/Abastecimento1.geojson ~/Downloads/

You can test the generated file at: http://geojson.io/ 20160821.SampleGeoJSON.png GEOJSON Sample

Reference: https://cran.r-project.org/web/packages/geojsonio/README.html

D3.JS Rendering Section

References:

http://geojson.io/ https://cran.r-project.org/web/packages/geojsonio/README.html http://www.dummies.com/how-to/content/how-to-create-a-data-frame-from-scratch-in-r.html

comments powered by Disqus