From 25b3e5e2ec820520d51bdc5d1e8dc65666882240 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Tue, 10 May 2016 14:24:21 -0400 Subject: [PATCH 1/5] update tests to account for json responses with different key orders and numeric precision --- .../41_observatory_augmentation_test.out | 38 ++++++------ .../sql/41_observatory_augmentation_test.sql | 60 ++++++++++++------- 2 files changed, 59 insertions(+), 39 deletions(-) diff --git a/src/pg/test/expected/41_observatory_augmentation_test.out b/src/pg/test/expected/41_observatory_augmentation_test.out index 20a9d09..6ea9f70 100644 --- a/src/pg/test/expected/41_observatory_augmentation_test.out +++ b/src/pg/test/expected/41_observatory_augmentation_test.out @@ -10,8 +10,8 @@ t obs_get_median_income_at_null_island t (1 row) -obs_getpoints_for_test_point -t +obs_getpoints_for_test_point_value|obs_getpoints_for_test_point_name|obs_getpoints_for_test_point_tablename|obs_getpoints_for_test_point_aggregate|obs_getpoints_for_test_point_type|obs_getpoints_for_test_point_description +t|t|t|t|t|t (1 row) obs_getpoints_for_null_island t @@ -34,39 +34,39 @@ t getcategories_at_null_island t (1 row) -obs_getmeasure_total_pop_point -10923.093200390833950 +obs_getmeasure_total_pop_point_test +t (1 row) -obs_getmeasure_total_pop_polygon -12327.3133495107 +obs_getmeasure_total_pop_polygon_test +t (1 row) obs_getmeasure_total_male_point_denominator -0.62157894736842105263 +t (1 row) obs_getmeasure_total_male_poly_denominator -0.49026340444793965457 +t (1 row) obs_getcategory_point -Wealthy, urban without Kids +t (1 row) obs_getcategory_polygon -Low income, mix of minorities +t (1 row) obs_getpopulation -10923.093200390833950 +t (1 row) -obs_getpopulation_polygon -12327.3133495107 +obs_getpopulation_polygon_test +t (1 row) obs_getuscensusmeasure_point_male_pop -6789.5647735060920500 +t (1 row) obs_getuscensusmeasure -6043.63061042765 +t (1 row) -obs_getuscensuscategory -Wealthy, urban without Kids +obs_getuscensuscategory_point +t (1 row) -obs_getuscensuscategory -Low income, mix of minorities +obs_getuscensuscategory_polygon +t (1 row) diff --git a/src/pg/test/sql/41_observatory_augmentation_test.sql b/src/pg/test/sql/41_observatory_augmentation_test.sql index 7ea52c9..a2371a6 100644 --- a/src/pg/test/sql/41_observatory_augmentation_test.sql +++ b/src/pg/test/sql/41_observatory_augmentation_test.sql @@ -43,13 +43,30 @@ WITH result as ( -- -------------------- -- {4809.33511352425} +-- SELECT +-- (cdb_observatory._OBS_GetPoints( +-- cdb_observatory._TestPoint(), +-- 'obs_c6fb99c47d61289fbb8e561ff7773799d3fcc308'::text, -- block groups (see _obs_geomtable) +-- (Array['{"colname":"total_pop","tablename":"obs_1a098da56badf5f32e336002b0a81708c40d29cd","aggregate":"sum","name":"Total Population","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'::json]) +-- ))[1]::text = '{"value":10923.093200390833950,"name":"Total Population","tablename":"obs_1a098da56badf5f32e336002b0a81708c40d29cd","aggregate":"sum","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}' +-- as OBS_GetPoints_for_test_point; +WITH cte As ( SELECT (cdb_observatory._OBS_GetPoints( cdb_observatory._TestPoint(), 'obs_c6fb99c47d61289fbb8e561ff7773799d3fcc308'::text, -- block groups (see _obs_geomtable) (Array['{"colname":"total_pop","tablename":"obs_1a098da56badf5f32e336002b0a81708c40d29cd","aggregate":"sum","name":"Total Population","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}'::json]) - ))[1]::text = '{"value":10923.093200390833950,"name":"Total Population","tablename":"obs_1a098da56badf5f32e336002b0a81708c40d29cd","aggregate":"sum","type":"Numeric","description":"The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates."}' - as OBS_GetPoints_for_test_point; + ))[1] + as OBS_GetPoints_for_test_point) +SELECT + (abs((OBS_GetPoints_for_test_point ->> 'value')::numeric - 10923.093200390833950) / 10923.093200390833950) < 0.001 As OBS_GetPoints_for_test_point_value, + (OBS_GetPoints_for_test_point ->> 'name') = 'Total Population' As OBS_GetPoints_for_test_point_name, + (OBS_GetPoints_for_test_point ->> 'tablename') = 'obs_1a098da56badf5f32e336002b0a81708c40d29cd' As OBS_GetPoints_for_test_point_tablename, + (OBS_GetPoints_for_test_point ->> 'aggregate') = 'sum' As OBS_GetPoints_for_test_point_aggregate, + (OBS_GetPoints_for_test_point ->> 'type') = 'Numeric' As OBS_GetPoints_for_test_point_type, + (OBS_GetPoints_for_test_point ->> 'description') = 'The total number of all people living in a given geographic area. This is a very useful catch-all denominator when calculating rates.' As OBS_GetPoints_for_test_point_description +FROM cte; + -- what happens at null island SELECT @@ -117,64 +134,67 @@ WITH result as ( from result; -- Point-based OBS_GetMeasure, default normalization (area) -SELECT * FROM +-- is result within 0.1% of expected +SELECT abs(OBS_GetMeasure_total_pop_point - 10923.093200390833950) / 10923.093200390833950 < 0.001 As OBS_GetMeasure_total_pop_point_test FROM cdb_observatory.OBS_GetMeasure( cdb_observatory._TestPoint(), 'us.census.acs.B01001001' ) As t(OBS_GetMeasure_total_pop_point); -- Poly-based OBS_GetMeasure, default normalization (none) -SELECT * FROM +-- is result within 0.1% of expected +SELECT abs(OBS_GetMeasure_total_pop_polygon - 12327.3133495107) / 12327.3133495107 < 0.001 As OBS_GetMeasure_total_pop_polygon_test FROM cdb_observatory.OBS_GetMeasure( cdb_observatory._TestArea(), 'us.census.acs.B01001001' ) As t(OBS_GetMeasure_total_pop_polygon); -- Point-based OBS_GetMeasure with denominator normalization -SELECT cdb_observatory.OBS_GetMeasure( +SELECT (abs(cdb_observatory.OBS_GetMeasure( cdb_observatory._TestPoint(), - 'us.census.acs.B01001002', 'denominator') As OBS_GetMeasure_total_male_point_denominator; + 'us.census.acs.B01001002', 'denominator') - 0.62157894736842105263) / 0.62157894736842105263) < 0.001 As OBS_GetMeasure_total_male_point_denominator; -- Poly-based OBS_GetMeasure with denominator normalization -SELECT cdb_observatory.OBS_GetMeasure( +SELECT abs(cdb_observatory.OBS_GetMeasure( cdb_observatory._TestArea(), - 'us.census.acs.B01001002', 'denominator') As OBS_GetMeasure_total_male_poly_denominator; + 'us.census.acs.B01001002', 'denominator') - 0.49026340444793965457) / 0.49026340444793965457 < 0.001 As OBS_GetMeasure_total_male_poly_denominator; -- Point-based OBS_GetCategory SELECT cdb_observatory.OBS_GetCategory( - cdb_observatory._TestPoint(), 'us.census.spielman_singleton_segments.X10') As OBS_GetCategory_point; + cdb_observatory._TestPoint(), 'us.census.spielman_singleton_segments.X10') = 'Wealthy, urban without Kids' As OBS_GetCategory_point; -- Poly-based OBS_GetCategory SELECT cdb_observatory.OBS_GetCategory( - cdb_observatory._TestArea(), 'us.census.spielman_singleton_segments.X10') As obs_getcategory_polygon; + cdb_observatory._TestArea(), 'us.census.spielman_singleton_segments.X10') = 'Low income, mix of minorities' As obs_getcategory_polygon; -- Point-based OBS_GetPopulation, default normalization (area) -SELECT * FROM +SELECT (abs(OBS_GetPopulation - 10923.093200390833950) / 10923.093200390833950) < 0.001 As OBS_GetPopulation FROM cdb_observatory.OBS_GetPopulation( cdb_observatory._TestPoint() - ); + ) As m(OBS_GetPopulation); -- Poly-based OBS_GetPopulation, default normalization (none) -SELECT * FROM +SELECT (abs(obs_getpopulation_polygon - 12327.3133495107) / 12327.3133495107) < 0.001 As obs_getpopulation_polygon_test +FROM cdb_observatory.OBS_GetPopulation( cdb_observatory._TestArea() - ) As obs_getpopulation_polygon; + ) As m(obs_getpopulation_polygon); -- Point-based OBS_GetUSCensusMeasure, default normalization (area) -SELECT cdb_observatory.obs_getuscensusmeasure( - cdb_observatory._testpoint(), 'male population') As obs_getuscensusmeasure_point_male_pop; +SELECT (abs(cdb_observatory.obs_getuscensusmeasure( + cdb_observatory._testpoint(), 'male population') - 6789.5647735060920500) / 6789.5647735060920500) < 0.001 As obs_getuscensusmeasure_point_male_pop; -- Poly-based OBS_GetUSCensusMeasure, default normalization (none) -SELECT cdb_observatory.obs_getuscensusmeasure( - cdb_observatory._testarea(), 'male population'); +SELECT (abs(cdb_observatory.obs_getuscensusmeasure( + cdb_observatory._testarea(), 'male population') - 6043.63061042765) / 6043.63061042765) < 0.001 As obs_getuscensusmeasure; -- Point-based OBS_GetUSCensusCategory SELECT cdb_observatory.OBS_GetUSCensusCategory( - cdb_observatory._testpoint(), 'Spielman-Singleton Segments: 10 Clusters'); + cdb_observatory._testpoint(), 'Spielman-Singleton Segments: 10 Clusters') = 'Wealthy, urban without Kids' As OBS_GetUSCensusCategory_point; -- Area-based OBS_GetUSCensusCategory SELECT cdb_observatory.OBS_GetUSCensusCategory( - cdb_observatory._testarea(), 'Spielman-Singleton Segments: 10 Clusters'); + cdb_observatory._testarea(), 'Spielman-Singleton Segments: 10 Clusters') = 'Low income, mix of minorities' As OBS_GetUSCensusCategory_polygon; \i test/fixtures/drop_fixtures.sql From dfbdb3c9ad0d561eb63e949e3e1af043b9aec994 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Tue, 10 May 2016 15:09:07 -0400 Subject: [PATCH 2/5] updating geometry types to (geometry/point, 4326) where appropriate --- src/pg/sql/40_observatory_utility.sql | 6 +-- src/pg/sql/41_observatory_augmentation.sql | 50 +++++++++++----------- src/pg/sql/42_observatory_exploration.sql | 2 +- src/pg/sql/44_observatory_geometries.sql | 4 +- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/pg/sql/40_observatory_utility.sql b/src/pg/sql/40_observatory_utility.sql index 03164e5..38ba4a6 100644 --- a/src/pg/sql/40_observatory_utility.sql +++ b/src/pg/sql/40_observatory_utility.sql @@ -4,7 +4,7 @@ -- table where there is multiple sources for a column from multiple -- geometries. CREATE OR REPLACE FUNCTION cdb_observatory._OBS_GeomTable( - geom geometry, + geom geometry(Geometry, 4326), geometry_id text, time_span text DEFAULT NULL ) @@ -84,7 +84,7 @@ $$ LANGUAGE plpgsql; --Test point cause Stuart always seems to make random points in the water CREATE OR REPLACE FUNCTION cdb_observatory._TestPoint() - RETURNS geometry + RETURNS geometry(Point, 4326) AS $$ BEGIN -- new york city @@ -95,7 +95,7 @@ $$ LANGUAGE plpgsql; --Test polygon cause Stuart always seems to make random points in the water -- TODO: remove as it's not used anywhere? CREATE OR REPLACE FUNCTION cdb_observatory._TestArea() - RETURNS geometry + RETURNS geometry(Geometry, 4326) AS $$ BEGIN -- Buffer NYC point by 500 meters diff --git a/src/pg/sql/41_observatory_augmentation.sql b/src/pg/sql/41_observatory_augmentation.sql index 655da6a..d6b43a1 100644 --- a/src/pg/sql/41_observatory_augmentation.sql +++ b/src/pg/sql/41_observatory_augmentation.sql @@ -22,7 +22,7 @@ -- Creates a table of demographic snapshot -CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetDemographicSnapshot(geom geometry, +CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetDemographicSnapshot(geom geometry(Geometry, 4326), time_span text DEFAULT NULL, boundary_id text DEFAULT NULL) RETURNS SETOF JSON @@ -140,7 +140,7 @@ $$ LANGUAGE plpgsql; -- Base augmentation fucntion. CREATE OR REPLACE FUNCTION cdb_observatory._OBS_Get( - geom geometry, + geom geometry(Geometry, 4326), column_ids text[], time_span text, geometry_level text @@ -163,26 +163,24 @@ BEGIN RETURN QUERY SELECT '{}'::text[], '{}'::NUMERIC[]; END IF; - execute' - select array_agg( _obs_getcolumndata) from cdb_observatory._OBS_GetColumnData($1, - $2, - $3);' - INTO data_table_info - using geometry_level, column_ids, time_span; + EXECUTE + 'SELECT array_agg(_obs_getcolumndata) + FROM cdb_observatory._OBS_GetColumnData($1, $2, $3);' + INTO data_table_info + USING geometry_level, column_ids, time_span; IF ST_GeometryType(geom) = 'ST_Point' THEN RAISE NOTICE 'geom_table_name %, data_table_info %', geom_table_name, data_table_info::json[]; results := cdb_observatory._OBS_GetPoints(geom, - geom_table_name, - data_table_info); + geom_table_name, + data_table_info); ELSIF ST_GeometryType(geom) IN ('ST_Polygon', 'ST_MultiPolygon') THEN - -- RAISE EXCEPTION 'polygons not supported for now'; results := cdb_observatory._OBS_GetPolygons(geom, - geom_table_name, - data_table_info); + geom_table_name, + data_table_info); END IF; RETURN QUERY @@ -199,7 +197,7 @@ $$ LANGUAGE plpgsql; -- If the variable of interest is just a rate return it as such, -- otherwise normalize it to the census block area and return that CREATE OR REPLACE FUNCTION cdb_observatory._OBS_GetPoints( - geom geometry, + geom geometry(Geometry, 4326), geom_table_name text, data_table_info json[] ) @@ -208,17 +206,17 @@ AS $$ DECLARE result NUMERIC[]; json_result json[]; - query text; + query text; i int; geoid text; - area NUMERIC; + area NUMERIC; BEGIN -- TODO: does 'geoid' need to be generalized to geom_ref?? EXECUTE format('SELECT geoid FROM observatory.%I - WHERE ST_WITHIN($1, the_geom)', + WHERE ST_Within($1, the_geom)', geom_table_name) USING geom INTO geoid; @@ -283,7 +281,7 @@ BEGIN meta->>'name' As name, meta->>'tablename' As tablename, meta->>'aggregate' As aggregate, - meta->>'type' As type, + meta->>'type' As type, meta->>'description' As description FROM (SELECT unnest($1) As values, unnest($2) As meta) b ) t @@ -297,7 +295,7 @@ $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetMeasure( - geom GEOMETRY, + geom geometry(Geometry, 4326), measure_id TEXT, normalize TEXT DEFAULT 'area', -- TODO none/null boundary_id TEXT DEFAULT NULL, @@ -352,7 +350,7 @@ $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetCategory( - geom GEOMETRY, + geom geometry(Geometry, 4326), category_id TEXT, boundary_id TEXT DEFAULT NULL, time_span TEXT DEFAULT NULL @@ -386,7 +384,7 @@ END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetUSCensusMeasure( - geom GEOMETRY, + geom geometry(Geometry, 4326), name TEXT, normalize TEXT DEFAULT 'area', boundary_id TEXT DEFAULT NULL, @@ -419,7 +417,7 @@ END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetUSCensusCategory( - geom GEOMETRY, + geom geometry(Geometry, 4326), name TEXT, boundary_id TEXT DEFAULT NULL, time_span TEXT DEFAULT NULL @@ -453,7 +451,7 @@ END; $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetPopulation( - geom geometry, + geom geometry(Geometry, 4326), normalize TEXT DEFAULT 'area', boundary_id TEXT DEFAULT NULL, time_span TEXT DEFAULT NULL @@ -478,7 +476,7 @@ $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION cdb_observatory._OBS_GetPolygons( - geom geometry, + geom geometry(Geometry, 4326), geom_table_name text, data_table_info json[] ) @@ -558,7 +556,7 @@ $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetSegmentSnapshot( - geom geometry, + geom geometry(Geometry, 4326), boundary_id text DEFAULT NULL ) RETURNS JSON @@ -666,7 +664,7 @@ $$ LANGUAGE plpgsql; --Get categorical variables from point CREATE OR REPLACE FUNCTION cdb_observatory._OBS_GetCategories( - geom geometry, + geom geometry(Geometry, 4326), dimension_names text[], boundary_id text DEFAULT NULL, time_span text DEFAULT NULL diff --git a/src/pg/sql/42_observatory_exploration.sql b/src/pg/sql/42_observatory_exploration.sql index 3c2a8c8..1b25419 100644 --- a/src/pg/sql/42_observatory_exploration.sql +++ b/src/pg/sql/42_observatory_exploration.sql @@ -82,7 +82,7 @@ $$ LANGUAGE plpgsql; -- TODO add test response CREATE OR REPLACE FUNCTION OBS_GetAvailableBoundaries( - geom geometry, + geom geometry(Geometry, 4326), timespan text DEFAULT null) RETURNS TABLE(boundary_id text, description text, time_span text, tablename text) as $$ DECLARE diff --git a/src/pg/sql/44_observatory_geometries.sql b/src/pg/sql/44_observatory_geometries.sql index cccbcd6..1546fff 100644 --- a/src/pg/sql/44_observatory_geometries.sql +++ b/src/pg/sql/44_observatory_geometries.sql @@ -22,7 +22,7 @@ -- CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetBoundary( - geom geometry(Geometry, 4326), + geom geometry(Point, 4326), boundary_id text, time_span text DEFAULT NULL) RETURNS geometry(Geometry, 4326) @@ -104,7 +104,7 @@ $$ LANGUAGE plpgsql; -- CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetBoundaryId( - geom geometry(Geometry, 4326), + geom geometry(Point, 4326), boundary_id text, time_span text DEFAULT NULL ) From f9394129d93e069b941039c59b311e4f691b9079 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Tue, 10 May 2016 15:21:58 -0400 Subject: [PATCH 3/5] add missing schema to function --- src/pg/sql/42_observatory_exploration.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pg/sql/42_observatory_exploration.sql b/src/pg/sql/42_observatory_exploration.sql index 1b25419..338298e 100644 --- a/src/pg/sql/42_observatory_exploration.sql +++ b/src/pg/sql/42_observatory_exploration.sql @@ -81,7 +81,7 @@ $$ LANGUAGE plpgsql; -------------------------------------------------------------------------------- -- TODO add test response -CREATE OR REPLACE FUNCTION OBS_GetAvailableBoundaries( +CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetAvailableBoundaries( geom geometry(Geometry, 4326), timespan text DEFAULT null) RETURNS TABLE(boundary_id text, description text, time_span text, tablename text) as $$ From 7c655dcaa6dbda0fd2a982bb08008df7c298fb62 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Tue, 10 May 2016 15:44:58 -0400 Subject: [PATCH 4/5] converting to point geoms --- src/pg/sql/44_observatory_geometries.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pg/sql/44_observatory_geometries.sql b/src/pg/sql/44_observatory_geometries.sql index 1546fff..27459a6 100644 --- a/src/pg/sql/44_observatory_geometries.sql +++ b/src/pg/sql/44_observatory_geometries.sql @@ -344,7 +344,7 @@ $$ LANGUAGE plpgsql; -- -- TODO: move to ST_DWithin instead of buffer + intersects? CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetBoundariesByPointAndRadius( - geom geometry(Geometry, 4326), -- point + geom geometry(Point, 4326), -- point radius numeric, -- radius in meters boundary_id text, time_span text DEFAULT NULL, @@ -485,7 +485,7 @@ $$ LANGUAGE plpgsql; -- CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetPointsByPointAndRadius( - geom geometry(Geometry, 4326), -- point + geom geometry(Point, 4326), -- point radius numeric, -- radius in meters boundary_id text, time_span text DEFAULT NULL, From 3839261d892beb73236d98f60db6f6c27d849ed7 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Tue, 10 May 2016 15:54:27 -0400 Subject: [PATCH 5/5] add all default args to function descriptions, fix return types --- doc/methods.md | 182 ++++++++++++++++++++++++++++--------------------- 1 file changed, 105 insertions(+), 77 deletions(-) diff --git a/doc/methods.md b/doc/methods.md index acc124c..5a18a87 100644 --- a/doc/methods.md +++ b/doc/methods.md @@ -14,7 +14,9 @@ Name |Description --- | --- point_geometry | a WGS84 point geometry (the_geom) measure_name | a human readable string name of a US Census variable. The glossary of measure_names is [available below]('measure_name table'). -normalize | for measures that are are **sums** (e.g. population) the default normalization is 'area' and response comes back as a rate per square kilometer. Other options are 'denominator', which will use the denominator specified in the +normalize | for measures that are are **sums** (e.g., population) the default normalization is 'area' and response comes back as a rate per square kilometer. Other options are 'denominator', which will use the denominator specified in the [Data Catalog](http://cartodb.github.io/bigmetadata/index.html) (optional) +boundary_id | source of geometries to pull measure from (e.g., 'us.census.tiger.census_tract') +time_span | time span of interest (e.g., 2010 - 2014) #### Returns @@ -29,7 +31,8 @@ value | the raw or normalized measure Add a Measure to an empty column based on point locations in your table ```SQL -UPDATE tablename SET local_male_population = OBS_GetUSCensusMeasure(the_geom, 'Male Population') +UPDATE tablename +SET local_male_population = OBS_GetUSCensusMeasure(the_geom, 'Male Population') ``` Get a measure at a single point location @@ -54,6 +57,8 @@ Name |Description point_geometry | a WGS84 polygon geometry (the_geom) measure_name | a human readable string name of a US Census variable. The glossary of measure_names is [available below]('measure_name table'). normalize | for measures that are are **sums** (e.g. population) the default normalization is 'none' and response comes back as a raw value. Other options are 'denominator', which will use the denominator specified in the [Data Catalog](http://cartodb.github.io/bigmetadata/index.html) (optional) +boundary_id | source of geometries to pull measure from (e.g., 'us.census.tiger.census_tract') +time_span | time span of interest (e.g., 2010 - 2014) #### Returns @@ -68,13 +73,18 @@ value | the raw or normalized measure Add a Measure to an empty column based on polygons in your table ```SQL -UPDATE tablename SET local_male_population = OBS_GetUSCensusMeasure(the_geom, 'Male Population') +UPDATE tablename +SET local_male_population = OBS_GetUSCensusMeasure(the_geom, 'Male Population') ``` Get a measure at a single polygon ```SQL -SELECT OBS_GetMeasure(ST_Buffer(CDB_LatLng(40.7, -73.9),0.001), 'Male Population') +SELECT OBS_GetMeasure( + ST_Buffer( + CDB_LatLng(40.7, -73.9)::geography, + 1000)::geometry, + 'Male Population') ```