private static bool IsWithinSegment(INetworkSegment segment, INetworkLocation location) { if (segment.Branch != location.Branch) { return(false); } var begin = segment.Chainage; var end = segment.EndChainage; if (!segment.DirectionIsPositive) { begin = segment.EndChainage; end = segment.Chainage; } //add some rounding margin begin += 0.000001; end -= 0.000001; if (begin < location.Chainage && location.Chainage < end) { return(true); } return(false); }
/// <summary> /// Returns the NetworkLocations for segment in the source coverage. If the start and/or end location of the /// segment are not in the source they are added. /// </summary> /// <param name="segment"></param> /// <param name="source"></param> /// <param name="addNewLocations">Should the end and start of the segment be returned?</param> /// <returns></returns> public static IEnumerable <INetworkLocation> GetLocationsForSegment(INetworkSegment segment, INetworkCoverage source, bool addNewLocations) { double min = Math.Min(segment.EndChainage, segment.Chainage); double max = Math.Max(segment.EndChainage, segment.Chainage); IList <INetworkLocation> locations = new List <INetworkLocation>(); if (addNewLocations) { var startChainage = segment.DirectionIsPositive ? segment.Chainage : segment.EndChainage; locations.Add(new NetworkLocation(segment.Branch, startChainage)); } //need a cast here ..but we are sure since we just built it. foreach (var location in source.Locations.Values.Where( nl => nl.Branch == segment.Branch && nl.Chainage >= min && nl.Chainage <= max)) { if (!locations.Contains(location)) { locations.Add(location); } } if (addNewLocations) { var endChainage = segment.DirectionIsPositive ? segment.EndChainage : segment.Chainage; var location = new NetworkLocation(segment.Branch, endChainage); if (!locations.Contains(location)) { locations.Add(location); } } return(!segment.DirectionIsPositive ? locations.Reverse() : locations); }
/// <summary> /// Returns the NetworkLocations for segment in the source coverage. If the start and/or end location of the /// segment are not in the source they are added. /// </summary> /// <param name="segment"></param> /// <param name="source"></param> /// <param name="addNewLocations">Should the end and start of the segment be returned?</param> /// <returns></returns> public static IEnumerable<INetworkLocation> GetLocationsForSegment(INetworkSegment segment, INetworkCoverage source, bool addNewLocations) { double min = Math.Min(segment.EndChainage, segment.Chainage); double max = Math.Max(segment.EndChainage, segment.Chainage); IList<INetworkLocation> locations = new List<INetworkLocation>(); if (addNewLocations) { var startChainage = segment.DirectionIsPositive ? segment.Chainage : segment.EndChainage; locations.Add(new NetworkLocation(segment.Branch, startChainage)); } //need a cast here ..but we are sure since we just built it. foreach (var location in source.Locations.Values.Where( nl => nl.Branch == segment.Branch && nl.Chainage >= min && nl.Chainage <= max)) { if (!locations.Contains(location)) { locations.Add(location); } } if (addNewLocations) { var endChainage = segment.DirectionIsPositive ? segment.EndChainage : segment.Chainage; var location = new NetworkLocation(segment.Branch, endChainage); if (!locations.Contains(location)) { locations.Add(location); } } return !segment.DirectionIsPositive ? locations.Reverse() : locations; }
public virtual double Evaluate(INetworkSegment segment) { //assumes the segments' index matches the location index var location = Locations.Values[Segments.Values.IndexOf(segment)]; return(Evaluate(location)); }
public override bool Render(IFeature feature, Graphics g, ILayer layer) { var segmentsLayer = (NetworkCoverageSegmentLayer)layer; var coverage = ((NetworkCoverageFeatureCollection)layer.DataSource).RenderedCoverage; IEnvelope mapExtents = layer.Map.Envelope; var sliceValues = coverage.GetValues(); // 1 find the segments withing the current extend var segments = coverage.Segments.Values;//.Where(seg => seg.Geometry.EnvelopeInternal.Intersects(mapExtents)).ToList(); for (int i = 0; i < segments.Count; i++) { INetworkSegment segment = segments[i]; if (segment.Geometry.EnvelopeInternal.Intersects(mapExtents) && sliceValues.Count > 0) { // 2 get the values for this segment // if SegmentGenerationMethod == SegmentGenerationMethod.RouteBetweenLocations the segments and // location do not have to match; return default value double value = coverage.SegmentGenerationMethod == SegmentGenerationMethod.RouteBetweenLocations ? 0 : (double)sliceValues[i]; // 3 use the Theme of the layer to draw var style = (VectorStyle)segmentsLayer.Theme.GetStyle(value); VectorRenderingHelper.RenderGeometry(g, layer.Map, segment.Geometry, style, null, true); } } return(true); }
public virtual double Evaluate(INetworkSegment segment) { //assumes the segments' index matches the location index #if MONO var location = (INetworkLocation)((IMultiDimensionalArray)Locations.Values)[Segments.Values.IndexOf(segment)]; #else var location = Locations.Values[Segments.Values.IndexOf(segment)]; #endif return(Evaluate(location)); }
private static void DrawSegment(VectorLayer segmentsLayer, INetworkCoverage coverage, ITheme theme, int segmentNumber, IList<double> allBranchLocationValues, bool firstSegment, bool lastSegment, Graphics graphics, INetworkSegment segment, VectorStyle defaultStyle, double offset) { var valueAtStart = allBranchLocationValues[segmentNumber * 2]; var value = allBranchLocationValues[segmentNumber * 2 + 1]; var valueAtEnd = allBranchLocationValues[segmentNumber * 2 + 2]; // extract based on valueAtStart and valueAtEnd the colors from the var styleStart = (theme != null) ? (VectorStyle)theme.GetStyle(valueAtStart) : segmentsLayer.Style; var themeStyle = (theme != null) ? (VectorStyle)theme.GetStyle(value) : segmentsLayer.Style; var styleEnd = (theme != null) ? (VectorStyle)theme.GetStyle(valueAtEnd) : segmentsLayer.Style; // check if within limits (preventing GDI+ overflow on 'ultrazoom') var strokes = Transform.TransformToImage((ILineString)segment.Geometry, segmentsLayer.Map); if (strokes.Any(s => !graphics.ClipBounds.Contains(s))) return; if (firstSegment && lastSegment) { // 1 segment; render segement based on coverage.Locations.InterpolationType if (coverage.Locations.ExtrapolationType == ExtrapolationType.None) { VectorRenderingHelper.RenderGeometry(graphics, segmentsLayer.Map, segment.Geometry, defaultStyle, null, true); return; } if (coverage.Locations.ExtrapolationType == ExtrapolationType.Linear) { VectorRenderingHelper.RenderGeometry(graphics, segmentsLayer.Map, segment.Geometry, themeStyle, null, true); return; } // todo use proper colors/styles from Theme; now 'via' styles are ignored. var kcolors = new[] { ((SolidBrush) styleStart.Fill).Color, ((SolidBrush) themeStyle.Fill).Color, ((SolidBrush) styleEnd.Fill).Color }; var kpositions = new[] { 0.0F, (float)((offset - segment.Chainage) / segment.Length), 1.0F }; DrawStrokesLinear(graphics, strokes, (int)themeStyle.Line.Width, kcolors, kpositions); return; } var positions = new[] { 0.0F, (float) ((offset - segment.Chainage)/segment.Length), (float) ((offset - segment.Chainage)/segment.Length), 1.0F }; var colors = CreateBeginEndColors(coverage, firstSegment, lastSegment, GetStyleColor(themeStyle), GetStyleColor(styleStart), GetStyleColor(styleEnd), GetStyleColor(defaultStyle)); // todo use proper colors/styles from Theme; now 'via' styles are ignored. if (!segment.Geometry.IsEmpty) { DrawStrokesLinear(graphics, strokes, (int)themeStyle.Line.Width, colors, positions); } }
private static bool IsWithinSegment(INetworkSegment segment,INetworkLocation location) { if (segment.Branch != location.Branch) return false; var begin = segment.Chainage; var end = segment.EndChainage; if (!segment.DirectionIsPositive) { begin = segment.EndChainage; end = segment.Chainage; } //add some rounding margin begin += 0.000001; end -= 0.000001; if (begin < location.Chainage && location.Chainage < end) return true; return false; }
private static void DrawSegment(VectorLayer segmentsLayer, INetworkCoverage coverage, ITheme theme, int segmentNumber, IList <double> allBranchLocationValues, bool firstSegment, bool lastSegment, Graphics graphics, INetworkSegment segment, VectorStyle defaultStyle, double offset) { var valueAtStart = allBranchLocationValues[segmentNumber * 2]; var value = allBranchLocationValues[segmentNumber * 2 + 1]; var valueAtEnd = allBranchLocationValues[segmentNumber * 2 + 2]; // extract based on valueAtStart and valueAtEnd the colors from the var styleStart = (theme != null) ? (VectorStyle)theme.GetStyle(valueAtStart) : segmentsLayer.Style; var themeStyle = (theme != null) ? (VectorStyle)theme.GetStyle(value) : segmentsLayer.Style; var styleEnd = (theme != null) ? (VectorStyle)theme.GetStyle(valueAtEnd) : segmentsLayer.Style; if (firstSegment && lastSegment) { // 1 segment; render segement based on coverage.Locations.InterpolationType if (coverage.Locations.ExtrapolationType == ExtrapolationType.None) { VectorRenderingHelper.RenderGeometry(graphics, segmentsLayer.Map, segment.Geometry, defaultStyle, null, true); return; } if (coverage.Locations.ExtrapolationType == ExtrapolationType.Linear) { VectorRenderingHelper.RenderGeometry(graphics, segmentsLayer.Map, segment.Geometry, themeStyle, null, true); return; } // todo use proper colors/styles from Theme; now 'via' styles are ignored. var kcolors = new[] { ((SolidBrush)styleStart.Fill).Color, ((SolidBrush)themeStyle.Fill).Color, ((SolidBrush)styleEnd.Fill).Color }; var kpositions = new[] { 0.0F, (float)((offset - segment.Offset) / segment.Length), 1.0F }; DrawStrokesLinear(graphics, Transform.TransformToImage((ILineString)segment.Geometry, segmentsLayer.Map), (int)themeStyle.Line.Width, kcolors, kpositions); return; } var positions = new[] { 0.0F, (float)((offset - segment.Offset) / segment.Length), (float)((offset - segment.Offset) / segment.Length), 1.0F }; var colors = CreateBeginEndColors(coverage, firstSegment, lastSegment, GetStyleColor(themeStyle), GetStyleColor(styleStart), GetStyleColor(styleEnd), GetStyleColor(defaultStyle)); // todo use proper colors/styles from Theme; now 'via' styles are ignored. if (!segment.Geometry.IsEmpty) { DrawStrokesLinear(graphics, Transform.TransformToImage((ILineString)segment.Geometry, segmentsLayer.Map), (int)themeStyle.Line.Width, colors, positions); } }