-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathopenstreetmap.neo4j-browser-guide
363 lines (327 loc) · 14.6 KB
/
openstreetmap.neo4j-browser-guide
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<style type="text/css" media="screen">
/*
.nodes-image {
margin:-100;
}
*/
@import url("//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css");
.imageblock .content img, .image img {max-width: 100%;}
.deck h3, .deck h4 {display: block !important;margin-bottom:8px;margin-top:5px;}
.listingblock {margin:8px;}
.pull-bottom {position:relative;bottom:1em;}
.admonitionblock td.icon [class^="fa icon-"]{font-size:2.5em;text-shadow:1px 1px 2px rgba(0,0,0,.5);cursor:default}
.admonitionblock td.icon .icon-note:before{content:"\f05a";color:#19407c}
.admonitionblock td.icon .icon-tip:before{content:"\f0eb";text-shadow:1px 1px 2px rgba(155,155,0,.8);color:#111}
.admonitionblock td.icon .icon-warning:before{content:"\f071";color:#bf6900}
.admonitionblock td.icon .icon-caution:before{content:"\f06d";color:#bf3400}
.admonitionblock td.icon .icon-important:before{content:"\f06a";color:#bf0000}
.admonitionblock.note.speaker { display:none; }
</style>
<style type="text/css" media="screen">
/* #editor.maximize-editor .CodeMirror-code { font-size:24px; line-height:26px; } */
</style>
<article class="guide" ng-controller="AdLibDataController">
<carousel class="deck container-fluid">
<!--slide class="row-fluid">
<div class="col-sm-3">
<h3>Exploring the area</h3>
<p class="lead">Information</p>
<!dl>
</dl>
</div>
<div class="col-sm-9">
<figure>
<img style="width:300px" src=""/>
</figure>
</div>
</slide-->
<h4>Exploring the area</h4>
<div class="paragraph">
<p>This guide is based on the <a href="https://medium.com/neo4j/summer-of-nodes-final-week-exploring-the-area-ac4b24735612" target="_blank">Summer of Nodes challenge: Walkabout</a></p>
</div>
<div class="paragraph">
<p>In this sandbox, we’ll be using points of interest in New York’s Central Park, to explore the Neo4j <a href="https://neo4j.com/docs/cypher-manual/current/functions/spatial/" target="_blank">spatial functions and types</a>.</p>
</div>
<div class="paragraph">
<p>Want to do your own thing with spatial data? Please do! The following plugins are also available on this sandbox:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://neo4j.com/labs/apoc/" target="_blank">APOC Library documentation</a></p>
</li>
<li>
<p><a href="https://neo4j.com/docs/graph-data-science/current/" target="_blank">Graph Data Science Library documentation</a></p>
</li>
</ul>
</div>
<slide class="row-fluid">
<div class="col-sm-12">
<h3>The data</h3>
<br/>
<div>
<div class="imageblock" style="float: left;">
<div class="content">
<img src="https://guides.neo4j.com/sandbox/openstreetmap/img/ny-central-park.jpeg" alt="ny central park" width="300">
</div>
<div class="title"><a href="https://unsplash.com/photos/WRygjt-uCpw" target="_blank">Central Park, New York</a> by Jorge Gardner</div>
</div>
<div class="paragraph">
<p>Central Park in New York is one of the most popular tourist attractions in the city. Last year, Central Park saw 42 million visitors alone. In this sandbox we are going to be using this amazing location to do some exploration, with graphs!</p>
</div>
<div class="paragraph">
<p>We have imported some routes and tagged Points of Interest for Central Park, based on OpenStreetMap, and we will be asking you to take on the role of the virtual tourist. We will be using the sandbox exclusively for the challenge this week.</p>
</div>
<div class="paragraph">
<p>For those of you who are interested, the data was extracted with <a href="https://github.com/neo4j-contrib/osm" target="_blank">this plugin</a>, and there was some Cypher data wrangling applied after import. As a result, we don’t have all the sights, but we do have a pretty good sample to work with.</p>
</div>
</div>
</div>
</slide>
<slide class="row-fluid">
<div class="col-sm-12">
<h3>The model</h3>
<br/>
<div>
<div class="paragraph">
<p>If you look at <code>db.schema.visualization()</code> you will see many labels and relationship types. Many of these labels we are not going to use in this sandbox example. There are only two node label types we’re going to be using:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>OSMNode</code> — Think of this as a junction node — it hooks together routes from specific points</p>
</li>
<li>
<p><code>PointOfInterest:OSMNode</code> — In addition to the above, this also has our points of interest, e.g. types of statues, restaurants, tennis courts, etc. and their names</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>And we’ll only be using the <code>ROUTE</code> relationship type. Here’s a simplified data model that you’ll need for this sandbox:</p>
</div>
<div class="imageblock">
<div class="content">
<img src="https://guides.neo4j.com/sandbox/openstreetmap/img/model.png" alt="model" width="600">
</div>
</div>
</div>
</div>
</slide>
<slide class="row-fluid">
<div class="col-sm-12">
<h3>Introduction to spatial</h3>
<br/>
<div>
<div class="paragraph">
<p>Cypher has built-in support for handling <a href="https://neo4j.com/docs/cypher-manual/current/syntax/spatial/" target="_blank">spatial values (points)</a>, and the underlying database supports storing these point values as properties on nodes and relationships in either 2 or 3 dimensions. These include:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Geographic coordinate reference systems</p>
</li>
<li>
<p>Cartesian coordinate reference systems</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Cypher also supports the following <a href="https://neo4j.com/docs/cypher-manual/current/functions/spatial/" target="_blank">spatial functions</a>:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>point.distance()</code> between points</p>
</li>
<li>
<p>Returning points in WGS 84 and Cartesian</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>You can find out more in the linked documentation above. Now, time for a walkabout!</p>
</div>
</div>
</div>
</slide>
<slide class="row-fluid">
<div class="col-sm-12">
<h3>Looking for a clock</h3>
<br/>
<div>
<div class="imageblock" style="float: right;">
<div class="content">
<img src="https://guides.neo4j.com/sandbox/openstreetmap/img/clock-search.jpeg" alt="clock search" width="250">
</div>
<div class="title"><a href="https://unsplash.com/photos/B_TdfGFuGwA" target="_blank">Behind a clock</a> by Murray Campbell</div>
</div>
<div class="paragraph">
<p>You’ll start your walking adventure at a clock (type:’clock’). What’s its name?</p>
</div>
<div class="listingblock">
<div class="content">
<pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->MATCH (p:PointOfInterest {type:'clock'})
RETURN p.name<!--/code--></pre>
</div>
</div>
<div class="paragraph">
<p>From this position, what other Point of Interest is within 100m from a straight line?</p>
</div>
<div class="listingblock">
<div class="content">
<pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->MATCH (p1:PointOfInterest {type:'clock'}), (p2:PointOfInterest)
WHERE p1<>p2 AND point.distance(p1.location,p2.location) < 100
RETURN p2.name<!--/code--></pre>
</div>
</div>
</div>
</div>
</slide>
<slide class="row-fluid">
<div class="col-sm-12">
<h3>Distances</h3>
<br/>
<div>
<div class="imageblock" style="float: right;">
<div class="content">
<img src="https://guides.neo4j.com/sandbox/openstreetmap/img/crow.jpeg" alt="crow" width="300">
</div>
<div class="title">By <a href="https://unsplash.com/photos/T5Ye7puWZxo" target="_blank">Tyler Quiring</a></div>
</div>
<div class="paragraph">
<p>How far apart are the zoo school and the clock as a straight line (as the crow flies)?</p>
</div>
<div class="listingblock">
<div class="content">
<pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->MATCH (p1:PointOfInterest {type:'clock'}), (p2:PointOfInterest {name:'Zoo School'})
RETURN point.distance(p1.location,p2.location)<!--/code--></pre>
</div>
</div>
<div class="paragraph">
<p>How far is the actual (walking) distance?</p>
</div>
<div class="listingblock">
<div class="content">
<pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->MATCH path=shortestpath((p1:PointOfInterest {type:'clock'})-[:ROUTE*]-(p2:PointOfInterest {name:'Zoo School'}))
WITH relationships(path) AS rels
UNWIND rels AS rel
RETURN sum(rel.distance)<!--/code--></pre>
</div>
</div>
</div>
</div>
</slide>
<slide class="row-fluid">
<div class="col-sm-12">
<h3>Time for a coffee and cycle!</h3>
<br/>
<div>
<div class="imageblock" style="float: left;">
<div class="content">
<img src="https://guides.neo4j.com/sandbox/openstreetmap/img/coffee-cycle.jpeg" alt="coffee cycle" width="200">
</div>
<div class="title"><a href="https://unsplash.com/photos/8e9hQXS9VQA" target="_blank">Coffee Shop</a> by Partha Narasimhan</div>
</div>
<div class="paragraph">
<p>You’re thinking of going for a cycle ride, but first a coffee! Locate which cafe <code>type:'cafe'</code> is closest to a bicycle rental place <code>type:'bicycle rental'</code>. What’s the name of the cafe?</p>
</div>
<div class="listingblock">
<div class="content">
<pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->MATCH path = shortestPath((p1:PointOfInterest {type:'cafe'})-[:ROUTE*]-(p2:PointOfInterest {type:'bicycle rental'}))
WITH p1, p2, relationships(path) AS rels //extract all the relationships in the path as an array
UNWIND rels AS rel //unwind the array of relationships
RETURN p1.name, p2.name, sum(rel.distance) AS dist ORDER BY dist<!--/code--></pre>
</div>
</div>
<div class="paragraph">
<p>Let’s compare the outputs of shortestPath() against weighted shortest path with the Dijkstra APOC function:</p>
</div>
<div class="listingblock">
<div class="content">
<pre mode="cypher" class="highlight pre-scrollable programlisting cm-s-neo code runnable standalone-example ng-binding" data-lang="cypher" lang="cypher"><!--code class="cypher language-cypher"-->MATCH path = (p1:PointOfInterest {type:'cafe'}),(p2:PointOfInterest {type:'bicycle rental'})
CALL apoc.algo.dijkstra(p1, p2, 'ROUTE', 'distance') YIELD weight AS dist
RETURN p1.name, p2.name, dist ORDER BY dist<!--/code--></pre>
</div>
</div>
<div class="paragraph">
<p>Confused? Let’s explore!</p>
</div>
</div>
</div>
</slide>
<slide class="row-fluid">
<div class="col-sm-12">
<h3>Shortest path versus weighted shortest path</h3>
<br/>
<div>
<div class="paragraph">
<p>The <a href="https://neo4j.com/docs/cypher-manual/current/clauses/match/#query-shortest-path" target="_blank"><code>shortestPath()</code></a> Cypher function will return the first shortest path by number of relationship hops it finds between two specified points.</p>
</div>
<div class="paragraph">
<p>The <a href="https://neo4j.com/labs/apoc/4.0/overview/apoc.algo/apoc.algo.dijkstra/" target="_blank"><code>apoc.algo.dijkstra()</code></a> APOC function will return the shortest weighted path, based on a specified property on relationships between two specified points, irrespective of the number of hops between them.</p>
</div>
<div class="paragraph">
<p>The previous two queries provide a great example that the shortest path by traversing the minimum number of nodes does not mean it’s the shortest distance by actual ground covered!</p>
</div>
</div>
</div>
</slide>
<slide class="row-fluid">
<div class="col-sm-12">
<h3>Vizualising the results: Neomaps</h3>
<br/>
<div>
<div class="imageblock" style="float: right;">
<div class="content">
<img src="https://guides.neo4j.com/sandbox/openstreetmap/imgneomap.png" alt="imgneomap" width="200">
</div>
</div>
<div class="paragraph">
<p>NeoMaps is an excellent graph app, created by community member Estelle Scifo. This fantastic app allows you to plot spatial data onto an OpenStreetMap view. The following image shows all of our <code>PointsOfInterest</code> plotted as points:</p>
</div>
<div class="paragraph">
<p>To find out how to get going, you can read about it in Estelle’s blog post <a href="https://medium.com/neo4j/introducing-neomap-a-neo4j-desktop-application-for-spatial-data-3e14aad59db2" target="_blank">here</a>.</p>
</div>
<div class="paragraph">
<p>To install NeoMap, you just need to paste the following into the graph apps tab in Neo4j Desktop: <code><a href="https://registry.npmjs.org/neomap" class="bare">https://registry.npmjs.org/neomap</a></code>. You can then use it on your sandbox by adding a 'remote database', with the sandbox details.</p>
</div>
<div class="paragraph">
<p>Estelle also gives you an example of <a href="https://medium.com/neo4j/visualizing-shortest-paths-with-neomap-0-4-0-and-the-neo4j-graph-data-science-plugin-18db92f680de" target="_blank">how to get up and running</a> with your own locations if you want to check out your local area too! It’s also useful for seeing how to work with shortest path.</p>
</div>
<div class="imageblock" style="float: right;">
<div class="content">
<img src="https://guides.neo4j.com/sandbox/openstreetmap/img/graph-app-install.png" alt="graph app install" width="200">
</div>
</div>
</div>
</div>
</slide>
<slide class="row-fluid">
<div class="col-sm-12">
<h3>Find out more</h3>
<br/>
<div>
<div class="paragraph">
<p>We hope you enjoyed this short exploration of the Neo4j spatial functions and types. The following links may be useful if you want to find out more, or experiment with the Graph Data Science or APOC libraries on this data set:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://neo4j.com/docs/cypher-manual/current/functions/spatial/" target="_blank">Spatial documentation</a></p>
</li>
<li>
<p><a href="https://neo4j.com/docs/graph-data-science/current/" target="_blank">Graph Data Science documentation</a></p>
</li>
<li>
<p><a href="https://neo4j.com/labs/apoc/" target="_blank">APOC documentation</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Perhaps you’d like to have a look at the other Summer of Nodes challenges? Check them out <a href="https://medium.com/neo4j/so-long-summer-of-nodes-2020-832f259baac6" target="_blank">here</a>.</p>
</div>
</div>
</div>
</slide>
</carousel>
</article>