Skip to content

v0.2.47..v0.2.48 changeset ServiceBuildingReplacementTest.sh.off

Garret Voltz edited this page Sep 27, 2019 · 1 revision
diff --git a/test-files/cmd/glacial/serial/replacement-test-archive/ServiceBuildingReplacementTest.sh.off b/test-files/cmd/glacial/serial/replacement-test-archive/ServiceBuildingReplacementTest.sh.off
new file mode 100755
index 0000000..00da7e1
--- /dev/null
+++ b/test-files/cmd/glacial/serial/replacement-test-archive/ServiceBuildingReplacementTest.sh.off
@@ -0,0 +1,100 @@
+#!/bin/bash
+set -e
+
+# Wholesale Building Replacement Workflow
+#
+# This test is lenient regarding the AOI, in that it may modify some features in the ref data that lie just outside of the AOI. Secondary 
+# features crossing the AOI may be included in the output or conflated with reference features. This workflow should work other polygon 
+# data types, but only buildings have been tested with it so far.
+
+TEST_NAME=ServiceBuildingReplacementTest
+IN_DIR=test-files/cmd/glacial/serial/$TEST_NAME
+OUT_DIR=test-output/cmd/glacial/serial/$TEST_NAME
+rm -rf $OUT_DIR
+mkdir -p $OUT_DIR
+
+source conf/database/DatabaseConfig.sh
+export OSM_API_DB_URL="osmapidb://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME_OSMAPI"
+export OSM_API_DB_AUTH="-h $DB_HOST -p $DB_PORT -U $DB_USER"
+export PGPASSWORD=$DB_PASSWORD_OSMAPI
+HOOT_DB_URL="hootapidb://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME"
+
+REF_LAYER_FILE=$OUT_DIR/BostonSubsetRoadBuilding_FromOsm-perturbed.osm
+REF_LAYER=$OSM_API_DB_URL
+SEC_LAYER_FILE=test-files/BostonSubsetRoadBuilding_FromOsm.osm
+SEC_LAYER="$HOOT_DB_URL/$TEST_NAME-sec"
+AOI="-71.4698,42.4866,-71.4657,42.4902"
+
+#ChangesetCreator;MapCropper;OsmMap;OsmMapWriterFactory
+GENERAL_OPTS="--warn -D log.class.filter= -D uuid.helper.repeatable=true -D writer.include.debug.tags=true -D changeset.xml.writer.add.timestamp=false -D reader.add.source.datetime=false -D writer.include.circular.error.tags=false -D debug.maps.write=false"
+DB_OPTS="-D api.db.email=OsmApiDbHootApiDbConflate@hoottestcpp.org -D hootapi.db.writer.create.user=true -D hootapi.db.writer.overwrite.map=true -D changeset.user.id=1"
+PERTY_OPTS="-D perty.seed=1 -D perty.systematic.error.x=15 -D perty.systematic.error.y=15 -D perty.ops="
+PRUNE_AND_CROP_OPTS="-D reader.use.data.source.ids=true -D convert.bounding.box.keep.entire.features.crossing.bounds=true -D convert.bounding.box.keep.only.features.inside.bounds=false -D convert.ops=hoot::RemoveElementsVisitor -D convert.bounding.box=$AOI -D remove.elements.visitor.element.criteria=hoot::BuildingCriterion -D remove.elements.visitor.recursive=true -D element.criterion.negate=true"
+COOKIE_CUT_OPTS="-D reader.use.data.source.ids=true -D crop.keep.entire.features.crossing.bounds=true -D crop.keep.only.features.inside.bounds=false -D debug.maps.filename=$OUT_DIR/cookie-cut.osm"
+# The reason we can't use the secondary element IDs here is that relations may have been added during cookie cut conflation that will be 
+# overlapping between the two datasets. Its ok to drop the secondary IDs because they all represent new features to be inserted into the
+# database anyway, which always start out as negative.
+CONFLATE_OPTS="-D debug.maps.filename=$OUT_DIR/conflate.osm -D conflate.use.data.source.ids.1=true -D conflate.use.data.source.ids.2=false -D debug.maps.filename=$OUT_DIR/conflated.osm"
+# If any ref features cross the bounds, we want to keep them intact unless they conflate with something in the secondary. Secondary features
+# crossing the bounds are ok to be in the output.
+CHANGESET_DERIVE_OPTS="-D changeset.user.id=1 -D convert.bounding.box=$AOI -D changeset.reference.keep.entire.features.crossing.bounds=true -D changeset.secondary.keep.entire.features.crossing.bounds=true -D changeset.reference.keep.only.features.inside.bounds=false -D changeset.secondary.keep.only.features.inside.bounds=false"
+
+# DATA PREP
+
+scripts/database/CleanAndInitializeOsmApiDb.sh
+echo ""
+echo "Writing the reference dataset to an osm api db (contains features to be replaced)..."
+echo ""
+hoot convert $GENERAL_OPTS $DB_OPTS $PERTY_OPTS -D debug.maps.filename=$OUT_DIR/data-prep-ref.osm -D reader.use.data.source.ids=false -D id.generator=hoot::PositiveIdGenerator -D convert.ops="hoot::SetTagValueVisitor;hoot::PertyOp" -D set.tag.value.visitor.element.criterion=hoot::BuildingCriterion -D set.tag.value.visitor.key=name -D set.tag.value.visitor.value="Building 1" $SEC_LAYER_FILE $REF_LAYER 
+# needed for examining test output only:
+hoot convert $GENERAL_OPTS $DB_OPTS -D debug.maps.filename=$OUT_DIR/data-prep-ref.osm -D reader.use.data.source.ids=true $REF_LAYER $REF_LAYER_FILE 
+echo ""
+echo "Writing the secondary dataset to a hoot api db (contains features to replace with)..."
+echo ""
+hoot convert $GENERAL_OPTS $DB_OPTS -D debug.maps.filename=$OUT_DIR/data-prep-sec.osm -D reader.use.data.source.ids=false -D convert.ops=hoot::SetTagValueVisitor -D set.tag.value.visitor.element.criterion=hoot::BuildingCriterion -D set.tag.value.visitor.key=name -D set.tag.value.visitor.value="Building 2" $SEC_LAYER_FILE $SEC_LAYER
+
+# PRUNING AND CROPPING
+
+echo "crop and prune"
+hoot convert $GENERAL_OPTS $DB_OPTS $PRUNE_AND_CROP_OPTS -D debug.maps.filename=$OUT_DIR/prune-and-crop-ref.osm  -D bounds.output.file=$OUT_DIR/$TEST_NAME-bounds.osm $REF_LAYER $OUT_DIR/$TEST_NAME-ref-cropped.osm --write-bounds
+hoot convert $GENERAL_OPTS $DB_OPTS $PRUNE_AND_CROP_OPTS -D debug.maps.filename=$OUT_DIR/prune-and-crop-sec.osm $SEC_LAYER $OUT_DIR/$TEST_NAME-sec-cropped.osm
+
+# COOKIE CUTTING
+
+echo "cookie cut"
+hoot generate-alpha-shape $GENERAL_OPTS -D debug.maps.filename=$OUT_DIR/alpha-shape.osm -D reader.use.data.source.ids=true $OUT_DIR/$TEST_NAME-sec-cropped.osm 1000 0 $OUT_DIR/$TEST_NAME-cutter-shape.osm
+# Need to force not cutting up any ref features crossing the bounds here.
+hoot cookie-cut $GENERAL_OPTS $COOKIE_CUT_OPTS $OUT_DIR/$TEST_NAME-cutter-shape.osm $OUT_DIR/$TEST_NAME-ref-cropped.osm $OUT_DIR/$TEST_NAME-cookie-cut.osm
+
+# CONFLATION
+
+echo "conflate"
+hoot conflate $GENERAL_OPTS $CONFLATE_OPTS $OUT_DIR/$TEST_NAME-cookie-cut.osm $OUT_DIR/$TEST_NAME-sec-cropped.osm $OUT_DIR/$TEST_NAME-conflated.osm
+
+# CHANGESET DERIVATION
+
+CHANGESET_DERIVATION_MSG="Deriving a changeset that completely replaces features in the reference dataset within the specified AOI with those from a secondary dataset"
+echo ""
+echo $CHANGESET_DERIVATION_MSG " (osm xml file secondary source; xml changeset out)..."
+echo ""
+hoot changeset-derive $GENERAL_OPTS $CHANGESET_DERIVE_OPTS -D debug.maps.filename=$OUT_DIR/changeset-xml.osm $OUT_DIR/$TEST_NAME-ref-cropped.osm $OUT_DIR/$TEST_NAME-conflated.osm $OUT_DIR/$TEST_NAME-changeset-1.osc
+echo ""
+echo $CHANGESET_DERIVATION_MSG " (osm xml file secondary source; sql changeset out)..."
+echo ""
+hoot changeset-derive $GENERAL_OPTS $CHANGESET_DERIVE_OPTS -D debug.maps.filename=$OUT_DIR/changeset-sql.osm $OUT_DIR/$TEST_NAME-ref-cropped.osm $OUT_DIR/$TEST_NAME-conflated.osm $OUT_DIR/$TEST_NAME-changeset-1.osc.sql $REF_LAYER
+
+# CHANGESET APPLICATION
+
+echo ""
+echo "Applying the changeset to the reference data..."
+echo ""
+hoot changeset-apply $GENERAL_OPTS $DB_OPTS $CHANGESET_DERIVE_OPTS -D debug.maps.filename=$OUT_DIR/changeset-apply.osm $OUT_DIR/$TEST_NAME-changeset-1.osc.sql $OSM_API_DB_URL
+echo ""
+echo "Reading the entire reference dataset out for verification..."
+echo ""
+hoot convert $GENERAL_OPTS $DB_OPTS -D debug.maps.filename=$OUT_DIR/final-write.osm $OSM_API_DB_URL $OUT_DIR/$TEST_NAME-replaced.osm
+hoot diff $GENERAL_OPTS $IN_DIR/$TEST_NAME-replaced.osm $OUT_DIR/$TEST_NAME-replaced.osm
+
+# CLEANUP
+
+hoot delete-db-map $HOOT_OPTS $DB_OPTS -D debug.maps.filename=$OUT_DIR/cleanup.osm $SEC_LAYER
Clone this wiki locally