-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ETL Pipe for download and ingest EEZ [MARXAN-1618] #1121
Draft
aagm
wants to merge
6
commits into
develop
Choose a base branch
from
feature/data/MARXAN-1618_ETL_EEZ
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+111
−3
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d887e89
ETL Pipe for download and ingest EEZ data into the geoprocessingdb
aagm 5d518ef
improved instructions in the master makefile doc
aagm 86d3623
finish pipe
aagm d8dc2ae
Update data/data_download/Makefile
aagm aae5e93
added index and new columns to geoentity
aagm 55a52be
Merge branch 'feature/data/MARXAN-1618_ETL_EEZ' of github.com:Vizzual…
aagm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
api/apps/geoprocessing/src/migrations/geoprocessing/1654090110000-AddEezToAdminRegions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class AddEezToAdminRegions1654090110000 | ||
|
||
implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
ALTER TYPE adm_level ADD VALUE IF NOT EXISTS 'eez'; | ||
|
||
CREATE TABLE IF NOT EXISTS admin_regions_eez PARTITION OF admin_regions FOR VALUES IN ('eez'); | ||
|
||
ALTER TABLE admin_regions ADD COLUMN IF NOT EXISTS pol_type text, | ||
ADD COLUMN IF NOT EXISTS mrgid_eez integer; | ||
|
||
CREATE UNIQUE INDEX IF NOT EXISTS unique_eez_regions ON admin_regions (mrgid_eez, level) where level = 'eez'; | ||
|
||
DROP INDEX admin_regions_l012_ids; | ||
|
||
CREATE INDEX admin_regions_l012_ids ON admin_regions (gid_0, gid_1, gid_2, mrgid_eez, level); | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
ALTER TABLE admin_regions | ||
DROP COLUMN pol_type, | ||
DROP COLUMN mrgid_eez; | ||
|
||
ALTER TABLE admin_regions DROP PARTITION admin_regions_eez; | ||
|
||
ALTER TYPE adm_level DROP VALUE IF EXISTS 'eez'; | ||
DROP INDEX unique_eez_regions; | ||
CREATE INDEX admin_regions_l012_ids ON admin_regions (gid_0, gid_1, gid_2, level); | ||
|
||
`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
.PHONY: import | ||
# MAKEFLAGS := --jobs=$(shell nproc) | ||
# MAKEFLAGS += --output-sync=target | ||
|
||
MarxanUser:=$(shell psql -X -A -t "postgresql://$$API_POSTGRES_USER:$$API_POSTGRES_PASSWORD@$$API_POSTGRES_HOST:$$API_POSTGRES_PORT/$$API_POSTGRES_DB" -c "select id from users limit 1") | ||
import: data/eez/eez_v11_simp.geojson | ||
ogr2ogr -makevalid \ | ||
-update -append \ | ||
-geomfield the_geom \ | ||
--config OGR_TRUNCATE NO \ | ||
-nln admin_regions -nlt PROMOTE_TO_MULTI \ | ||
-t_srs EPSG:4326 -a_srs EPSG:4326 \ | ||
-f PostgreSQL PG:"dbname=$$GEO_POSTGRES_DB host=$$GEO_POSTGRES_HOST \ | ||
port=$$GEO_POSTGRES_PORT user=$$GEO_POSTGRES_USER password=$$GEO_POSTGRES_PASSWORD" $< \ | ||
-sql "select *,'$(MarxanUser)' as created_by from \"$$(basename -s .geojson "$<")\""; | ||
|
||
data/eez/eez_v11_simp.geojson: data/eez/World_EEZ_v11_20191118/eez_v11.shp | ||
mapshaper-xl -i $< snap \ | ||
-simplify 25% planar keep-shapes \ | ||
-filter-islands min-vertices=3 min-area=10000m2 remove-empty \ | ||
-filter-slivers min-area=10000m2 remove-empty \ | ||
-clean rewind \ | ||
-each 'level= "eez"' \ | ||
-rename-fields NAME_0=GEONAME,ISO3=ISO_SOV1 \ | ||
-drop fields=MRGID,MRGID_TER1,MRGID_SOV1,TERRITORY1,ISO_TER1,SOVEREIGN1,MRGID_TER2,MRGID_SOV2,TERRITORY2,ISO_TER2,SOVEREIGN2,MRGID_TER3,MRGID_SOV3,TERRITORY3,ISO_TER3,SOVEREIGN3,X_1,Y_1,AREA_KM2,ISO_SOV2,ISO_SOV3,UN_SOV1,UN_SOV2,UN_SOV3,UN_TER1,UN_TER2,UN_TER3 \ | ||
-o $@ format=geojson force ndjson && \ | ||
rm -rf data/eez/World_EEZ_v11_20191118 | ||
|
||
data/eez/World_EEZ_v11_20191118/eez_v11.shp: data/eez/World_EEZ_v11_20191118.zip | ||
unzip -u $< -d data/eez | ||
|
||
data/eez/World_EEZ_v11_20191118.zip: data/eez | ||
cd $< && \ | ||
curl --location --request POST 'https://www.marineregions.org/download_file.php?name=World_EEZ_v11_20191118.zip' \ | ||
--header 'Cookie: PHPSESSID=870e305efbc0519d59b361427dbd8336; vliz_webc=vliz_webc1' \ | ||
--form 'name="Jen"' \ | ||
--form 'organisation="TNC"' \ | ||
--form 'email="[email protected]"' \ | ||
--form 'country="EEUU"' \ | ||
--form 'user_category="academia"' \ | ||
--form 'purpose_category="Conservation"' \ | ||
--form 'agree="1"' \ | ||
--output './World_EEZ_v11_20191118.zip' | ||
|
||
data/eez: | ||
mkdir -p $@ | ||
|
||
clean: | ||
rm -rf data/eez/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry I had missed parts of this PR while I reviewed it - probably my tab wasn't refreshed when you pushed later changes... this bit, I recommend to handle it differently, without hardcoding cookie and most of the form data such as name, org, email, country, user_category, purpose_category
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how to do this... my first thought would be to move the whole curl command to a simple shell script that is committed to the repo with placeholders, and needs to be copied to a specific file (that should be added to
.gitignore
, similarly toenv.default
vs.env
), mounted in the eez ingestion container, and executed in the eez Makefile