From 3ca89a93669e6ab47019761a1663b5ba457c9a96 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Fri, 5 Jul 2024 10:09:21 +0100 Subject: [PATCH] What Kat did in https://github.com/specklesystems/speckle-sharp/pull/3546 --- .../ToHost/Raw/FeatureClassToHostConverter.cs | 2 +- .../TopLevel/VectorLayerToHostConverter.cs | 4 +-- .../TopLevel/VectorLayerToSpeckleConverter.cs | 16 +--------- .../Utils/FeatureClassUtils.cs | 19 ------------ .../Utils/GISAttributeFieldType.cs | 2 ++ .../Utils/GISLayerGeometryType.cs | 31 +++++++++++++++++++ .../Utils/IFeatureClassUtils.cs | 1 - 7 files changed, 37 insertions(+), 38 deletions(-) diff --git a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/Raw/FeatureClassToHostConverter.cs b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/Raw/FeatureClassToHostConverter.cs index d491ca2a1..76e7d951d 100644 --- a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/Raw/FeatureClassToHostConverter.cs +++ b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/Raw/FeatureClassToHostConverter.cs @@ -74,7 +74,7 @@ private List RecoverOutdatedGisFeatures(VectorLayer target) public FeatureClass Convert(VectorLayer target) { - ACG.GeometryType geomType = _featureClassUtils.GetLayerGeometryType(target); + ACG.GeometryType geomType = GISLayerGeometryType.GetNativeLayerGeometryType(target); FileGeodatabaseConnectionPath fileGeodatabaseConnectionPath = new(_contextStack.Current.Document.SpeckleDatabasePath); diff --git a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/TopLevel/VectorLayerToHostConverter.cs b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/TopLevel/VectorLayerToHostConverter.cs index 5c7dd8c9e..c2d0ff144 100644 --- a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/TopLevel/VectorLayerToHostConverter.cs +++ b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToHost/TopLevel/VectorLayerToHostConverter.cs @@ -34,7 +34,7 @@ IFeatureClassUtils featureClassUtils public string Convert(VectorLayer target) { // pointcloud layers need to be checked separately, because there is no ArcGIS Geometry type - // for Pointcloud. In ArcGIS it's a completely different layer class, so "GetLayerGeometryType" + // for Pointcloud. In ArcGIS it's a completely different layer class, so "GetNativeLayerGeometryType" // will return "Invalid" type if (target.geomType == GISLayerGeometryType.POINTCLOUD) { @@ -42,7 +42,7 @@ public string Convert(VectorLayer target) } // check if Speckle VectorLayer should become a FeatureClass, StandaloneTable or PointcloudLayer - ACG.GeometryType geomType = _featureClassUtils.GetLayerGeometryType(target); + ACG.GeometryType geomType = GISLayerGeometryType.GetNativeLayerGeometryType(target); if (geomType != ACG.GeometryType.Unknown) // feature class { return _featureClassConverter.Convert(target).GetName(); diff --git a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToSpeckle/TopLevel/VectorLayerToSpeckleConverter.cs b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToSpeckle/TopLevel/VectorLayerToSpeckleConverter.cs index 8d2a36e33..1ab1e5c02 100644 --- a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToSpeckle/TopLevel/VectorLayerToSpeckleConverter.cs +++ b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ToSpeckle/TopLevel/VectorLayerToSpeckleConverter.cs @@ -36,20 +36,6 @@ public Base Convert(object target) return Convert((FeatureLayer)target); } - private string AssignSpeckleGeometryType(esriGeometryType nativeGeometryType) - { - return nativeGeometryType switch - { - esriGeometryType.esriGeometryMultipoint => GISLayerGeometryType.POINT, - esriGeometryType.esriGeometryPoint => GISLayerGeometryType.POINT, - esriGeometryType.esriGeometryLine => GISLayerGeometryType.POLYLINE, - esriGeometryType.esriGeometryPolyline => GISLayerGeometryType.POLYLINE, - esriGeometryType.esriGeometryPolygon => GISLayerGeometryType.POLYGON, - esriGeometryType.esriGeometryMultiPatch => GISLayerGeometryType.MULTIPATCH, - _ => GISLayerGeometryType.NONE, - }; - } - public VectorLayer Convert(FeatureLayer target) { VectorLayer speckleLayer = new(); @@ -93,7 +79,7 @@ public VectorLayer Convert(FeatureLayer target) speckleLayer.attributes = allLayerAttributes; // get a simple geometry type - string spekleGeometryType = AssignSpeckleGeometryType(target.ShapeType); + string spekleGeometryType = GISLayerGeometryType.LayerGeometryTypeToSpeckle(target.ShapeType); speckleLayer.geomType = spekleGeometryType; // search the rows diff --git a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/FeatureClassUtils.cs b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/FeatureClassUtils.cs index 6e3a587b4..85393763e 100644 --- a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/FeatureClassUtils.cs +++ b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/FeatureClassUtils.cs @@ -110,23 +110,4 @@ public void AddNonGISFeaturesToFeatureClass( } } } - - public ACG.GeometryType GetLayerGeometryType(VectorLayer target) - { - string? originalGeomType = target.geomType != null ? target.geomType : target.nativeGeomType; - return originalGeomType switch - { - GISLayerGeometryType.NONE => ACG.GeometryType.Unknown, - GISLayerGeometryType.POINT => ACG.GeometryType.Multipoint, - GISLayerGeometryType.POLYGON => ACG.GeometryType.Polygon, - GISLayerGeometryType.POLYLINE => ACG.GeometryType.Polyline, - GISLayerGeometryType.MULTIPATCH => ACG.GeometryType.Multipatch, - GISLayerGeometryType.POLYGON3D => ACG.GeometryType.Multipatch, - _ - => throw new ArgumentOutOfRangeException( - nameof(target), - $"Geometry type '{originalGeomType}' is not recognized." - ), - }; - } } diff --git a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/GISAttributeFieldType.cs b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/GISAttributeFieldType.cs index 4da3d0900..a23ceb353 100644 --- a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/GISAttributeFieldType.cs +++ b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/GISAttributeFieldType.cs @@ -16,6 +16,7 @@ public static class GISAttributeFieldType public const string DATEONLY = "DateOnly"; public const string TIMEONLY = "TimeOnly"; public const string TIMESTAMPOFFSET = "TimeStampOffset"; + public const string BOOL = "Bool"; // not supported in ArcGIS, only in QGIS public static string FieldTypeToSpeckle(FieldType fieldType) { @@ -55,6 +56,7 @@ public static FieldType FieldTypeToNative(object fieldType) DATEONLY => FieldType.DateOnly, TIMEONLY => FieldType.TimeOnly, TIMESTAMPOFFSET => FieldType.String, // sending and receiving as stings + BOOL => FieldType.String, // not supported in ArcGIS, converting to string _ => throw new ArgumentOutOfRangeException(nameof(fieldType)), }; } diff --git a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/GISLayerGeometryType.cs b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/GISLayerGeometryType.cs index 612eff480..f10c872d6 100644 --- a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/GISLayerGeometryType.cs +++ b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/GISLayerGeometryType.cs @@ -1,3 +1,5 @@ +using ArcGIS.Core.CIM; + namespace Speckle.Converters.ArcGIS3.Utils; public static class GISLayerGeometryType @@ -9,4 +11,33 @@ public static class GISLayerGeometryType public const string POLYGON3D = "Polygon3d"; public const string MULTIPATCH = "Multipatch"; public const string POINTCLOUD = "Pointcloud"; + + public static string LayerGeometryTypeToSpeckle(esriGeometryType nativeGeometryType) + { + return nativeGeometryType switch + { + esriGeometryType.esriGeometryMultipoint => GISLayerGeometryType.POINT, + esriGeometryType.esriGeometryPoint => GISLayerGeometryType.POINT, + esriGeometryType.esriGeometryLine => GISLayerGeometryType.POLYLINE, + esriGeometryType.esriGeometryPolyline => GISLayerGeometryType.POLYLINE, + esriGeometryType.esriGeometryPolygon => GISLayerGeometryType.POLYGON, + esriGeometryType.esriGeometryMultiPatch => GISLayerGeometryType.MULTIPATCH, + _ => GISLayerGeometryType.NONE, + }; + } + + public static ACG.GeometryType GetNativeLayerGeometryType(Objects.GIS.VectorLayer target) + { + string? originalGeomType = target.geomType != null ? target.geomType : target.nativeGeomType; + return originalGeomType switch + { + GISLayerGeometryType.NONE => ACG.GeometryType.Unknown, + GISLayerGeometryType.POINT => ACG.GeometryType.Multipoint, + GISLayerGeometryType.POLYGON => ACG.GeometryType.Polygon, + GISLayerGeometryType.POLYLINE => ACG.GeometryType.Polyline, + GISLayerGeometryType.MULTIPATCH => ACG.GeometryType.Multipatch, + GISLayerGeometryType.POLYGON3D => ACG.GeometryType.Multipatch, + _ => throw new ArgumentOutOfRangeException(nameof(target)), + }; + } } diff --git a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/IFeatureClassUtils.cs b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/IFeatureClassUtils.cs index b60cf4bfe..b79e0946e 100644 --- a/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/IFeatureClassUtils.cs +++ b/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/IFeatureClassUtils.cs @@ -20,5 +20,4 @@ void AddNonGISFeaturesToFeatureClass( List<(FieldDescription, Func)> fieldsAndFunctions ); void AddFeaturesToTable(Table newFeatureClass, List gisFeatures, List fields); - public ACG.GeometryType GetLayerGeometryType(VectorLayer target); }