Download - The strength of a spatial database
![Page 1: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/1.jpg)
Peter Horsbøll MøllerSenior Systems Engineer
Pitney Bowes Software
![Page 2: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/2.jpg)
The Strength of a Spatial Database
Peter Horsbøll MøllerSenior Systems EngineerJune 15, 2012
Every connection is a new opportunity™
![Page 3: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/3.jpg)
The spatial database
The basis
The benefits
The next step
1
2
3
4
3
Agenda
![Page 4: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/4.jpg)
What is a spatial database?
• In my view a spatial database is a database that can handle alfanumerical as well as spatial data
• If you are working with MI Pro you probably use a spatial database, but maybe you aren’t aware: The tab-format is one example of a spatial database.
• But in this session we will look at ”larger” spatial databases, like SQL Server 2008, Oracle or PostgreSQL/PostGIS and not basic filbased databases
4
![Page 5: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/5.jpg)
The spatial database
The basis
The benefits
The next step
1
2
3
4
5
Agenda
![Page 6: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/6.jpg)
The basis
• We have MapInfo Professional 10.0 or even never
• We have a spatial database, such as• SQL Server 2008• Oracle• PostgreSQL/PostGIS
• My examples are based on SQL Server 2008
![Page 7: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/7.jpg)
The basis
• We have a connection between MapInfo Professional and the database using ODBC or OCI
• We have prepared the database with the MapInfo MapCatalog
Data
Data
![Page 8: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/8.jpg)
The basis
• We have uploaded our data with, for instance, EasyLoader
• So the tools are ready, the database is ready and the data is ready ....
• If not I’ll need another two hours to get you upon speed on that, too
![Page 9: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/9.jpg)
What now?
• Now it’s time to take advantage of the spatial database
![Page 10: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/10.jpg)
The spatial database
The basis
The benefits
The next step
1
2
3
4
10
Agenda
![Page 11: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/11.jpg)
What advantages?
There are plenty• Security (and data access)• Triggers• Views• Programmability• Multi user editing• ”Open access”
• ... just to mention some
![Page 12: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/12.jpg)
Security & Data access
![Page 13: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/13.jpg)
Security
• Only allow access to the data to those who should access it
• Access can be given as database user or as a Windows/OS user
![Page 14: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/14.jpg)
Security
Security can be handled at different levels:• On the database server• On the database• On a schema• On a table
• and as read, write or read-write access
Choose the one that fits your need
![Page 15: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/15.jpg)
Data Access
As a MapInfo Professional user you can access the database thru a linked table or thru a live table.
• Linked stores data in a tab file• Live always reads data from the database
![Page 16: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/16.jpg)
Data Access
Each type has it’s pros and cons:
• From a security perspective you might want to choose Live
• From a performance perspective you might want to choose linked
• But other things might influence this choice
![Page 17: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/17.jpg)
Data Access
• Use LIVE WITH CACHE when– Your data must be kept secure– The table data is very large and it is not feasible to create
a filter query to download less data– Your data changes regulary, for instance every day or
during the day• Use LINKED when
– Your data is static or only changes ones a day, week, month or year
– Performance is important– You want to do advanced spatial analysis on the data in
MapInfo Professional
![Page 18: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/18.jpg)
Data Access
![Page 19: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/19.jpg)
Triggers
![Page 20: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/20.jpg)
What are Triggers?
• A trigger can be called when something happens in the database
• It can be called when records are inserted, updated, deleted
• It can be called when a user logs onto the database• A trigger can be used to stamp records with information
on who changed them and when• A trigger can be used to copy changed records to a
historic table
![Page 21: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/21.jpg)
What are Triggers good for?
Triggers can be used for a veriaty of things:• A trigger can be used to stamp records with information
on who changed them and when• A trigger can be used to copy changed records to a
historic table• A trigger can do certain checks before data is interted
![Page 22: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/22.jpg)
Tables within a trigger
• SQL Server, for one, has two temporary tables, that can be accessed within a trigger:
• inserted– Contains the new records, that are to be inserted. This table
contains the changed records as they look after the change– Exists on insert and on update
• deleted– Contains the records that have been deleted or updated. This
table contains the records as they look before they are changed/deleted
– Exists on update and on delete
![Page 23: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/23.jpg)
Create a timestamp trigger on update
CREATE TRIGGER dbo.trg_MY_TABLE_AfterUpdate ON dbo. MY_TABLEAFTER UPDATEAS Begin Update dbo.MY_TABLE Set DATE_CHANGED = CURRENT_TIMESTAMP,
USER_CHANGED = USER Where MI_PRINX In (Select MI_PRINX From inserted);EndGO
![Page 24: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/24.jpg)
Create a timestamp trigger after insert
CREATE TRIGGER dbo.trg_MY_TABLE_AfterInsert ON dbo. MY_TABLEAFTER INSERTAS Begin Update dbo.MY_TABLE Set DATE_CREATED = CURRENT_TIMESTAMP,
USER_CREATED = USER Where MI_PRINX In (Select MI_PRINX From inserted);EndGO
![Page 25: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/25.jpg)
Create a ”history” trigger
CREATE TRIGGER dbo.trgCopyToHistory ON dbo.ADM_KOMMUNE_2007 AFTER DELETE,UPDATEAS Begin Insert Into dbo.ADM_KOMMUNE_2007_history (OBJECTID, NAME, OBJECTTYPE, ADM_CODE
, MI_PRINX_ORIGINAL, SP_GEOMETRY, MI_STYLE) Select OBJECTID, NAME, OBJECTTYPE, ADM_CODE
, MI_PRINX, SP_GEOMETRY, MI_STYLEFrom deleted
EndGo
![Page 26: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/26.jpg)
Views
![Page 27: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/27.jpg)
What are views?
A view • can be seen as a way to look at your data• behaves very much like a table, but doesn’t hold any
data• Extracts data from one or more tables – or views
![Page 28: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/28.jpg)
What are views good for?
With a view you can • limit the number of columns and/or records you want to
see, for instance to separate a table of roads into different road classes
• merge multiple columns to one column, for instance merge road name and house no to an address column
• enrich one table with data from another table, for instance by transfering the postal area name from a postal table to a table with addresses
• merge multiple tables into one, for instance merge several tables with names to search for into one search table
![Page 29: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/29.jpg)
Please note!
• Do remember to add the views to the MapCatalog if you want to use these inside MapInfo Professional as mappable tables.
• You can do this thru the Table > Maintenance > Make DBMS table mappable option within MapInfo Professional
![Page 30: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/30.jpg)
Nice user interface!
![Page 31: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/31.jpg)
Filtering view
Create View [dbo].[viewROAD_MOTORWAYS] AsSELECT VEJNAVN, VEJKODE, VEJKLASSE, RUTENR
, MI_STYLE, MI_PRINX, SP_GEOMETRYFROM [UKGIS].[dbo].[KEY_ROAD]Where VEJKLASSE = 1
![Page 32: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/32.jpg)
Column merging view
Create View [dbo].[viewADDRESSES] AsSelect VEJNAVN
+ ' ' + Cast(HUS_NR as VarChar) + HUSBOGSTAV + ', ' + Cast(POSTNR As VarChar) + ' ' + POSTDIST As SEARCHVALUE
, MI_PRINX, SP_GEOMETRYFrom MAPS.KEY_ADDRESS
![Page 33: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/33.jpg)
Union view
Create View [dbo].[viewSearch] WITH SCHEMABINDING AsSelect VEJNAVN
+ ' ' + Cast(HUS_NR as VarChar) + HUSBOGSTAV + ', ' + Cast(POSTNR As VarChar) + ' ' + POSTDIST As SEARCHVALUE, MI_PRINX, SP_GEOMETRY
From MAPS.KEY_ADDRESSUnion AllSelect MAS_MATRNR + ' ' + ELAVNAVN As SEARCHVALUE
, (1000000 + MI_PRINX) As MI_PRINX
, SP_GEOMETRYFrom MAPS.KEY_CADASTRE
![Page 34: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/34.jpg)
Views
![Page 35: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/35.jpg)
Programmability
![Page 36: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/36.jpg)
Programma-what?
• With stored procedures and user defined functions you can build part of your business logic into the database
• A stored procedure can be compared to a batch job• A user defined function can take some parametes, does
some calculations and returns calculated value
• And you can use MapBasic or a .NET programming language to program application that take advantage of your spatial database
![Page 37: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/37.jpg)
What’s the benefit of this?
• Being able to encapsulation for instance certain calculations into a stored procedure or user defined functions, helps doing the calculation in the same way each time
• Makes it easier to reuse an already existing function/calculation
![Page 38: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/38.jpg)
Create an address function
Create FUNCTION GetAddress ( @road varchar(250), @houseno int, @letter varchar(1), @zipcode int, @ziparea varchar(250))RETURNS varchar(250)ASBEGIN
DECLARE @address varchar(250)Set @address = @road
+ ' ' + Cast(@houseno as VarChar) + @letter+ ', ' + Cast(@zipcode As VarChar) + ' ' + @ziparea
RETURN @addressEND
![Page 39: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/39.jpg)
Multi user editing
![Page 40: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/40.jpg)
Multi user editing, really?
• With a normal tab file only one user can edit this dataset at a given time. If another user tries to, he will get told that it’s not possible
• This issue is caused by file locking – MI Pro stores the changes in a set of transaction file and only one of these can exist at a time
• If each user connects to the database thru their own local tab file, the database and MI Pro can handle that multiple users edit the same dataset at the same time
• So yes, multi user editing will be possible
46
![Page 41: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/41.jpg)
How are conflicts handled?
A conflict might arrise if two users edit the same record at ”the same time”
When MI Pro is updating a record in the database, it compares the current database record with the record when it was read from the database
• If they are the same, the update continues• If they aren’t the same, someone else changed the
record in the database and a conflict resolution dialog appears
47
![Page 42: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/42.jpg)
”Open Access”
![Page 43: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/43.jpg)
What do you mean?
• Data is stored in a database that a lot of tools and applications can access
• Even non-GIS applications can read at least the non-GIS part of the GIS data
• Even if the applications can’t view or work with the spatial data, it can still use the spatial part of the database to extract results
![Page 44: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/44.jpg)
And what should the be good for?
• You can design and create spatial views in the database, that returns a non spatial dataset
• Eventhough your query does use spatial data to find the result, the spatial data might not be necessary for the end user (GIS without the Map)
![Page 45: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/45.jpg)
Build data forms using MS Access
• You could use MS Access to build easy to use data entry forms for your spatial tables.
• These could be used for your non-GIS users
![Page 46: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/46.jpg)
Business systems
• If your business system can access the database, it can use the sptial data or the spatial queries without really understanding spatial data and spatial relationships
• Here the programmability part might also come in handy
![Page 47: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/47.jpg)
The spatial database
The basis
The benefits
The next step
1
2
3
4
53
Agenda
![Page 48: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/48.jpg)
So what do we do now?
![Page 49: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/49.jpg)
Let’s get going
• There are a number of good reasons for moving towards a spatial database ...
• ... but there are also a few pitfalls
• You do not need to be more than a handfull users to harvest some of the benefits
• All in all the benefits are bigger than the few pitfalls
• In Denmark there is a ”rush” towards spatial databases, especially in the public sector
![Page 50: The strength of a spatial database](https://reader034.vdocuments.site/reader034/viewer/2022051514/54b70a134a7959524f8b45f4/html5/thumbnails/50.jpg)
How do we get going?
• There are a number of ”free” database, that you could use to get familiar with the concept
• Maybe you already have a spatial database in-house without knowing it – or using it
• Start uploading a number of your dataset
• Consider and test the different data access types in MapInfo Professional
56