the strength of a spatial database

Post on 15-Jan-2015

363 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

A presentation I used at a session at the Insights Conference in June 2012 in New Orleans

TRANSCRIPT

Peter Horsbøll MøllerSenior Systems Engineer

Pitney Bowes Software

The Strength of a Spatial Database

Peter Horsbøll MøllerSenior Systems EngineerJune 15, 2012

Every connection is a new opportunity™

The spatial database

The basis

The benefits

The next step

1

2

3

4

3

Agenda

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

The spatial database

The basis

The benefits

The next step

1

2

3

4

5

Agenda

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

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

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

What now?

• Now it’s time to take advantage of the spatial database

The spatial database

The basis

The benefits

The next step

1

2

3

4

10

Agenda

What advantages?

There are plenty• Security (and data access)• Triggers• Views• Programmability• Multi user editing• ”Open access”

• ... just to mention some

Security & Data access

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

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

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

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

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

Data Access

Triggers

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

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

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

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

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

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

Views

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

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

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

Nice user interface!

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

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

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

Views

Programmability

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

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

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

Multi user editing

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

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

”Open Access”

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

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)

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

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

The spatial database

The basis

The benefits

The next step

1

2

3

4

53

Agenda

So what do we do now?

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

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

Thank You

Peter Horsbøll Møller

peter.moller@pb.com

top related