Skip to content

Commit

Permalink
parallel demo
Browse files Browse the repository at this point in the history
  • Loading branch information
womeimingzi11 committed Nov 20, 2020
1 parent 79ae1e6 commit ee77d38
Show file tree
Hide file tree
Showing 3 changed files with 432 additions and 61 deletions.
38 changes: 37 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
out.width = "100%",
tidy = TRUE
)
```

Expand Down Expand Up @@ -40,6 +41,41 @@ amapGeocode is inspired by [baidumap](https://github.com/badbye/baidumap) and [b

However, AutoNavi has significant high precise, in my case, the Results from Baidu were unsatisfactory.

## BIG NEWS: Parallel is Here!
Since `v0.5`, parallel operation finally come to `amapGeocode` with the `parallel` package as the backend. There is a really huge performance improvement for batch queries. Here is a demo from my PC with below specification

>
1. CPU: AMD Ryzen 3600 @ 3.6GHz (6 cores with 12 threads)
2. RAM: 32GB DDR4 2933MHz
3. System Disk: Sandisk Ultra 3D NVME aka. WD SN550 with 1TB
4. OS: Windows 10 Pro @ Insider Fast Ring (Build 20257.1)
5. Internet: CMCC @ 200Mbps from Chengdu, Sichuan, China

```{r parallel_performance_revealR, message=FALSE}
library(amapGeocode)
library(readr)
sample_site <-
read_csv('sample_site.csv')
str(sample_site)
# Here is the old implement
start_time <- proc.time()
old <- lapply(sample_site$address, amapGeocode:::getCoord.individual)
proc.time() - start_time
# Here is the new implement
start_time <- proc.time()
new <- getCoord(sample_site$address)
proc.time() - start_time
```

Around 10 TIMES FASTER!

All you need to do is **upgrade** `amapGeocode` to the **latest version** without changing any code!

*While parallel support is a totally threads depending operation, so you will get completely different speed on different devices.*

## Installation

You can install the released version of amapGeocode from [CRAN](https://CRAN.R-project.org/package=amapGeocode) with:
Expand Down
154 changes: 94 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,55 @@ the Baidu Map API, these packages are good choices.
However, AutoNavi has significant high precise, in my case, the Results
from Baidu were unsatisfactory.

## BIG NEWS: Parallel is Here\!

Since `v0.5`, parallel operation finally come to `amapGeocode` with the
`parallel` package as the backend. There is a really huge performance
improvement for batch queries. Here is a demo from my PC with below
specification

> 1. CPU: AMD Ryzen 3600 @ 3.6GHz (6 cores with 12 threads)
> 2. RAM: 32GB DDR4 2933MHz
> 3. System Disk: Sandisk Ultra 3D NVME aka. WD SN550 with 1TB
> 4. OS: Windows 10 Pro @ Insider Fast Ring (Build 20257.1)
> 5. Internet: CMCC @ 200Mbps from Chengdu, Sichuan, China
``` r
library(amapGeocode)
library(readr)
sample_site <- read_csv("sample_site.csv")

str(sample_site)
#> tibble [300 x 1] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
#> $ address: chr [1:300] "四川省 绵阳市 游仙区 四川省绵阳市游仙区" "四川省 自贡市 自流井区 自流井区五星街珍珠寺新森3组" "四川省 绵阳市 游仙区 游仙区" "四川省 眉山市 仁寿县 向家乡平安村1组" ...
#> - attr(*, "spec")=
#> .. cols(
#> .. address = col_character()
#> .. )

# Here is the old implement
start_time <- proc.time()
old <- lapply(sample_site$address, amapGeocode:::getCoord.individual)
proc.time() - start_time
#> user system elapsed
#> 3.17 0.34 80.91

# Here is the new implement
start_time <- proc.time()
new <- getCoord(sample_site$address)
proc.time() - start_time
#> user system elapsed
#> 0.02 0.14 9.20
```

Around 10 TIMES FASTER\!

All you need to do is **upgrade** `amapGeocode` to the **latest
version** without changing any code\!

*While parallel support is a totally threads depending operation, so you
will get completely different speed on different devices.*

## Installation

You can install the released version of amapGeocode from
Expand Down Expand Up @@ -89,8 +138,7 @@ Then get result of geocoding, by `getCoord` function.
``` r
library(amapGeocode)
# An individual request
res <-
getCoord('四川省中医院')
res <- getCoord("四川省中医院")
knitr::kable(res)
```

Expand All @@ -100,10 +148,7 @@ knitr::kable(res)

``` r
# Batch requests
res <-
getCoord(c('四川省中医院',
'四川省人民医院',
'成都中医药大学十二桥校区'))
res <- getCoord(c("四川省中医院", "四川省人民医院", "成都中医药大学十二桥校区"))
knitr::kable(res)
```

Expand All @@ -124,8 +169,7 @@ or **XML**. The result can further be parsed by `extractCoord`.

``` r
# An individual request
res <-
getCoord('成都中医药大学', output = 'XML',to_table = FALSE)
res <- getCoord("成都中医药大学", output = "XML", to_table = FALSE)
res
#> {xml_document}
#> <response>
Expand All @@ -139,8 +183,7 @@ res
`extractCoord` is created to get a result as a data.table.

``` r
tb <-
extractCoord(res)
tb <- extractCoord(res)
knitr::kable(tb)
```

Expand All @@ -153,8 +196,7 @@ knitr::kable(tb)
get result of reverse geocoding, by `getLocation` function.

``` r
res <-
getLocation(104.043284, 30.666864)
res <- getLocation(104.043284, 30.666864)
knitr::kable(res)
```

Expand All @@ -163,8 +205,7 @@ knitr::kable(res)
| 四川省成都市金牛区西安路街道成都中医药大学附属医院腹泻门诊成都中医药大学(十二桥校区) | 中国 | 四川省 | 成都市 | 金牛区 | 西安路街道 | 028 | 510106024000 |

``` r
res <-
getLocation(104.043284, 30.666864, output = 'XML',to_table = FALSE)
res <- getLocation(104.043284, 30.666864, output = "XML", to_table = FALSE)
res
#> {xml_document}
#> <response>
Expand All @@ -177,8 +218,7 @@ res
`extractLocation` is created to get a result as a data.table.

``` r
tb <-
extractLocation(res)
tb <- extractLocation(res)
knitr::kable(tb)
```

Expand All @@ -201,8 +241,7 @@ This is becasue, this function support different administrative region
levels, bind their result is nonsense.

``` r
res <-
getAdmin(c('四川省','成都市','济宁市'))
res <- getAdmin(c("四川省", "成都市", "济宁市"))
knitr::kable(res)
```

Expand All @@ -216,26 +255,26 @@ knitr::kable(res)

| lng | lat | name | level | citycode | adcode |
| -------: | -------: | :-------- | :---- | :------- | :----- |
| 106.7537 | 31.85881 | 巴中市 | city | 0827 | 511900 |
| 104.0657 | 30.65946 | 成都市 | city | 028 | 510100 |
| 104.3987 | 31.12799 | 德阳市 | city | 0838 | 510600 |
| 105.8298 | 32.43367 | 广元市 | city | 0839 | 510800 |
| 105.5713 | 30.51331 | 遂宁市 | city | 0825 | 510900 |
| 104.6419 | 30.12221 | 资阳市 | city | 0832 | 512000 |
| 104.0657 | 30.65946 | 成都市 | city | 028 | 510100 |
| 104.7417 | 31.46402 | 绵阳市 | city | 0816 | 510700 |
| 106.6334 | 30.45640 | 广安市 | city | 0826 | 511600 |
| 107.5023 | 31.20948 | 达州市 | city | 0818 | 511700 |
| 104.3987 | 31.12799 | 德阳市 | city | 0838 | 510600 |
| 106.7537 | 31.85881 | 巴中市 | city | 0827 | 511900 |
| 106.0830 | 30.79528 | 南充市 | city | 0817 | 511300 |
| 105.0661 | 29.58708 | 内江市 | city | 1832 | 511000 |
| 104.6308 | 28.76019 | 宜宾市 | city | 0831 | 511500 |
| 105.4433 | 28.88914 | 泸州市 | city | 0830 | 510500 |
| 102.2214 | 31.89979 | 阿坝藏族羌族自治州 | city | 0837 | 513200 |
| 104.7734 | 29.35277 | 自贡市 | city | 0813 | 510300 |
| 103.0010 | 29.98772 | 雅安市 | city | 0835 | 511800 |
| 105.4433 | 28.88914 | 泸州市 | city | 0830 | 510500 |
| 104.6419 | 30.12221 | 资阳市 | city | 0832 | 512000 |
| 103.8318 | 30.04832 | 眉山市 | city | 1833 | 511400 |
| 103.7613 | 29.58202 | 乐山市 | city | 0833 | 511100 |
| 101.7160 | 26.58045 | 攀枝花市 | city | 0812 | 510400 |
| 104.6308 | 28.76019 | 宜宾市 | city | 0831 | 511500 |
| 105.5713 | 30.51331 | 遂宁市 | city | 0825 | 510900 |
| 105.0661 | 29.58708 | 内江市 | city | 1832 | 511000 |
| 107.5023 | 31.20948 | 达州市 | city | 0818 | 511700 |
| 102.2587 | 27.88676 | 凉山彝族自治州 | city | 0834 | 513400 |
| 101.7160 | 26.58045 | 攀枝花市 | city | 0812 | 510400 |
| 103.0010 | 29.98772 | 雅安市 | city | 0835 | 511800 |
| 102.2214 | 31.89979 | 阿坝藏族羌族自治州 | city | 0837 | 513200 |
| 101.9638 | 30.05066 | 甘孜藏族自治州 | city | 0836 | 513300 |

</td>
Expand All @@ -245,25 +284,25 @@ knitr::kable(res)
| lng | lat | name | level | citycode | adcode |
| -------: | -------: | :--- | :------- | :------- | :----- |
| 103.9412 | 30.98516 | 彭州市 | district | 028 | 510182 |
| 103.6279 | 30.99114 | 都江堰市 | district | 028 | 510181 |
| 103.5224 | 30.58660 | 大邑县 | district | 028 | 510129 |
| 103.5115 | 30.19436 | 蒲江县 | district | 028 | 510131 |
| 104.2549 | 30.88344 | 青白江区 | district | 028 | 510113 |
| 104.5503 | 30.39067 | 简阳市 | district | 028 | 510185 |
| 103.5224 | 30.58660 | 大邑县 | district | 028 | 510129 |
| 103.6279 | 30.99114 | 都江堰市 | district | 028 | 510181 |
| 103.6710 | 30.63148 | 崇州市 | district | 028 | 510184 |
| 104.5503 | 30.39067 | 简阳市 | district | 028 | 510185 |
| 103.5115 | 30.19436 | 蒲江县 | district | 028 | 510131 |
| 103.8124 | 30.41428 | 新津区 | district | 028 | 510118 |
| 104.4156 | 30.85842 | 金堂县 | district | 028 | 510121 |
| 103.4614 | 30.41327 | 邛崃市 | district | 028 | 510183 |
| 103.8124 | 30.41428 | 新津区 | district | 028 | 510132 |
| 103.8368 | 30.69800 | 温江区 | district | 028 | 510115 |
| 103.8878 | 30.80875 | 郫都区 | district | 028 | 510117 |
| 103.9227 | 30.57324 | 双流区 | district | 028 | 510116 |
| 103.8878 | 30.80875 | 郫都区 | district | 028 | 510117 |
| 104.0517 | 30.63086 | 武侯区 | district | 028 | 510107 |
| 104.0435 | 30.69206 | 金牛区 | district | 028 | 510106 |
| 104.1602 | 30.82422 | 新都区 | district | 028 | 510114 |
| 104.2692 | 30.56065 | 龙泉驿区 | district | 028 | 510112 |
| 104.1602 | 30.82422 | 新都区 | district | 028 | 510114 |
| 104.1031 | 30.66027 | 成华区 | district | 028 | 510108 |
| 104.0557 | 30.66765 | 青羊区 | district | 028 | 510105 |
| 104.0810 | 30.65769 | 锦江区 | district | 028 | 510104 |
| 104.0557 | 30.66765 | 青羊区 | district | 028 | 510105 |

</td>

Expand Down Expand Up @@ -292,8 +331,7 @@ knitr::kable(res)
</table>

``` r
res <-
getAdmin('四川省', output = 'XML', to_table = FALSE)
res <- getAdmin("四川省", output = "XML", to_table = FALSE)
res
#> {xml_document}
#> <response>
Expand All @@ -317,33 +355,32 @@ res
#> [4] <count>1</count>
#> [5] <suggestion>\n <keywords type="list"/>\n <cities type="list"/>\n</sugge ...
#> [6] <districts type="list">\n <district>\n <citycode/>\n <adcode>51000 ...
tb <-
extractAdmin(res)
tb <- extractAdmin(res)
knitr::kable(tb)
```

| lng | lat | name | level | citycode | adcode |
| -------: | -------: | :-------- | :---- | :------- | :----- |
| 106.7537 | 31.85881 | 巴中市 | city | 0827 | 511900 |
| 104.0657 | 30.65946 | 成都市 | city | 028 | 510100 |
| 104.3987 | 31.12799 | 德阳市 | city | 0838 | 510600 |
| 105.8298 | 32.43367 | 广元市 | city | 0839 | 510800 |
| 105.5713 | 30.51331 | 遂宁市 | city | 0825 | 510900 |
| 104.6419 | 30.12221 | 资阳市 | city | 0832 | 512000 |
| 104.0657 | 30.65946 | 成都市 | city | 028 | 510100 |
| 104.7417 | 31.46402 | 绵阳市 | city | 0816 | 510700 |
| 106.6334 | 30.45640 | 广安市 | city | 0826 | 511600 |
| 107.5023 | 31.20948 | 达州市 | city | 0818 | 511700 |
| 104.3987 | 31.12799 | 德阳市 | city | 0838 | 510600 |
| 106.7537 | 31.85881 | 巴中市 | city | 0827 | 511900 |
| 106.0830 | 30.79528 | 南充市 | city | 0817 | 511300 |
| 105.0661 | 29.58708 | 内江市 | city | 1832 | 511000 |
| 104.6308 | 28.76019 | 宜宾市 | city | 0831 | 511500 |
| 105.4433 | 28.88914 | 泸州市 | city | 0830 | 510500 |
| 102.2214 | 31.89979 | 阿坝藏族羌族自治州 | city | 0837 | 513200 |
| 104.7734 | 29.35277 | 自贡市 | city | 0813 | 510300 |
| 103.0010 | 29.98772 | 雅安市 | city | 0835 | 511800 |
| 105.4433 | 28.88914 | 泸州市 | city | 0830 | 510500 |
| 104.6419 | 30.12221 | 资阳市 | city | 0832 | 512000 |
| 103.8318 | 30.04832 | 眉山市 | city | 1833 | 511400 |
| 103.7613 | 29.58202 | 乐山市 | city | 0833 | 511100 |
| 101.7160 | 26.58045 | 攀枝花市 | city | 0812 | 510400 |
| 104.6308 | 28.76019 | 宜宾市 | city | 0831 | 511500 |
| 105.5713 | 30.51331 | 遂宁市 | city | 0825 | 510900 |
| 105.0661 | 29.58708 | 内江市 | city | 1832 | 511000 |
| 107.5023 | 31.20948 | 达州市 | city | 0818 | 511700 |
| 102.2587 | 27.88676 | 凉山彝族自治州 | city | 0834 | 513400 |
| 101.7160 | 26.58045 | 攀枝花市 | city | 0812 | 510400 |
| 103.0010 | 29.98772 | 雅安市 | city | 0835 | 511800 |
| 102.2214 | 31.89979 | 阿坝藏族羌族自治州 | city | 0837 | 513200 |
| 101.9638 | 30.05066 | 甘孜藏族自治州 | city | 0836 | 513300 |

### Convert coordinate point from other coordinate system to AutoNavi
Expand All @@ -357,8 +394,7 @@ input method is not as delicate as I expect. If you have any good idea,
please let me know or just fork repo and pull a reques.**

``` r
res <-
convertCoord('116.481499,39.990475',coordsys = 'gps')
res <- convertCoord("116.481499,39.990475", coordsys = "gps")
knitr::kable(res)
```

Expand All @@ -367,8 +403,7 @@ knitr::kable(res)
| 116.4876 | 39.99175 |

``` r
res <-
convertCoord('116.481499,39.990475',coordsys = 'gps', to_table = FALSE)
res <- convertCoord("116.481499,39.990475", coordsys = "gps", to_table = FALSE)
res
#> $status
#> [1] "1"
Expand All @@ -386,8 +421,7 @@ res
`extractConvertCoord` is created to get result as data.table.

``` r
tb <-
extractConvertCoord(res)
tb <- extractConvertCoord(res)
knitr::kable(tb)
```

Expand Down
Loading

0 comments on commit ee77d38

Please sign in to comment.