Skip to content

Instantly share code, notes, and snippets.

View KarthiAru's full-sized avatar

Karthik Arumugham KarthiAru

View GitHub Profile
install.packages('rgdal', type = "source", configure.args=c(
'--with-gdal-config=/Library/Frameworks/GDAL.framework/Programs/gdal-config',
'--with-proj-include=/Library/Frameworks/PROJ.framework/Headers',
'--with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib'))
install.packages('rgeos', type = "source", configure.args=c(
'--with-gdal-config=/Library/Frameworks/GDAL.framework/Programs/gdal-config',
'--with-proj-include=/Library/Frameworks/PROJ.framework/Headers',
'--with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib'))
conda install gdal
gdalinfo --version
# GDAL 2.1.0, released 2016/04/25
echo 'export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH' >> ~/.bash_profile
source ~/.bash_profile
library(rgdal)
library(rgeos)
library(maptools)
# Convert from .shp to .geojson files
$ ogr2ogr -skipfailures -f GeoJSON -t_srs crs:84 [filename].geojson [filename].shp
# Convert from .kml to .geojson files
$ ogr2ogr -skipfailures -f GeoJSON -t_srs crs:84 [filename].geojson [filename].kml
# Convert from .kml to .shp files
$ ogr2ogr -skipfailures -f 'ESRI SHAPEFILE' [filename].shp [filename].kml
# Convert from .shp to .kml files
$ ogr2ogr -skipfailures -f KML [filename].kml [filename].shp
> ogrDrivers()$name
[1] "AeronavFAA" "AmigoCloud" "ARCGEN" "AVCBin"
[5] "AVCE00" "BNA" "Carto" "Cloudant"
[9] "CouchDB" "CSV" "CSW" "DGN"
[13] "DXF" "EDIGEO" "ElasticSearch" "ESRI Shapefile"
[17] "Geoconcept" "GeoJSON" "GeoRSS" "GFT"
[21] "GML" "GPKG" "GPSBabel" "GPSTrackMaker"
[25] "GPX" "HTF" "HTTP" "Idrisi"
[29] "Interlis 1" "Interlis 2" "JML" "JP2OpenJPEG"
[33] "JPEG2000" "KML" "LIBKML" "MapInfo File"
# Get the layers from .kml file
layers <- ogrListLayers('bbmp.kml')[2:198]
i<-1
# Get polygon from first layer
poly.data <- readOGR(dsn="bbmp.kml", layer=layers[1], encoding="utf-8", verbose = F)
n <- length(slot(poly.data, "polygons"))
poly.data <- spChFIDs(poly.data, as.character(i:(i+n-1)))
i <- i + n
# Combine remaining polygons with first polygon
timer_all <- Sys.time()
# Get the layers from .kml file
layers <- ogrListLayers('bbmp.kml')
# Import layers to a list
timer_all <- Sys.time()
pb <- txtProgressBar(max=length(layers), style = 3)
options(warn=-1) # disable warnings
poly.data <- list()
for (i in 1:length(layers)) {
poly.data[i] <- readOGR(dsn="bbmp.kml", layer=layers[i], encoding="utf-8", verbose = F)
}
#plot the first layer
plot(poly.data[[1]])
#plot the other layers
for (i in 2:length(layers)) {
plot(poly.data[[i]], add=T)
}
library(httr)
key <- '[your apikey]'
img_url <- '[your image url]'
# Submit an OCR job
request <- POST(url='https://api.havenondemand.com/1/api/async/ocrdocument/v1',
body = list(apikey = key,
url = img_url,
mode = 'document_photo'))