In this workshop, I will:
- tell you that the Earth is not flat (SHOCK!) and why that's very inconvenient;
- define common terms (What's projection? There's also a coordinate system?.. OGC, OSM, WKT, WGS, ESPG?);
- teach you All Things You Need To Know (tm) to become a geo-developer and build things for geo or using geo;
- explain popular caveats - Dos and Don'ts - when working with geo;
- give you an overview of geo-technologies, databases, libraries;
- give you references for further reading.
2. smartpuffin.com | @ice_lenor | #geo
Who am I?
● 10 years in Geo
● Started in 2GIS
● Built a distributed scalable
GIS-system called Fiji
○ Tailored to needs of
3000 cartographers
● Allowed the business to
scale world-wide
● 3 years in Geo team in
Booking
● Built GeoObject database
● Built process of data
collection between Tech
and Geo Content
departments
4. smartpuffin.com | @ice_lenor | #geo
What is an integer?
● A whole number
● 4 bytes (nowadays, mostly)
● Unsigned or signed
○ Signed range: [-2,147,483,648 .. 2,147,483,647]
○ Unsigned range: [0, 4,294,967,295]
● If you divide 2 integers, you'll get an integer
5. smartpuffin.com | @ice_lenor | #geo
Common wisdom
● One doesn't store money in double
● When working with strings, mind the encoding
● Theoretically, π is endless; but practically, first
~10 digits will do
● A very large or small double loses precision
● Array representation in memory depends
28. smartpuffin.com | @ice_lenor | #geo
Latitude
0°
90° North
-90° South
North Pole
South Pole
30th parallel North
30° N
30°
40th parallel South
40° S
-40°
Equator
0° N
29. smartpuffin.com | @ice_lenor | #geo
Longitude
0°
-180°
West
180°
East
40th meridian east
40° E
40°20th meridian west
40° W
-40°
Prime meridian
0°
30. smartpuffin.com | @ice_lenor | #geosmartpuffin.com | @ice_lenor | #geo
Datums and
Coordinate Systems
How round is Earth, exactly?
33. smartpuffin.com | @ice_lenor | #geo
WGS84
The latest revision is WGS 84 (also known as WGS
1984, EPSG:4326). The WGS 84 datum surface is
an oblate spheroid with equatorial radius a =
6378137 m at the equator and flattening f =
1/298.257223563. The polar semi-minor axis b
then equals a × (1 − f) = 6356752.3142 m. Currently,
WGS 84 uses the Earth Gravitational Model 1996
(EGM96) geoid, revised in 2004. This geoid defines
the nominal sea level surface by means of a
spherical harmonics series of degree 360 (which
provides about 100 km latitudinal resolution near
the Equator). The deviations of the EGM96 geoid
from the WGS 84 reference ellipsoid range from
about −105 m to about +85 m.[8] EGM96 differs
from the original WGS 84 geoid, referred to as
EGM84.
34. smartpuffin.com | @ice_lenor | #geo
WGS84
radius
R = 6378 km
flattening
F = 1 / 298.25
● Earth is an ellipsoid
○ flattened from the poles
○ has a certain radius
● (0,0) is specified
● Latitude is [90..-90]
● Longitude is [180..-180]
(0,0) is here
38. smartpuffin.com | @ice_lenor | #geo
Formula for distance: flat
Point(0 0) to Point(1 1) = 1.414 (units)
● We all learned it in school
● Derived from the Pythagorean
theorem
● Doesn’t know about Earth
● Just plain old distance.
39. smartpuffin.com | @ice_lenor | #geo
Formula for distance: haversine
● Uses radius
● Doesn’t use flattening
● => Calculates on sphere!
Point(0 0) to Point(1 1) = 157.2 km
40. smartpuffin.com | @ice_lenor | #geo
Formula for distance: Vincenty
● Uses radius
● And flattening
● => Calculates on WGS84!
○ Or any ellipsoid provided
● => Millimetre precision!
Point(0 0) to Point(1 1) = 156.899568 km
41. smartpuffin.com | @ice_lenor | #geo
SRID: Spatial Reference Id
● EPSG - European Petroleum Survey
Group
○ A registry of datums and projections
● WGS84's SRID is EPSG:4326
● There are other SRIDs
● You must specify SRID with your
geometry for correct math
○ I.e., when storing geodata in a database
○ Or using a library or a formula
42. smartpuffin.com | @ice_lenor | #geo
Why is a SRID like a toothbrush?
Because everyone has got one.
● British National Grid
○ Ellipsoid: Airy 1830
● Amersfoort / RD New -- Netherlands
○ Ellipsoid: Bessel 1841
● Geoscience Australia Lambert
○ Ellipsoid: GRS 1980
46. smartpuffin.com | @ice_lenor | #geo
Projection
● A means to display a N-dimensional object
in a (N-1)-dimensional space
● For maps:
○ How do we display 3D Earth on a 2D paper?
○ Or a piece of parchment?
○ Or a tapestry?
○ Or a computer screen?
49. smartpuffin.com | @ice_lenor | #geo
Projections
● A sphere can't be flattened without problems
○ You have to tug and stretch and shrink
● No projections are "100% accurate depictions"
● One has to choose what traits to preserve
○ direction
○ shape
○ area
○ distance
50. smartpuffin.com | @ice_lenor | #geo
Specific way of flattening,
shrinking, stretching, fitting
is called
a projection
51. smartpuffin.com | @ice_lenor | #geo
Mercator Projection
● Preserves angles and shapes of
small objects
● => Good for navigation
● Loses sizes (Greenland larger than
Africa)
● Mercator on WGS84 is popular
(EPSG:3395)
● What does Google use? Read on.
52. smartpuffin.com | @ice_lenor | #geo
Orthographic
● "Like I'm looking at it from
space!"
● Directions from the central
point are preserved
● The closer to the edge, the
more objects are distorted
53. smartpuffin.com | @ice_lenor | #geo
Plate Carrée
● longitude => y
● latitude => x
● Preserves angles
● Loses everything
else :)
54. smartpuffin.com | @ice_lenor | #geo
Equal-area (i.e., Mollweide, Lambert, etc)
● Preserves
relative areas
● Distorts angles
and shapes
55. smartpuffin.com | @ice_lenor | #geo
Winkel Tripel: A Compromise?
● Tries to preserve all at once
● Minimises distortion of area,
direction, and distance
● Cool name
● Used by
56. smartpuffin.com | @ice_lenor | #geo
Universal Transverse Mercator (UTM)
● Family of 60 projections ("zones")
○ Slice Earth like an orange
○ Each slice has own coordinates
● => Flat coordinates! In meters!
● Coordinate system AND projection,
in one
● Can't make map of whole planet,
only one slice
59. smartpuffin.com | @ice_lenor | #geo
Web Mercator: A Cursed Projection :)
● "Invented" by Google
○ They mix sphere and ellipsoid, boo!
○ "The underlying geographic coordinates
are defined using WGS84 [ellipsoid]
(as in 3857), but projected as if they
were defined on a sphere (as in 3785)".
● Wasn't accepted for a long time
● Old unofficial code: EPSG:900913, official: EPSG:3857
● Now - alas! - is used by many online maps
61. smartpuffin.com | @ice_lenor | #geo
OGC Standard
● Open Geospatial Consortium: 500+ companies
● De-facto defines the geo-industry
● A set of documents about how to:
○ Define geodata
○ Store geodata (in databases)
○ Index it
○ Manipulate it (in databases and in libraries)
● => Start reading with Simple Features
62. smartpuffin.com | @ice_lenor | #geosmartpuffin.com | @ice_lenor | #geo
What can I do with my geodata?
Geo Math:
Spatial Operations
63. smartpuffin.com | @ice_lenor | #geo
Distance
Point(0 0)
Point(4, 2)
Distance = 222.4 km
(calculated on WGS84)
Distance = 4.472
(calculated on flat coords)
72. smartpuffin.com | @ice_lenor | #geo
● Coordinates must be within SRID's limits
○ I.e., 95° North latitude is a no-no
● Line:
○ Must have min 2 points
○ Length must be > 0
● Polygon:
○ Must have min 4 points
○ Area must be > 0
○ First and last points must be the same (closed ring)
○ Can't intersect itself
○ Holes must be inside
IsValid
73. smartpuffin.com | @ice_lenor | #geo
1
5
2
IsValid, MakeValid: Self-Intersection
3
4
● 8-shape polygon
● "Butterfly" geometry
● Is NOT valid!
● Must be stored as
MultiPolygon of 2 polygons
○ MakeValid(geom) may fix
problems
75. smartpuffin.com | @ice_lenor | #geo
Well-known geometry representation
● Defined in OGC standard
● Well-known text
○ "Point(0 0)"
○ "LineString(0 0, 1 0)"
○ "Polygon((0 0, 5 0, 5 5, 0 5, 0 0), (1 1, 1 4, 4 4, 4 1, 1 1))"
● Well-known binary
○ 0x0101000000000000000000f03f0000000000000040
A hole in the
polygon
76. smartpuffin.com | @ice_lenor | #geo
Spatial databases
● OGC-compliant
● Store and index spatial data
○ Fast and correct querying
○ Geometry validation
● Support spatial operations: Union, Buffer, etc
● Support different SRIDs
○ => Support flat coordinates and geography
○ Support all geo math correctly
78. smartpuffin.com | @ice_lenor | #geo
Spatial Elasticsearch?
● Supports only geographical coordinates on
WGS84
● Index: GeoHash
● Imprecise operations (only uses index, doesn't
do precise calculations)
● Slow to reindex
● Still, can be useful
79. smartpuffin.com | @ice_lenor | #geo
Spatial indexes
● Quickly answer questions:
○ "What is close to this place"
○ "What is inside this area"
● Usually rough answer, needs precise
calculation afterwards
● Usually already implemented in database or in
library
80. smartpuffin.com | @ice_lenor | #geo
Spatial index: Quadtree
● Divides space into 4
squares recursively
● Adding new objects is
easy and cheap
● Good for constantly
changing data
81. smartpuffin.com | @ice_lenor | #geo
Spatial index: R-tree
● Divides space into
rectangles
● Efficient for reading
● Adding new objects
(reindexing) is
expensive
82. smartpuffin.com | @ice_lenor | #geo
Spatial index: Z-order Curve
● Efficient for reading
● And for writing
● Harder to comprehend
○ And implement
● Though looks cool :)
83. smartpuffin.com | @ice_lenor | #geo
File formats
● Download your geodata into a file (like .csv)
● Then upload it somewhere else
● No indexing, no operations, simple plain file
● Standardised file formats:
○ .kml
○ .kmz - zipped kml
○ .geojson
○ shapefile
84. smartpuffin.com | @ice_lenor | #geo
Libraries
● OGC defines the API
● Can load a geometry from spatial db
● Can operate on it in memory
● Supports all topological operations
○ Java: Java Topology Suite
○ C#: NetTopologySuite
○ Ports to many different languages
85. smartpuffin.com | @ice_lenor | #geo
GIS-systems
Geographic information
systems: apps for creating
and editing geodata.
● ArcGIS from ESRI
● OpenStreetMap editor
● QGIS
● ... many of them
86. smartpuffin.com | @ice_lenor | #geo
GIS-systems
● Users: geo-specialists (cartographers)
● Create layers (types of objects: "Buildings", "Rivers",
"Parks")
● Create geoobjects
○ Draw geometry
○ Add attributes (names, tags, etc)
○ Do spatial operations, data validations ("buildings
should not intersect each other")
88. smartpuffin.com | @ice_lenor | #geo
new Point (lat, lon)
OR
new Point (lon, lat)
?
● Library-dependent
● Always check!
89. smartpuffin.com | @ice_lenor | #geo
Units: degrees
● Units of latitude and longitude: degrees
● You CAN'T measure distance in them!
90. smartpuffin.com | @ice_lenor | #geo
Units: degrees
● Two points on the equator:
● Point 1: latitude 0, longitude 0.
● Point 2: latitude 0, longitude 1.
● Distance between them, measured as if they
were flat coordinates: 1. (Units: degrees.)
● Distance between them, measured as if they're
on the planet Earth: 111.19 km.
91. smartpuffin.com | @ice_lenor | #geo
Units: degrees
● Two points on Amsterdam's latitude (52° N):
● Point 1: latitude 52, longitude 0.
● Point 2: latitude 52, longitude 1.
● Distance between them, measured as if they
were flat coordinates: still 1. (Units: degrees.)
● Distance between them, measured as if they're
on the planet Earth: 68.46 km.
98. smartpuffin.com | @ice_lenor | #geo
Poles
● One latitude: 90° or -90°
● All longitudes meet there
=> It's all exactly the same point!
○ Point (lat=90, lon=0)
○ Point (lat=90, lon=100)
○ Point (lat=90, lon=-140)
99. smartpuffin.com | @ice_lenor | #geo
Poles
● Some projections don't support poles
● I.e., Mercator on WGS84:
○ "World between 80°S and 84°N."
○ Otherwise, poles would be stretched into infinity
● => If you need poles, check if your projection
and datum support them
100. smartpuffin.com | @ice_lenor | #geo
Spatial operations around problem areas
● Math close to 180th meridian must work
correctly!
● Same goes for poles!