Skip to content

Instantly share code, notes, and snippets.

View KarthiAru's full-sized avatar

Karthik Arumugham KarthiAru

  • Bangalore
View GitHub Profile
@KarthiAru
KarthiAru / Asker and Answerer for a specified tag and date range
Created January 7, 2017 08:02
Stack Exchange Data Explorer - For graph analysis you'd need the source, target and weight i.e. Asker -> Answerer or vice versa. This query will return the same for a specified tag, date range and answer score. You can use 'Score' as the weight.
DECLARE @tag0 nvarchar(25) = ##tag0:string?r##
DECLARE @start datetime = ##start:string?2014-01-01##
DECLARE @end datetime = ##end:string?2014-12-31##
DECLARE @minscore int = ##minscore?10##
SELECT a.Id AS [Post Link], u.DisplayName AS "Asker", au.DisplayName AS "Answerer",
a.Score, p.CreationDate AS "Q_Date", a.CreationDate AS "A_Date"
FROM Tags t
JOIN PostTags pt ON pt.TagId = t.Id
library(googleAuthR)
library(RCurl)
library(stringi)
# Google AuthR Credentials
options('googleAuthR.client_id' = '[your client id]')
options('googleAuthR.client_secret' = '[your client secret]')
# Input
img_url <- '[Image URL]'
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'))
#plot the first layer
plot(poly.data[[1]])
#plot the other layers
for (i in 2:length(layers)) {
plot(poly.data[[i]], add=T)
}
# 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)
}
# 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()
> 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"
# 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
library(rgdal)
library(rgeos)
library(maptools)
echo 'export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH' >> ~/.bash_profile
source ~/.bash_profile