![]() ![]() 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.įor example, the ST_Buffer(geography,distance) function transforms the geography object into a “best” projection, buffers it, and then transforms it back to geographics. The buffer and intersection functions are actually wrappers on top of a cast to geometry, and are not carried out natively in spherical coordinates. ST_DWithin(geography_A, geography_B, R): Returns true if A is within R meters of B. ST_Azimuth(geography_A, geography_B): Returns the direction from A to B in radians. ST_X(point): Returns the X coordinate of the point, or NULL if not available. ST_Transform(geometry, srid): Returns a new geometry with its coordinates transformed to the SRID referenced by the integer parameter. ST_GeographyFromText(text): Returns a specified geography value from Well-Known Text representation or extended (WKT). For geography type defaults to return spheroidal minimum distance between two geographies in meters. ST_Distance(geometry, geometry): For geometry type Returns the 2-dimensional Cartesian minimum distance (based on spatial ref) between two geometries in projected units. ![]() And casting to geometry can offset most functionality limitations. The application complexity you save by working in geography will offset any performance issues. If you need to measure distance with a dataset that is geographically dispersed (covering much of the world), use the geography type. See the site and type in the name of your region for a selection of possible reference systems. 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. Trigonometric functions are very costly, and spherical calculations involve a lot of them. The spherical formula for distance (Haversine) involves two sqrt() calls, an arctan() call, four sin() calls and two cos() calls. ![]() For example, the Cartesian formula for distance (Pythagoras) involves one call to sqrt(). Second, the calculations on a sphere are computationally far more expensive than Cartesian calculations. You may spend a lot of time working around geography type limitations. Why not use geography all the time?įirst, as noted earlier, there are far fewer functions available (right now) that directly support the geography type. ![]() Geographics are universally accepted coordinates – everyone understands what latitude/longitude mean, but very few people understand what UTM coordinates mean. ST_Intersection(geography, geography) returns geography 1 ST_Buffer(geography, float8) returns geography 1 ST_Intersects(geography, geography) returns boolean ST_CoveredBy(geography, geography) returns boolean ST_Covers(geography, geography) returns boolean ST_DWithin(geography, geography, float8) returns boolean ST_Distance(geography, geography) returns double ST_GeographyFromText(text) returns geography There are only a small number of native functions for the geography type: Here’s a query to find all the subway stations within 500 meters of the Empire State Building. 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. Note that the SRID of 4326 declares a geographic spatial reference system.ĬREATE INDEX nyc_subway_stations_geog_gix ON nyc_subway_stations_geog USING GIST ( geog ) The following calculates the distance between Los Angeles and Paris using the standard PostGIS Cartesian ST_Distance(geometry, geometry). The distance between points get larger as problem areas like the poles or the international dateline are approached.įor example, here are the coordinates of Los Angeles and Paris. 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. However, measurements of distance, length and area will be nonsensical. You can treat geographic coordinates as approximate Cartesian coordinates and continue to do spatial calculations. In spherical coordinates a point is specified by the angle of rotation from a reference meridian (longitude), and the angle from the equator (latitude). Rather, these spherical coordinates describe angular coordinates on a globe. Geographic coordinates do not represent a linear distance from an origin as plotted on a plane. Unlike coordinates in Mercator, UTM, or Stateplane, geographic coordinates are not Cartesian coordinates. It is very common to have data in which the coordinate are “geographics” or “latitude/longitude”. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |