I would like to ask what is the difference between geometry and geography using the PostGIS function ST_Azimuth.
When I execute the following query:
SELECT degrees( ST_Azimuth(ST_MakePoint(21.304116745663165, 38.68607570952619), ST_MakePoint(21.286237118117278,38.71455640443629)) )
I get 327.880195438529 degrees.
But when I cast the geometries to geography as the following query :
SELECT degrees( ST_Azimuth(ST_MakePoint(21.304116745663165, 38.68607570952619)::geography, ST_MakePoint(21.286237118117278,38.71455640443629)::geography) )
I get 333.810802282843 degrees.
Does the cast to geography give a more accurate result? Or a different calculation is made?
My geometries have SRID=4326.
Thank you in advance.
It looks to me as if geography gives you the point-point azimuth on the WGS84 Earth (so an approximately spherical surface) while the geometry gives you the point-point azimuth on the plane.
So, yes, a different calculation is made.
Related
What is the difference between the arango function - DISTANCE() and GE0_DISTANCE(). I know both of them calculates distance using haversines formula.
Thanks,
Nilotpal
Both are used for two different purposes
DISTANCE(latitude1, longitude1, latitude2, longitude2) → distance
The value is computed using the haversine formula, which is based on a spherical Earth model. It’s fast to compute and is accurate to around 0.3%, which is sufficient for most use cases such as location-aware services.
GEO_DISTANCE(geoJsonA, geoJsonB, ellipsoid) → distance
Return the distance between two GeoJSON objects, measured from the centroid of each shape. For a list of supported types see the geo index page. (Ref: https://www.arangodb.com/docs/3.8/aql/functions-geo.html#geo-index-functions)
This GeoJSON objects can be anything like GEO_LINESTRING, GEO_MULTILINESTRING, GEO_MULTIPOINT, GEO_POINT, GEO_POLYGON and GEO_MULTIPOLYGON - Reference<2>
Reference:
https://www.arangodb.com/docs/3.8/aql/functions-geo.html#geo-utility-functions
https://www.arangodb.com/docs/3.8/aql/functions-geo.html#geojson-constructors
I've run into a peculiar situation where I am trying to find any geospatial objects that lie (partially) in a polygon. When I apply the ST_Intersect function on two Geometries using the WGS84 SRID the intersection of a polygon and a point clearly North of the polygon returns FALSE as expected:
SELECT ST_Intersects(
ST_GeomFromText('POLYGON((-12 0,12 0,12 50.7,-12 50.7,-12 0))', 4326),
ST_GeomFromText('POINT(6.0 50.9)', 4326)
);
Now when I run this same query, but with two geographies instead of geometries the query returns TRUE:
SELECT ST_Intersects(
ST_GeogFromText('POLYGON((-12 0,12 0,12 50.7,-12 50.7,-12 0))'),
ST_GeogFromText('POINT(6 50.9)')
);
I expect that the geography version uses shortest great circle distance to create the polygon, while the geometry version creates the polygon on a flat plane and only then projects this on the WGS84 ellipse.
Can someone verify or debunk my suspicions?
I am running postgresql 9.6 with PostGis 2.4.4
Operations on geography data type are done over a sphere. Operations on geometry data type are done over a plane.
The shortest line joining two points on a plane is a straight line.
The shortest line joining two points on a sphere is an arc. This arc is called the great circle arc and is build by intersecting the sphere with a plan going through the 2 points and the center of the earth.
Consequently, the arc going through -12;50.7N and +12;50.7N with pass through a point near 0;51.3N. This holds true for lines but also for polygon boundaries.
This doc has some interesting graphics to understand the concepts behind the geography type
I need to check if the distance between two geographic point is less then N km. I'm trying to execute this query:
select st_distance(
ST_GeomFromText('point(45.764043 4.835658999999964)', 4326),
ST_GeomFromText('point(45.750371 5.053963)', 4326)
) < :n
But it doesn't work because:
So far the SRID property is just a dummy in MySQL, it is stored as part of a geometries meta data but all actual calculations ignore it and calculations are done assuming Euclidean (planar) geometry.
(https://mariadb.com/kb/en/mariadb/st_transform-missing/)
My goal is to convert this distance to the metric distance or to convert the N to the degrees.
How I can do it?
Maybe, you know a better solution?
P.S. I need a solution based on the spatial methods (or more better for the performance).
I don't think the "distance" function is available (yet) in SPATIAL. There is a regular FUNCTION in https://mariadb.com/kb/en/latitudelongitude-indexing/ that does the work. However, the args and output are scaled lat/lng (10000*degrees). The code could be altered to avoid the scaling, but it is needed in the context of that blog page.
First let me thank you for taking the time in reading my question.
My plan was to add latitude and longitude records on my persons records in dynamodb and then use a geo library, preferably written in nodejs, for calculating nearby persons in a given radius. So the plan was, for example, return the persons only from this 50 mile radius.
So far, the only geo-libraries i have tried allows me to pass lat and long to it and confirm if it is within the radius given. The problem with this is that I have to loop my whole dynamodb table to get results. Is there a reverse kind of function for this in which I pass a latlong point and radius to the geo library and then the geo library passes me some lat and long boundaries so that I can easily query it to dynamodb(ex. (lat<:latboundary1 AND lat>:latboundary 2) AND (long<:longboundary1 AND long>:longboundary 2) )
This nodejs library provides a function that calculates the bounding box based on a point and a radius. You can use the returned SW and NE points for your query.
.boundingCoordinates(distance, radius, inKilometers): Calculates the bounding coordinates of distance from the point and returns an array with the SW and NE points of the bounding box . If radius is not provided, the radius of the Earth will be used. The distance is calculated in miles unless inKilometers is true
I have a large array of lat/lng points. Could be up to 20k points. I'm plotting them using KML. What I want to do is to take only the outter most points and use them to draw a polygon instead. I already know how to draw a polygon in kml, I just need to figure out how to select only the outer most points of the group.
Any ideas? I'd like to have at least 5 points to the polygon but no more than 25 points total.
So far i've come up with checking for top most and bottom most points (basically crearing a square) using < & > logic.
The points will be in america & canada only if that matters.
Thanks for any help.
EDIT: I've gotten the Convex Hull algorithm to work, but it isnt exactly what I need. I'm trying to map out zip codes. If a zip code has an L shape then the polygon is going to be a triangle shape and not an L shape. Any ideas?
You need to use a Convex Hull algorithm. It's not too hard to implement yourself if it's not available in whatever software package you're using.