Skip to content
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

Jw/feature service to events #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions app/actions/handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import arcgis
import pandas as pd
import geopandas as gpd
from shapely.validation import make_valid

"""
Params:
SERVER-URL: The AGOL URL
USERNAME: AGOL Username
PASSWORD: AGOL Password
FEATURE-SERVICE-ID: The AGOL unique asset ID
TIMECOLUMN: The name of the time column representing the event 'time'
"""

def sdf_to_gdf(sdf):
tmp = sdf.copy()
tmp = tmp[~tmp['SHAPE'].isna()]
gdf = gpd.GeoDataFrame(tmp, geometry=tmp["SHAPE"], crs=4326).set_index('objectid')
gdf['geometry'] = gdf['geometry'].apply(lambda x: make_valid(x)) # try to fix any geoemtry issues
gdf.drop(columns=['Shape__Area', 'Shape__Length', 'SHAPE'], errors='ignore', inplace=True)
return gdf


gis = arcgis.gis.GIS("SERVER-URL", "USERNAME", "PASSWORD")
points_sdf = gis.content.get("FEATURE-SERVICE-ID").layers[0].query().sdf # todo: support multi-layers
events = sdf_to_gdf(points_sdf)

events["location"] = pd.DataFrame({"longitude": events.geometry.x, "latitude": events.geometry.y}).to_dict(
"records"
)
del events["geometry"]

events["time"] = pd.to_datetime(events["TIMECOLUMN"])

events = events.to_dict("records")

# to-do: post events to Gundi based on the action runner status
3 changes: 3 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# Add your integration-specific dependencies here
arcgis
geopandas
shapely