-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Arcgis documentation kate jedd (#3459)
* expanding context stack Document from Map to (Project, Map) * move all database operations to context stack (it should only be called once per any operation and results (e.g. database path) accessible throughout converters) * fix Uri format needed for adding layers * Register ArcGISDocument * database URI fix --------- Co-authored-by: oguzhankoral <[email protected]>
- Loading branch information
1 parent
53b9055
commit 3191365
Showing
22 changed files
with
171 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 96 additions & 4 deletions
100
DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3/ArcGISConversionContextStack.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,110 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using ArcGIS.Core.Geometry; | ||
using ArcGIS.Core.Data.DDL; | ||
using ArcGIS.Core.Data; | ||
using ArcGIS.Desktop.Core; | ||
using ArcGIS.Desktop.Framework.Threading.Tasks; | ||
using ArcGIS.Desktop.Mapping; | ||
using Speckle.Converters.Common; | ||
|
||
namespace Speckle.Converters.ArcGIS3; | ||
|
||
public class ArcGISDocument | ||
{ | ||
public Project Project { get; } | ||
public Map Map { get; } | ||
public Uri SpeckleDatabasePath { get; } | ||
|
||
public ArcGISDocument() | ||
{ | ||
Project = Project.Current; | ||
Map = MapView.Active.Map; | ||
SpeckleDatabasePath = EnsureOrAddSpeckleDatabase(); | ||
} | ||
|
||
private const string FGDB_NAME = "Speckle.gdb"; | ||
|
||
public Uri EnsureOrAddSpeckleDatabase() | ||
{ | ||
return AddDatabaseToProject(GetDatabasePath()); | ||
} | ||
|
||
public Uri GetDatabasePath() | ||
{ | ||
try | ||
{ | ||
var parentDirectory = Directory.GetParent(Project.Current.URI); | ||
if (parentDirectory == null) | ||
{ | ||
throw new ArgumentException($"Project directory {Project.Current.URI} not found"); | ||
} | ||
var fGdbPath = new Uri(parentDirectory.FullName); | ||
return new Uri($"{fGdbPath}/{FGDB_NAME}"); | ||
} | ||
catch (Exception ex) | ||
when (ex | ||
is IOException | ||
or UnauthorizedAccessException | ||
or ArgumentException | ||
or NotSupportedException | ||
or System.Security.SecurityException | ||
) | ||
{ | ||
throw; | ||
} | ||
} | ||
|
||
public Uri AddDatabaseToProject(Uri databasePath) | ||
{ | ||
// Create a FileGeodatabaseConnectionPath with the name of the file geodatabase you wish to create | ||
FileGeodatabaseConnectionPath fileGeodatabaseConnectionPath = new(databasePath); | ||
// Create actual database in the specified Path unless already exists | ||
try | ||
{ | ||
Geodatabase geodatabase = SchemaBuilder.CreateGeodatabase(fileGeodatabaseConnectionPath); | ||
geodatabase.Dispose(); | ||
} | ||
catch (ArcGIS.Core.Data.Exceptions.GeodatabaseWorkspaceException) | ||
{ | ||
// geodatabase already exists, do nothing | ||
} | ||
|
||
// Add a folder connection to a project | ||
var parentFolder = Path.GetDirectoryName(databasePath.AbsolutePath); | ||
if (parentFolder == null) | ||
{ | ||
// POC: customize the exception type | ||
throw new ArgumentException($"Invalid path: {databasePath}"); | ||
} | ||
var fGdbName = databasePath.Segments[^1]; | ||
Item folderToAdd = ItemFactory.Instance.Create(parentFolder); | ||
// POC: QueuedTask | ||
QueuedTask.Run(() => Project.Current.AddItem(folderToAdd as IProjectItem)); | ||
|
||
// Add a file geodatabase or a SQLite or enterprise database connection to a project | ||
var gdbToAdd = folderToAdd | ||
.GetItems() | ||
.FirstOrDefault(folderItem => folderItem.Name.Equals(fGdbName, StringComparison.Ordinal)); | ||
if (gdbToAdd is not null) | ||
{ | ||
// POC: QueuedTask | ||
var addedGeodatabase = QueuedTask.Run(() => Project.Current.AddItem(gdbToAdd as IProjectItem)); | ||
} | ||
|
||
return databasePath; | ||
} | ||
} | ||
|
||
// POC: Suppressed naming warning for now, but we should evaluate if we should follow this or disable it. | ||
[SuppressMessage( | ||
"Naming", | ||
"CA1711:Identifiers should not have incorrect suffix", | ||
Justification = "Name ends in Stack but it is in fact a Stack, just not inheriting from `System.Collections.Stack`" | ||
)] | ||
public class ArcGISConversionContextStack : ConversionContextStack<Map, Unit> | ||
public class ArcGISConversionContextStack : ConversionContextStack<ArcGISDocument, ACG.Unit> | ||
{ | ||
public ArcGISConversionContextStack(IHostToSpeckleUnitConverter<Unit> unitConverter) | ||
: base(MapView.Active.Map, MapView.Active.Map.SpatialReference.Unit, unitConverter) { } | ||
public ArcGISConversionContextStack( | ||
IHostToSpeckleUnitConverter<ACG.Unit> unitConverter, | ||
ArcGISDocument arcGisDocument | ||
) | ||
: base(arcGisDocument, MapView.Active.Map.SpatialReference.Unit, unitConverter) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
...verters/ArcGIS/Speckle.Converters.ArcGIS3/Features/MultipatchFeatureToSpeckleConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.