Bienvenue sur PostGIS.fr

Bienvenue sur PostGIS.fr , le site de la communauté des utilisateurs francophones de PostGIS.

PostGIS ajoute le support d'objets géographique à la base de données PostgreSQL. En effet, PostGIS "spatialise" le serverur PostgreSQL, ce qui permet de l'utiliser comme une base de données SIG.

Maintenu à jour, en fonction de nos disponibilités et des diverses sorties des outils que nous testons, nous vous proposons l'ensemble de nos travaux publiés en langue française.

source: trunk/workshop-foss4g/creating_db.rst @ 13

Revision 1, 4.9 KB checked in by djay, 13 years ago (diff)

Initial import of the svn tree

RevLine 
[1]1.. _creating_db:
2
3Section 3: Creating a Spatial Database
4======================================
5
6The Dashboard and PgAdmin
7-------------------------
8
9The "Dashboard" is the central application to access all portions of the OpenGeo Suite.
10
11When you first start the dashboard, it provides a reminder about the default password for accessing GeoServer.
12
13.. image:: ./screenshots/dashboard_01.png
14
15.. note::
16
17  The PostGIS database has been installed with unrestricted access for local users (users connecting from the same machine as the database is running). That means that it will accept *any* password you provide. If you need to connect from a remote computer, the password for the ``postgres`` user has been set to ``postgres``.
18
19For this workshop, we will be using the entries under the "PostGIS" section of the Dashboard almost exclusively.
20
21#. First, we need to start up PostGIS. Click the green **Start** button at the top right corner of the Dashboard.
22
23#. The first time the Suite starts, it initializes a data area and sets up template databases. This can take a couple minutes. Once the Suite has started, you can click the **Manage** option under the *PostGIS* component to start the pgAdmin utility.
24
25      .. image:: ./screenshots/dashboard_02.png
26 
27      .. note:: 
28 
29         PostgreSQL has a number of administrative front-ends.  The primary is `psql <http://www.postgresql.org/docs/8.1/static/app-psql.html>`_ a command-line tool for entering SQL queries.  Another popular PostgreSQL front-end is the free and open source graphical tool `pgAdmin <http://www.pgadmin.org/>`_. All queries done in pgAdmin can also be done on the command line with psql.
30
31#. If this is the first time you have run pgAdmin, you should have a server entry for **PostGIS (localhost:54321)** already configured in pgAdmin. Double click the entry, and enter anything you like at the password prompt to connect to the database.
32
33    .. image:: ./screenshots/pgadmin_01.png
34
35    .. note::
36
37      If you have a previous installation of PgAdmin on your computer, you will not have an entry for **(localhost:54321)**. You will need to create a new connection.  Go to *File > Add Server*, and register a new server  at **localhost** and port **54321** (note the non-standard port number) in order to connect to the PostGIS bundled with the OpenGeo Suite.
38
39Creating a Database
40-------------------
41PostgreSQL has the notion of a **template database** that can be used to initialize a new database.  The new database automatically gets a copy of everything from the template. When you installed PostGIS, a spatially enabled database called ``template_postgis`` was created. If we use ``template_postgis`` as a template when creating our new database, the new database will be spatially enabled.
42
43#. Open the Databases tree item and have a look at the available databases.  The ``postgres`` database is the user database for the default postgres user and is not too interesting to us.  The ``template_postgis`` database is what we are going to use to create spatial databases.
44
45#. Right-click on the ``Databases`` item and select ``New Database``.
46
47   .. image:: ./screenshots/pgadmin_02.png
48
49   .. note:: If you receive an error indicating that the source database (``template_postgis``) is being accessed by other users, this is likely because you still have it selected.  Right-click on the ``PostGIS (localhost:54321)`` item and select ``Disconnect``.  Double-click the same item to reconnect and try again.
50
51#. Fill in the ``New Database`` form as shown below and click **OK**
52
53   .. list-table::
54
55      * - **Name**
56        - ``nyc``
57      * - **Owner**
58        - ``postgres``
59      * - **Encoding**
60        - ``UTF8``
61      * - **Template**
62        - ``template_postgis``
63
64   .. image:: ./screenshots/pgadmin_03.png
65
66#. Select the new ``nyc`` database and open it up to display the tree of objects. You'll see the ``public`` schema, and under that a couple of PostGIS-specific metadata tables -- ``geometry_columns`` and ``spatial_ref_sys``.
67
68   .. image:: ./screenshots/pgadmin_04.png
69
70#. Click on the SQL query button indicated below (or go to *Tools > Query Tool*).
71
72   .. image:: ./screenshots/pgadmin_05.png
73
74#. Enter the following query into the query text field:
75
76   .. code-block:: sql
77
78      SELECT postgis_full_version();
79
80   .. note::
81   
82      This is our first SQL query.  ``postgis_full_version()`` is management function that returns version and build configuration.
83     
84#. Click the **Play** button in the toolbar (or press **F5**) to "Execute the query." The query will return the following string, confirming that PostGIS is properly enabled in the database.
85
86   .. image:: ./screenshots/pgadmin_06.png
87   
88You have successfully created a PostGIS spatial database!!
89
90Function List
91-------------
92
93`PostGIS_Full_Version <http://postgis.org/documentation/manual-svn/PostGIS_Full_Version.html>`_: Reports full postgis version and build configuration info.
Note: See TracBrowser for help on using the repository browser.