Skip to content

Commit b531dd2

Browse files
author
adam-t-shaw
committed
Adding type 2 changefile coop work example
1 parent 29772bf commit b531dd2

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

examples/cooperative_work_examples.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
api = maproulette.Task(config)
1010

1111
# Setting a challenge ID in which we'll place our cooperative task
12-
challenge_id = "1234"
12+
challenge_id = 14452
1313

1414
# We'll start by creating some 'child' operations to apply to the target objects add them to a list:
1515
child_operations_list = [maproulette.ChildOperationModel(operation="setTags",
@@ -25,13 +25,13 @@
2525
# will be applied:
2626
test_parent_relation = [maproulette.ParentOperationModel(operation_type="modifyElement",
2727
element_type="way",
28-
osm_id="31110737",
28+
osm_id="175208404",
2929
child_operations=child_operations_list).to_dict()]
3030

3131
# The below flags error when handling is in the constructor, but not when in the setter:
3232
test_2 = maproulette.ParentOperationModel(operation_type="modifyElement",
3333
element_type="way",
34-
osm_id="31110737",
34+
osm_id="175208404",
3535
child_operations=child_operations_list)
3636

3737

@@ -46,7 +46,7 @@
4646
with open('data/Example_Geometry.geojson', 'r') as data_file:
4747
data = json.loads(data_file.read())
4848

49-
test_task = maproulette.TaskModel(name="Test_Coop_Task",
49+
test_task = maproulette.TaskModel(name="Test_Coop_Task_Kastellet",
5050
parent=challenge_id,
5151
geometries=data,
5252
cooperative_work=test_cooperative_work).to_dict()
@@ -56,3 +56,19 @@
5656
# endpoint, creating this new task with our cooperative work model applied
5757
print(json.dumps(api.create_task(test_task), indent=4, sort_keys=True))
5858

59+
60+
# Alternatively, cooperative work can be populated as in-progress edits via an OSM changefile (osc file)
61+
# as 'type 2' cooperative work:
62+
with open('data/ExampleChangefile.osc', 'rb') as data_file:
63+
osc_file = base64.b64encode(data_file.read()).decode('ascii')
64+
65+
test_osc_cooperative_work = maproulette.CooperativeWorkModel(type=2,
66+
content=osc_file).to_dict()
67+
68+
test_osc_task = maproulette.TaskModel(name="Test_Coop_Task_Kastellet_OSC_2",
69+
parent=challenge_id,
70+
geometries=data,
71+
cooperative_work=test_osc_cooperative_work).to_dict()
72+
73+
print(json.dumps(api.create_task(test_osc_task), indent=4, sort_keys=True))
74+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<osmChange version="0.6" generator="acme osm editor">
2+
<create>
3+
<node id="-1" changeset="-1" version="1" lat="55.69378277487475" lon="12.593096457148427" />
4+
<node id="-2" changeset="-1" version="1" lat="55.689697320811575" lon="12.597881450158676" />
5+
<way id="-3" changeset="-1" version="1">
6+
<nd ref="-1"/>
7+
<nd ref="-2"/>
8+
</way>
9+
</create>
10+
</osmChange>

0 commit comments

Comments
 (0)