-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create custom CRS; use RevitProjectInfo on Receive
- Loading branch information
1 parent
483fe7d
commit 8cc400c
Showing
5 changed files
with
83 additions
and
2 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
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
64 changes: 64 additions & 0 deletions
64
DUI3-DX/Converters/ArcGIS/Speckle.Converters.ArcGIS3/Utils/CRSorigin.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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using ArcGIS.Core.Geometry; | ||
using Objects.BuiltElements.Revit; | ||
using Speckle.Core.Models; | ||
|
||
namespace Speckle.Converters.ArcGIS3.Utils; | ||
|
||
/// <summary> | ||
/// Container with origin coordinates and rotation angle | ||
/// </summary> | ||
public readonly struct CRSorigin | ||
{ | ||
public double LatDegrees { get; } | ||
public double LonDegrees { get; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of <see cref="CRSorigin"/>. | ||
/// </summary> | ||
/// <param name="latDegrees">Latitude (Y) in degrees.</param> | ||
/// <param name="lonDegrees">Longitude (X) in degrees.</param> | ||
public CRSorigin(double latDegrees, double lonDegrees) | ||
{ | ||
LatDegrees = latDegrees; | ||
LonDegrees = lonDegrees; | ||
} | ||
|
||
public static CRSorigin? FromRevitData(Base rootObject) | ||
{ | ||
foreach (KeyValuePair<string, object?> prop in rootObject.GetMembers(DynamicBaseMemberType.Dynamic)) | ||
{ | ||
if (prop.Key == "info") | ||
{ | ||
ProjectInfo? revitProjInfo = (ProjectInfo?)rootObject[prop.Key]; | ||
if (revitProjInfo != null) | ||
{ | ||
try | ||
{ | ||
double lat = Convert.ToDouble(revitProjInfo["latitude"]); | ||
double lon = Convert.ToDouble(revitProjInfo["longitude"]); | ||
double trueNorth; | ||
if (revitProjInfo["locations"] is List<Base> locationList && locationList.Count > 0) | ||
{ | ||
Base location = locationList[0]; | ||
trueNorth = Convert.ToDouble(location["trueNorth"]); | ||
} | ||
return new CRSorigin(lat * 180 / Math.PI, lon * 180 / Math.PI); | ||
} | ||
catch (Exception ex) when (ex is FormatException || ex is InvalidCastException || ex is OverflowException) | ||
{ | ||
// origin not found, do nothing | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public SpatialReference CreateCustomCRS() | ||
{ | ||
string wktString = | ||
$"PROJCS[\"unknown\", GEOGCS[\"unknown\", DATUM[\"WGS_1984\", SPHEROID[\"WGS 84\", 6378137, 298.257223563], AUTHORITY[\"EPSG\", \"6326\"]], PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433]], PROJECTION[\"Transverse_Mercator\"], PARAMETER[\"latitude_of_origin\", {LatDegrees}], PARAMETER[\"central_meridian\", {LonDegrees}], PARAMETER[\"scale_factor\", 1], PARAMETER[\"false_easting\", 0], PARAMETER[\"false_northing\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"Easting\", EAST], AXIS[\"Northing\", NORTH]]"; | ||
return SpatialReferenceBuilder.CreateSpatialReference(wktString); | ||
} | ||
} |
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