Beispiel #1
0
        private void AndroidMapMapSingleTap(object sender, Android.Views.MotionEvent e)
        {
            PointF     location = new PointF(e.GetX(), e.GetY());
            PointShape position = ExtentHelper.ToWorldCoordinate(androidMap.CurrentExtent, location.X,
                                                                 location.Y, androidMap.Width, androidMap.Height);

            LayerOverlay overlay   = androidMap.Overlays["RoadOverlay"] as LayerOverlay;
            FeatureLayer roadLayer = overlay.Layers["TXlkaA40"] as FeatureLayer;

            LayerOverlay         highlightOverlay = androidMap.Overlays["HighlightOverlay"] as LayerOverlay;
            InMemoryFeatureLayer highlightLayer   = (InMemoryFeatureLayer)highlightOverlay.Layers["HighlightLayer"];

            roadLayer.Open();
            Collection <Feature> selectedFeatures = roadLayer.QueryTools.GetFeaturesNearestTo(position, GeographyUnit.DecimalDegree, 1, new string[1] {
                "fename"
            });

            roadLayer.Close();

            if (selectedFeatures.Count > 0)
            {
                LineBaseShape lineShape = (LineBaseShape)selectedFeatures[0].GetShape();
                highlightLayer.Open();
                highlightLayer.InternalFeatures.Clear();
                highlightLayer.InternalFeatures.Add(new Feature(lineShape));
                highlightLayer.Close();

                double length        = lineShape.GetLength(GeographyUnit.DecimalDegree, DistanceUnit.Meter);
                string lengthMessage = string.Format(CultureInfo.InvariantCulture, "{0} has a length of {1:F2} meters.", selectedFeatures[0].ColumnValues["fename"].Trim(), length);

                messageLabel.Text = lengthMessage;
                highlightOverlay.Refresh();
            }
        }
Beispiel #2
0
        protected override Road GetRoadByIdCore(string roadId)
        {
            Feature feature = featureSource.GetFeatureById(roadId, ReturningColumnsType.NoColumns);

            LineBaseShape          sourceShape = (LineBaseShape)feature.GetShape();
            Collection <LineShape> lines       = ConvertLineBaseShapeToLines(sourceShape);

            List <string> adjacentIDs = new List <string>();

            foreach (LineShape line in lines)
            {
                Collection <Feature> features = featureSource.GetFeaturesInsideBoundingBox(line.GetBoundingBox(), ReturningColumnsType.NoColumns);
                foreach (Feature tempFeature in features)
                {
                    BaseShape tempShape = tempFeature.GetShape();
                    if (feature.Id != tempFeature.Id && line.Intersects(tempShape))
                    {
                        adjacentIDs.Add(tempFeature.Id);
                    }
                }
            }
            //adjacentIDs.Sort();

            PointShape center  = sourceShape.GetCenterPoint();
            float      centerX = (float)center.X;
            float      centerY = (float)center.Y;
            float      length  = (float)sourceShape.GetLength(GeographyUnit.Meter, DistanceUnit.Meter);
            Road       road    = new Road(roadId, RoadType.LocalRoad, length, adjacentIDs, centerX, centerY, roadId);

            return(road);
        }
Beispiel #3
0
        public string GetLengthOfFeature(Map map, GeoCollection <object> args)
        {
            PointShape point = new PointShape(Convert.ToDouble(args[0]), Convert.ToDouble(args[1]));

            FeatureLayer         worldLayer  = (FeatureLayer)map.StaticOverlay.Layers["RoadLayer"];
            InMemoryFeatureLayer streetLayer = (InMemoryFeatureLayer)map.DynamicOverlay.Layers["StreetLayer"];

            streetLayer.InternalFeatures.Clear();

            worldLayer.Open();
            Collection <Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesNearestTo(point, GeographyUnit.DecimalDegree, 1, new string[1] {
                "FENAME"
            });

            worldLayer.Close();

            string popupContentHtml = string.Empty;

            if (selectedFeatures.Count > 0)
            {
                LineBaseShape lineShape   = (LineBaseShape)selectedFeatures[0].GetShape();
                double        length      = lineShape.GetLength(GeographyUnit.DecimalDegree, DistanceUnit.Meter);
                string        contentHtml = "<span style='color:red'>{0}</span> has a length of <span style='color:red'>{1:N0}</span> meters.";
                string        information = string.Format(contentHtml, selectedFeatures[0].ColumnValues["FENAME"].Trim(), length);
                popupContentHtml = "<div style='font-size:10px; font-family:verdana; padding:4px;'>" + information + "</div>";

                streetLayer.InternalFeatures.Add("Street", new Feature(lineShape));
            }

            return(popupContentHtml);
        }
Beispiel #4
0
        private void winformsMap1_MapClick(object sender, MapClickWinformsMapEventArgs e)
        {
            FeatureLayer worldLayer = winformsMap1.FindFeatureLayer("RoadLayer");

            // Find the road the user clicked on.
            worldLayer.Open();
            Collection <Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesNearestTo(e.WorldLocation, GeographyUnit.DecimalDegree, 1, new string[1] {
                "FENAME"
            });

            worldLayer.Close();

            //Determine the length of the road.
            if (selectedFeatures.Count > 0)
            {
                LineBaseShape lineShape = (LineBaseShape)selectedFeatures[0].GetShape();
                double        length    = lineShape.GetLength(GeographyUnit.DecimalDegree, DistanceUnit.Meter);
                MessageBox.Show(string.Format(CultureInfo.InvariantCulture, "{0} has a length of {1:F2} meters.", selectedFeatures[0].ColumnValues["FENAME"].Trim(), length), "Length", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
            }
        }
        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");
        }