Created
June 15, 2014 10:45
-
-
Save iambibhas/351f87bbee00e9d30672 to your computer and use it in GitHub Desktop.
Another way of querying geo data from JSON column
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
explain analyze | |
SELECT tmp_table.tid, | |
tmp_table.screen_name, | |
tmp_table.text | |
FROM | |
(SELECT tid, | |
data->'user'->>'screen_name' AS screen_name, | |
data->>'text' AS text, | |
ST_GeomFromText('POINT(' || CAST(data#>>'{geo,coordinates,1}' as varchar) || ' ' || CAST(data#>>'{geo,coordinates,0}' as varchar) || ')', 4326) AS geom | |
FROM tweet | |
WHERE data->>'geo' <> '') AS tmp_table | |
WHERE ST_Distance( | |
ST_Transform(geom, 26986), | |
ST_Transform(ST_GeomFromText('POINT(77.620176 13.004616)',4326), 26986) | |
) < 50000; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment