Skip to content

Commit

Permalink
sync creation and assignment of ActiveCRS on send&receive (host&root …
Browse files Browse the repository at this point in the history
…obj builder); assignment to Sent & Received GIS/nonGIS classes
  • Loading branch information
KatKatKateryna committed Jun 29, 2024
1 parent 1f6191f commit b2d59d8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ public HostObjectBuilderResult Build(
CancellationToken cancellationToken
)
{
// get active CRS & offsets
// get active CRS & offsets on Receive
SpatialReference activeSpatialRef = _contextStack.Current.Document.Map.SpatialReference;
// Browse for any trace of geolocation in non-GIS apps (e.g. Revit: implemented, Blender: todo on Blender side, Civil3d: ?)
// ATM, GIS commit CRS is stored per layer, but should be moved to the Root level too
CRSorigin? dataOrigin = null; // e.g. CRSorigin.FromRevitData(rootObject);
if (dataOrigin is CRSorigin crsOrigin)
{
Expand All @@ -56,7 +57,7 @@ CancellationToken cancellationToken
double latOffset = 0;
double lonOffset = 0;
CRSoffsetRotation crsOffsetRotation = new(activeSpatialRef, latOffset, lonOffset, trueNorthRadians);
// set active CRS & offsets
// set active CRS & offsets on Receive
_contextStack.Current.Document.ActiveCRSoffsetRotation = crsOffsetRotation;

// Prompt the UI conversion started. Progress bar will swoosh.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ public RootObjectBuilderResult Build(
CancellationToken ct = default
)
{
// set active CRS & offsets
// set active CRS & offsets on Send
double trueNorth = 0;
CRSoffsetRotation crsOffsetRotation = new(_contextStack.Current.Document.Map.SpatialReference, trueNorth);
double latOffset = 0;
double lonOffset = 0;
CRSoffsetRotation crsOffsetRotation =
new(_contextStack.Current.Document.Map.SpatialReference, latOffset, lonOffset, trueNorth);
_contextStack.Current.Document.ActiveCRSoffsetRotation = crsOffsetRotation;

// POC: does this feel like the right place? I am wondering if this should be called from within send/rcv?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public ArcGISDocument()
Project = Project.Current;
Map = MapView.Active.Map;
SpeckleDatabasePath = EnsureOrAddSpeckleDatabase();
// CRS of either: incoming commit to be applied to all received objects, or CRS to convert all objects to, before sending
// created per Send/Receive operation, will be the same for all objects in the operation
ActiveCRSoffsetRotation = new CRSoffsetRotation(MapView.Active.Map.SpatialReference);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public FeatureClass Convert(VectorLayer target)
{
wktString = target.crs.wkt.ToString();
}
// ATM, GIS commit CRS is stored per layer, but should be moved to the Root level too, and created once per Receive
ACG.SpatialReference spatialRef = ACG.SpatialReferenceBuilder.CreateSpatialReference(wktString);
_contextStack.Current.Document.ActiveCRSoffsetRotation = new CRSoffsetRotation(spatialRef);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ public VectorLayer Convert(FeatureLayer target)
{
VectorLayer speckleLayer = new();

// get document CRS (for writing geometry coords)
var spatialRef = _contextStack.Current.Document.Map.SpatialReference;
// get Active CRS (for writing geometry coords)
var spatialRef = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpatialReference;
speckleLayer.crs = new CRS
{
wkt = spatialRef.Wkt,
name = spatialRef.Name,
units_native = spatialRef.Unit.ToString(),
units_native = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString,
};

// other properties
speckleLayer.name = target.Name;
speckleLayer.units = _contextStack.Current.SpeckleUnits;
speckleLayer.units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString;

// get feature class fields
var allLayerAttributes = new Base();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private void CreateDatasetInDatabase(
Geodatabase geodatabase = new(fileGeodatabaseConnectionPath);
SchemaBuilder schemaBuilder = new(geodatabase);

// get Spatial Reference from the document
// get Spatial Reference from the Active CRS for Receive
ACG.SpatialReference spatialRef = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpatialReference;

// create Fields
Expand Down

0 comments on commit b2d59d8

Please sign in to comment.