How to create geospatial module with AWS lambda and dynamo db - node.js

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

Related

Difference between distance() and geo_distance() in arangodb

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

Google Places API doesn't restrict results to given radius parameter

I'm using this code in NodeJS to retrieve the results:
return googleMaps.places({
language: 'en',
query: keywords,
location: [loc.lat, loc.lng],
radius: 5000
})
As you can see, there's a restriction for 5000 meters max. For some reason I got results from another city which is about 50KM away from that lat, lng (some of the results were in the relevant distance, half were not..)
Any thoughts?
It looks like you're using Google's Place Text Search service. The documentation states:
radius — Defines the distance (in meters) within which to bias place
results. The maximum allowed radius is 50 000 meters. Results inside
of this region will be ranked higher than results outside of the
search circle; however, prominent results from outside of the search
radius may be included.
You may bias results to a specified circle by passing a location and a
radius parameter. This will instruct the Google Places service to
prefer showing results within that circle. Results outside the defined
area may still be displayed. Biasing results to a region or circle is
recommended to improve relevance of results for otherwise ambiguous
queries.
So this appears to be expected behavior from the API. There is no way to fully restrict Text Search results within a given location/radius.
Hope this helps!

Get values from geospatial image

I have a Geoserver which serves WMS layers. I have a requirement where I select a location which has latitude and longitude and corresponding to the latitude and longitude I have to fetch the value from WMS layer. I am not able to find a solution to this requirement. Any help is highly appreciated.
The WMS spec provides a GetFeatureInfo request that allows you to query a point on the map, however it uses image coordinates rather than map coordinates (lat/lon). Provided that your image is reasonably small you should be able to get away with assuming a linear relationship between the two coordinate systems so by using the bounds of the map (which you know from the WMS request bbox param) and the size of the image (also part of the WMS request) you should be able to convert a lat/lon pair to an image coordinate (remember to flip the Y-axis though, as the image origin is top left).

Mariadb: geography

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.

Difference between geometry and geography in ST_Azimuth function of PostGIS

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.

Resources