public void AddRouteSegmentInfo(RouteSegmentInfo routeSegmentInfo) { _routeSegmentInfos.Add(routeSegmentInfo.Id, routeSegmentInfo); var reader = new NetTopologySuite.IO.GeoJsonReader(); // Calculate length var line = reader.Read <LineString>("{ \"type\": \"LineString\", \"coordinates\": " + routeSegmentInfo.Geometry.GeoJsonCoordinates + "}"); double length = 0; for (int i = 1; i < line.NumPoints; i++) { var sCoord = new GeoCoordinate(line.GetPointN(i - 1).Y, line.GetPointN(i - 1).X); var eCoord = new GeoCoordinate(line.GetPointN(i).Y, line.GetPointN(i).X); length += sCoord.GetDistanceTo(eCoord); } routeSegmentInfo.Length = length; // Add object relations to facilitate easier and faster lookup and traversal routeSegmentInfo.FromRouteNode = GetRouteNodeInfo(routeSegmentInfo.FromRouteNodeId); routeSegmentInfo.ToRouteNode = GetRouteNodeInfo(routeSegmentInfo.ToRouteNodeId); ((RouteNodeInfo)routeSegmentInfo.FromRouteNode).AddOutgoingSegment(routeSegmentInfo); ((RouteNodeInfo)routeSegmentInfo.ToRouteNode).AddIngoingSegment(routeSegmentInfo); }
private RouteSegment CreateRouteSegment(dynamic routeSegment) { var mappedRouteSegment = new RouteSegment { Mrid = new Guid(routeSegment.mrid.ToString()), Coord = (JObject)routeSegment.coord is null ? null : Convert.FromBase64String(routeSegment.coord.wkb.ToString()), Username = routeSegment.user_name.ToString(), WorkTaskMrid = routeSegment.work_task_mrid.ToString() == string.Empty ? System.Guid.Empty : new Guid(routeSegment.work_task_mrid.ToString()), ApplicationName = routeSegment.application_name.ToString(), MarkAsDeleted = (bool)routeSegment.marked_to_be_deleted, ApplicationInfo = routeSegment.application_info.ToString(), DeleteMe = (bool)routeSegment.delete_me, LifeCycleInfo = new LifecycleInfo( _infoMapper.MapDeploymentState((string)routeSegment.lifecycle_deployment_state), (DateTime?)routeSegment.lifecycle_installation_date, (DateTime?)routeSegment.lifecycle_removal_date ), MappingInfo = new MappingInfo( _infoMapper.MapMappingMethod((string)routeSegment.mapping_method), (string)routeSegment.mapping_vertical_accuracy, (string)routeSegment.mapping_horizontal_accuracy, (DateTime?)routeSegment.mapping_survey_date, (string)routeSegment.mapping_source_info ), NamingInfo = new NamingInfo( (string)routeSegment.naming_name, (string)routeSegment.naming_description ), SafetyInfo = new SafetyInfo( (string)routeSegment.safety_classification, (string)routeSegment.safety_remark ), RouteSegmentInfo = new RouteSegmentInfo( _infoMapper.MapRouteSegmentKind((string)routeSegment.routesegment_kind), (string)routeSegment.routesegment_width, (string)routeSegment.routesegment_height ) }; // Make fully empty objects into nulls. mappedRouteSegment.LifeCycleInfo = AreAnyPropertiesNotNull <LifecycleInfo>(mappedRouteSegment.LifeCycleInfo) ? mappedRouteSegment.LifeCycleInfo : null; mappedRouteSegment.MappingInfo = AreAnyPropertiesNotNull <MappingInfo>(mappedRouteSegment.MappingInfo) ? mappedRouteSegment.MappingInfo : null; mappedRouteSegment.NamingInfo = AreAnyPropertiesNotNull <NamingInfo>(mappedRouteSegment.NamingInfo) ? mappedRouteSegment.NamingInfo : null; mappedRouteSegment.RouteSegmentInfo = AreAnyPropertiesNotNull <RouteSegmentInfo>(mappedRouteSegment.RouteSegmentInfo) ? mappedRouteSegment.RouteSegmentInfo : null; mappedRouteSegment.SafetyInfo = AreAnyPropertiesNotNull <SafetyInfo>(mappedRouteSegment.SafetyInfo) ? mappedRouteSegment.SafetyInfo : null; return(mappedRouteSegment); }