SlideShare uma empresa Scribd logo
1 de 27
Building Location Based Services
What about adding a new dimension to your data?
Anders Karlsson
Principal Sales Engineer, MariaDB
Location based services and GIS
Do you know all there is to know about your business from
your data?
What if you could add another dimension to that data?
What if that dimension could be used to bring a new way to
use and view your data?
And what if that dimension could come more or less free?
Agenda
● GIS concepts explained
● GIS data in Databases
○ Datatypes
○ Functions
○ Indexing
● Practical examples of using Location Data in Databases
An introduction to GIS
GIS Systems and GIS Data
● GIS systems are systems that specialized in GIS applications
○ The leader in this field is ESRI
○ Research
○ Mapping
○ Exploration
● Today, with GPS receivers in almost every car and cellphone this is changing
○ Navigation
○ Mapping objects on maps
○ GIS data is become an important components of social networks
GIS objects
● A GIS object is something that is mapped in coordinates on some kind of map
or grid
○ A point
○ A line
○ A polygon
■ There are numerous specialized polygons of course. Square, rectangle etc.
○ Other geometric shapes
GIS Surfaces
● The surface the GIS objects are mapped on
can be anything
○ A simple 2d map
○ The earth
● The above are the most common uses
○ Of course a map is a subset of the earth, but many maps reflects such a small part of the earth
so it can be simplified as being flat
○ Note: If your earth is flat, many assumptions made on this and the following slides are largely
incorrect
Latitude and Longitude
Latitude
0
Longitude
0
40.715088, -74.015289
GIS Terms
GIS Terms – WKB and WKT
● WKT and WKB are standard GIS formats for representing GIS shapes (up to 4
dimensions)
● WKT – Well Known Text
● WKB – Well Known Binary
● Both are standardized by the Open GIS Consortium (OGC) and is used by
most database systems to represent GIS data
GIS Terms - MBR
● MBR (Minimum Bounding Rectangle) - A rectangular shape that is
the smallest one to encompass some other shape
● In the illustration to the right
○ Point A is within the Polygon
and within the MBR of the
Polygon
○ Point B is within the MBR
of the Polygon but not within
the Polygon itself
MBR
POLYGON
A
B
GIS Terms - SRID
● SRID (Spatial Reference Identifier) is what defines the Grid where we
place our shapes
○ In other words, the SRID defines how we map our flat map onto a
curved reality, such as the
earth
○ There are several different LAT/LONG
mappings
● There is also a “flat” or Euclidian SRID
○ This is what is used by MariaDB
GIS in databases
GIS Database types
● The supported shapes are arranged in a hierarchy
○ Top level is GEOMETRY
● There is also support for collections of shapes
○ MULTIPOLYGON for example
GIS Database types
● GIS datatypes are organized in a hierarchy (see below)
● To store any kind of GIS data, the type to use is GEOMETRY
● To create an index of a GIS datatype column, you create a SPATIAL INDEX
○ Note that you can also use BTREE indexes on GIS data, but these are usually only good for
exact matches and are far from as powerful as a SPATIAL index
GEOMETRY
POINTPOLYGONLINESTRING COLLECTION
MULTILINESTRING MULTIPOLYGON MULTIPOINT
GIS data indexing
● Rtree (Rectange Tree) - A way to index GIS shapes by creating a
tree-like hierarchy using the MBR of the shape
● Without Rtree indexes, we would be limited to exact location
searches for GIS data in databases
● Using Rtree indexes we can index
operations such as
○ Find all shapes that are
contained within another shape
○ Find all shapes that overlaps a given shape
○ Find all lines that crosses a given polygon
R2
R1
R6
R3
R4
R7
R5
R1 R2
R3 R4 R5 R6
R7
Creating a data tables containing GIS data
CREATE TABLE state(state VARCHAR(2) NOT NULL PRIMARY KEY,
name VARCHAR(25) NOT NULL,
state_fips VARCHAR(2) NOT NULL,
shape GEOMETRY NOT NULL,
UNIQUE(state_fips),
SPATIAL INDEX(shape));
CREATE TABLE road(id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(120) NOT NULL,
state VARCHAR(2) NOT NULL,
shape GEOMETRY NOT NULL,
length DOUBLE,
SPATIAL INDEX(shape),
FOREIGN KEY(state) REFERENCES state(state));
GIS Functions
● There are three groups of GIS functions
○ Constructors, for example
■ POINT to create a POINT
■ POINTFROMTEXT to create a POINT from a textstring
○ Geometry relations, for example
■ CONTAINS to determine of one geometry contain another
■ OVERLAPS to determine of one geometry overlaps another
○ Geometry attributes, for example
■ GEOMETRYN – Get a specific geometry from a GEOMETRYCOLLECTION
■ AREA – Get the area of a POLYGON
■ CENTROID – Get the mathematical center of a POLYGON or MULTIPOLYGON
GIS Data – Getting practical
GIS Data goes to work
● Mapping
○ Showing locations on maps
○ Showing venues given some condition and a current location
● Locating
○ Locating people
○ Finding the location of a car accident
○ Finding houses for sale in the current area
● Big data analytics, Visualization
○ Find trends in geographies
○ Where do my customers come from
○ Where do my customers NOT come from
● The use cases are many more than used to be the case
○ Cellphones have GPS receivers
○ GPS Location can be retrieved by a an application
Populating GIS Data
● There is a wealth of free GIS data available
○ Government
○ Research
○ Other sources
● The most data you find is find is, regrettably, in shape or .shp files
● The good thing is that the shape format is, for the most part, open and documented
○ ESRI, the leader in Geospatial applications, created and develops the shp format
○ For Linux, you will find GDAL (Geospatial Data Abstraction Library) real helpful
○ GDAL is available in Linux repositories and contains libraries and tools
○ Among them is ogr2ogr, a Geospatial data format converter
○ Note that you need all the files in a set, not just the shp file!
$ ogr2ogr -f MySQL MySQL: "db,host=h1,user=anka,port=3306" -nln
roads -a_srs "EPSG:4326" roads.shp -lco ENGINE=InnoDB
Querying GIS data
MariaDB> SELECT r.name, s.state_name
FROM roads r JOIN states s ON CROSSES(r.shape, s.shape)
WHERE r.name LIKE 'US Route 101%'
GROUP BY r.name, s.state_name
ORDER BY MIN(Y(CENTROID(ENVELOPE(r.shape))));
+-----------------------------+------------+
| name | state_name |
+-----------------------------+------------+
| US Route 101, State Route 1 | California |
| US Route 101 | California |
| US Route 101 | Oregon |
| US Route 101 | Washington |
+-----------------------------+------------+
Get all states that US 101 passes through, ordered from south to north
Querying GIS data
MariaDB> SELECT s.state_name, SUM(r.length) length
FROM roads r JOIN states s ON CROSSES(r.shape, s.shape)
WHERE r.name LIKE 'US Route 101%'
GROUP BY s.state_name
ORDER BY MIN(Y(CENTROID(ENVELOPE(r.shape))));
+------------+--------+
| state_name | length |
+------------+--------+
| California | 1.770 |
| Oregon | 2.276 |
| Washington | 3.196 |
+------------+--------+
Get the length of US 101 in all the states that is passes through, ordered from south to north
Querying GIS data
MariaDB> SELECT state_name
FROM states
WHERE contains(shape, PointFromText('POINT(-73.985170
40.758902)'));
+------------+
| state_name |
+------------+
| New York |
+------------+
In which state is Times Square?
Conclusion
● GIS data adds a new dimension to your data
● Combining GIS data with your business data provides valuable insights
● Using GIS data provides a base for new ways of visualize data
● There is a lot of free GIS data out there, for you to use
● GIS data fits nicely into a relational structure and is fully supported by
MariaDB
○ Functions
○ Data types
○ Indexing
○ GeoJSON
Resources and further reading
● MariaDB GIS Features reference
○ Knowledge base: https://mariadb.com/kb/en/mariadb/gis-functionality/
○ Future plans: https://mariadb.com/kb/en/mariadb/mariadb-plans-gis/
● Open GIS Consortium (OGC) – Simple Features Access SQL
○ Reference: http://www.opengeospatial.org/standards/sfs
● R-Tree indexes
○ Wikipedia: https://en.wikipedia.org/wiki/R-tree
○ MariaDB Knowledge Base: https://mariadb.com/kb/en/mariadb/spatial-index/
● MariaDB GIS Datatypes
○ MariaDB Knowledge Base: https://mariadb.com/kb/en/mariadb/geometry-types/
● Google maps API
○ Google: https://developers.google.com/maps/
Thank you!
Building Location Based Services
Anders Karlsson
Principal Sales Engineer, MariaDB
anders @mariadb.com

Mais conteúdo relacionado

Semelhante a M|18 Building Location-Based Services with Geospatial Data

Sql server 2008 r2 spatial data whitepaper
Sql server 2008 r2 spatial data whitepaperSql server 2008 r2 spatial data whitepaper
Sql server 2008 r2 spatial data whitepaper
Klaudiia Jacome
 
GIS Introduction.ppt
GIS Introduction.pptGIS Introduction.ppt
GIS Introduction.ppt
misterjis
 

Semelhante a M|18 Building Location-Based Services with Geospatial Data (20)

GPS and GIS
GPS and GISGPS and GIS
GPS and GIS
 
Introduction to GIS-basic principles and description
Introduction to GIS-basic principles and descriptionIntroduction to GIS-basic principles and description
Introduction to GIS-basic principles and description
 
Sql server 2008 r2 spatial data whitepaper
Sql server 2008 r2 spatial data whitepaperSql server 2008 r2 spatial data whitepaper
Sql server 2008 r2 spatial data whitepaper
 
Fundamentals of GIS
Fundamentals of GISFundamentals of GIS
Fundamentals of GIS
 
Geographic Information System unit 1
Geographic Information System   unit 1Geographic Information System   unit 1
Geographic Information System unit 1
 
Geographical Information System
Geographical Information SystemGeographical Information System
Geographical Information System
 
What is Geography Information Systems (GIS)
What is Geography Information Systems (GIS)What is Geography Information Systems (GIS)
What is Geography Information Systems (GIS)
 
Rs unit iii-gis--- [repaired]
Rs unit iii-gis--- [repaired]Rs unit iii-gis--- [repaired]
Rs unit iii-gis--- [repaired]
 
Rs unit iii-gis--- [repaired]
Rs unit iii-gis--- [repaired]Rs unit iii-gis--- [repaired]
Rs unit iii-gis--- [repaired]
 
GIS PPT
GIS PPTGIS PPT
GIS PPT
 
GIS
GISGIS
GIS
 
GIS in Geography
GIS in GeographyGIS in Geography
GIS in Geography
 
What is GIS (PDF).pdf
What is GIS (PDF).pdfWhat is GIS (PDF).pdf
What is GIS (PDF).pdf
 
Introduction and Application of GIS
Introduction and Application of GISIntroduction and Application of GIS
Introduction and Application of GIS
 
Introduction to gis and arc gis
Introduction to gis and arc gis Introduction to gis and arc gis
Introduction to gis and arc gis
 
Intro to Spatial data
Intro to Spatial data Intro to Spatial data
Intro to Spatial data
 
Geographic information system
Geographic information systemGeographic information system
Geographic information system
 
Gp straining
Gp strainingGp straining
Gp straining
 
GIS Introduction.ppt
GIS Introduction.pptGIS Introduction.ppt
GIS Introduction.ppt
 
introduction to GIS
introduction to GIS introduction to GIS
introduction to GIS
 

Mais de MariaDB plc

Mais de MariaDB plc (20)

MariaDB Paris Workshop 2023 - MaxScale 23.02.x
MariaDB Paris Workshop 2023 - MaxScale 23.02.xMariaDB Paris Workshop 2023 - MaxScale 23.02.x
MariaDB Paris Workshop 2023 - MaxScale 23.02.x
 
MariaDB Paris Workshop 2023 - Newpharma
MariaDB Paris Workshop 2023 - NewpharmaMariaDB Paris Workshop 2023 - Newpharma
MariaDB Paris Workshop 2023 - Newpharma
 
MariaDB Paris Workshop 2023 - Cloud
MariaDB Paris Workshop 2023 - CloudMariaDB Paris Workshop 2023 - Cloud
MariaDB Paris Workshop 2023 - Cloud
 
MariaDB Paris Workshop 2023 - MariaDB Enterprise
MariaDB Paris Workshop 2023 - MariaDB EnterpriseMariaDB Paris Workshop 2023 - MariaDB Enterprise
MariaDB Paris Workshop 2023 - MariaDB Enterprise
 
MariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance OptimizationMariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance Optimization
 
MariaDB Paris Workshop 2023 - MaxScale
MariaDB Paris Workshop 2023 - MaxScale MariaDB Paris Workshop 2023 - MaxScale
MariaDB Paris Workshop 2023 - MaxScale
 
MariaDB Paris Workshop 2023 - novadys presentation
MariaDB Paris Workshop 2023 - novadys presentationMariaDB Paris Workshop 2023 - novadys presentation
MariaDB Paris Workshop 2023 - novadys presentation
 
MariaDB Paris Workshop 2023 - DARVA presentation
MariaDB Paris Workshop 2023 - DARVA presentationMariaDB Paris Workshop 2023 - DARVA presentation
MariaDB Paris Workshop 2023 - DARVA presentation
 
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
 
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-BackupMariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
 
Einführung : MariaDB Tech und Business Update Hamburg 2023
Einführung : MariaDB Tech und Business Update Hamburg 2023Einführung : MariaDB Tech und Business Update Hamburg 2023
Einführung : MariaDB Tech und Business Update Hamburg 2023
 
Hochverfügbarkeitslösungen mit MariaDB
Hochverfügbarkeitslösungen mit MariaDBHochverfügbarkeitslösungen mit MariaDB
Hochverfügbarkeitslösungen mit MariaDB
 
Die Neuheiten in MariaDB Enterprise Server
Die Neuheiten in MariaDB Enterprise ServerDie Neuheiten in MariaDB Enterprise Server
Die Neuheiten in MariaDB Enterprise Server
 
Global Data Replication with Galera for Ansell Guardian®
Global Data Replication with Galera for Ansell Guardian®Global Data Replication with Galera for Ansell Guardian®
Global Data Replication with Galera for Ansell Guardian®
 
Introducing workload analysis
Introducing workload analysisIntroducing workload analysis
Introducing workload analysis
 
Under the hood: SkySQL monitoring
Under the hood: SkySQL monitoringUnder the hood: SkySQL monitoring
Under the hood: SkySQL monitoring
 
Introducing the R2DBC async Java connector
Introducing the R2DBC async Java connectorIntroducing the R2DBC async Java connector
Introducing the R2DBC async Java connector
 
MariaDB Enterprise Tools introduction
MariaDB Enterprise Tools introductionMariaDB Enterprise Tools introduction
MariaDB Enterprise Tools introduction
 
Faster, better, stronger: The new InnoDB
Faster, better, stronger: The new InnoDBFaster, better, stronger: The new InnoDB
Faster, better, stronger: The new InnoDB
 
The architecture of SkySQL
The architecture of SkySQLThe architecture of SkySQL
The architecture of SkySQL
 

Último

Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
amitlee9823
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
amitlee9823
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
amitlee9823
 
Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter Lessons
JoseMangaJr1
 

Último (20)

Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
ALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptxALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptx
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFx
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptx
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter Lessons
 
Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 

M|18 Building Location-Based Services with Geospatial Data

  • 1. Building Location Based Services What about adding a new dimension to your data? Anders Karlsson Principal Sales Engineer, MariaDB
  • 2. Location based services and GIS Do you know all there is to know about your business from your data? What if you could add another dimension to that data? What if that dimension could be used to bring a new way to use and view your data? And what if that dimension could come more or less free?
  • 3. Agenda ● GIS concepts explained ● GIS data in Databases ○ Datatypes ○ Functions ○ Indexing ● Practical examples of using Location Data in Databases
  • 5. GIS Systems and GIS Data ● GIS systems are systems that specialized in GIS applications ○ The leader in this field is ESRI ○ Research ○ Mapping ○ Exploration ● Today, with GPS receivers in almost every car and cellphone this is changing ○ Navigation ○ Mapping objects on maps ○ GIS data is become an important components of social networks
  • 6. GIS objects ● A GIS object is something that is mapped in coordinates on some kind of map or grid ○ A point ○ A line ○ A polygon ■ There are numerous specialized polygons of course. Square, rectangle etc. ○ Other geometric shapes
  • 7. GIS Surfaces ● The surface the GIS objects are mapped on can be anything ○ A simple 2d map ○ The earth ● The above are the most common uses ○ Of course a map is a subset of the earth, but many maps reflects such a small part of the earth so it can be simplified as being flat ○ Note: If your earth is flat, many assumptions made on this and the following slides are largely incorrect
  • 10. GIS Terms – WKB and WKT ● WKT and WKB are standard GIS formats for representing GIS shapes (up to 4 dimensions) ● WKT – Well Known Text ● WKB – Well Known Binary ● Both are standardized by the Open GIS Consortium (OGC) and is used by most database systems to represent GIS data
  • 11. GIS Terms - MBR ● MBR (Minimum Bounding Rectangle) - A rectangular shape that is the smallest one to encompass some other shape ● In the illustration to the right ○ Point A is within the Polygon and within the MBR of the Polygon ○ Point B is within the MBR of the Polygon but not within the Polygon itself MBR POLYGON A B
  • 12. GIS Terms - SRID ● SRID (Spatial Reference Identifier) is what defines the Grid where we place our shapes ○ In other words, the SRID defines how we map our flat map onto a curved reality, such as the earth ○ There are several different LAT/LONG mappings ● There is also a “flat” or Euclidian SRID ○ This is what is used by MariaDB
  • 14. GIS Database types ● The supported shapes are arranged in a hierarchy ○ Top level is GEOMETRY ● There is also support for collections of shapes ○ MULTIPOLYGON for example
  • 15. GIS Database types ● GIS datatypes are organized in a hierarchy (see below) ● To store any kind of GIS data, the type to use is GEOMETRY ● To create an index of a GIS datatype column, you create a SPATIAL INDEX ○ Note that you can also use BTREE indexes on GIS data, but these are usually only good for exact matches and are far from as powerful as a SPATIAL index GEOMETRY POINTPOLYGONLINESTRING COLLECTION MULTILINESTRING MULTIPOLYGON MULTIPOINT
  • 16. GIS data indexing ● Rtree (Rectange Tree) - A way to index GIS shapes by creating a tree-like hierarchy using the MBR of the shape ● Without Rtree indexes, we would be limited to exact location searches for GIS data in databases ● Using Rtree indexes we can index operations such as ○ Find all shapes that are contained within another shape ○ Find all shapes that overlaps a given shape ○ Find all lines that crosses a given polygon R2 R1 R6 R3 R4 R7 R5 R1 R2 R3 R4 R5 R6 R7
  • 17. Creating a data tables containing GIS data CREATE TABLE state(state VARCHAR(2) NOT NULL PRIMARY KEY, name VARCHAR(25) NOT NULL, state_fips VARCHAR(2) NOT NULL, shape GEOMETRY NOT NULL, UNIQUE(state_fips), SPATIAL INDEX(shape)); CREATE TABLE road(id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(120) NOT NULL, state VARCHAR(2) NOT NULL, shape GEOMETRY NOT NULL, length DOUBLE, SPATIAL INDEX(shape), FOREIGN KEY(state) REFERENCES state(state));
  • 18. GIS Functions ● There are three groups of GIS functions ○ Constructors, for example ■ POINT to create a POINT ■ POINTFROMTEXT to create a POINT from a textstring ○ Geometry relations, for example ■ CONTAINS to determine of one geometry contain another ■ OVERLAPS to determine of one geometry overlaps another ○ Geometry attributes, for example ■ GEOMETRYN – Get a specific geometry from a GEOMETRYCOLLECTION ■ AREA – Get the area of a POLYGON ■ CENTROID – Get the mathematical center of a POLYGON or MULTIPOLYGON
  • 19. GIS Data – Getting practical
  • 20. GIS Data goes to work ● Mapping ○ Showing locations on maps ○ Showing venues given some condition and a current location ● Locating ○ Locating people ○ Finding the location of a car accident ○ Finding houses for sale in the current area ● Big data analytics, Visualization ○ Find trends in geographies ○ Where do my customers come from ○ Where do my customers NOT come from ● The use cases are many more than used to be the case ○ Cellphones have GPS receivers ○ GPS Location can be retrieved by a an application
  • 21. Populating GIS Data ● There is a wealth of free GIS data available ○ Government ○ Research ○ Other sources ● The most data you find is find is, regrettably, in shape or .shp files ● The good thing is that the shape format is, for the most part, open and documented ○ ESRI, the leader in Geospatial applications, created and develops the shp format ○ For Linux, you will find GDAL (Geospatial Data Abstraction Library) real helpful ○ GDAL is available in Linux repositories and contains libraries and tools ○ Among them is ogr2ogr, a Geospatial data format converter ○ Note that you need all the files in a set, not just the shp file! $ ogr2ogr -f MySQL MySQL: "db,host=h1,user=anka,port=3306" -nln roads -a_srs "EPSG:4326" roads.shp -lco ENGINE=InnoDB
  • 22. Querying GIS data MariaDB> SELECT r.name, s.state_name FROM roads r JOIN states s ON CROSSES(r.shape, s.shape) WHERE r.name LIKE 'US Route 101%' GROUP BY r.name, s.state_name ORDER BY MIN(Y(CENTROID(ENVELOPE(r.shape)))); +-----------------------------+------------+ | name | state_name | +-----------------------------+------------+ | US Route 101, State Route 1 | California | | US Route 101 | California | | US Route 101 | Oregon | | US Route 101 | Washington | +-----------------------------+------------+ Get all states that US 101 passes through, ordered from south to north
  • 23. Querying GIS data MariaDB> SELECT s.state_name, SUM(r.length) length FROM roads r JOIN states s ON CROSSES(r.shape, s.shape) WHERE r.name LIKE 'US Route 101%' GROUP BY s.state_name ORDER BY MIN(Y(CENTROID(ENVELOPE(r.shape)))); +------------+--------+ | state_name | length | +------------+--------+ | California | 1.770 | | Oregon | 2.276 | | Washington | 3.196 | +------------+--------+ Get the length of US 101 in all the states that is passes through, ordered from south to north
  • 24. Querying GIS data MariaDB> SELECT state_name FROM states WHERE contains(shape, PointFromText('POINT(-73.985170 40.758902)')); +------------+ | state_name | +------------+ | New York | +------------+ In which state is Times Square?
  • 25. Conclusion ● GIS data adds a new dimension to your data ● Combining GIS data with your business data provides valuable insights ● Using GIS data provides a base for new ways of visualize data ● There is a lot of free GIS data out there, for you to use ● GIS data fits nicely into a relational structure and is fully supported by MariaDB ○ Functions ○ Data types ○ Indexing ○ GeoJSON
  • 26. Resources and further reading ● MariaDB GIS Features reference ○ Knowledge base: https://mariadb.com/kb/en/mariadb/gis-functionality/ ○ Future plans: https://mariadb.com/kb/en/mariadb/mariadb-plans-gis/ ● Open GIS Consortium (OGC) – Simple Features Access SQL ○ Reference: http://www.opengeospatial.org/standards/sfs ● R-Tree indexes ○ Wikipedia: https://en.wikipedia.org/wiki/R-tree ○ MariaDB Knowledge Base: https://mariadb.com/kb/en/mariadb/spatial-index/ ● MariaDB GIS Datatypes ○ MariaDB Knowledge Base: https://mariadb.com/kb/en/mariadb/geometry-types/ ● Google maps API ○ Google: https://developers.google.com/maps/
  • 27. Thank you! Building Location Based Services Anders Karlsson Principal Sales Engineer, MariaDB anders @mariadb.com