1
1
# Open Location Code PL/SQL
2
+
2
3
This is the pl/sql implementation of the Open Location Code.
3
4
4
5
The library file is in ` pluscode_functions.sql ` .
5
6
6
7
All functions are installed in the public Schema.
7
8
8
- # Tests
9
+ ## Tests
10
+
11
+ Unit tests require [ Docker] ( https://www.docker.com/ ) to be installed.
12
+
13
+ Download the ` pluscode_functions.sql ` and ` tests_script_l.sql ` files.
9
14
10
- Unit tests require docker,
11
- [ DockerDesktop] ( https://www.docker.com/ )
15
+ Start a [ PostgreSQL Docker] ( https://hub.docker.com/_/postgres ) image and copy the Open Location Code files to it:
12
16
13
- Download the pluscode_functions.sql file.
17
+ 1 . Download and run a PostgreSQL image. Call it ` pgtest ` and run on port 5433:
14
18
15
- Download the tests_script_l.sql file.
19
+ ``` shell
20
+ docker run --name pgtest -e POSTGRES_PASSWORD=postgres -d -p 5433:5432 postgres
21
+ ```
16
22
17
- Before run the tests :
23
+ 1. Copy the Open Location Code files to the container and change the permissions to allow the ` postgres ` user to read them :
18
24
19
- A - Upload and run postgresql image name : pgtest port 5433
20
- ` docker run --name pgtest -e POSTGRES_PASSWORD=postgres -d -p 5433:5432 postgres `
25
+ ` ` ` shell
26
+ docker cp pluscode_functions.sql pgtest:/pluscode_functions.sql
27
+ docker cp tests_script_l.sql pgtest:/tests_script_l.sql
28
+ sudo docker exec pgtest chmod a+r * .sql
29
+ ` ` `
21
30
22
- B - COPY file with olc functions in the container
23
- ` docker cp c:/path/to/file/pluscode_functions.sql pgtest:/pluscode_functions.sql `
31
+ 1. Execute the SQL that defines the functions in the db:
24
32
25
- C - COPY file with Tests in the container
26
- ` docker cp c:/path/to/file/tests_script_l.sql pgtest:/tests_script_l.sql `
33
+ ` ` ` shell
34
+ docker exec -u postgres pgtest psql postgres postgres -f ./pluscode_functions.sql
35
+ ` ` `
27
36
28
- D - Execute openlocation.sql in db
29
- ` docker exec -u postgres pgtest psql postgres postgres -f ./pluscode_functions.sql `
37
+ 1. Execute tests script
30
38
31
- Then Execute tests script
32
- ` docker exec -u postgres pgtest psql postgres postgres -f ./tests_script_l.sql `
39
+ ` ` ` shell
40
+ docker exec -u postgres pgtest psql postgres postgres -f ./tests_script_l.sql
41
+ ` ` `
33
42
43
+ # # Functions
34
44
35
- ## pluscode_encode()
45
+ # ## pluscode_encode()
36
46
37
47
` ` ` sql
38
48
pluscode_encode(latitude, longitude, codeLength) → {string}
@@ -48,7 +58,7 @@ Encode a location into an Open Location Code.
48
58
| ` longitude` | ` number` |
49
59
| ` codeLength` | ` number` |
50
60
51
- ## pluscode_decode()
61
+ # ## pluscode_decode()
52
62
53
63
` ` ` sql
54
64
pluscode_decode(code) → {codearea record}
@@ -66,8 +76,7 @@ Decodes an Open Location Code into its location coordinates.
66
76
67
77
The ` CodeArea` record.
68
78
69
-
70
- ## pluscode_shorten()
79
+ # ## pluscode_shorten()
71
80
72
81
` ` ` sql
73
82
pluscode_shorten(code, latitude, longitude) → {string}
@@ -88,8 +97,7 @@ Remove characters from the start of an OLC code.
88
97
The code, shortened as much as possible that it is still the closest matching
89
98
code to the reference location.
90
99
91
-
92
- ## pluscode_recoverNearest()
100
+ # ## pluscode_recoverNearest()
93
101
94
102
` ` ` sql
95
103
pluscode_recoverNearest(shortCode, referenceLatitude, referenceLongitude) → {string}
0 commit comments