simplifying raster experiments
This commit is contained in:
@@ -412,6 +412,12 @@ BEGIN
|
|||||||
END
|
END
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
--create table observatory.obs_column_table_tile_simple as select table_id, column_id, tile_id, st_band(tile, 2) as tile from observatory.obs_column_table_tile ;
|
||||||
|
|
||||||
|
--create table observatory.obs_column_table_tile_simpler as select table_id,
|
||||||
|
--column_id, tile_id, st_reclass(tile, '0-65536:0-65536', '16BUI') as tile
|
||||||
|
--from observatory.obs_column_table_tile_simple ;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_observatory._OBS_GetGeometryScores(
|
CREATE OR REPLACE FUNCTION cdb_observatory._OBS_GetGeometryScores(
|
||||||
bounds Geometry(Geometry, 4326) DEFAULT NULL,
|
bounds Geometry(Geometry, 4326) DEFAULT NULL,
|
||||||
filter_geom_ids TEXT[] DEFAULT NULL,
|
filter_geom_ids TEXT[] DEFAULT NULL,
|
||||||
@@ -439,16 +445,19 @@ BEGIN
|
|||||||
FROM (
|
FROM (
|
||||||
WITH clipped_geom AS (
|
WITH clipped_geom AS (
|
||||||
SELECT column_id, table_id
|
SELECT column_id, table_id
|
||||||
, CASE WHEN $1 IS NOT NULL THEN ST_Clip(tile, $1, True)
|
, CASE WHEN $1 IS NOT NULL THEN ST_Clip(tile, 1, $1, True)
|
||||||
ELSE tile END clipped_tile
|
ELSE tile END clipped_tile
|
||||||
|
--, tile as clipped_tile
|
||||||
, tile
|
, tile
|
||||||
FROM observatory.obs_column_table_tile
|
FROM observatory.obs_column_table_tile_simpler
|
||||||
WHERE ($1 IS NULL OR ST_Intersects($1, tile))
|
WHERE ($1 IS NULL OR ST_Intersects($1, tile))
|
||||||
AND (column_id = ANY($2) OR cardinality($2) = 0)
|
AND (column_id = ANY($2) OR cardinality($2) = 0)
|
||||||
), clipped_geom_countagg AS (
|
), clipped_geom_countagg AS (
|
||||||
SELECT column_id, table_id
|
SELECT column_id, table_id
|
||||||
, ST_CountAgg(clipped_tile, 2, True)::Numeric notnull_pixels
|
--, 10 notnull_pixels
|
||||||
, ST_CountAgg(clipped_tile, 2, False)::Numeric pixels
|
--, 10 pixels
|
||||||
|
, ST_CountAgg(clipped_tile, 1, True)::Numeric notnull_pixels
|
||||||
|
, ST_CountAgg(clipped_tile, 1, False)::Numeric pixels
|
||||||
FROM clipped_geom
|
FROM clipped_geom
|
||||||
GROUP BY column_id, table_id
|
GROUP BY column_id, table_id
|
||||||
) SELECT
|
) SELECT
|
||||||
@@ -457,23 +466,29 @@ BEGIN
|
|||||||
THEN cdb_observatory.FIRST(notnull_pixels) / cdb_observatory.FIRST(pixels)
|
THEN cdb_observatory.FIRST(notnull_pixels) / cdb_observatory.FIRST(pixels)
|
||||||
ELSE 1
|
ELSE 1
|
||||||
END)::Numeric AS notnull_percent
|
END)::Numeric AS notnull_percent
|
||||||
|
--, null::numeric as notnull_percent
|
||||||
|
|
||||||
|
--, 10::numeric as numgeoms
|
||||||
, (CASE WHEN cdb_observatory.FIRST(notnull_pixels) > 0
|
, (CASE WHEN cdb_observatory.FIRST(notnull_pixels) > 0
|
||||||
THEN (ST_SummaryStatsAgg(clipped_tile, 2, True)).sum
|
THEN (ST_SummaryStatsAgg(clipped_tile, 1, True)).sum
|
||||||
ELSE COALESCE(ST_Value(cdb_observatory.FIRST(tile), 2, ST_PointOnSurface($1)), 0) * (ST_Area($1) / ST_Area(ST_PixelAsPolygon(cdb_observatory.FIRST(tile), 0, 0)) * cdb_observatory.FIRST(pixels))
|
ELSE COALESCE(ST_Value(cdb_observatory.FIRST(tile), 1, ST_PointOnSurface($1)), 0) * (ST_Area($1) / ST_Area(ST_PixelAsPolygon(cdb_observatory.FIRST(tile), 0, 0)) * cdb_observatory.FIRST(pixels))
|
||||||
END)::Numeric AS numgeoms
|
END)::Numeric AS numgeoms
|
||||||
, (CASE WHEN cdb_observatory.FIRST(notnull_pixels) > 0
|
|
||||||
THEN (ST_SummaryStatsAgg(clipped_tile, 3, True)).mean
|
, null::numeric as percentfill
|
||||||
ELSE COALESCE(ST_Value(cdb_observatory.FIRST(tile), 3, ST_PointOnSurface($1)), 0)
|
--, (CASE WHEN cdb_observatory.FIRST(notnull_pixels) > 0
|
||||||
END)::Numeric AS percentfill
|
-- THEN (ST_SummaryStatsAgg(clipped_tile, 3, True)).mean
|
||||||
, ((ST_Area(ST_Transform($1, 3857)) / 1000000) / NullIf(
|
-- ELSE COALESCE(ST_Value(cdb_observatory.FIRST(tile), 3, ST_PointOnSurface($1)), 0)
|
||||||
CASE WHEN cdb_observatory.FIRST(notnull_pixels) > 0
|
-- END)::Numeric AS percentfill
|
||||||
THEN (ST_SummaryStatsAgg(clipped_tile, 1, True)).mean
|
, null::numeric estnumgeoms, null::numeric meanmediansize
|
||||||
ELSE Coalesce(ST_Value(cdb_observatory.FIRST(tile), 1, ST_PointOnSurface($1)), 0)
|
--, ((ST_Area(ST_Transform($1, 3857)) / 1000000) / NullIf(
|
||||||
END, 0))::Numeric AS estnumgeoms
|
-- CASE WHEN cdb_observatory.FIRST(notnull_pixels) > 0
|
||||||
, (CASE WHEN cdb_observatory.FIRST(notnull_pixels) > 0
|
-- THEN (ST_SummaryStatsAgg(clipped_tile, 1, True)).mean
|
||||||
THEN (ST_SummaryStatsAgg(clipped_tile, 1, True)).mean
|
-- ELSE Coalesce(ST_Value(cdb_observatory.FIRST(tile), 1, ST_PointOnSurface($1)), 0)
|
||||||
ELSE COALESCE(ST_Value(cdb_observatory.FIRST(tile), 1, ST_PointOnSurface($1)), 0)
|
-- END, 0))::Numeric AS estnumgeoms
|
||||||
END)::Numeric AS meanmediansize
|
--, (CASE WHEN cdb_observatory.FIRST(notnull_pixels) > 0
|
||||||
|
-- THEN (ST_SummaryStatsAgg(clipped_tile, 1, True)).mean
|
||||||
|
-- ELSE COALESCE(ST_Value(cdb_observatory.FIRST(tile), 1, ST_PointOnSurface($1)), 0)
|
||||||
|
-- END)::Numeric AS meanmediansize
|
||||||
FROM clipped_geom_countagg a, clipped_geom b
|
FROM clipped_geom_countagg a, clipped_geom b
|
||||||
WHERE a.table_id = b.table_id
|
WHERE a.table_id = b.table_id
|
||||||
AND a.column_id = b.column_id
|
AND a.column_id = b.column_id
|
||||||
@@ -483,4 +498,4 @@ BEGIN
|
|||||||
$string$) USING bounds, filter_geom_ids, desired_num_geoms;
|
$string$) USING bounds, filter_geom_ids, desired_num_geoms;
|
||||||
RETURN;
|
RETURN;
|
||||||
END
|
END
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql IMMUTABLE;
|
||||||
|
|||||||
Reference in New Issue
Block a user