diff --git a/src/pg/sql/41_observatory_augmentation.sql b/src/pg/sql/41_observatory_augmentation.sql index 11193a8..3dc3512 100644 --- a/src/pg/sql/41_observatory_augmentation.sql +++ b/src/pg/sql/41_observatory_augmentation.sql @@ -439,7 +439,7 @@ BEGIN WHERE ST_Intersects(%L, geom.%I) AND ST_Area(ST_Intersection(%L, geom.%I)) / ST_Area(geom.%I) > 0) SELECT SUM(numer.%I * (SELECT _geom.overlap FROM _geom WHERE _geom.geom_ref = numer.%I)) / - ST_Area(%L::Geography) + (ST_Area(%L::Geography) / 1000000) FROM observatory.%I numer WHERE numer.%I = ANY ((SELECT ARRAY_AGG(geom_ref) FROM _geom)::TEXT[])', geom, geom_colname, geom_colname, diff --git a/src/pg/test/expected/41_observatory_augmentation_test.out b/src/pg/test/expected/41_observatory_augmentation_test.out index c0476a6..c95323c 100644 --- a/src/pg/test/expected/41_observatory_augmentation_test.out +++ b/src/pg/test/expected/41_observatory_augmentation_test.out @@ -42,9 +42,21 @@ t obs_getmeasure_total_pop_point_test t (1 row) +obs_getmeasure_total_pop_point_null_normalization_test +t +(1 row) +obs_getmeasure_total_pop_point_area_test +t +(1 row) obs_getmeasure_total_pop_polygon_test t (1 row) +obs_getmeasure_total_pop_polygon_null_normalization_test +t +(1 row) +obs_getmeasure_total_pop_polygon_area_test +t +(1 row) obs_getmeasure_total_male_point_denominator 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 cf162f4..3b7b2e6 100644 --- a/src/pg/test/sql/41_observatory_augmentation_test.sql +++ b/src/pg/test/sql/41_observatory_augmentation_test.sql @@ -148,6 +148,22 @@ SELECT abs(OBS_GetMeasure_total_pop_point - 10923.093200390833950) / 10923.09320 'us.census.acs.B01003001' ) As t(OBS_GetMeasure_total_pop_point); +-- Point-based OBS_GetMeasure, default normalization by NULL (area) +-- is result within 0.1% of expected +SELECT abs(OBS_GetMeasure_total_pop_point_null_normalization - 10923.093200390833950) / 10923.093200390833950 < 0.001 As OBS_GetMeasure_total_pop_point_null_normalization_test FROM + cdb_observatory.OBS_GetMeasure( + cdb_observatory._TestPoint(), + 'us.census.acs.B01003001', NULL +) As t(OBS_GetMeasure_total_pop_point_null_normalization); + +-- Point-based OBS_GetMeasure, explicit area normalization area +-- is result within 0.1% of expected +SELECT abs(OBS_GetMeasure_total_pop_point_area - 10923.093200390833950) / 10923.093200390833950 < 0.001 As OBS_GetMeasure_total_pop_point_area_test FROM + cdb_observatory.OBS_GetMeasure( + cdb_observatory._TestPoint(), + 'us.census.acs.B01003001', 'area' +) As t(OBS_GetMeasure_total_pop_point_area); + -- Poly-based OBS_GetMeasure, default normalization (none) -- 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 @@ -156,6 +172,22 @@ SELECT abs(OBS_GetMeasure_total_pop_polygon - 12327.3133495107) / 12327.31334951 'us.census.acs.B01003001' ) As t(OBS_GetMeasure_total_pop_polygon); +-- Poly-based OBS_GetMeasure, default normalization by NULL (none) +-- is result within 0.1% of expected +SELECT abs(OBS_GetMeasure_total_pop_polygon_null_normalization - 12327.3133495107) / 12327.3133495107 < 0.001 As OBS_GetMeasure_total_pop_polygon_null_normalization_test FROM + cdb_observatory.OBS_GetMeasure( + cdb_observatory._TestArea(), + 'us.census.acs.B01003001', NULL +) As t(OBS_GetMeasure_total_pop_polygon_null_normalization); + +-- Poly-based OBS_GetMeasure, explicit area normalization +-- is result within 0.1% of expected +SELECT abs(OBS_GetMeasure_total_pop_polygon_area - 15787.4325563538) / 15787.4325563538 < 0.001 As OBS_GetMeasure_total_pop_polygon_area_test FROM + cdb_observatory.OBS_GetMeasure( + cdb_observatory._TestArea(), + 'us.census.acs.B01003001', 'area' +) As t(OBS_GetMeasure_total_pop_polygon_area); + -- Point-based OBS_GetMeasure with denominator normalization SELECT (abs(cdb_observatory.OBS_GetMeasure( cdb_observatory._TestPoint(),