
SELECT * FROM data_collector;


SELECT cartodb_id,description,name,ST_AsText(dc_geom) FROM data_collector;


SELECT cartodb_id,description,name,ST_Distance(ST_Transform(ST_GeomFromText('POINT(830000 812000)', 2326),4326), dc_geom) FROM data_collector;


--
-- Output the result of "SELECT * FROM data_collector;" in GeoJSON format
--
SELECT row_to_json(fc) FROM (SELECT 'FeatureCollection' AS type, array_to_json(array_agg(f)) AS features FROM (SELECT 'Feature' AS type, ST_AsGeoJSON(lg.dc_geom)::json AS geometry, row_to_json((SELECT l FROM (SELECT cartodb_id, description, name) AS l)) AS properties FROM data_collector AS lg) AS f) AS fc;


--
-- The same SQL statement as above but expressed in multi lines for easy readability
--
SELECT row_to_json(fc) FROM (
	SELECT 'FeatureCollection' AS type, array_to_json(array_agg(f)) AS features FROM (
		SELECT 'Feature' AS type,
			ST_AsGeoJSON(lg.dc_geom)::json AS geometry,
			row_to_json((SELECT l FROM (SELECT cartodb_id, description, name) AS l)) AS properties
		FROM data_collector AS lg
	) AS f
) AS fc;
