Changes in trunk/workshop-foss4g/geography.rst [1:53]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/workshop-foss4g/geography.rst
r1 r53 1 1 .. _geography: 2 2 3 Section 17: Geography 4 ===================== 5 6 I t is very common to have data in which the coordinate are "geographics" or "latitude/longitude".7 8 Unlike coordinates in Mercator, UTM, or Stateplane, geographic coordinates are **not cartesian coordinates**. Geographic coordinates do not represent a linear distance from an origin as plotted on a plane. Rather, these **spherical coordinates** describe the angular distance between the equator and the poles. In spherical coordinates a point is specified by the distance from the origin (the radius), the angle of rotation from the initial meridian plane, and the angle from the polar axis (analogous to a vector from the origin through the North Pole). 3 Partie 17 : Coordonnées géographiques 4 ===================================== 5 6 Il est trÚs fréquent de manipuler des données à coordonnées "géographiques" ou de "longitude/latitude". 7 8 Au contraire des coordonnées de type Mercator, UTM ou Stateplane, les coordonnées géographiques ne représentent pas une distance linéaire depuis une origine, tel que dans un plan. Elles décrivent la distance angulaire entre l'équateur et les pÃŽles. Dans les sytÚmes de coordonnées sphériques, un point est spécifié par son rayon (distance à l'origine), son angle de rotation par rapport au méridien plan, et son angle par rapport à l'axe pÃŽlaire. 9 9 10 10 .. image:: ./geography/cartesian_spherical.jpg 11 11 12 You can treat geographic coordinates as approximate cartesian coordinates and continue to do spatial calculations. However, measurements of distance, length and area will be nonsensical. Since spherical coordinates measure **angular** distance, the units are in "degrees." Further, the approximate results from indexes and true/false tests like intersects and contains can become terribly wrong. The distance between points get larger as problem areas like the poles or the international dateline are approached. 13 14 For example, here are the coordinates of Los Angeles and Paris. 12 13 Vous pouvez continuer à utiliser des coordonnées géographiques comme des coordonnées cartésiennes approximatives pour vos analyses spatiales. Par contre les mesures de distances, d'aires et de longueur seront éronées. Etant donné que les coordonnées spériques mesurent des angles, l'unité est le dégré. Par exemple, les résultats cartésien approximatifs de tests tels que 'intersects' et 'contains' peuvent s'avérer terriblement faux. Par ailleurs, plus une zone est située prÚs du pÃŽle ou de la ligne de date internationale, plus la distance entre les points est agrandie. 14 15 16 Voici par exemple les coordonnées des villes de Los Angeles et Paris. 15 17 16 18 * Los Angeles: ``POINT(-118.4079 33.9434)`` 17 19 * Paris: ``POINT(2.3490 48.8533)`` 18 20 19 The following calculates the distance between Los Angeles and Paris using the standard PostGIS cartesian :command:`ST_Distance(geometry, geometry)`. Note that the SRID of 4326 declares a geographic spatial reference system.21 La requête suivante calcule la distance entre Los Angeles et Paris en utilisant le systÚme cartésien standard de PostGIS :command:`ST_Distance(geometry, geometry)`. Notez que le SRID 4326 déclare un systÚme de références spatiales géographiques. 20 22 21 23 .. code-block:: sql … … 30 32 121.898285970107 31 33 32 Aha! 121! But, what does that mean? 33 34 The units for spatial reference 4326 are degrees. So our answer is 121 degrees. But (again), what does that mean? 35 36 On a sphere, the size of one "degree square" is quite variable, becoming smaller as you move away from the equator. Think of the meridians (vertical lines) on the globe getting closer to each other as you go towards the poles. So, a distance of 121 degrees doesn't *mean* anything. It is a nonsense number. 37 38 In order to calculate a meaningful distance, we must treat geographic coordinates not as approximate cartesian coordinates but rather as true spherical coordinates. We must measure the distances between points as true paths over a sphere -- a portion of a great circle. 39 40 Starting with version 1.5, PostGIS provides this functionality through the ``geography`` type. 34 Aha! 121! Mais, que veut dire cela ? 35 36 L'unité pour SRID 4326 est le degré. Donc la réponse signifie 121 degrés. Sur une sphÚre, la taille d'un degré "au carré" est assez variable. Elle devient plsu petite au fur et à mesure que l'on s'éloigne de l'équateur. Pensez par exemple aux méridiens sur le globe qui se ressÚrent entre eux au niveau des pÃŽles. Donc une distance de 121 degrés ne veut rien dire ! 37 38 Pour calculer une distance ayant du sens, nous devons traiter les coordonnées géographiques non pas come des coordonnées cartésiennes approximatives, mais plutÃŽt comme de réelles coordonnées sphériques. Nous devons mesurer les distances entre les points comme de vrais chemins par dessus uen sphÚre, comme une portion d'un grand cercle. 39 40 Depuis sa version 1.5, PostGIS fournit cette fonctionnalité avec le type ``geography``. 41 41 42 42 .. note:: 43 43 44 Diff erent spatial databases have different approaches for "handling geographics"45 46 * Oracle attempts to paper over the differences by transparently doing geographic calculations when the SRID is geographic.47 * SQL Server u ses two spatial types, "STGeometry" for cartesian data and "STGeography" for geographics.48 * Informix Spatial is a pure cartesian extension to Informix, while Informix Geodetic is a pure geographic extension.49 * Similar to SQL Server, PostGIS uses two types, "geometry" and"geography".50 51 Using the ``geography`` instead of ``geometry`` type, let's try again to measure the distance between Los Angeles and Paris. Instead of :command:`ST_GeometryFromText(text)`, we will use:command:`ST_GeographyFromText(text)`.44 Différentes bases de données spatiales développent différentes approches pour manipuler les coordonnées géographiques. 45 46 * Oracle essaye de mettre à jour la différence de maniÚre transparente en lanacant des calculs lorsuqe le SRID est géographique. 47 * SQL Server utilise deux types spatiaux, "STGeometry" pour les coordonnées cartésiens et STGeography" pour les coordonnées géographqiues. 48 * Informix Spatial est une pure extension cartésienne d'Informix, alors qu'Informix Geodetic est une pure extension géographique. 49 * Comme SQL Server, PostGIS utilise deux types: "geometry" et "geography". 50 51 En utilisant le type ``geography`` plutot que ``geometry``, essayon sà nouveau de mesurer la distance entre Los Angeles et Paris. Au lieu de la commande :command:`ST_GeometryFromText(text)`, nous utiliserons cette fois :command:`ST_GeographyFromText(text)`. 52 52 53 53 .. code-block:: sql … … 62 62 9124665.26917268 63 63 64 A big number! All return values from ``geography`` calculations are in meters, so our answer is 9124km. 65 66 Older versions of PostGIS supported very basic calculations over the sphere using the :command:`ST_Distance_Spheroid(point, point, measurement)` function. However, :command:`ST_Distance_Spheroid` is substantially limited. The function only works on points and provides no support for indexing across the poles or international dateline.67 68 The need to support non-point geometries becomes very clear when posing a question like "How close will a flight from Los Angeles to Paris come to Iceland?"64 Toutes les valeurs retournées étant en mÚtres, notre réponse est donc 9124 kilomÚtres. 65 66 Les versions plus anciennes de PostGIS supportaient uniquement des calculs sur sphÚre trÚs basiques comme la fonction :command:`ST_Distance_Spheroid(point, point, measurement)`. Celle-ci est trÚs limitée et ne fonctionne uniquement sur des points. Elle ne supporte pas non plus l'indexation au niveau des pÃŽles ou de la ligne de date internationale. 67 68 Le besoin du support des autres types de géométries se fit ressentir lorsqu'il s'agissait de répondre à des questions du type "A quelle distance la ligne de vol d'un avion Los Angeles/Paris passe-t-elle de l'Islande?" 69 69 70 70 .. image:: ./geography/lax_cdg.jpg 71 71 72 Working with geographic coordinates on a cartesian plane (the purple line) yields a *very* wrong answer indeed! Using great circle routes (the red lines) gives the right answer. If we convert our LAX-CDG flight into a line string and calculate the distance to a point in Iceland using ``geography`` we'll get the right answer (recall) in meters. 72 Répondre à cette question en travaillant avec un plan cartésien fournit une trÚs mauvaise réponse en effet ! En utilisant la ligne rouge, nou sobtenon sune bien meilleure réponse. Si nous convertissons notre vol LAX-CDG en une ligne et que nous calculons la distance à un point en Islande, nous obtiendrons la réponse exacte, en mÚtres. 73 73 74 74 .. code-block:: sql … … 83 83 531773.757079116 84 84 85 So the closest approach to Iceland on the LAX-CDG route is a relatively small 532km. 86 87 The cartesian approach to handling geographic coordinates breaks down entirely for features that cross the international dateline. The shortest great-circle route from Los Angeles to Tokyo crosses the Pacific Ocean. The shortest cartesian route crosses the Atlantic and Indian Oceans. 85 Donc le point le plu sproche de l'Islande pendant le vol LAX-CDG est de 532 kilomÚtres.S 86 87 L'approche cartésienne pour manipuler les coordonnées géographiques pert tout son sens pour les objets situées au dessus de la ligne de date internationale. La route "sphérique" la plus courte entre Los-Angeles et Tokyo traverse l'océan Pacifique. La route "cartésienne" la plus courte traverse quant à elle les océans Atlantique et Indien. 88 88 89 89 .. image:: ./geography/lax_nrt.png … … 107 107 108 108 109 U sing Geography110 --------------- 111 112 In order to load geometry data into a geography table, the geometry first needs to be projected into EPSG:4326 (longitude/latitude), then it needs to be changed into geography. The :command:`ST_Transform(geometry,srid)` function converts coordinates to geographics and the :command:`Geography(geometry)` function "casts" them from geometry to geography.109 Utiliser le type 'Geography' 110 ---------------------------- 111 112 Afin d'importer des données dans une table de type geography, les objets géographiques doivent d'avord être projetées dans le systÚme EPSG:4326 (longitude/latitude), ensuite elles doivent être converties en objets de type géographies. La fonction :command:`ST_Transform(geometry,srid)` convertie les coordonnées en géographies et la fonction :command:`Geography(geometry)` change le type ("cast") de géométrie à géographie. 113 113 114 114 .. code-block:: sql … … 121 121 FROM nyc_subway_stations; 122 122 123 Building a spatial index on a geography table is exactly the same as for geometry: 123 La construction d'une indexation spatiale sur une table stockant des objets de type géographie est exactement identique à la méthode employée pour les géométries : 124 124 125 125 .. code-block:: sql … … 128 128 ON nyc_subway_stations_geog USING GIST (geog); 129 129 130 The difference is under the covers: the geography index will correctly handle queries that cover the poles or the international date-line, while the geometry one will not.131 132 There are only a small number of native functions for the geography type: 133 134 * :command:`ST_AsText(geography)` ret urns ``text``135 * :command:`ST_GeographyFromText(text)` ret urns``geography``136 * :command:`ST_AsBinary(geography)` ret urns``bytea``137 * :command:`ST_GeogFromWKB(bytea)` ret urns``geography``138 * :command:`ST_AsSVG(geography)` ret urns``text``139 * :command:`ST_AsGML(geography)` ret urns``text``140 * :command:`ST_AsKML(geography)` ret urns``text``141 * :command:`ST_AsGeoJson(geography)` ret urns``text``142 * :command:`ST_Distance(geography, geography)` ret urns``double``143 * :command:`ST_DWithin(geography, geography, float8)` ret urns``boolean``144 * :command:`ST_Area(geography)` ret urns``double``145 * :command:`ST_Length(geography)` ret urns``double``146 * :command:`ST_Covers(geography, geography)` ret urns``boolean``147 * :command:`ST_CoveredBy(geography, geography)` ret urns``boolean``148 * :command:`ST_Intersects(geography, geography)` ret urns``boolean``149 * :command:`ST_Buffer(geography, float8)` ret urns``geography`` [#Casting_note]_150 * :command:`ST_Intersection(geography, geography)` ret urns``geography`` [#Casting_note]_151 152 Cr eating a Geography Table153 -------------------------- 154 155 The SQL for creating a new table with a geography column is much like that for creating a geometry table. However, geography includes the ability to specify the object type directly at the time of table creation. For example:130 La différence est camouflé : l'indexation des objets de type géographie gére correctement les requêtes qui recouvrent les pÃŽles ou traverses les fuseaux horraires, alors que les géométries ne le supporteront pas. 131 132 Il n'y a qu'un petit nombre de fonctions disponibles pour le type géographie : 133 134 * :command:`ST_AsText(geography)` retourne la représentation ``textuelle`` 135 * :command:`ST_GeographyFromText(text)` retourne un objet de type ``geography`` 136 * :command:`ST_AsBinary(geography)` retourne la représentation binaire ``bytea`` 137 * :command:`ST_GeogFromWKB(bytea)` retourne un objet de type ``geography`` 138 * :command:`ST_AsSVG(geography)` retourne ``text`` 139 * :command:`ST_AsGML(geography)` retourne ``text`` 140 * :command:`ST_AsKML(geography)` retourne ``text`` 141 * :command:`ST_AsGeoJson(geography)` retourne ``text`` 142 * :command:`ST_Distance(geography, geography)` retourne ``double`` 143 * :command:`ST_DWithin(geography, geography, float8)` retourne ``boolean`` 144 * :command:`ST_Area(geography)` retourne ``double`` 145 * :command:`ST_Length(geography)` retourne ``double`` 146 * :command:`ST_Covers(geography, geography)` retourne ``boolean`` 147 * :command:`ST_CoveredBy(geography, geography)` retourne ``boolean`` 148 * :command:`ST_Intersects(geography, geography)` retourne ``boolean`` 149 * :command:`ST_Buffer(geography, float8)` retourne ``geography`` [#Casting_note]_ 150 * :command:`ST_Intersection(geography, geography)` retourne ``geography`` [#Casting_note]_ 151 152 Création d'une table stockant des géograhpies 153 --------------------------------------------- 154 155 Le code SQL permettant la création d'une nouvelle table avec une colonne de type géographie ressemble à la création d'une table stockant des géométries. Cependant, les objets de type géographie permettent de spécifier directement le type d'objet géographique à la création de la table. Par exemple : 156 156 157 157 .. code-block:: sql … … 166 166 INSERT INTO airports VALUES ('REK', 'POINT(-21.8628 64.1286)'); 167 167 168 In the table definition, the ``GEOGRAPHY(Point)`` specifies our airport data type as points. The new geography fields don't get registered in the ``geometry_columns``. Instead, they are registered in a new view called ``geography_columns`` that is automatically kept up to date without need for an :command:`AddGeom...` like functions.168 Lors de la définitionn le type ``GEOGRAPHY(Point)`` spécifie que nos airoports sont des points. Les nouveau champs géographie n'est pas référencé dans la table ``geometry_columns``. Le stockage des métadonnées relatives aux données de type géograhpie sont stockées dans une vue appellée ``geography_columns`` qui est maintenue à jour automatiquement sans avoir besoin d'utiliser des fonctions comme ``geography_columns``. 169 169 170 170 .. code-block:: sql … … 181 181 .. note:: 182 182 183 The ability to define geometry types and SRIDs inside the table ``CREATE`` statement, and the automatic update of the ``geometry_columns`` metadata are features that have been prototyped with ``geography`` and will be added to the ``geometry`` type for PostGIS 2.0. 184 185 186 Casting to Geometry 183 La possibilité de définir les types et le SRID lors de la création de la table (requête ``CREATE``), et la mise à jour automatique des métadonnées ``geometry_columns`` sont des fonctionalités qui seront adaptées pour le type géométrie pour la version 2.0 de PostGIS. 184 185 Conversion de type 187 186 ------------------- 188 187 189 While the basic functions for geography types can handle many use cases, there are times when you might need access to other functions only supported by the geometry type. Fortunately, you can convert objects back and forth from geography to geometry.190 191 The PostgreSQL syntax convention for casting is to append ``::typename`` to the end of the value you wish to cast. So, ``2::text`` with convert a numeric two to a text string '2'. And ``'POINT(0 0)'::geometry`` will convert the text representation of point into a geometry point.192 193 The :command:`ST_X(point)` function only supports the geometry type. How can we read the X coordinate from our geographies?188 Bien que les fonctions de bases qui s'appliquent au type géographie peuvent être utilisées dans un grand nombre de cas d'utilisation, il est parfois nécessaire d'accéder aux autres fonctions qui ne supportent que le type géométrie. Heureusement, il est possible de convertir des objets de type géométries en des objets de types géographies et inversement. 189 190 La syntaxe habituelle de PostgreSQL pour les conversion de type consiste à ajouter à la valeur la chaîne suivante ``::typename``. Donc, ``2::text`` convertie la valeur numérique deux en une chaîne de caractÚres '2'. La commande : ``'POINT(0 0)'::geometry`` convertira la représentation textuelle d'un point en une point géométrique. 191 192 La fonction :command:`ST_X(point)` supporte seulement le type géométrique. Comment lire la coordonée X d'une de nos géographie ? 194 193 195 194 .. code-block:: sql … … 205 204 REK | -21.8628 206 205 207 By appending ``::geometry`` to our geography value, we convert the object to a geometry with an SRID of 4326. From there we can use as many geometry functions as strike our fancy. But, remember -- now that our object is a geometry, the coordinates will be interpretted as cartesian coordinates, not spherical ones.208 209 210 Why (Not) Use Geography 211 ----------------------- 212 213 Geographics are universally accepted coordinates -- everyone understands what latitude/longitude mean, but very few people understand what UTM coordinates mean. Why not use geography all the time?214 215 * First, as noted earlier, there are far fewer functions available (right now) that directly support the geography type. You may spend a lot of time working around geography type limitations.216 * Second, the calculations on a sphere are computationally far more expensive than cartesian calculations. For example, the cartesian formula for distance (Pythagoras) involves one call to sqrt(). The spherical formula for distance (Haversine) involves two sqrt() calls, an arctan() call, four sin() calls and two cos() calls. Trigonometric functions are very costly, and spherical calculations involve a lot of them.217 218 The conclusion?219 220 If your data is geographically compact (contained within a state, county or city), use the ``geometry`` type with a cartesian projection that makes sense with your data. See the http://spatialreference.org site and type in the name of your region for a selection of possible reference systems.221 222 If, on the other hand, you need to measure distance with a dataset that is geographically dispersed (covering much of the world), use the ``geography`` type. The application complexity you save by working in ``geography`` will offset any performance issues. And, casting to ``geometry`` can offset most functionality limitations.223 224 Function List 225 ------------- 226 227 `ST_Distance(geometry, geometry) <http://postgis.org/docs/ST_Distance.html>`_: For geometry type Returns the 2-dimensional cartesian minimum distance (based on spatial ref) between two geometries in projected units. For geography type defaults to return spheroidal minimum distance between two geographies in meters.228 229 `ST_GeographyFromText(text) <http://postgis.org/docs/ST_GeographyFromText.html>`_: Ret urns a specified geography value from Well-Known Text representation or extended (WKT).230 231 `ST_Transform(geometry, srid) <http://postgis.org/docs/ST_Transform.html>`_: Ret urns a new geometry with its coordinates transformed to the SRID referenced by the integer parameter.232 233 `ST_X(point) <http://postgis.org/docs/ST_X.html>`_: Ret urns the X coordinate of the point, or NULL if not available. Input must be apoint.206 En ajoutant la chaîne ``::geometry`` à notre valeur géographique, nous la convertissons en une géographie ayant le SRID : 4326. à partir de maintenant, nous pouvons utiliser autemps de fonctions s'appliquant au géométries que nous le souhaitons. Mais, souvenez-vous - maintenant que nos objets sont des géométries, leur coordonnées seront interprétées comme des coordonnées cartésiennes, non pas sphériques. 207 208 209 Pourquoi (ne pas) utiliser les géographies 210 ------------------------------------------ 211 212 Les géographies ont des coordonnées universellement acceptées - chacun peut comprendre que représente la latitue et la longitude, mais peut de personne comprennent ce que les coordonnées UTM signifient. Pourquoi ne pas tout le temps utiliser des géographies ? 213 214 * PremiÚrement, comme indiqué précédemment, il n'y a que quelques fonctions qui supportent ce type de données. Vous risquer de perdre beaucoup de temps à contourner les problÚmes liés à la non-disponibilité de certaines fonctions. 215 * DeuxiÚmement, les calculs sur une sphÚre sont plus consomateurs en ressource que les mêmes calculs dans un systÚme cartésien. Par exemple, la formule de calcul de distance (Pythagore) entraine un seul appÚle à la fonction racine carré (sqrt()). La formule de calcul de distance sphérique (Haversine) utilise deux appÚle à la fonction racine carré, et un appÚle à arctan(), quatre appÚle à sin() et deux à cos(). Les fonctions trigonométriques sont trÚs couteuses, et les calculs sphériques les utilisent massivement. 216 217 Quel conclusion en tirer ? 218 219 Si vos données sont géograhpiquement compact (contenu à l'intérieur d'un état, d'un pays ou d'une ville), utilisez le type ``geometry`` avec une projection cartésienne qui est pertinent pour votre localisation. Consultez le site http://spatialreference.org et tapez le nom de votre région pour visualiser la liste des systÚme de projection applicables dans votre cas. 220 221 Si, d'un autre coté, vous avez besoin de calculer des distances qui est géographiquement éparse (recouvrant la plupart du monde), utiliser le type ``geography``. La compléxité de l'application que vous éviterait en travaillant avec des objets de type ``geography`` dépassera les problÚmes de performances. La conversion de type en géométrie permettra de dépasser les limites des fonctionnalités proposé pour ce type. 222 223 Liste des fonctions 224 ------------------- 225 226 `ST_Distance(geometry, geometry) <http://postgis.org/docs/ST_Distance.html>`_: Pour le type géométrie, renvoit la distance cartésienne, pour les géographies la distance sphérique en métres. 227 228 `ST_GeographyFromText(text) <http://postgis.org/docs/ST_GeographyFromText.html>`_: Retourne la valeur géographique à partir d'une représentation en WKT ou EWKT. 229 230 `ST_Transform(geometry, srid) <http://postgis.org/docs/ST_Transform.html>`_: Retourne une nouvelle géométrie avec ses coordonnées reprojetées dans le systÚme de référence spatial référencé par le SRID fournit. 231 232 `ST_X(point) <http://postgis.org/docs/ST_X.html>`_: Retourne la coordonnée X d'un point, ou NULL si non disponible. La valeur passée doit être un point. 234 233 235 234 236 235 .. rubric:: Footnotes 237 236 238 .. [#Casting_note] The buffer and intersection functions are actually wrappers on top of a cast to geometry, and are not carried out natively in spherical coordinates. As a result, they may fail to return correct results for objects with very large extents that cannot be cleanly converted to a planar representation.239 240 For example, the :command:`ST_Buffer(geography,distance)` function transforms the geography object into a "best" projection, buffers it, and then transforms it back to geographics. If there is no "best" projection (the object is too large), the operation can fail or return a malformed buffer.241 237 .. [#Casting_note] Les fonctions buffer et intersection sont actuellement construite sur le principe de conversion de type en géométries, et ne sont pas actuellement capable de gérer des coordonnées sphariques. Il en résulte qu'elles peuvent ne pas parvenir à retourner un résultat correcte pour des objets ayant une grande étendue qui ne peut être représenté correctement avec une représentation planaire. 238 239 Par exemple, la fonction :command:`ST_Buffer(geography,distance)` transforme les objets géographiques dans la "meilleure" projection, crée la zone tampon, puis les transforme à nouveau en des géographies. S'il n'y a pas de "meilleure" projection (l'objet est trop vaste), l'opération peut ne pas réussir à retourner une valeur correct ou retourner une one tampon mal formée. 240
Note: See TracChangeset
for help on using the changeset viewer.