You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a feature has more than 1 duplicate, then they each just get merged with the first "original", but not with each other. I was using the golf course in testVectorToGeoJsonGrid as an example.
(I had added in a call to mergeAllPolygonsInFeatureCollection(featureCollection) to the test).
My attempts to fix this failed as the result of the first duplicate/original merge was failing validation attempts when going on to merge with subsequent duplicates. My changes (which could be wrong!) looked like this:
--- a/app/src/main/java/org/scottishtecharmy/soundscape/geoengine/utils/TileUtils.kt
+++ b/app/src/main/java/org/scottishtecharmy/soundscape/geoengine/utils/TileUtils.kt
@@ -1662,7 +1662,7 @@ fun mergeAllPolygonsInFeatureCollection(
}
}
- val mergedPolygonsFeatureCollection = FeatureCollection()
+ val mergedPolygons = hashMapOf<Double, Feature>()
val duplicateLineStringsAndPoints = FeatureCollection()
val originalPolygonsUsedInMerge = mutableSetOf<Any>() // Track original polygons
@@ -1674,7 +1674,23 @@ fun mergeAllPolygonsInFeatureCollection(
// Merge duplicate polygons
if (originalFeature != null && originalFeature.geometry.type == "Polygon" && duplicate.geometry.type == "Polygon") {
- mergedPolygonsFeatureCollection.features.add(mergePolygons(originalFeature, duplicate))
+
+ originalFeature.foreign?.get("osm_ids")?.let {
+ val osmIdArray = it as ArrayList<Double>
+ if(!mergedPolygons.containsKey(osmIdArray[0])) {
+ mergedPolygons[osmIdArray[0]] = mergePolygons(
+ originalFeature,
+ duplicate
+ )
+ } else {
+ mergedPolygons[osmIdArray[0]] = mergePolygons(
+ mergedPolygons[osmIdArray[0]]!!,
+ duplicate
+ )
+ }
+ if(osmIdArray[0] == 2191281972.0)
+ println("Golf!")
+ }
// Add to the set
originalFeature.foreign?.get("osm_ids")?.let { originalPolygonsUsedInMerge.add(it) }
// Add to the set
@@ -1690,8 +1706,9 @@ fun mergeAllPolygonsInFeatureCollection(
val finalFeatureCollection = FeatureCollection()
// Add merged Polygons
- finalFeatureCollection.features.addAll(mergedPolygonsFeatureCollection.features)
-
+ for(feature in mergedPolygons) {
+ finalFeatureCollection.addFeature(feature.value)
+ }
The text was updated successfully, but these errors were encountered:
If a feature has more than 1 duplicate, then they each just get merged with the first "original", but not with each other. I was using the golf course in
testVectorToGeoJsonGrid
as an example.(I had added in a call to
mergeAllPolygonsInFeatureCollection(featureCollection)
to the test).My attempts to fix this failed as the result of the first duplicate/original merge was failing validation attempts when going on to merge with subsequent duplicates. My changes (which could be wrong!) looked like this:
The text was updated successfully, but these errors were encountered: