Reputation: 1392
Using SAP HANA Spatial, how do I query for all the points contained within a circle? Ideally, I would like to specify the latitude and longitude of the center, as well as the radius.
For instance, select all landmarks around 'Berlin - Alexanderplatz' (52.5219184 13.4132147) in a radius of 10 kilometers.
PS. To try it out:
Create a database table: Click the button Open SQL Console (Command-Alt-C), enter the following SQL code and click the Run (F8) button.
CREATE COLUMN TABLE "COORDINATES" ("LOCATION_NAME" VARCHAR(100), "COORDINATE" ST_POINT(0) CS_POINT);
INSERT INTO "COORDINATES" VALUES ('Berlin - Brandenburger Tor', NEW ST_Point('POINT(52.5162746 13.377704)'));
INSERT INTO "COORDINATES" VALUES ('Berlin - Gendarmenmarkt', NEW ST_Point('POINT(52.5137224 13.3926698)'));
INSERT INTO "COORDINATES" VALUES ('Paris - Tour Eiffel', NEW ST_Point('POINT(48.8583701 2.2944813)'));
To query by rectangle, fire the following statement.
SELECT LOCATION_NAME, COORDINATE.ST_ASGEOJSON() FROM COORDINATES WHERE (NEW ST_Polygon('Polygon((52 13, 52 14, 53 14, 53 13, 52 13))').ST_Contains(COORDINATE)) = 1;
Upvotes: 0
Views: 550
Reputation: 10396
Wouldn't that be the case that the distance between your circle center point and your objects need to be smaller than the radius? Something like
SELECT LOCATION_NAME, COORDINATE.ST_ASGEOJSON()
FROM COORDINATES
WHERE
COORDINATE.ST_Distance( NEW ST_Point('POINT(52.5162746 13.377704)')) <= 2;
Here I just put the coordinates for the Brandenburger Tor and the radius of 2 - but you should get the picture.
Upvotes: 0