From e8f55cb9f0c95d1fc211c66383a2d6217d004019 Mon Sep 17 00:00:00 2001 From: bozmir Date: Thu, 13 Feb 2025 16:02:45 +0100 Subject: [PATCH 1/5] init error fix van coordinate package --- .../_BuildingBlocks/FloatingOrigin/Editor/CoordinateGUI.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/_BuildingBlocks/FloatingOrigin/Editor/CoordinateGUI.cs b/Assets/_BuildingBlocks/FloatingOrigin/Editor/CoordinateGUI.cs index 7a6c71cdd..3e77ea6d9 100644 --- a/Assets/_BuildingBlocks/FloatingOrigin/Editor/CoordinateGUI.cs +++ b/Assets/_BuildingBlocks/FloatingOrigin/Editor/CoordinateGUI.cs @@ -18,11 +18,11 @@ public static bool CoordinateField(bool foldout, IHasCoordinate coordinateContai ? ((CoordinateSystem)coordinate.CoordinateSystem).ToString() : "Undefined"; EditorGUILayout.LabelField("Coordinate System", coordinateSystemAsString); - - var coordinatePoints = coordinate.Points ?? new double[]{}; EditorGUILayout.LabelField( "Points", - coordinatePoints.Length > 0 ? string.Join(", ", coordinatePoints) : "There are no points defined" + coordinate.PointsLength == 2 ? string.Join(", ", coordinate.value1, coordinate.value2) : + coordinate.PointsLength == 3 ? string.Join(", ", coordinate.value1, coordinate.value2, coordinate.value3) : + "There are no points defined" ); EditorGUI.indentLevel--; From b17f27514b44bbbf25c8b386d153b26008959ebf Mon Sep 17 00:00:00 2001 From: bozmir Date: Thu, 13 Feb 2025 16:28:22 +0100 Subject: [PATCH 2/5] package update & coordinategui fix (previous commit) --- Packages/manifest.json | 2 +- Packages/packages-lock.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Packages/manifest.json b/Packages/manifest.json index eda4f6c31..8421d987b 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -17,7 +17,7 @@ "eu.netherlands3d.address-search": "2.0.0", "eu.netherlands3d.cartesiantiles": "1.1.3", "eu.netherlands3d.collada": "0.1.1", - "eu.netherlands3d.coordinates": "1.9.0", + "eu.netherlands3d.coordinates": "1.9.1", "eu.netherlands3d.event-containers": "0.1.1", "eu.netherlands3d.filebrowser": "2.2.0", "eu.netherlands3d.geojson": "1.1.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index c22911063..2bb79742f 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -275,7 +275,7 @@ "url": "https://package.openupm.com" }, "eu.netherlands3d.coordinates": { - "version": "1.9.0", + "version": "1.9.1", "depth": 0, "source": "registry", "dependencies": {}, From fc6be168626bdd36f65266e5b0a68624f2f41768 Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Fri, 14 Feb 2025 11:58:10 +0100 Subject: [PATCH 3/5] Bounding boxes were not correctly determined because the CRS was not correctly interpreted, there was an issue with the conversion of decimal separators and the xpath query cannot work for both a ElementNode and AttributeNode --- .../Wms/Scripts/WmsGetCapabilities.cs | 64 ++++++++++++------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/Assets/_Functionalities/Wms/Scripts/WmsGetCapabilities.cs b/Assets/_Functionalities/Wms/Scripts/WmsGetCapabilities.cs index abe2ce9a8..538295831 100644 --- a/Assets/_Functionalities/Wms/Scripts/WmsGetCapabilities.cs +++ b/Assets/_Functionalities/Wms/Scripts/WmsGetCapabilities.cs @@ -93,20 +93,31 @@ public BoundingBoxContainer GetBounds() string layerName = layerNode.SelectSingleNode("*[local-name()='Name']", namespaceManager)?.InnerText; if (string.IsNullOrEmpty(layerName)) continue; - var boundingBoxNode = layerNode.SelectSingleNode("*[local-name()='BoundingBox']", namespaceManager); - if (boundingBoxNode != null) + // We prefer EPSG:28992 because it matches our application better .. + var boundingBoxNode = layerNode.SelectSingleNode("*[local-name()='BoundingBox' and @CRS='EPSG:28992']", namespaceManager); + // .. Ok, WGS84 is Okay too .. + boundingBoxNode ??= layerNode.SelectSingleNode("*[local-name()='BoundingBox' and @CRS='EPSG:3857']", namespaceManager); + // .. Seriously? That one isn't there either? Ok, let's pick the first and see what gives + boundingBoxNode ??= layerNode.SelectSingleNode("*[local-name()='BoundingBox']", namespaceManager); + + // Wait what? Nothing? + if (boundingBoxNode == null) continue; + + string crsString = boundingBoxNode.Attributes["CRS"].Value; + // A hack used to aid identifying the correct CRS, the crsString that our coordinate converter + // looks for is CRS84 and not CRS:84. The latter is the actual designation. Please see Annex B of + // the WMS specification https://portal.ogc.org/files/?artifact_id=14416 to see more information + // on the use of the CRS namespace -hence the colon between CRS and 84. + if (crsString == "CRS:84") crsString = "CRS84"; + + var hasCRS = CoordinateSystems.FindCoordinateSystem(crsString, out var crs); + if (!hasCRS) { - string crsString = boundingBoxNode.Attributes["CRS"]?.Value; - var hasCRS = CoordinateSystems.FindCoordinateSystem(crsString, out var crs); - - if (!hasCRS) - { - crs = CoordinateSystem.CRS84; //default - Debug.LogWarning("Custom CRS BBox found, but not able to be parsed, defaulting to WGS84 CRS. Founds CRS string: " + crsString); - } - - container.LayerBoundingBoxes[layerName] = ParseBoundingBox(boundingBoxNode, crs); + crs = CoordinateSystem.CRS84; //default + Debug.LogWarning("CRS for BBox could not be recognized, defaulting to CRS:84. Found string: " + crsString); } + + container.LayerBoundingBoxes[layerName] = ParseBoundingBox(boundingBoxNode, crs); } return container; @@ -117,17 +128,26 @@ private BoundingBox ParseBoundingBox(XmlNode node, CoordinateSystem crs) if (node == null) return null; - var minXString = node.SelectSingleNode("*[local-name()='westBoundLongitude' or @minx]", namespaceManager)?.InnerText; - var minYString = node.SelectSingleNode("*[local-name()='southBoundLatitude' or @miny]", namespaceManager)?.InnerText; - var maxXString = node.SelectSingleNode("*[local-name()='eastBoundLongitude' or @maxx]", namespaceManager)?.InnerText; - var maxYString = node.SelectSingleNode("*[local-name()='northBoundLatitude' or @maxy]", namespaceManager)?.InnerText; - - //replace , with . to ensure the parse function works as intended. + // This method seems to be reused in reading the EX_GeographicBoundingBox -which is always in CRS:84 but I + // hope the caller does this correct- + var minXString = node.SelectSingleNode("*[local-name()='westBoundLongitude']", namespaceManager)?.InnerText; + var minYString = node.SelectSingleNode("*[local-name()='southBoundLatitude']", namespaceManager)?.InnerText; + var maxXString = node.SelectSingleNode("*[local-name()='eastBoundLongitude']", namespaceManager)?.InnerText; + var maxYString = node.SelectSingleNode("*[local-name()='northBoundLatitude']", namespaceManager)?.InnerText; + + // Ugly solution to support both EX_GeographicBoundingBox and BoundingBox, the latter uses attributes + minXString ??= node.Attributes["minx"]?.Value; + minYString ??= node.Attributes["miny"]?.Value; + maxXString ??= node.Attributes["maxx"]?.Value; + maxYString ??= node.Attributes["maxy"]?.Value; + + // replace , with . to ensure the parse function works as intended because some Dutch agencies use the wrong + // decimal separators. Because Fuck standards? minXString = minXString?.Replace(',', '.'); - minYString = minXString?.Replace(',', '.'); - maxXString = minXString?.Replace(',', '.'); - maxYString = minXString?.Replace(',', '.'); - + minYString = minYString?.Replace(',', '.'); + maxXString = maxXString?.Replace(',', '.'); + maxYString = maxYString?.Replace(',', '.'); + if (!double.TryParse(minXString, out var minX)) return null; if (!double.TryParse(minYString, out var minY)) From e352fe8015a92c339b4339e6eb46726662d57efc Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Fri, 14 Feb 2025 13:24:34 +0100 Subject: [PATCH 4/5] Fixate BBOX CRS on CRS:84 as an ugly workaround for a couple of WMS servers that show 4326 as default and this gives problems because somehow the coordinates are reversed in the bbox. Needs more research on monday, but this fixes the issue --- .../Wms/Scripts/WMSTileDataLayer.cs | 14 ++++++++++---- .../Wms/Scripts/WmsGetCapabilities.cs | 4 ++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Assets/_Functionalities/Wms/Scripts/WMSTileDataLayer.cs b/Assets/_Functionalities/Wms/Scripts/WMSTileDataLayer.cs index e65dc6a8e..78a22b083 100644 --- a/Assets/_Functionalities/Wms/Scripts/WMSTileDataLayer.cs +++ b/Assets/_Functionalities/Wms/Scripts/WMSTileDataLayer.cs @@ -115,10 +115,16 @@ private BoundingBox DetermineBoundingBox(TileChange tileChange, MapFilters mapFi var bottomLeft = new Coordinate(CoordinateSystem.RD, tileChange.X, tileChange.Y, 0); var topRight = new Coordinate(CoordinateSystem.RD, tileChange.X + tileSize, tileChange.Y + tileSize, 0); - var splitReferenceCode = mapFilters.spatialReference.Split(':'); - string coordinateSystemAsString = splitReferenceCode[0].ToLower() == "epsg" - ? splitReferenceCode[^1] - : DefaultEpsgCoordinateSystem; + // Yes, there is a semicolon missing, this is on purpose because FindCoordinateSystem finds this and not + // with the semicolon + string coordinateSystemAsString = "CRS84"; + if (mapFilters.spatialReference != "CRS:84") + { + var splitReferenceCode = mapFilters.spatialReference.Split(':'); + coordinateSystemAsString = splitReferenceCode[0].ToLower() == "epsg" + ? splitReferenceCode[^1] + : DefaultEpsgCoordinateSystem; + } CoordinateSystems.FindCoordinateSystem(coordinateSystemAsString, out var foundCoordinateSystem); diff --git a/Assets/_Functionalities/Wms/Scripts/WmsGetCapabilities.cs b/Assets/_Functionalities/Wms/Scripts/WmsGetCapabilities.cs index 538295831..16a620c7a 100644 --- a/Assets/_Functionalities/Wms/Scripts/WmsGetCapabilities.cs +++ b/Assets/_Functionalities/Wms/Scripts/WmsGetCapabilities.cs @@ -187,6 +187,10 @@ public List GetMaps(int width, int height, bool transparent) // CRS/SRS may be defined in the current MapNode, but can also inherit from a parent if it is not // specified the flag at the end of this function will check the current node and its parents var spatialReference = GetInnerTextForNode(mapNode, mapTemplate.spatialReferenceType, true); + + // TODO: Really ugly fix to deal issues around EPSG:4326. So we fixate on CRS:84 now, hoping that will + // work in all situations + spatialReference = "CRS:84"; var map = new MapFilters() { From c96ea4ef0e9f7e757d7cf81ab4b76531bca1b8a3 Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Fri, 14 Feb 2025 14:06:49 +0100 Subject: [PATCH 5/5] Removed frustration - this does not belong here --- Assets/_Functionalities/Wms/Scripts/WmsGetCapabilities.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/_Functionalities/Wms/Scripts/WmsGetCapabilities.cs b/Assets/_Functionalities/Wms/Scripts/WmsGetCapabilities.cs index 16a620c7a..2bb267221 100644 --- a/Assets/_Functionalities/Wms/Scripts/WmsGetCapabilities.cs +++ b/Assets/_Functionalities/Wms/Scripts/WmsGetCapabilities.cs @@ -142,7 +142,7 @@ private BoundingBox ParseBoundingBox(XmlNode node, CoordinateSystem crs) maxYString ??= node.Attributes["maxy"]?.Value; // replace , with . to ensure the parse function works as intended because some Dutch agencies use the wrong - // decimal separators. Because Fuck standards? + // decimal separators. minXString = minXString?.Replace(',', '.'); minYString = minYString?.Replace(',', '.'); maxXString = maxXString?.Replace(',', '.');