diff --git a/doc/discovery_functions.md b/doc/discovery_functions.md index 356ddd3..697a163 100644 --- a/doc/discovery_functions.md +++ b/doc/discovery_functions.md @@ -228,7 +228,7 @@ SELECT * FROM cdb_observatory.OBS_GetAvailableDenominators( WHERE valid_timespan IS True; ``` -## OBS_GetAvailableGeometries(bounds, filter_tags, numer_id, denom_id, timespan) +## OBS_GetAvailableGeometries(bounds, filter_tags, numer_id, denom_id, timespan, number_geometries) Return available geometries within a boundary and with the specified `filter_tags`. @@ -242,6 +242,7 @@ filter_tags | Text[] | a list of filters. Only geometries for which all of thes numer_id | Text | the ID of a numerator to check whether the geometry is valid against. Will not reduce length of returned table, but will change values for `valid_numer` (optional) denom_id | Text | the ID of a denominator to check whether the geometry is valid against. Will not reduce length of returned table, but will change values for `valid_denom` (optional) timespan | Text | the ID of a timespan to check whether the geometry is valid against. Will not reduce length of returned table, but will change values for `valid_timespan` (optional) +number_geometries | Integer | Number of geometries of the source data in order to calculate more accurately the score value to know which geometry fits better with the provided extent. (optional) #### Returns diff --git a/src/pg/observatory.control b/src/pg/observatory.control index 149b6a5..84e7094 100644 --- a/src/pg/observatory.control +++ b/src/pg/observatory.control @@ -1,5 +1,5 @@ comment = 'CartoDB Observatory backend extension' -default_version = '1.7.0' +default_version = '1.8.0' requires = 'postgis' superuser = true schema = cdb_observatory diff --git a/src/pg/sql/42_observatory_exploration.sql b/src/pg/sql/42_observatory_exploration.sql index bbd5e56..272eec2 100644 --- a/src/pg/sql/42_observatory_exploration.sql +++ b/src/pg/sql/42_observatory_exploration.sql @@ -323,7 +323,8 @@ CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetAvailableGeometries( filter_tags TEXT[] DEFAULT NULL, numer_id TEXT DEFAULT NULL, denom_id TEXT DEFAULT NULL, - timespan TEXT DEFAULT NULL + timespan TEXT DEFAULT NULL, + number_geoms INTEGER DEFAULT NULL ) RETURNS TABLE ( geom_id TEXT, geom_name TEXT, @@ -390,15 +391,16 @@ BEGIN FROM observatory.obs_meta_geom o WHERE %s (geom_tags ?& $4 OR CARDINALITY($4) = 0) ), scores AS ( - SELECT * FROM cdb_observatory._OBS_GetGeometryScores($5, - (SELECT ARRAY_AGG(geom_id) FROM available_geoms) + SELECT * FROM cdb_observatory._OBS_GetGeometryScores(bounds => $5, + filter_geom_ids => (SELECT ARRAY_AGG(geom_id) FROM available_geoms), + desired_num_geoms => $6::integer ) ) SELECT DISTINCT ON (geom_id) available_geoms.*, score, numtiles, notnull_percent, numgeoms, percentfill, estnumgeoms, meanmediansize FROM available_geoms, scores WHERE available_geoms.geom_id = scores.column_id $string$, geom_clause) - USING numer_id, denom_id, timespan, filter_tags, bounds; + USING numer_id, denom_id, timespan, filter_tags, bounds, number_geoms; RETURN; END $$ LANGUAGE plpgsql;