-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 18533-school-zone-beacons
- Loading branch information
Showing
12 changed files
with
167 additions
and
44 deletions.
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
1 change: 1 addition & 0 deletions
1
moped-database/migrations/1725649291445_add_exploded_moped_geometry_view_for_agol/down.sql
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 @@ | ||
DROP VIEW IF EXISTS exploded_component_arcgis_online_view; |
14 changes: 14 additions & 0 deletions
14
moped-database/migrations/1725649291445_add_exploded_moped_geometry_view_for_agol/up.sql
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,14 @@ | ||
CREATE VIEW exploded_component_arcgis_online_view AS | ||
SELECT | ||
component_arcgis_online_view.project_id, | ||
component_arcgis_online_view.project_component_id, | ||
ST_GEOMETRYTYPE(dump.geom) AS geometry_type, | ||
dump.path[1] AS point_index, -- ordinal value of the point in the MultiPoint geometry | ||
component_arcgis_online_view.geometry AS original_geometry, | ||
ST_ASGEOJSON(dump.geom) AS exploded_geometry, -- noqa: RF04 | ||
component_arcgis_online_view.project_updated_at | ||
FROM | ||
component_arcgis_online_view, | ||
LATERAL ST_DUMP(ST_GEOMFROMGEOJSON(component_arcgis_online_view.geometry)) AS dump -- noqa: RF04 | ||
WHERE | ||
ST_GEOMETRYTYPE(ST_GEOMFROMGEOJSON(component_arcgis_online_view.geometry)) = 'ST_MultiPoint'; |
13 changes: 13 additions & 0 deletions
13
moped-database/views/exploded_component_arcgis_online_view.sql
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,13 @@ | ||
-- Most recent migration: moped-database/migrations/1725649291445_add_exploded_moped_geometry_view_for_agol/up.sql | ||
|
||
CREATE OR REPLACE VIEW exploded_component_arcgis_online_view AS SELECT | ||
component_arcgis_online_view.project_id, | ||
component_arcgis_online_view.project_component_id, | ||
st_geometrytype(dump.geom) AS geometry_type, | ||
dump.path[1] AS point_index, | ||
component_arcgis_online_view.geometry AS original_geometry, | ||
st_asgeojson(dump.geom) AS exploded_geometry, | ||
component_arcgis_online_view.project_updated_at | ||
FROM component_arcgis_online_view, | ||
LATERAL st_dump(st_geomfromgeojson(component_arcgis_online_view.geometry)) dump (path, geom) | ||
WHERE st_geometrytype(st_geomfromgeojson(component_arcgis_online_view.geometry)) = 'ST_MultiPoint'::text; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
env_file | ||
.git% | ||
__pycache__ | ||
*.json |
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 @@ | ||
*json |
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 |
---|---|---|
@@ -1,38 +1,33 @@ | ||
# ArcGIS ETLs | ||
# Moped → ArcGIS Online ETL | ||
|
||
Scripts which integrate Moped data with Esri ArcGIS | ||
Python script integration pushing Moped data to ESRI's ArcGIS Online (AGOL) platform | ||
|
||
## Publish components to ArcGIS Online (AGOL) | ||
## Publish components to AGOL | ||
|
||
The script `components_to_agol.py` is used to publish component record data to ArcGIS Online (AGOL). It replaces all records in the AGOL feature services with the latest component data in Moped. | ||
The script `components_to_agol.py` is used to publish component record data to AGOL. It has two primary modes of operation: | ||
|
||
The data is sourced from a view, `component_arcgis_online_view` which defines all columns which are available to be processed. | ||
- Full refresh: This mode will delete all existing records in the AGOL feature layer and replace them with the current data from the Moped database. | ||
- Incremental refresh: This mode will only update records that have been modified since a given timestamp. | ||
|
||
The AGOL layers can be found here: | ||
The script is responsible for maintaining four layers in the AGOL in the [Moped Project Components](https://austin.maps.arcgis.com/home/item.html?id=1c084c8756a84e6db7e2796c98c850a2) feature service: | ||
|
||
- [Project component points](https://austin.maps.arcgis.com/home/item.html?id=997555f6e0904aa88eafe73f19ee65c0) | ||
- [Project component lines](https://austin.maps.arcgis.com/home/item.html?id=e8f03d2cec154cacae539b630bcaa70b) | ||
- [Moped Points](https://austin.maps.arcgis.com/home/item.html?id=1c084c8756a84e6db7e2796c98c850a2&sublayer=0): Components best represented as points, utilizing MultiPoint geometries | ||
- [Moped Lines](https://austin.maps.arcgis.com/home/item.html?id=1c084c8756a84e6db7e2796c98c850a2&sublayer=1): Components best represented as lines, using Line geometries | ||
- [MOPED CombinedGeometries](https://austin.maps.arcgis.com/home/item.html?id=1c084c8756a84e6db7e2796c98c850a2&sublayer=2) (SIC): All components, where points are transformed into a line ringing the location | ||
- [Moped Feature Points](https://austin.maps.arcgis.com/home/item.html?id=1c084c8756a84e6db7e2796c98c850a2&sublayer=3): Components best represented as points, but where MultiPoints are exploded into individual points. Note, the same component can be represented as multiple features, one for each point in the MultiPoint. | ||
|
||
### Get it running | ||
The data for the first three layers listed above is sourced from a view, `component_arcgis_online_view` which defines all columns which are available to be processed. | ||
|
||
1. Configure an `env_file` according to the `env_template` example. You can find the AGOL Scripts Publisher username and password in the API Secrets vault in the team password store. | ||
|
||
2. Create and activate a Python environment that meets the requirments in `requirements.txt`. Alternatively, you can use the provided Dockerfile. | ||
|
||
3. Run the script | ||
The fourth layer is sourced from a derivative view, `exploded_component_arcgis_online_view`, which takes the previous view and explodes MultiPoint geometries into individual points. | ||
|
||
If you want to fully replace the dataset: | ||
## Running the Script | ||
|
||
```shell | ||
$ python components_to_agol.py -f | ||
``` | ||
Or, if you want to replace only data updated since a timestamp with time zone offset: | ||
```shell | ||
$ python components_to_agol.py -d <timestamptz> | ||
``` | ||
1. Configure an `env_file` according to the `env_template` example. You can find the AGOL Scripts Publisher username and password in the API Secrets vault in the team password store. | ||
|
||
or, to mount your local copy to a Docker container | ||
1. `docker compose build` to build the container. | ||
|
||
```shell | ||
docker run -it --rm --network host --env-file env_file -v ${PWD}:/app atddocker/atd-moped-etl-arcgis:production python components_to_agol.py | ||
``` | ||
1. Run the script via one or more of the following: | ||
- `docker compose run arcgis -d` to start the script with the default interval of changes over the last week. | ||
- `docker compose run arcgis -f` to start the script with a full refresh. | ||
- `docker compose run arcgis -d <timestamptz>` to start the script with a refresh since the given timestamp. | ||
- `docker compose run --entrypoint /bin/bash arcgis` to start a shell inside the container. |
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,10 @@ | ||
services: | ||
arcgis: | ||
build: | ||
context: . | ||
volumes: | ||
- .:/app | ||
entrypoint: python /app/components_to_agol.py | ||
command: -d | ||
env_file: | ||
- env_file |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
AGOL_USERNAME= | ||
AGOL_PASSWORD= | ||
HASURA_ENDPOINT=http://localhost:8080/v1/graphql | ||
HASURA_ENDPOINT=http://host.docker.internal:8080/v1/graphql | ||
HASURA_ADMIN_SECRET=hasurapassword |
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