private void SetProfileProperty(ProfileLine profileSessionProfileLine) { var profileProperty = new ProfileProperties(); profileProperty.LineId = profileSessionProfileLine.Id; var profileSurfacePoints = _profileSession.ProfileSurfaces.FirstOrDefault(surface => surface.LineId == profileSessionProfileLine.Id).ProfileSurfacePoints; profileProperty.MaxHeight = profileSurfacePoints.Max(point => point.Z); profileProperty.MinHeight = profileSurfacePoints.Min(point => point.Z); var angles = FindAngles(profileSurfacePoints); profileProperty.MaxAngle = angles.Exists(angle => angle > 0) ? Math.Abs(angles.Where(angle => angle > 0).Max()) : 0; profileProperty.MinAngle = angles.Exists(angle => angle < 0) ? Math.Abs(angles.Where(angle => angle < 0).Min()) : 0; profileProperty.PathLength = FindLength(profileSurfacePoints); profileProperty.Azimuth = profileSessionProfileLine.Azimuth; profileProperty.ObserverHeight = _defaultObserverHeight; _surfaceProfileChart.ProfilesProperties.Add(profileProperty); }
internal void AddProfileToTab(int profileSessionId, int lineId) { var profileSession = GetProfileSessionById(profileSessionId); if (profileSession != null) { ProfileLine profileLine = null; if (profileSession.DefinitionType == ProfileSettingsTypeEnum.Points) { profileLine = profileSession.ProfileLines.FirstOrDefault(); } else { profileLine = profileSession.ProfileLines.FirstOrDefault(line => line.Id == lineId); } if (profileLine != null) { var profileSurface = profileSession.ProfileSurfaces.First(surface => surface.LineId == profileLine.Id); GraphicsLayerManager.RemoveLineFromGraphic(profileSessionId, profileLine.Id); profileLine.SessionId = profileSessionId; graphsController.AddProfileToTab(profileLine, profileSurface); } } }
private static ProfileLine EndOfLineHandler(ProfileLine endLine, ProfileSurface allSurfaces, int pointIndex) { endLine.PointTo = new ProfilePoint { X = allSurfaces.ProfileSurfacePoints[pointIndex].X, Y = allSurfaces.ProfileSurfacePoints[pointIndex].Y }; return(endLine); }
internal void AddLineToGraph(ProfileLine profileLine, ProfileSurface profileSurface) { if (_profileSession.ProfileLines == null) { InitializeComposedGraph(profileLine, profileSurface); } else { AddProfile(profileLine, profileSurface); } }
private static void StartOfLineHandler(ref ProfileLine startLine, int startLineId, ProfileSurface allSurfaces, int pointIndex) { startLine.PointFrom = new ProfilePoint { X = allSurfaces.ProfileSurfacePoints[pointIndex].X, Y = allSurfaces.ProfileSurfacePoints[pointIndex].Y }; startLine.Id = startLineId; }
private void InitializeComposedGraph(ProfileLine profileLine, ProfileSurface profileSurface) { profileLine.Id = 1; profileSurface.LineId = 1; _profileSession.ProfileLines = new ProfileLine[] { profileLine }; _profileSession.ProfileSurfaces = new ProfileSurface[] { profileSurface }; _profileSession.SetSegments(profileLine.SpatialReference); _surfaceProfileChart.IsGraphEmptyHandler(false); _surfaceProfileChart.InitializeGraph(); _surfaceProfileChart.SetControlSize(); }
internal void ShowProfileOnMap(int profileId = -1, ProfileLine line = null) { var mapScale = View.ActiveView.FocusMap.MapScale; ProfileSession profile; if (profileId == -1) { profile = GetProfileSessionFromSelectedNode(); } else { profile = GetProfileSessionById(profileId); } if (profile == null) { logger.ErrorEx("Cannot find Selected Profiles set"); return; } IEnumerable <IGeometry> profileLines; if (line == null) { profileLines = profile.ProfileLines.Select(profileLine => profileLine.Line as IGeometry); } else { profileLines = new List <IGeometry> { line.Line }; } IEnvelope env = new EnvelopeClass(); foreach (var profileLine in profileLines) { env.Union(profileLine.Envelope); } EsriTools.PanToGeometry(View.ActiveView, env); if (profile.DefinitionType == ProfileSettingsTypeEnum.Primitives) { EsriTools.FlashGeometry(View.ActiveView.ScreenDisplay, profile.Segments.First().Polylines); } else { logger.InfoEx("Flashing geomerty"); EsriTools.FlashGeometry(View.ActiveView.ScreenDisplay, profileLines); logger.InfoEx("Geomerty flashed"); } }
private void AddProfile(ProfileLine profileLine, ProfileSurface profileSurface) { var lineId = _profileSession.ProfileLines.Last().Id + 1; profileLine.Id = lineId; profileSurface.LineId = lineId; var profileLines = new List <ProfileLine>(); var profileSurfaces = new List <ProfileSurface>(); profileLines.AddRange(_profileSession.ProfileLines); profileSurfaces.AddRange(_profileSession.ProfileSurfaces); profileLines.Add(profileLine); profileSurfaces.Add(profileSurface); _profileSession.ProfileLines = profileLines.ToArray(); _profileSession.ProfileSurfaces = profileSurfaces.ToArray(); _profileSession.SetSegments(profileLine.SpatialReference, _profileSession.ProfileLines.Last()); _surfaceProfileChart.InitializeProfile(); _surfaceProfileChart.SetControlSize(); }
private static List <ProfileLine> GetLines(ProfileSurface allSurface, ProfileSurface invisibleSurface, int sessionId) { var profileLines = new List <ProfileLine>(); var lineId = 1; var j = 0; var isInvisiblePointsFinished = false; if (invisibleSurface.ProfileSurfacePoints.Count() == 0) { isInvisiblePointsFinished = true; } var profileVisibleLine = new ProfileLine { Visible = true }; var profileInvisibleLine = new ProfileLine { Visible = false }; var profileVisiblePoints = new List <ProfileSurfacePoint>(); var profileInvisiblePoints = new List <ProfileSurfacePoint>(); for (int i = 0; i < allSurface.ProfileSurfacePoints.Count(); i++) { if (!isInvisiblePointsFinished && allSurface.ProfileSurfacePoints[i] == invisibleSurface.ProfileSurfacePoints[j]) { if (profileInvisiblePoints.Count == 0) { StartOfLineHandler(ref profileInvisibleLine, lineId, allSurface, i); lineId++; if (profileVisiblePoints.Count > 0) { profileLines.Add(EndOfLineHandler(profileVisibleLine, allSurface, i)); profileVisibleLine = new ProfileLine { Visible = true }; profileVisiblePoints = new List <ProfileSurfacePoint>(); } } if (i == allSurface.ProfileSurfacePoints.Count() - 1) { profileLines.Add(EndOfLineHandler(profileInvisibleLine, allSurface, i)); profileInvisibleLine = new ProfileLine { Visible = false }; profileInvisiblePoints = new List <ProfileSurfacePoint>(); } if (j == invisibleSurface.ProfileSurfacePoints.Count() - 1) { isInvisiblePointsFinished = true; } profileInvisiblePoints.Add(allSurface.ProfileSurfacePoints[i]); j++; } else { if (profileVisiblePoints.Count == 0) { StartOfLineHandler(ref profileVisibleLine, lineId, allSurface, i); lineId++; if (profileInvisiblePoints.Count > 0) { profileLines.Add(EndOfLineHandler(profileInvisibleLine, allSurface, i)); profileInvisibleLine = new ProfileLine { Visible = false }; profileInvisiblePoints = new List <ProfileSurfacePoint>(); } } if (i == allSurface.ProfileSurfacePoints.Count() - 1) { profileLines.Add(EndOfLineHandler(profileVisibleLine, allSurface, i)); profileVisibleLine = new ProfileLine { Visible = true }; profileVisiblePoints = new List <ProfileSurfacePoint>(); } profileVisiblePoints.Add(allSurface.ProfileSurfacePoints[i]); } } return(profileLines); }
internal void AddProfileToTab(ProfileLine profileLine, ProfileSurface profileSurface) { View.SetCurrentChart(); _surfaceProfileChartController.AddLineToGraph(profileLine, profileSurface); }
internal void InvokeIntersectionLinesDrawing(ProfileLine selectedLine, ProfileSession profileSession) { IntersectionLinesDrawing?.Invoke(selectedLine, profileSession); }
private static IEnumerable <ProfileLine> GetProfileLines(IFeatureClass profileLines) { var result = new List <ProfileLine>(); IQueryFilter queryFilter = new QueryFilter() { WhereClause = WhereAllRecords }; var allrecords = profileLines.Search(queryFilter, true); IFeature line = null; while ((line = allrecords.NextFeature()) != null) { if (line.Shape is IPointCollection points) { var from = points.Point[0]; var to = points.Point[points.PointCount - 1]; ILine ln = new Line() { FromPoint = from, ToPoint = to, SpatialReference = line.Shape.SpatialReference }; var transformedFrom = from.CloneWithProjecting(); var transformedTo = to.CloneWithProjecting(); IPolyline polyline = line.ShapeCopy as IPolyline; polyline.Project(EsriTools.Wgs84Spatialreference); var profileLine = new ProfileLine { PointFrom = new ProfilePoint { X = transformedFrom.X, Y = transformedFrom.Y }, PointTo = new ProfilePoint { X = transformedTo.X, Y = transformedTo.Y }, Id = line.OID, Length = polyline.Length, Line = polyline, SpatialReference = EsriTools.Wgs84Spatialreference, Azimuth = double.MinValue }; var vertices = profileLine.Vertices; if (vertices.Count() == 2) { profileLine.Azimuth = ln.Azimuth(); } else { profileLine.PointCollection = vertices.Select(p => { var pnt = p.CloneWithProjecting(); return(new ProfilePoint { X = pnt.X, Y = pnt.Y }); }).ToArray(); } result.Add(profileLine); } } Marshal.ReleaseComObject(allrecords); return(result); }
private void CalcIntesectionsWithLayers(ProfileLine selectedLine, ProfileSession profileSession) { var allIntersectionLines = new List <IntersectionsInLayer>(); var layers = View.GetLayers(); var spatialReference = ArcMap.Document.FocusMap.SpatialReference; List <IPolyline> polylines; List <ProfilePoint> pointsFrom; profileSession.Layers = new List <string>(); if (selectedLine == null) { return; } if (selectedLine.Line.SpatialReference != spatialReference) { selectedLine.Line.Project(spatialReference); } var lineSurface = profileSession.ProfileSurfaces.First(surface => surface.LineId == selectedLine.Id); var profileSegment = profileSession.Segments.First(segment => segment.LineId == selectedLine.Id); var distance = 0.0; if (profileSegment.IsPrimitive) { polylines = ProfileLinesConverter.ConvertLineToPrimitivePolylines(lineSurface, selectedLine.Line.SpatialReference); pointsFrom = profileSegment.Vertices; } else { polylines = new List <IPolyline> { selectedLine.Line }; pointsFrom = new List <ProfilePoint> { selectedLine.PointFrom }; } int j = 0; for (int n = 0; n < polylines.Count; n++) { var intersectionLines = new List <IntersectionsInLayer>(); for (int i = 0; i < layers.Count; i++) { if (!string.IsNullOrEmpty(layers[i])) { var layer = EsriTools.GetLayer(layers[i], ArcMap.Document.FocusMap); var lines = EsriTools.GetIntersections(polylines[n], layer); var layerFullName = $"Path/{layer.Name}"; if (!profileSession.Layers.Exists(sessionLayer => sessionLayer == layerFullName)) { profileSession.Layers.Add(layerFullName); } if (lines != null && lines.Count() > 0) { var layerType = (LayersEnum)Enum.GetValues(typeof(LayersEnum)).GetValue(i); var intersectionLine = new IntersectionsInLayer { Lines = ProfileLinesConverter.ConvertEsriPolylineToIntersectionLines(lines, pointsFrom[j], layerType, distance), Type = layerType, }; intersectionLine.SetDefaultColor(); intersectionLines.Add(intersectionLine); SetLayersForPoints(intersectionLine, lineSurface); } } } allIntersectionLines.AddRange(intersectionLines); if (polylines.Count > 1) { j++; if (n < polylines.Count - 1) { distance += EsriTools.CreatePolylineFromPoints(polylines[n].FromPoint, polylines[n + 1].FromPoint).Length; } } } graphsController.SetIntersections(allIntersectionLines, selectedLine.Id); }
public ProfileSession GenerateProfile( string profileSource, IEnumerable <IPolyline> profileLines, ProfileSettingsTypeEnum profileSettingsTypeEnum, int sessionId, string sessionName, double observHeight, string azimuthes) { string profileSourceName = GdbAccess.Instance.AddProfileLinesToCalculation(profileLines); var action = new ActionParam <string>() { ParamName = ActionParamNamesCore.Action, Value = ActionsEnum.bsp.ToString() }; string sdtnow = MilSpace.DataAccess.Helper.GetTemporaryNameSuffix(); var resuTable = $"{MilSpaceConfiguration.ConnectionProperty.TemporaryGDBConnection}\\StackProfile{sdtnow}"; var profileLineFeatureClass = GdbAccess.Instance.GetProfileLinesFeatureClass(profileSourceName); var prm = new List <IActionParam> { action, new ActionParam <string>() { ParamName = ActionParameters.FeatureClass, Value = profileLineFeatureClass }, new ActionParam <string>() { ParamName = ActionParameters.ProfileSource, Value = profileSource }, new ActionParam <string>() { ParamName = ActionParameters.DataWorkSpace, Value = resuTable }, new ActionParam <string>() { ParamName = ActionParameters.OutGraphName, Value = "" } }; var procc = new ActionProcessor(prm); var res = procc.Process <BoolResult>(); if (!res.Result) { if (res.Exception != null) { throw res.Exception; } //TODO: Log error throw new Exception(res.ErrorMessage); } //Take the table and import the data ISpatialReference currentSpatialreference = profileLines.First().SpatialReference; try { string tempTableName = $"StackProfile{sdtnow}"; ITable profiletable = GdbAccess.Instance.GetProfileTable(tempTableName); IFeatureClass lines = GdbAccess.Instance.GetCalcProfileFeatureClass(profileSourceName); IQueryFilter queryFilter = new QueryFilter() { WhereClause = WhereAllRecords }; ICursor featureCursor = profiletable.Search(queryFilter, true); IRow profileRow; int distanceFld = profiletable.FindField(FIRST_DIST_Field); int zFld = profiletable.FindField(FIRST_Z_Field); int idFld = profiletable.FindField(LINE_ID_Field); List <ProfileSurface> profileSurfaces = new List <ProfileSurface>(); ProfileSession session = new ProfileSession() { ProfileSurfaces = profileSurfaces.ToArray(), ProfileLines = GetProfileLines(lines).ToArray(), SessionId = sessionId, SessionName = sessionName, DefinitionType = profileSettingsTypeEnum, ObserverHeight = observHeight, SurfaceLayerName = profileSource, CreatedBy = Environment.UserName, CreatedOn = DateTime.Now, Shared = false, Azimuth = azimuthes }; Dictionary <int, List <ProfileSurfacePoint> > surface = new Dictionary <int, List <ProfileSurfacePoint> >(); int curLine = -1; IPolyline line = null; IEnumerable <IPoint> verticesCache; Dictionary <IPoint, ProfileSurfacePoint> mapProfilePointToVertex = new Dictionary <IPoint, ProfileSurfacePoint>(); Dictionary <IPoint, double> mapProfilePointToDistance = new Dictionary <IPoint, double>(); ProfileLine profileLine = null; verticesCache = new IPoint[0]; int pointsCount = 0; while ((profileRow = featureCursor.NextRow()) != null) { int lineId = Convert.ToInt32(profileRow.Value[idFld]); pointsCount++; if (!session.ProfileLines.Any(l => l.Id == lineId)) { throw new MilSpaceProfileLineNotFound(lineId, profileLineFeatureClass); } List <ProfileSurfacePoint> points; if (!surface.ContainsKey(lineId)) { points = new List <ProfileSurfacePoint>(); surface.Add(lineId, points); } else { points = surface[lineId]; } if (curLine != lineId) // data for new line { curLine = lineId; profileLine = session.ProfileLines.FirstOrDefault(l => l.Id == lineId); line = lines.GetFeature(profileLine.Id).Shape as IPolyline; verticesCache = line.Vertices(); mapProfilePointToVertex.ToList().ForEach(v => { if (!v.Value.IsEmpty) { v.Value.isVertex = true; } }); mapProfilePointToVertex = verticesCache.ToDictionary(k => k, t => new ProfileSurfacePoint()); mapProfilePointToDistance = verticesCache.ToDictionary(k => k, t => - 1.0); } //Returns the point with Origin (Taken from firstPoint) Spatial reference //var profilePointSource = EsriTools.GetPointFromAngelAndDistance(firstPoint, profileLine.Angel, (double)profileRow.Value[distanceFld]); //var profilePoint = profilePointSource.CloneWithProjecting(); // Try to define if this point is close to a vertex double distance = (double)profileRow.Value[distanceFld]; ProfileSurfacePoint newSurface = new ProfileSurfacePoint { Distance = distance, Z = (double)profileRow.Value[zFld], //X = profilePoint.X, //Y = profilePoint.Y }; IPoint point = new Point(); line.QueryPoint(esriSegmentExtension.esriNoExtension, newSurface.Distance, false, point); IProximityOperator proximity = point as IProximityOperator; foreach (var vertx in verticesCache) { var profilePoint = mapProfilePointToVertex[vertx]; if (mapProfilePointToDistance[vertx] == 0)// profilePoint.isVertex) { continue; } double localDistance = proximity.ReturnDistance(vertx); if (mapProfilePointToDistance[vertx] == -1 || mapProfilePointToDistance[vertx] > localDistance) { mapProfilePointToDistance[vertx] = localDistance; mapProfilePointToVertex[vertx] = newSurface; if (localDistance == 0) { newSurface.isVertex = true; } } } var projected = point.CloneWithProjecting(); newSurface.X = projected.X; newSurface.Y = projected.Y; points.Add(newSurface); } mapProfilePointToVertex.ToList().ForEach(v => { if (!v.Value.IsEmpty) { v.Value.isVertex = true; } }); //Delete temp table form the GDB GdbAccess.Instance.DeleteTemporarSource(tempTableName, profileSourceName); Marshal.ReleaseComObject(featureCursor); //TODO: Clean memo using Marhsaling IRow session.ProfileSurfaces = surface.Select(r => new ProfileSurface { LineId = r.Key, ProfileSurfacePoints = r.Value.ToArray() } ).ToArray(); return(session); } catch (MilSpaceCanotDeletePrifileCalcTable ex) { //TODO: Log error throw ex; } catch (MilSpaceDataException ex) { //TODO: Log error throw ex; } catch (Exception ex) { //TODO: Log error throw ex; } }
internal void InvokePanToSelectedProfile(int sessionId, ProfileLine line) { PanToSelectedProfile.Invoke(sessionId, line); }
private void PanToSelectedProfile(int sessionId, ProfileLine line) { ShowProfileOnMap(sessionId, line); }