Skip to content

Commit

Permalink
Agis fix required units (#224)
Browse files Browse the repository at this point in the history
* fix arcgis units

* usings

* correct units

---------

Co-authored-by: Jedd Morgan <45512892+JR-Morgan@users.noreply.github.com>
  • Loading branch information
KatKatKateryna and JR-Morgan authored Sep 10, 2024
1 parent 2db4dfa commit 957a4ed
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Sdk.Common;

namespace Speckle.Converters.ArcGIS3.ToHost.Raw;

Expand All @@ -27,7 +26,7 @@ public ACG.Multipatch Convert(List<SGIS.GisMultipatchGeometry> target)
{
newPatch.AddPoint(
_pointConverter.Convert(
new SOG.Point(part.vertices[i * 3], part.vertices[i * 3 + 1], part.vertices[i * 3 + 2], Units.Meters) //TODO: this can't be right (units)
new SOG.Point(part.vertices[i * 3], part.vertices[i * 3 + 1], part.vertices[i * 3 + 2], part.units)
)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using ArcGIS.Core.Data;
using Speckle.Converters.ArcGIS3.Utils;
using Speckle.Converters.Common;
using Speckle.Converters.Common.Objects;
using Speckle.Objects;
using Speckle.Sdk.Common;
using Speckle.Sdk.Models;

namespace Speckle.Converters.ArcGIS3.ToSpeckle.Raw;
Expand All @@ -15,14 +15,16 @@ public class GisFeatureToSpeckleConverter : ITypedConverter<(Row, string), IGisF
private readonly ITypedConverter<ACG.Polygon, IReadOnlyList<SGIS.PolygonGeometry>> _polygonConverter;
private readonly ITypedConverter<ACG.Multipatch, IReadOnlyList<Base>> _multipatchConverter;
private readonly ITypedConverter<Row, Base> _attributeConverter;
private readonly IConversionContextStack<ArcGISDocument, ACG.Unit> _contextStack;

public GisFeatureToSpeckleConverter(
ITypedConverter<ACG.MapPoint, SOG.Point> pointConverter,
ITypedConverter<ACG.Multipoint, IReadOnlyList<SOG.Point>> multiPointConverter,
ITypedConverter<ACG.Polyline, IReadOnlyList<SOG.Polyline>> polylineConverter,
ITypedConverter<ACG.Polygon, IReadOnlyList<SGIS.PolygonGeometry>> polygonConverter,
ITypedConverter<ACG.Multipatch, IReadOnlyList<Base>> multipatchConverter,
ITypedConverter<Row, Base> attributeConverter
ITypedConverter<Row, Base> attributeConverter,
IConversionContextStack<ArcGISDocument, ACG.Unit> contextStack
)
{
_pointConverter = pointConverter;
Expand All @@ -31,6 +33,7 @@ ITypedConverter<Row, Base> attributeConverter
_polygonConverter = polygonConverter;
_multipatchConverter = multipatchConverter;
_attributeConverter = attributeConverter;
_contextStack = contextStack;
}

private List<SOG.Mesh> GetPolygonDisplayMeshes(List<SGIS.PolygonGeometry> polygons)
Expand Down Expand Up @@ -60,7 +63,7 @@ ITypedConverter<Row, Base> attributeConverter
{
vertices = boundaryPts.SelectMany(x => new List<double> { x.x, x.y, x.z }).ToList(),
faces = faces,
units = Units.Meters, //TODO: This can't be right
units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString
};
displayVal.Add(mesh);
}
Expand All @@ -78,7 +81,7 @@ ITypedConverter<Row, Base> attributeConverter
{
vertices = geo.vertices,
faces = geo.faces,
units = Units.Meters //TODO: This can't be right
units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString
};
displayVal.Add(displayMesh);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public IReadOnlyList<Base> Convert(ACG.Multipatch target)
{
List<Base> converted = new();
// placeholder, needs to be declared in order to be used in the Ring patch type
SGIS.PolygonGeometry3d polygonGeom = new() { };
SGIS.PolygonGeometry3d polygonGeom =
new() { units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString };

// convert and store all multipatch points per Part
List<List<SOG.Point>> allPoints = new();
Expand All @@ -52,19 +53,19 @@ public IReadOnlyList<Base> Convert(ACG.Multipatch target)
if (patchType == ACG.PatchType.TriangleStrip)
{
SGIS.GisMultipatchGeometry multipatch = target.CompleteMultipatchTriangleStrip(allPoints, idx);
multipatch.units = _contextStack.Current.SpeckleUnits;
multipatch.units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString;
converted.Add(multipatch);
}
else if (patchType == ACG.PatchType.Triangles)
{
SGIS.GisMultipatchGeometry multipatch = target.CompleteMultipatchTriangles(allPoints, idx);
multipatch.units = _contextStack.Current.SpeckleUnits;
multipatch.units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString;
converted.Add(multipatch);
}
else if (patchType == ACG.PatchType.TriangleFan)
{
SGIS.GisMultipatchGeometry multipatch = target.CompleteMultipatchTriangleFan(allPoints, idx);
multipatch.units = _contextStack.Current.SpeckleUnits;
multipatch.units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString;
converted.Add(multipatch);
}
// in case of RingMultipatch - return PolygonGeometry3d
Expand All @@ -78,10 +79,19 @@ public IReadOnlyList<Base> Convert(ACG.Multipatch target)
}

// first ring means a start of a new PolygonGeometry3d
polygonGeom = new() { voids = new List<SOG.Polyline>() };
polygonGeom = new()
{
voids = new List<SOG.Polyline>(),
units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString
};
List<double> pointCoords = allPoints[idx].SelectMany(x => new List<double>() { x.x, x.y, x.z }).ToList();

SOG.Polyline polyline = new() { value = pointCoords, units = _contextStack.Current.SpeckleUnits };
SOG.Polyline polyline =
new()
{
value = pointCoords,
units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString
};
polygonGeom.boundary = polyline;

// if it's already the last part, add to list
Expand All @@ -93,7 +103,12 @@ public IReadOnlyList<Base> Convert(ACG.Multipatch target)
else if (patchType == ACG.PatchType.Ring)
{
List<double> pointCoords = allPoints[idx].SelectMany(x => new List<double>() { x.x, x.y, x.z }).ToList();
SOG.Polyline polyline = new() { value = pointCoords, units = _contextStack.Current.SpeckleUnits };
SOG.Polyline polyline =
new()
{
value = pointCoords,
units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString
};

// every outer ring is oriented clockwise
bool isClockwise = polyline.IsClockwisePolygon();
Expand All @@ -106,7 +121,12 @@ public IReadOnlyList<Base> Convert(ACG.Multipatch target)
{
// add existing polygon to list, start a new polygon with a boundary
converted.Add(polygonGeom);
polygonGeom = new() { voids = new List<SOG.Polyline>(), boundary = polyline };
polygonGeom = new()
{
voids = new List<SOG.Polyline>(),
boundary = polyline,
units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString
};
}
// if it's already the last part, add to list
if (idx == target.PartCount - 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ namespace Speckle.Converters.ArcGIS3.ToSpeckle.Raw;
public class PolygonFeatureToSpeckleConverter : ITypedConverter<ACG.Polygon, IReadOnlyList<PolygonGeometry>>
{
private readonly ITypedConverter<ACG.ReadOnlySegmentCollection, SOG.Polyline> _segmentConverter;
private readonly IConversionContextStack<ArcGISDocument, ACG.Unit> _contextStack;

public PolygonFeatureToSpeckleConverter(ITypedConverter<ACG.ReadOnlySegmentCollection, SOG.Polyline> segmentConverter)
public PolygonFeatureToSpeckleConverter(
ITypedConverter<ACG.ReadOnlySegmentCollection, SOG.Polyline> segmentConverter,
IConversionContextStack<ArcGISDocument, ACG.Unit> contextStack
)
{
_segmentConverter = segmentConverter;
_contextStack = contextStack;
}

public IReadOnlyList<PolygonGeometry> Convert(ACG.Polygon target)
Expand All @@ -35,7 +40,12 @@ public IReadOnlyList<PolygonGeometry> Convert(ACG.Polygon target)
bool isExteriorRing = target.IsExteriorRing(idx);
if (isExteriorRing)
{
polygon = new() { boundary = polyline, voids = new List<SOG.Polyline>() };
polygon = new()
{
boundary = polyline,
voids = new List<SOG.Polyline>(),
units = _contextStack.Current.Document.ActiveCRSoffsetRotation.SpeckleUnitString
};
polygonList.Add(polygon);
}
else // interior part
Expand Down

0 comments on commit 957a4ed

Please sign in to comment.