Skip to content

Commit 669fc9e

Browse files
taimoorzaeemsteve-chavez
authored andcommitted
docs: restructure PostGIS page
Restructure PostGIS page with order: - `Accept: application/geo+json` request example - Generated column example - String representation example Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
1 parent 0df56f9 commit 669fc9e

2 files changed

Lines changed: 30 additions & 13 deletions

File tree

docs/integrations/postgis.rst

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
PostGIS
44
=======
55

6-
You can use the string representation for `PostGIS <https://postgis.net/>`_ data types such as ``geometry`` or ``geography`` (you need to `install PostGIS <https://postgis.net/documentation/getting_started/>`_ first).
6+
To work with `PostGIS <https://postgis.net/>`_ data types such as ``geometry`` or ``geography``, you'll need to `install PostGIS <https://postgis.net/documentation/getting_started/>`_ first.
77

88
.. code-block:: postgres
99
@@ -16,20 +16,16 @@ You can use the string representation for `PostGIS <https://postgis.net/>`_ data
1616
area geometry
1717
);
1818
19-
To add areas in polygon format, you can use string representation:
19+
insert into coverage (id, name, area) values
20+
(1, 'small', ST_GeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))',4326)),
21+
(2, 'big', ST_GeomFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))', 4326);
2022
21-
.. code-block:: bash
23+
.. _application/geo+json:
2224

23-
curl "http://localhost:3000/coverage" \
24-
-X POST -H "Content-Type: application/json" \
25-
-d @- << EOF
26-
[
27-
{ "id": 1, "name": "small", "area": "SRID=4326;POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))" },
28-
{ "id": 2, "name": "big", "area": "SRID=4326;POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))" }
29-
]
30-
EOF
25+
``application/geo+json``
26+
------------------------
3127

32-
Now, when you request the information, PostgREST will automatically cast the ``area`` column into a ``Polygon`` geometry type. Although this is useful, you may need the whole output to be in `GeoJSON <https://geojson.org/>`_ format out of the box, which can be done by including the ``Accept: application/geo+json`` in the request. This will work for PostGIS versions 3.0.0 and up and will return the output as a `FeatureCollection Object <https://www.rfc-editor.org/rfc/rfc7946#section-3.3>`_:
28+
PostgREST supports the `standard <https://www.iana.org/assignments/media-types/application/geo+json>`_ ``application/geo+json`` media type which can be used to get the output in `GeoJSON <https://geojson.org/>`_ format. This will work for PostGIS versions 3.0.0 and up and will return the output as a `FeatureCollection Object <https://www.rfc-editor.org/rfc/rfc7946#section-3.3>`_:
3329

3430
.. code-block:: bash
3531
@@ -70,6 +66,9 @@ Now, when you request the information, PostgREST will automatically cast the ``a
7066
]
7167
}
7268
69+
Using generated columns
70+
-----------------------
71+
7372
If you need to add an extra property, like the area in square units by using ``st_area(area)``, you could add a generated column to the table and it will appear in the ``properties`` key of each ``Feature``.
7473

7574
.. code-block:: postgres
@@ -135,3 +134,21 @@ Now this query will return the same results:
135134
}
136135
]
137136
}
137+
138+
Using string representation
139+
---------------------------
140+
141+
To insert areas in polygon format, you can use string representation:
142+
143+
.. code-block:: bash
144+
145+
curl "http://localhost:3000/coverage" \
146+
-X POST -H "Content-Type: application/json" \
147+
-d @- << EOF
148+
[
149+
{ "id": 3, "name": "strip", "area": "SRID=4326;POLYGON((0 0, 50 0, 50 2, 0 2, 0 0))" },
150+
{ "id": 4, "name": "diamond", "area": "SRID=4326;POLYGON((5 0, 10 5, 5 10, 0 5, 5 0))" }
151+
]
152+
EOF
153+
154+
PostgREST will automatically cast the ``area`` column into a ``Polygon`` geometry type.

docs/references/api/resource_representation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Builtin handlers are offered for common standard media types.
5151

5252
* ``text/csv`` and ``application/json``, for all API endpoints. See :ref:`tables_views` and :ref:`functions`.
5353
* ``application/openapi+json``, for the root endpoint. See :ref:`open-api`.
54-
* ``application/geo+json``, see :ref:`ww_postgis`.
54+
* ``application/geo+json``, see :ref:`application/geo+json`.
5555
* ``*/*``, resolves to ``application/json`` for API endpoints and to ``application/openapi+json`` for the root endpoint.
5656

5757
The following vendor media types handlers are also supported.

0 commit comments

Comments
 (0)