-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Markus Kainu
committed
Jun 21, 2018
0 parents
commit 8427541
Showing
10 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
^.*\.Rproj$ | ||
^\.Rproj\.user$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData | ||
.Ruserdata | ||
digitransit.Rproj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Package: digitransit | ||
Type: Package | ||
Title: A client for digitransit API services | ||
Version: 0.1.0 | ||
Author: Markus Kainu | ||
Maintainer: Markus Kainu <[email protected]> | ||
Description: Geocode and reverse geocode addresses and poinst in Finland | ||
License: MIT | ||
Depends: httr, | ||
jsonlite | ||
Encoding: UTF-8 | ||
LazyData: true | ||
RoxygenNote: 6.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exportPattern("^[[:alpha:]]+") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#' Geocode a place name or an address | ||
#' | ||
#' @param string plane name or an address | ||
#' @param hits Number of hits returned | ||
#' @return Data frame with latitude and longitude of the place | ||
#' @examples | ||
#' geocode(string = "Eduskuntatalo", hits = 1) | ||
|
||
|
||
geocode <- function(string = "helsinki", hits = 1) { | ||
string <- gsub(" ", "%20", string) | ||
resp <- httr::GET(paste0("https://api.digitransit.fi/geocoding/v1/search?text=",string,"&size=",hits)) | ||
# print("Hello, world!") | ||
tmp <- jsonlite::fromJSON(content(resp, "text"), simplifyVector = FALSE) | ||
dat <- data.frame(string = string, | ||
lon = tmp[[3]][[1]]$geometry$coordinates[[1]], | ||
lat = tmp[[3]][[1]]$geometry$coordinates[[2]], | ||
label = tmp[[3]][[1]]$properties$label) | ||
return(dat) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#' Reverse geocode a geographical location | ||
#' | ||
#' @param lon longitute | ||
#' @param lat A latitude | ||
#' @param hits Number of hits returned | ||
#' @return Data frame with information about the point | ||
#' @examples | ||
#' reverse_geocode(lon = "24.95126", lat = "60.15948", hits = 1) | ||
|
||
reverse_geocode <- function(lon = "24.95126", lat = "60.15948", hits = 1) { | ||
resp <- httr::GET(paste0("https://api.digitransit.fi/geocoding/v1/reverse?point.lat=",lat,"&point.lon=",lon,"&size=",hits)) | ||
# print("Hello, world!") | ||
tmp <- jsonlite::fromJSON(content(resp, "text"), simplifyVector = FALSE) | ||
dat <- data.frame(lon = lon, | ||
lat = lat, | ||
country = tmp[[3]][[1]]$properties$country, | ||
country_a = tmp[[3]][[1]]$properties$country_a, | ||
region = tmp[[3]][[1]]$properties$region, | ||
localadmin = tmp[[3]][[1]]$properties$localadmin, | ||
locality = tmp[[3]][[1]]$properties$locality, | ||
label = tmp[[3]][[1]]$properties$label) | ||
return(dat) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
R client for digitransit.fi API | ||
========================================== | ||
|
||
API documentation: https://digitransit.fi/en/developers/apis/2-geocoding-api/ | ||
|
||
|
||
Install | ||
|
||
```r | ||
devtools::install_git("https://gitlab.com/muuankarski/digitransit") | ||
``` | ||
|
||
Use | ||
|
||
```r | ||
digitransit::geocode("Eduskuntatalo") | ||
# string lon lat label | ||
# 1 Eduskuntatalo 24.93315 60.1725 Eduskuntatalo, Mannerheimintie 30, Helsinki | ||
``` | ||
|
||
|
||
```r | ||
digitransit::reverse_geocode(lon = 24.93315, lat = 60.1725) | ||
# lon lat country country_a region localadmin locality label | ||
# 1 24.93315 60.1725 Suomi FIN Uusimaa Helsinki Helsinki Mannerheimintie 30, Helsinki | ||
|
||
``` | ||
|
||
- (C) Markus Kainu 2018 | ||
- License: MIT | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
\name{hello} | ||
\alias{hello} | ||
\title{Hello, World!} | ||
\usage{ | ||
hello() | ||
} | ||
\description{ | ||
Prints 'Hello, world!'. | ||
} | ||
\examples{ | ||
hello() | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.