示例#1
0
        private void RenderRoadInformation(ShapeFileFeatureLayer featureLayer, RouteSegment road)
        {
            InMemoryFeatureLayer currentRoadLayer = ((LayerOverlay)winformsMap1.Overlays["currentRoadOverlay"]).Layers["currentRoadLayer"] as InMemoryFeatureLayer;
            string  featureId          = road.FeatureId;
            Feature currentRoadFeature = featureLayer.FeatureSource.GetFeatureById(featureId, ReturningColumnsType.AllColumns);

            currentRoadLayer.InternalFeatures.Clear();
            currentRoadLayer.InternalFeatures.Add(currentRoadFeature);

            txtStartPoint.Text = String.Format("{0}, {1}", road.StartPoint.X.ToString("F4", CultureInfo.InvariantCulture), road.StartPoint.Y.ToString("F4", CultureInfo.InvariantCulture));
            txtEndPoint.Text   = String.Format("{0}, {1}", road.EndPoint.X.ToString("F4", CultureInfo.InvariantCulture), road.EndPoint.Y.ToString("F4", CultureInfo.InvariantCulture));
            LineShape line = ((MultilineShape)currentRoadFeature.GetShape()).Lines[0];

            txtLength.Text = Math.Round(line.GetLength(GeographyUnit.DecimalDegree, DistanceUnit.Meter), 4).ToString(CultureInfo.InvariantCulture);

            switch (road.RouteSegmentType)
            {
            case 0:
                txtRoadType.Text = "Local Road";
                break;

            case 1:
                txtRoadType.Text = "Major Road";
                break;

            case 2:
                txtRoadType.Text = "High Way";
                break;

            default:
                break;
            }
        }
示例#2
0
        private LineShape GetTangentForLinePosition(LineShape lineShape, double stationKM)
        {
            const double OFFSET_KM = 0.000000001;
            PointShape   tangentPointShape1, tangentPointShape2;
            double       offsetTangentStart = OFFSET_KM;
            double       offsetTangentEnd   = OFFSET_KM;
            LineShape    tangentLineShape;

            if (stationKM == 0.0)
            {
                offsetTangentStart = 0.0;
            }

            if (stationKM == lineShape.GetLength(GeographyUnit.Meter, DistanceUnit.Kilometer))
            {
                offsetTangentEnd = 0.0;
            }

            tangentPointShape1 = lineShape.GetPointOnALine(StartingPoint.FirstPoint, stationKM - offsetTangentStart,
                                                           GeographyUnit.Meter, DistanceUnit.Kilometer);
            tangentPointShape2 = lineShape.GetPointOnALine(StartingPoint.FirstPoint, stationKM + offsetTangentEnd,
                                                           GeographyUnit.Meter, DistanceUnit.Kilometer);
            tangentLineShape = new LineShape(new Vertex[] { new Vertex(tangentPointShape1), new Vertex(tangentPointShape2) });

            return(tangentLineShape);
        }
 private void MeasureRadius()
 {
     if (TrackMode == TrackMode.Circle)
     {
         if (TrackShapeLayer.InternalFeatures.Count > 0 && radiusLine != null)
         {
             double radius = radiusLine.GetLength(MapUnit, DistanceUnit);
             textBlock.Text = string.Format(CultureInfo.InvariantCulture, "{0:N3} {1}", radius, GetAbbreviateDistanceUnit(DistanceUnit));
         }
     }
 }
 private void DrawMeasureResult(GeoCanvas canvas)
 {
     if (TrackMode == TrackMode.Circle && isTracking)
     {
         if (TrackShapeLayer.InternalFeatures.Count > 0 && radiusLine != null)
         {
             double r = radiusLine.GetLength(mapUnit, distanceUnit);
             radiusValueString = string.Format(CultureInfo.InvariantCulture, "{0:N3} {1}", r, GetAbbreviateDistanceUnit(distanceUnit));
             canvas.DrawTextWithScreenCoordinate(radiusValueString, new GeoFont(),
                                                 new GeoSolidBrush(GeoColor.SimpleColors.Black), mouseScreenPointF.X,
                                                 mouseScreenPointF.Y, DrawingLevel.LabelLevel);
         }
     }
 }
        private LineShape GetLineOnALine(LineShape line, Vertex vertex1, Vertex vertex2, GeographyUnit unit)
        {
            LineShape result1 = new LineShape();
            LineShape result2 = new LineShape();

            int index1 = line.Vertices.IndexOf(vertex1);
            int index2 = line.Vertices.IndexOf(vertex2);

            if (index1 < index2)
            {
                for (int i = index1; i <= index2; i++)
                {
                    result1.Vertices.Add(line.Vertices[i]);
                }

                for (int i = index1; i >= 0; i--)
                {
                    result2.Vertices.Add(line.Vertices[i]);
                }

                for (int i = line.Vertices.Count - 2; i >= index2; i--)
                {
                    result2.Vertices.Add(line.Vertices[i]);
                }
            }
            else
            {
                for (int i = index2; i <= index1; i++)
                {
                    result1.Vertices.Add(line.Vertices[i]);
                }

                for (int i = index2; i >= 0; i--)
                {
                    result2.Vertices.Add(line.Vertices[i]);
                }

                for (int i = line.Vertices.Count - 2; i >= index1; i--)
                {
                    result2.Vertices.Add(line.Vertices[i]);
                }
            }

            double length1 = result1.GetLength(unit, DistanceUnit.Meter);
            double length2 = result2.GetLength(unit, DistanceUnit.Meter);

            return(length1 > length2 ? result2 : result1);
        }
示例#6
0
        protected override RouteSegment GetRouteSegmentByFeatureIdCore(string roadId)
        {
            Feature feature = featureSource.GetFeatureById(roadId, ReturningColumnsType.NoColumns);

            LineBaseShape shape       = feature.GetShape() as LineBaseShape;
            LineShape     sourceShape = ConvertLineBaseShapeToLines(shape)[0];

            sourceShape.Id = feature.Id;
            Collection <string> startIds = new Collection <string>();
            Collection <string> endIds   = new Collection <string>();

            GetAdjacentFeataureIds(featureSource, sourceShape, startIds, endIds);
            PointShape   startPoint = new PointShape(sourceShape.Vertices[0]);
            PointShape   endPoint   = new PointShape(sourceShape.Vertices[sourceShape.Vertices.Count - 1]);
            float        length     = (float)sourceShape.GetLength(GeographyUnit.Meter, DistanceUnit.Meter);
            RouteSegment road       = new RouteSegment(feature.Id, 0, length, startPoint, startIds, endPoint, endIds);

            return(road);
        }
示例#7
0
 public virtual float CalculateRoadCost(LineShape lineShape)
 {
     return((float)lineShape.GetLength(DataUnit, DistanceUnit));
 }
示例#8
0
 public virtual float CalculateRoadCost(LineShape lineShape)
 {
     return (float)lineShape.GetLength(DataUnit, DistanceUnit);
 }
示例#9
0
        private void TrackOverlay_TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e)
        {
            if (mapModel.MapControl.TrackOverlay.TrackMode == TrackMode.Polygon)
            {
                PolygonShape polygonShape = e.TrackShape as PolygonShape;
                if (polygonShape != null)
                {
                    double area     = -1;
                    string areaUnit = "sq.m.";
                    switch (SelectedUnitSystem)
                    {
                    case UnitSystem.Metric:
                        areaUnit = "sq.m.";
                        area     = polygonShape.GetArea(GeographyUnit.Meter, AreaUnit.SquareMeters);
                        break;

                    case UnitSystem.Imperial:
                        areaUnit = "ac.";
                        area     = polygonShape.GetArea(GeographyUnit.Meter, AreaUnit.Acres);
                        break;
                    }
                    if (area > 0)
                    {
                        string content = string.Format(CultureInfo.InvariantCulture, "Area: {0} {1}", area.ToString("N1"), areaUnit);
                        ShowPopup(new PointShape(polygonShape.OuterRing.Vertices[polygonShape.OuterRing.Vertices.Count - 2]), content);
                    }
                    mapModel.MapControl.TrackOverlay.TrackShapeLayer.InternalFeatures.LastOrDefault().Tag = "Measure";
                }
            }

            if (mapModel.MapControl.TrackOverlay.TrackMode == TrackMode.Line)
            {
                string    unit      = string.Empty;
                LineShape lineShape = e.TrackShape as LineShape;
                if (lineShape != null)
                {
                    double lenth = 0;
                    if (SelectedUnitSystem == UnitSystem.Metric)
                    {
                        lenth = lineShape.GetLength(GeographyUnit.Meter, DistanceUnit.Meter);
                        unit  = "m";
                        if (lenth >= 1000)
                        {
                            unit  = "km";
                            lenth = Math.Round(lenth / 1000d, 1, MidpointRounding.AwayFromZero);
                        }
                    }
                    else if (SelectedUnitSystem == UnitSystem.Imperial)
                    {
                        lenth = lineShape.GetLength(GeographyUnit.Meter, DistanceUnit.Feet);
                        unit  = "ft";
                        if (lenth >= 5280)
                        {
                            unit  = "mi";
                            lenth = Math.Round(lenth / 5280d, 1, MidpointRounding.AwayFromZero);
                        }
                    }

                    string lengthString = lenth.ToString("N1");
                    string content      = string.Format(CultureInfo.InvariantCulture, "Total Length: {0} {1}", lengthString, unit);
                    ShowPopup(new PointShape(lineShape.Vertices[lineShape.Vertices.Count - 1]), content);
                    mapModel.MapControl.TrackOverlay.TrackShapeLayer.InternalFeatures.LastOrDefault().Tag = "Measure";
                }
            }
        }
        private void btnCalculate_Click(object sender, RoutedEventArgs e)
        {
            //Get a reference to the results MapShapeLayer and clear it so we can display our new results.
            MapShapeLayer results = (MapShapeLayer)((LayerOverlay)mapView.Overlays["layerOverlay"]).Layers["Results"];

            results.MapShapes.Clear();

            //Get a reference to the test data layer.
            InMemoryFeatureLayer testDataLayer = (InMemoryFeatureLayer)((LayerOverlay)mapView.Overlays["layerOverlay"]).Layers["TestData"];

            //Check to see if the test data has been edited.
            if (mapView.EditOverlay.EditShapesLayer.InternalFeatures.Count > 0)
            {
                //Loop through the edited test data and update the test data layer.
                testDataLayer.EditTools.BeginTransaction();
                foreach (Feature feature in mapView.EditOverlay.EditShapesLayer.InternalFeatures)
                {
                    testDataLayer.EditTools.Update(feature.CloneDeep());
                }
                testDataLayer.EditTools.CommitTransaction();
                //Clear out the EditOverlay since we are done editing.
                mapView.EditOverlay.EditShapesLayer.InternalFeatures.Clear();
                //Since we are done editing, turn visibility back on the for the layer overlay so we can see our test data again.
                mapView.Overlays["layerOverlay"].IsVisible = true;
            }

            //Get the test point feature from the test data layer.
            Feature testPointFeature = testDataLayer.QueryTools.GetFeaturesByColumnValue("Name", "TestPoint", ReturningColumnsType.AllColumns)[0];
            //Get the test line feature from the test data layer.
            Feature testLineFeature = testDataLayer.QueryTools.GetFeaturesByColumnValue("Name", "TestLine", ReturningColumnsType.AllColumns)[0];
            //Take the test line feature and create a line shape so we can use line-specific APIs for finding the shortest line and line-on-line.
            LineShape testLine = new MultilineShape(testLineFeature.GetWellKnownText()).Lines[0];

            //Calculate the shortest line between our test line and test point.
            LineShape shortestLineResult = testLine.GetShortestLineTo(testPointFeature.GetShape(), GeographyUnit.Meter).Lines[0];
            //Take the result and create a MapShape so we can display the shortest line on the map in a blue color.
            MapShape shortestLine = new MapShape(new Feature(shortestLineResult));

            shortestLine.ZoomLevels.ZoomLevel01.DefaultLineStyle    = LineStyle.CreateSimpleLineStyle(GeoColors.Blue, 4, false);
            shortestLine.ZoomLevels.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            results.MapShapes.Add("ShortestLine", shortestLine);
            string message = "Length of Blue Line is: " + shortestLineResult.GetLength(GeographyUnit.Meter, DistanceUnit.Kilometer).ToString() + " KM" + '\n';

            //Split the test line from the left side based on where the shortest line touches it.
            LineBaseShape leftSideOfLineResult = testLine.GetLineOnALine(new PointShape(testLine.Vertices[0]), new PointShape(shortestLineResult.Vertices[0]));

            //Make sure the split was valid and the closest point wasn't at the beginning or end of the line.
            if (leftSideOfLineResult.Validate(ShapeValidationMode.Simple).IsValid)
            {
                MapShape leftSideOfLine = new MapShape(new Feature(leftSideOfLineResult));
                leftSideOfLine.ZoomLevels.ZoomLevel01.DefaultLineStyle    = LineStyle.CreateSimpleLineStyle(GeoColors.Green, 2, false);
                leftSideOfLine.ZoomLevels.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
                results.MapShapes.Add("LeftSideofLine", leftSideOfLine);
                message += "Length of Green Line is: " + leftSideOfLineResult.GetLength(GeographyUnit.Meter, DistanceUnit.Kilometer).ToString() + " KM" + '\n';
            }

            //Split the test line from the right side based on where the shortest line touches it.
            LineBaseShape rightSideOfLineResult = testLine.GetLineOnALine(new PointShape(shortestLineResult.Vertices[0]), new PointShape(testLine.Vertices[testLine.Vertices.Count - 1]));

            //Make sure the split was valid and the closest point wasn't at the beginning or end of the line.
            if (rightSideOfLineResult.Validate(ShapeValidationMode.Simple).IsValid)
            {
                MapShape rightSideOfLine = new MapShape(new Feature(rightSideOfLineResult));
                rightSideOfLine.ZoomLevels.ZoomLevel01.DefaultLineStyle    = LineStyle.CreateSimpleLineStyle(GeoColors.Yellow, 2, false);
                rightSideOfLine.ZoomLevels.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
                results.MapShapes.Add("RightSideofLine", rightSideOfLine);
                message += "Length of Yellow Line is: " + rightSideOfLineResult.GetLength(GeographyUnit.Meter, DistanceUnit.Kilometer).ToString() + " KM" + '\n';
            }
            //Display the length of each line in kilometers.
            message += "Length of Red Line is: " + testLine.GetLength(GeographyUnit.Meter, DistanceUnit.Kilometer).ToString() + " KM";
            mapView.Refresh();
            MessageBox.Show(message, "Results");
        }