Skip to content

Commit

Permalink
Merge pull request #122 from Vizzuality/fix/postgis_schema
Browse files Browse the repository at this point in the history
[SKY30-176] Moved postgis to public schema and removed data. namespacing
  • Loading branch information
Agnieszka Figiel authored Dec 19, 2023
2 parents b6e7e03 + 21518a8 commit 7943188
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cloud_functions/analysis/src/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ def get_locations_stats(db: sqlalchemy.engine.base.Engine, geojson: JSON) -> dic
with db.connect() as conn:
stmt = sqlalchemy.text(
"""
with user_data as (select data.ST_GeomFromGeoJSON(:geometry) as geom),
user_data_stats as (select *, round((data.st_area(data.st_transform(geom,'+proj=longlat +datum=WGS84 +no_defs +type=crs', '+proj=moll +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +type=crs'))/1e6)) user_area_km2 from user_data)
with user_data as (select ST_GeomFromGeoJSON(:geometry) as geom),
user_data_stats as (select *, round((st_area(st_transform(geom,'+proj=longlat +datum=WGS84 +no_defs +type=crs', '+proj=moll +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +type=crs'))/1e6)) user_area_km2 from user_data)
select area_km2, iso_sov1, iso_sov2, iso_sov3,
round((data.st_area(data.st_transform(data.st_makevalid(data.st_intersection(the_geom, user_data_stats.geom)),'+proj=longlat +datum=WGS84 +no_defs +type=crs', '+proj=moll +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +type=crs'))/1e6)) portion_area_km2,
round((st_area(st_transform(st_makevalid(st_intersection(the_geom, user_data_stats.geom)),'+proj=longlat +datum=WGS84 +no_defs +type=crs', '+proj=moll +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +type=crs'))/1e6)) portion_area_km2,
user_data_stats.user_area_km2
from data.eez_minus_mpa emm, user_data_stats
where data.st_intersects(the_geom, user_data_stats.geom)
from eez_minus_mpa emm, user_data_stats
where st_intersects(the_geom, user_data_stats.geom)
"""
)
data_response = conn.execute(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
async up(knex) {
// create postgis extension in the data schema
await knex.raw('DROP EXTENSION IF EXISTS postgis CASCADE');
await knex.raw('CREATE EXTENSION postgis SCHEMA public');
},
}

0 comments on commit 7943188

Please sign in to comment.