[1] | 1 | .. _introduction: |
---|
| 2 | |
---|
| 3 | Partie 1 : Introduction |
---|
| 4 | ************************ |
---|
| 5 | |
---|
| 6 | Qu'est-ce qu'une base de données spatiales ? |
---|
| 7 | ============================================ |
---|
| 8 | |
---|
| 9 | PostGIS est une base de données spatiales. Oracle Spatial et SQL Server 2008 sont aussi des bases de données spatiales. Mais qu'est-ce que cela signifie, qu'est-ce qui différentie un serveur de base de données spatiales d'un non spatiale ? |
---|
| 10 | |
---|
| 11 | La réponse courte, est ... |
---|
| 12 | |
---|
| 13 | **Les base de données spatiales permettent les stocage et la manipulation des objets spatiaux comme les autres objets de la base de données.** |
---|
| 14 | |
---|
| 15 | Ce qui suit présente briÚvement l'évolution des base de données spatiales, puis les liens |
---|
| 16 | entre les données spatiales et la base de données (types de données, indexes et fonctions). |
---|
| 17 | |
---|
| 18 | #. **Types de données spatiales** fait référence aux géométries de type point, ligne et polygone; |
---|
| 19 | #. L'**indexation spatiale** est utilisée pour améliorer les performance d'exécution des opérations spatiales; |
---|
| 20 | #. Les **fonctions spatiales**, au sens :term:`SQL`, sont utilsées pour accéder à des propriétées ou des relations spatiales. |
---|
| 21 | |
---|
| 22 | Conbiné, les types de données spatiales, les indexes et les fonctions fournissent une structure flexible pour optimiser les performance et les analyses. |
---|
| 23 | |
---|
| 24 | Au commencement |
---|
| 25 | ---------------- |
---|
| 26 | |
---|
| 27 | Dans les premiÚres implémentations :term:`SIG` historiques, toutes les données |
---|
| 28 | spatiales étaient stoquées sous la forme de fichiers plats et certaines applications |
---|
| 29 | :term:`SIG` spécifiques étaient nécessaires pour interpréter et manipuler les données. |
---|
| 30 | Ces outils de gestion de premiÚre génération, avaient été conçu pour répondre aux |
---|
| 31 | besoins des utilisateurs pour lesquels toute les données étaient localisé au sein de leur |
---|
| 32 | agence. C'est outils étaient propriétaire, des systÚme specifiquement créé pour gérer les |
---|
| 33 | données spatiales. |
---|
| 34 | |
---|
| 35 | La seconde génération des systÚmes de gestion de données spatiales stoque certaines données dans une base de données relationelle |
---|
| 36 | |
---|
| 37 | Second-generation spatial systems store some data in relational databases (usually the "attribute" or non-spatial parts) but still lack the flexibility afforded with direct integration. |
---|
| 38 | |
---|
| 39 | **Effectivement, les bases de données spatiales sont nés lorsque les gens ont commencé à considérer les objet spatiaux comme des objets de base de données.** |
---|
| 40 | |
---|
| 41 | Spatial databases fully integrate spatial data with an object relational database. The orientation changes from GIS-centric to database-centric. |
---|
| 42 | |
---|
| 43 | .. image:: ./introduction/beginning.png |
---|
| 44 | |
---|
| 45 | .. note:: A spatial database management system may be used in applications besides the geographic world. Spatial databases are used to manage data related to the anatomy of the human body, large-scale integrated circuits, molecular structures, and electro-magnetic fields, among others. |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | Spatial Data Types |
---|
| 49 | ------------------ |
---|
| 50 | |
---|
| 51 | An ordinary database has strings, numbers, and dates. A spatial database adds additional (spatial) types for representing **geographic features**. These spatial data types abstract and encapsulate spatial structures such as boundary and dimension. In many respects, spatial data types can be understood simply as shapes. |
---|
| 52 | |
---|
| 53 | .. image:: ./introduction/hierarchy.png |
---|
| 54 | :align: center |
---|
| 55 | |
---|
| 56 | Spatial data types are organized in a type hierarchy. Each sub-type inherits the structure (attributes) and the behavior (methods or functions) of its super-type. |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | Spatial Indexes and Bounding Boxes |
---|
| 60 | ---------------------------------- |
---|
| 61 | |
---|
| 62 | An ordinary database provides "access methods" -- commonly known as **indexes** -- to allow for fast and random access to subsets of data. Indexing for standard types (numbers, strings, dates) is usually done with `B-tree <http://en.wikipedia.org/wiki/B-tree>`_ indexes. A B-tree partitions the data using the natural sort order to put the data into a hierarchical tree. |
---|
| 63 | |
---|
| 64 | The natural sort order of numbers, strings, and dates is simple to determine -- every value is less than, greater than or equal to every other value. But because polygons can overlap, can be contained in one another, and are arrayed in a two-dimensional (or more) space, a B-tree cannot be used to efficiently index them. Real spatial databases provide a "spatial index" that instead answers the question "which objects are within this particular bounding box?". |
---|
| 65 | |
---|
| 66 | A **bounding box** is the smallest size rectangle capable of containing a given feature. |
---|
| 67 | |
---|
| 68 | .. image:: ./introduction/boundingbox.png |
---|
| 69 | :align: center |
---|
| 70 | |
---|
| 71 | Bounding boxes are used because answering the question "is A inside B?" is very computationally intensive for polygons but very fast in the case of rectangles. Even the most complex polygons and linestrings can be represented by a simple bounding box. |
---|
| 72 | |
---|
| 73 | Indexes have to perform quickly in order to be useful. So instead of providing exact results, as B-trees do, spatial indexes provide approximate results. The question "what lines are inside this polygon?" will be instead interpreted by a spatial index as "what lines have bounding boxes that are contained inside this polygon's bounding box?" |
---|
| 74 | |
---|
| 75 | The actual spatial indexes implemented by various databases vary widely. The most common implementation is the `R-tree <http://en.wikipedia.org/wiki/R-tree>`_ (used in PostGIS), but there are also implementations of `Quadtrees <http://en.wikipedia.org/wiki/Quadtree>`_, and `grid-based indexes <http://en.wikipedia.org/wiki/Grid_(spatial_index)>`_ in shipping spatial databases. |
---|
| 76 | |
---|
| 77 | Spatial Functions |
---|
| 78 | ----------------- |
---|
| 79 | |
---|
| 80 | For manipulating data during a query, an ordinary database provides **functions** such as concatenating strings, performing hash operations on strings, doing mathematics on numbers, and extracting information from dates. A spatial database provides a complete set of functions for analyzing geometric components, determining spatial relationships, and manipulating geometries. These spatial functions serve as the building block for any spatial project. |
---|
| 81 | |
---|
| 82 | The majority of all spatial functions can be grouped into one of the following five categories: |
---|
| 83 | |
---|
| 84 | #. **Conversion**: Functions that *convert* between geometries and external data formats. |
---|
| 85 | #. **Management**: Functions that *manage* information about spatial tables and PostGIS administration. |
---|
| 86 | #. **Retrieval**: Functions that *retrieve* properties and measurements of a Geometry. |
---|
| 87 | #. **Comparison**: Functions that *compare* two geometries with respect to their spatial relation. |
---|
| 88 | #. **Generation**: Functions that *generate* new geometries from others. |
---|
| 89 | |
---|
| 90 | The list of possible functions is very large, but a common set of functions is defined by the :term:`OGC` :term:`SFSQL` and implemented (along with additional useful functions) by PostGIS. |
---|
| 91 | |
---|
| 92 | What is PostGIS? |
---|
| 93 | ================ |
---|
| 94 | |
---|
| 95 | PostGIS turns the `PostgreSQL <http://www.postgresql.org/>`_ Database Management System into a spatial database by adding adding support for the three features: spatial types, indexes, and functions. Because it is built on PostgreSQL, PostGIS automatically inherits important "enterprise" features as well as open standards for implementation |
---|
| 96 | |
---|
| 97 | But what is PostgreSQL? |
---|
| 98 | ----------------------- |
---|
| 99 | |
---|
| 100 | PostgreSQL is a powerful, object-relational database management system (ORDBMS). It is released under a BSD-style license and is thus free and open source software. As with many other open source programs, PostgreSQL is not controlled by any single company, but has a global community of developers and companies to develop it. |
---|
| 101 | |
---|
| 102 | PostgreSQL was designed from the very start with type extension in mind -- the ability to add new data types, functions and access methods at run-time. Because of this, the PostGIS extension can be developed by a separate development team, yet still integrate very tightly into the core PostgreSQL database. |
---|
| 103 | |
---|
| 104 | Why choose PostgreSQL? |
---|
| 105 | ~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 106 | |
---|
| 107 | A common question from people familiar with open source databases is, "Why wasn't PostGIS built on MySQL?". |
---|
| 108 | |
---|
| 109 | PostgreSQL has: |
---|
| 110 | |
---|
| 111 | * Proven reliability and transactional integrity by default (ACID) |
---|
| 112 | * Careful support for SQL standards (full SQL92) |
---|
| 113 | * Pluggable type extension and function extension |
---|
| 114 | * Community-oriented development model |
---|
| 115 | * No limit on column sizes ("TOAST"able tuples) to support big GIS objects |
---|
| 116 | * Generic index structure (GiST) to allow R-Tree index |
---|
| 117 | * Easy to add custom functions |
---|
| 118 | |
---|
| 119 | Combined, PostgreSQL provides a very easy development path to add new spatial types. In the proprietary world, only Illustra (now Informix Universal Server) allows such easy extension. This is no coincidence; Illustra is a proprietary re-working of the original PostgreSQL code base from the 1980's. |
---|
| 120 | |
---|
| 121 | Because the development path for adding types to PostgreSQL was so straightforward, it made sense to start there. When MySQL released basic spatial types in version 4.1, the PostGIS team took a look at their code, and the exercise reinforced the original decision to use PostgreSQL. Because MySQL spatial objects had to be hacked on top of the string type as a special case, the MySQL code was spread over the entire code base. Development of PostGIS 0.1 took under a month. Doing a "MyGIS" 0.1 would have taken a lot longer, and as such, might never have seen the light of day. |
---|
| 122 | |
---|
| 123 | Why not Shapefiles? |
---|
| 124 | ------------------- |
---|
| 125 | |
---|
| 126 | The `shapefile <http://en.wikipedia.org/wiki/Shapefile>`_ (and other file formats) have been the standard way of storing and interacting with spatial data since GIS software was first written. However, these "flat" files have the following disadvantages: |
---|
| 127 | |
---|
| 128 | * **Files require special software to read and write.** SQL is an abstraction for random data access and analysis. Without that abstraction, you will need to write all the access and analysis code yourself. |
---|
| 129 | * **Concurrent users can cause corruption.** While it's possible to write extra code to ensure that multiple writes to the same file do not corrupt the data, by the time you have solved the problem and also solved the associated performance problem, you will have written the better part of a database system. Why not just use a standard database? |
---|
| 130 | * **Complicated questions require complicated software to answer.** Complicated and interesting questions (spatial joins, aggregations, etc) that are expressible in one line of SQL in the database take hundreds of lines of specialized code to answer when programming against files. |
---|
| 131 | |
---|
| 132 | Most users of PostGIS are setting up systems where multiple applications will be expected to access the data, so having a standard SQL access method simplifies deployment and development. Some users are working with large data sets; with files, they might be segmented into multiple files, but in a database they can be stored as a single large table. |
---|
| 133 | |
---|
| 134 | In summation, the combination of support for multiple users, complex ad hoc queries, and performance on large data sets are what sets spatial databases apart from file-based systems. |
---|
| 135 | |
---|
| 136 | A brief history of PostGIS |
---|
| 137 | -------------------------- |
---|
| 138 | |
---|
| 139 | In the May of 2001, `Refractions Research <http://www.refractions.net/>`_ released the first version of PostGIS. PostGIS 0.1 had objects, indexes and a handful of functions. The result was a database suitable for storage and retrieval, but not analysis. |
---|
| 140 | |
---|
| 141 | As the number of functions increased, the need for an organizing principle became clear. The "Simple Features for SQL" (:term:`SFSQL`) specification from the Open Geospatial Consortium provided such structure with guidelines for function naming and requirements. |
---|
| 142 | |
---|
| 143 | With PostGIS support for simple analysis and spatial joins, `Mapserver <http://mapserver.org/>`_ became the first external application to provide visualization of data in the database. |
---|
| 144 | |
---|
| 145 | Over the next several years the number of PostGIS functions grew, but its power remained limited. Many of the most interesting functions (e.g., ST_Intersects(), ST_Buffer(), ST_Union()) were very difficult to code. Writing them from scratch promised years of work. |
---|
| 146 | |
---|
| 147 | Fortunately a second project, the "Geometry Engine, Open Source" or `GEOS <http://trac.osgeo.org/geos>`_, came along. The GEOS library provides the necessary algorithms for implementing the :term:`SFSQL` specification. By linking in GEOS, PostGIS provided complete support for :term:`SFSQL` by version 0.8. |
---|
| 148 | |
---|
| 149 | As PostGIS data capacity grew, another issue surfaced: the representation used to store geometry proved relatively inefficient. For small objects like points and short lines, the metadata in the representation had as much as a 300% overhead. For performance reasons, it was necessary to put the representation on a diet. By shrinking the metadata header and required dimensions, overhead greatly reduced. In PostGIS 1.0, this new, faster, lightweight representation became the default. |
---|
| 150 | |
---|
| 151 | Recent updates of PostGIS have worked on expanding standards compliance, adding support for curve-based geometries and function signatures specified in the ISO :term:`SQL/MM` standard. Through a continued focus on performance, PostGIS 1.4 significantly improved the speed of geometry testing routines. |
---|
| 152 | |
---|
| 153 | Who uses PostGIS? |
---|
| 154 | ----------------- |
---|
| 155 | |
---|
| 156 | For a complete list of case studies, see the `PostGIS case studies <http://www.postgis.org/documentation/casestudies/>`_ page. |
---|
| 157 | |
---|
| 158 | Institut Geographique National, France |
---|
| 159 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 160 | |
---|
| 161 | IGN is the national mapping agency of France, and uses PostGIS to store the high resolution topographic map of the country, "BDUni". BDUni has more than 100 million features, and is maintained by a staff of over 100 field staff who verify observations and add new mapping to the database daily. The IGN installation uses the database transactional system to ensure consistency during update processes, and a `warm standby system <http://developer.postgresql.org/pgdocs/postgres/warm-standby.html>`_ to maintain uptime in the event of a system failure. |
---|
| 162 | |
---|
| 163 | GlobeXplorer |
---|
| 164 | ~~~~~~~~~~~~ |
---|
| 165 | |
---|
| 166 | GlobeXplorer is a web-based service providing online access to petabytes of global satellite and aerial imagery. GlobeXplorer uses PostGIS to manage the metadata associated with the imagery catalogue, so queries for imagery first search the PostGIS catalogue to find the location of the relevant images, then pull the images from storage and return them to the client. In building their system, GlobeXplorer tried other spatial databases but eventually settled on PostGIS because of the great combination of price and performance it offers. |
---|
| 167 | |
---|
| 168 | What applications support PostGIS? |
---|
| 169 | ---------------------------------- |
---|
| 170 | |
---|
| 171 | PostGIS has become a widely used spatial database, and the number of third-party programs that support storing and retrieving data using it has increased as well. The `programs that support PostGIS <http://trac.osgeo.org/postgis/wiki/UsersWikiToolsSupportPostgis>`_ include both open source and proprietary software on both server and desktop systems. |
---|
| 172 | |
---|
| 173 | The following table shows a list of some of the software that leverages PostGIS: |
---|
| 174 | |
---|
| 175 | +-------------------------------------------------+----------------------------------------------+ |
---|
| 176 | | Open/Free | Closed/Proprietary | |
---|
| 177 | +=================================================+==============================================+ |
---|
| 178 | | | | |
---|
| 179 | | * Loading/Extracting | * Loading/Extracting | |
---|
| 180 | | | | |
---|
| 181 | | * Shp2Pgsql | * Safe FME Desktop Translator/Converter | |
---|
| 182 | | * ogr2ogr | | |
---|
| 183 | | * Dxf2PostGIS | | |
---|
| 184 | | | * Web-Based | |
---|
| 185 | | * Web-Based | | |
---|
| 186 | | | * Ionic Red Spider (now ERDAS) | |
---|
| 187 | | * Mapserver | * Cadcorp GeognoSIS | |
---|
| 188 | | * GeoServer (Java-based WFS / WMS -server ) | * Iwan Mapserver | |
---|
| 189 | | * SharpMap SDK - for ASP.NET 2.0 | * MapDotNet Server | |
---|
| 190 | | * MapGuide Open Source (using FDO) | * MapGuide Enterprise (using FDO) | |
---|
| 191 | | | * ESRI ArcGIS Server 9.3+ | |
---|
| 192 | | * Desktop | | |
---|
| 193 | | | * Desktop | |
---|
| 194 | | * uDig | | |
---|
| 195 | | * QGIS | * Cadcorp SIS | |
---|
| 196 | | * mezoGIS | * Microimages TNTmips GIS | |
---|
| 197 | | * OpenJUMP | * ESRI ArcGIS 9.3+ | |
---|
| 198 | | * OpenEV | * Manifold | |
---|
| 199 | | * SharpMap SDK for Microsoft.NET 2.0 | * GeoConcept | |
---|
| 200 | | * ZigGIS for ArcGIS/ArcObjects.NET | * MapInfo (v10) | |
---|
| 201 | | * GvSIG | * AutoCAD Map 3D (using FDO) | |
---|
| 202 | | * GRASS | | |
---|
| 203 | | | | |
---|
| 204 | +-------------------------------------------------+----------------------------------------------+ |
---|
| 205 | |
---|