Test de conformation OGC de données géographique pour MS SQL Server 2008 (SIG)

Basé sur l’excellent article de Morten Nielsen mais corrigé (quelques erreur si vous utilisez une base à collation sensible à la casse), voici le test de conformation OGC de données spatiales dans MS SQL Server.

L’article original est ici : http://www.sharpgis.net/post/2008/02/24/Creating-OGC-conformance-test-map-in-SQL-Server-2008.aspx#comment

Création de la base des tables et insertion des données :


/******************************************************************************
*** CRÉATION DE LA BASE                                                     ***
******************************************************************************/
 
CREATE DATABASE DB_SPACE;
Go
 
USE DB_SPACE;
GO
 
/******************************************************************************
*** CRÉATION DES TABLES                                                     ***
******************************************************************************/
 
-- Lacs
CREATE TABLE lakes  
(fid          INTEGER NOT NULL PRIMARY KEY,
 name         VARCHAR(64),
 shore        geometry);
-- Segment de routes
CREATE TABLE road_segments  
(fid          INTEGER NOT NULL PRIMARY KEY,
 name         VARCHAR(64),
 aliases      VARCHAR(64),
 num_lanes    INTEGER,
 centerline   geometry);
-- Routes à deux voies
CREATE TABLE divided_routes  
(fid          INTEGER NOT NULL PRIMARY KEY,
 name         VARCHAR(64),num_lanes INTEGER,
 centerlines  geometry);
-- Forêts
CREATE TABLE forests  
(fid          INTEGER NOT NULL PRIMARY KEY,
 name         VARCHAR(64),
 boundary     geometry);
-- Ponts
CREATE TABLE bridges  
(fid          INTEGER NOT NULL PRIMARY KEY,
 name         VARCHAR(64),
 position     geometry);
-- Rivières
CREATE TABLE streams  
(fid          INTEGER NOT NULL PRIMARY KEY,
 name         VARCHAR(64),
 centerline geometry);
-- Bâtiments
CREATE TABLE buildings  
(fid          INTEGER NOT NULL PRIMARY KEY,
 address      VARCHAR(64),
 position     geometry,
 footprint    geometry);
-- Lacs
CREATE TABLE ponds  
(fid          INTEGER NOT NULL PRIMARY KEY,
 name         VARCHAR(64),  
 type         VARCHAR(64),
 shores       geometry);
-- Lieudits
CREATE TABLE named_places  
(fid          INTEGER NOT NULL PRIMARY KEY,
 name         VARCHAR(64),
 boundary     geometry);
-- Limite cartographiques
CREATE TABLE map_neatlines  
(fid          INTEGER NOT NULL PRIMARY KEY,
 neatline     geometry);
 
/******************************************************************************
*** Insertion des données                                                   ***
******************************************************************************/
 
-- Lacs
INSERT INTO lakes  
VALUES (101, 'BLUE LAKE', geometry::STPolyFromText('POLYGON((52 18,66 23,73 9,48 6,52 18),(59 18,67 18,67 13,59 13,59 18))', 101));
-- Segments de routes
INSERT INTO road_segments  
VALUES (102, 'Route 5', NULL, 2, geometry::STLineFromText('LINESTRING( 0 18, 10 21, 16 23, 28 26, 44 31 )' ,101)),
       (103, 'Route 5', 'Main Street', 4, geometry::STLineFromText('LINESTRING( 44 31, 56 34, 70 38 )' ,101)),  
       (104, 'Route 5', NULL, 2, geometry::STLineFromText('LINESTRING( 70 38, 72 48 )' ,101)),
       (105, 'Main Street', NULL, 4, geometry::STLineFromText('LINESTRING( 70 38, 84 42 )' ,101)),
       (106, 'Dirt Road by Green Forest', NULL, 1, geometry::STLineFromText('LINESTRING( 28 26, 28 0 )',101));
-- Routes à deux voies
INSERT INTO divided_routes  
VALUES (119, 'Route 75', 4, geometry::STMLineFromText('MULTILINESTRING((10 48,10 21,10 0),(16 0,16 23,16 48))', 101));
-- Forêts
INSERT INTO forests  
VALUES (109, 'Green Forest', geometry::STMPolyFromText('MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))', 101));
-- Ponts
INSERT INTO bridges  
VALUES (110, 'Cam Bridge', geometry::STPointFromText('POINT( 44 31 )', 101));
-- Rivières
INSERT INTO streams  
VALUES (111, 'Cam Stream',geometry::STLineFromText('LINESTRING( 38 48, 44 41, 41 36, 44 31, 52 18 )', 101)),
       (112, NULL,geometry::STLineFromText('LINESTRING( 76 0, 78 4, 73 9 )', 101));
-- Bâtiments
INSERT INTO buildings  
VALUES (113, '123 Main Street',geometry::STPointFromText('POINT( 52 30 )', 101),geometry::STPolyFromText('POLYGON( ( 50 31, 54 31, 54 29, 50 29, 50 31) )', 101)),
       (114, '215 Main Street',geometry::STPointFromText('POINT( 64 33 )', 101),geometry::STPolyFromText('POLYGON( ( 66 34, 62 34, 62 32, 66 32, 66 34) )', 101));
-- Ponds
INSERT INTO Lacs
VALUES (120, NULL, 'Stock Pond',geometry::STMPolyFromText('MULTIPOLYGON( ( ( 24 44, 22 42, 24 40, 24 44) ),( ( 26 44, 26 40, 28 42, 26 44) ) )', 101));
-- Lieudits
INSERT INTO named_places  
VALUES (117, 'Ashton',geometry::STPolyFromText('POLYGON( ( 62 48, 84 48, 84 30, 56 30, 56 34, 62 48) )', 101)),
       (118, 'Goose Island',geometry::STPolyFromText('POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )', 101));
-- Limites cartographiques
INSERT INTO map_neatlines  
VALUES (115,geometry::STPolyFromText('POLYGON( ( 0 0, 0 48, 84 48, 84 0, 0 0 ) )', 101));

Exemple de requête spatiale :


SELECT neatline AS GEO,        NULL as name
FROM   map_neatlines  
UNION  ALL
SELECT shores,                 name
FROM   ponds  
UNION  ALL
SELECT boundary,               name
FROM   forests  
UNION  ALL
SELECT shore,                  name
FROM   lakes  
UNION  ALL
SELECT boundary,               name
FROM   named_places  
UNION  ALL
SELECT centerline,             name
FROM   streams  
UNION  ALL
SELECT centerline,             name
FROM   streams  
UNION  ALL
SELECT centerline,             name
FROM   road_segments  
UNION  ALL
SELECT centerlines,            name
FROM   divided_routes  
UNION  ALL
SELECT footprint,              address
FROM   buildings  
UNION  ALL
SELECT position.STBuffer(0.5), address
FROM   buildings  
UNION  ALL
SELECT position.STBuffer(1),   name
FROM   bridges;

Résultat visible dans l’onglet « Résultats spatiaux » de SSMS :
Test de conformation de données SIG OGC pour MS SQL Server

Si vous voulez utiliser l’outil de rendu des données spatiales de Morten Nielsen, téléchargeable à l’adresse suivante : http://www.sharpgis.net/page/SQL-Server-2008-Spatial-Tools.aspx, alors vous pouvez utiliser la requête suivante qui permet d epiloter le rendu en ajoutant :
1) Colonne Layer : libellé
2) Colonne FillColor : couleur de remplissage
3) Colonne LineColor : couleur des limites
4) Colonne LineThickness : épaisseur des traits

SELECT neatline, ‘Background’ as name, ‘map_neatlines’ as layer, ‘White’ as FillColor, ‘Transparent’ as LineColor, 1 as LineThickness FROM

map_neatlines UNION ALL
SELECT shores, name, 'ponds' as layer, 'LightBlue' as FillColor, 'Blue' as LineColor, 1 as LineThickness FROM ponds UNION ALL
SELECT boundary, name, 'forests' as layer, 'Green' as FillColor, '#ff005500' as LineColor, 4 as LineThickness FROM forests UNION ALL
SELECT shore, name, 'lakes' as layer, 'Blue' as FillColor, 'Transparent' as LineColor, 2 as LineThickness FROM lakes UNION ALL
SELECT boundary, name, 'named_places' as layer, '#00ffff99' as FillColor, 'Brown' as LineColor, 2 as LineThickness FROM named_places UNION ALL
SELECT centerline, name, 'streams_outline' as layer, 'Blue' as FillColor, 'Blue' as LineColor, 5 as LineThickness FROM streams UNION ALL
SELECT centerline, name, 'streams_fill' as layer, 'LightBlue' as FillColor, 'LightBlue' as LineColor, 3 as LineThickness FROM streams UNION ALL
SELECT centerline, name, 'road_segments' as layer, 'LightGreen' as FillColor, 'Black' as LineColor, num_lanes*2 as LineThickness FROM road_segments UNION ALL
SELECT centerlines, name, 'divided_routes' as layer, 'LightGreen' as FillColor, '#aaff0000' as LineColor, num_lanes*2 as LineThickness FROM divided_routes UNION ALL
SELECT footprint, address, 'buildings_footprint' as layer, 'Black' as FillColor, 'Transparent' as LineColor, 1 as LineThickness FROM buildings UNION ALL
SELECT position.STBuffer(0.5), address, 'buildings_position' as layer, 'Red' as FillColor, 'Transparent' as LineColor, 1 as LineThickness FROM buildings UNION ALL
SELECT position.STBuffer(1), name, 'bridges' as layer, '#550000ff' as FillColor, 'Black' as LineColor, 1 as LineThickness FROM bridges;

Voici l’exemple ci dessus rendu dans l’outil « SQL Spatial Query Visualizer » :
SQL Spatial Query Visualizer


--------
Frédéric Brouard, SQLpro - ARCHITECTE DE DONNÉES, http://sqlpro.developpez.com/
Expert bases de données relationnelles et langage SQL. MVP Microsoft SQL Server
www.sqlspot.com : modélisation, conseil, audit, optimisation, tuning, formation
* * * * *  Enseignant CNAM PACA - ISEN Toulon - CESI Aix en Provence  * * * * *

MVP Microsoft SQL Server

Laisser un commentaire