Geoapplications development http://rgeo.wikience.org Higher School - - PowerPoint PPT Presentation

geoapplications development http rgeo wikience org
SMART_READER_LITE
LIVE PREVIEW

Geoapplications development http://rgeo.wikience.org Higher School - - PowerPoint PPT Presentation

Geoapplications development http://rgeo.wikience.org Higher School of Economics, Moscow, www.cs.hse.ru 2 Agenda 3 Binary search and DB index Index Data Index Data 1 34 2 3 2 3 3 12 3 12 5 21 4 55 1 34 5 21 4 55


slide-1
SLIDE 1

Geoapplications development http://rgeo.wikience.org

Higher School of Economics, Moscow, www.cs.hse.ru

slide-2
SLIDE 2

Agenda

2

slide-3
SLIDE 3

Binary search and DB index

3

Approach 1 (straightforward): Sequential scan, O(N) Drawback: slow Index Data 1 34 2 3 3 12 4 55 5 21 Index Data 2 3 3 12 5 21 1 34 4 55 Approach 2 (optimized): Binary search, O(log N) Drawback: need to maintain index

slide-4
SLIDE 4

Intersection problem: approach 1

4

Approach 1 (straightforward): for each pair (gi, gj) compute Egenhofer matrix, if it is not empty, gi and gj intersect Drawback: slow, because

  • peration is complex
slide-5
SLIDE 5

Intersection problem: approach 2

5

Approach 2 (with MBR):

  • 1. for each geometry gi find MBR_i
  • 2. for each (MBR_i, MBR_j) test

whether they intersect (fast)

  • 3. if they do, compute Egenhofer

matrix, check for intersection pattern (slower) Significantly reduce the need to perform step 3

slide-6
SLIDE 6

Minimum Bounding Rectangle (MBR)

6

http://purl.oclc.org/coordinates/a2.htm 3D case – Minimum Bounding Box (MBB)

https://en.wikipedia.org/wiki/Minimum_bounding_box https://en.wikipedia.org/wiki/Minimum_bounding_rectangle

http://www.scriptspot.com/files/u9133/tm_bbox.png

slide-7
SLIDE 7

Java Topology Suite: Envelope/MBR Checks

7

public boolean crosses(Geometry g) { // short-circuit test if (! getEnvelopeInternal().intersects(g.getEnvelopeInternal())) return false; return relate(g).isCrosses(getDimension(), g.getDimension()); } public boolean intersects(Envelope other) { if (isNull() || other.isNull()) { return false; } return !(other.minx > maxx ||

  • ther.maxx < minx ||
  • ther.miny > maxy ||
  • ther.maxy < miny);

} package com.vividsolutions.jts.geom;

slide-8
SLIDE 8

PostGIS Envelope

8

http://postgis.net/docs/manual-2.2/ST_Envelope.html geometry ST_Envelope(geometry g1); Implements:

  • OpenGIS Simple Features Implementation Specification for SQL 1.1.
  • SQL/MM specification. SQL-MM 3: 5.1.15

geometry ST_MakeEnvelope(double precision xmin, double precision ymin, double precision xmax, double precision ymax, integer srid=unknown); Example: SELECT ST_AsText(ST_Envelope('LINESTRING(0 0, 1 3)'::geometry)); POLYGON((0 0,0 3,1 3,1 0,0 0))

slide-9
SLIDE 9

Subset problem

9

Approach 1 (straightforward): Compute intersection of points/geometries with rectangle Approach 2:

slide-10
SLIDE 10

Geohash

10

https://en.wikipedia.org/wiki/Geohash

slide-11
SLIDE 11

Geohash: decode example, step 1

11

https://en.wikipedia.org/wiki/Geohash

Only 5 bits are valid (2^31 = 11111) u = 26 (decimal) = 11010 (binary) c = 11 = ‭ 01011‭ f = 14 = ‭ 01110‭ t = 25 = ‭ 11001‭ and so on . . . the resulting sequence of bits 11010 01011 01110 11001 . . .

slide-12
SLIDE 12

Geohash: decode example, step 2

12

11010 01011 01110 11001 . . .

Odd bits for lat, even bits for lon (left to right):

lat = 1001101010 . . . lon = 1100111101 . . .

https://en.wikipedia.org/wiki/Geohash

slide-13
SLIDE 13

Geohash: decode example, step 3

13

lat = 1001101010…, lon = 1100111101… 1001101010…

slide-14
SLIDE 14

Geohash properties: precision

14

source

slide-15
SLIDE 15

Geohash properties: neighborhood

15

slide-16
SLIDE 16

Geohash limitations

16

Source

slide-17
SLIDE 17

Geohash algorithms: filter by rectangle

17

  • source
slide-18
SLIDE 18

Geohash algorithms: Ngram Tree Traveral

18

source

  • 1. Determine a “good” grid cell size with minimal overlap
  • f grid to query shape
  • 2. Get list of overlapping grid cells <g1, g2, …, gN>
  • 3. For each grid cell gi:
  • Seek all points with geohashes with having prefix of

gi gird cell

  • For each point decode its geohash and intersect

with query shape

slide-19
SLIDE 19

Geohash algorithms: filter – fixed grid depth

19

source

  • 1. Index each point at every grid level :

D, DR, DRT, DRT2, DRT2Y

  • 2. Recursive loop across top grid cells:
  • If cell is within query shape, simply add

all assigned documents to result

  • If cell intersects query shape,

recursive(cell.subcells) This requires careful implementation

slide-20
SLIDE 20

Geohash uses

20

GeoHash Java implementations:

https://github.com/kungfoo/geohash-java https://github.com/astrapi69/jgeohash https://github.com/davidmoten/geo

slide-21
SLIDE 21

R-Tree

21

  • Query not intersecting MBR
  • f a given node, cannot

intersect any of the contained geometries

slide-22
SLIDE 22

R-Tree: challenges

22

slide-23
SLIDE 23

R-Tree: one more example

23

https://en.wikipedia.org/wiki/R-tree

slide-24
SLIDE 24

R-Tree operations: insert

24

slide-25
SLIDE 25

R*-Tree, R+Tree

25

https://en.wikipedia.org/wiki/R%2B_tree https://en.wikipedia.org/wiki/R*_tree

slide-26
SLIDE 26

JTS and R-Tree

26

slide-27
SLIDE 27

PostGIS and R-Tree

27

http://postgis.net/docs/manual-2.2/using_postgis_dbmanagement.html#gist_indexes

slide-28
SLIDE 28

Problem: efficient read of 2D slice from disk

28

slide-29
SLIDE 29

Hilbert Curve

29

https://en.wikipedia.org/wiki/Hilbert_curve

slide-30
SLIDE 30

Readings

30

  • https://en.wikipedia.org/wiki/Geohash
slide-31
SLIDE 31

Practical task

31

slide-32
SLIDE 32