Beispiel #1
0
        protected override RectangleShape GetBoundingBoxCore()
        {
            RectangleShape boundingBox = null;

            if (!LoadingFromShapeFile)
            {
                if (firstInputFeatureLayer.InternalFeatures.Count > 0)
                {
                    firstInputFeatureLayer.Open();
                    boundingBox = firstInputFeatureLayer.GetBoundingBox();
                }

                if (secondInputFeatureLayer.InternalFeatures.Count > 0)
                {
                    secondInputFeatureLayer.Open();
                    if (boundingBox != null)
                    {
                        boundingBox.ExpandToInclude(secondInputFeatureLayer.GetBoundingBox());
                    }
                    else
                    {
                        boundingBox = secondInputFeatureLayer.GetBoundingBox();
                    }
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(firstShapeFilePathName))
                {
                    ShapeFileFeatureLayer coveredShapeFileFeatureLayer = new ShapeFileFeatureLayer(firstShapeFilePathName);
                    coveredShapeFileFeatureLayer.Open();
                    boundingBox = coveredShapeFileFeatureLayer.GetBoundingBox();
                    coveredShapeFileFeatureLayer.Close();
                }
                if (!string.IsNullOrEmpty(secondShapeFilePathName))
                {
                    ShapeFileFeatureLayer coveringShapeFileFeatureLayer = new ShapeFileFeatureLayer(secondShapeFilePathName);
                    coveringShapeFileFeatureLayer.Open();
                    if (boundingBox == null)
                    {
                        boundingBox = coveringShapeFileFeatureLayer.GetBoundingBox();
                    }
                    else
                    {
                        boundingBox.ExpandToInclude(coveringShapeFileFeatureLayer.GetBoundingBox());
                    }
                    coveringShapeFileFeatureLayer.Close();
                }
            }
            return(boundingBox);
        }
Beispiel #2
0
        private void btnRoute_Click(object sender, EventArgs e)
        {
            RtgRoutingSource routingSource = new RtgRoutingSource(@"..\..\SampleData\Austinstreets.rtg");
            RoutingEngine    routingEngine = new RoutingEngine(routingSource, featureSource);

            routingEngine.GeneratingServiceArea += new EventHandler <GeneratingServiceAreaRoutingEngineEventArgs>(routingEngine_GeneratingServiceArea);
            float averageSpeed   = float.Parse(txtAverageSpeed.Text);
            int   drivingMinutes = int.Parse(txtDrivingMinutes.Text);

            PolygonShape         polygonShape = routingEngine.GenerateServiceArea(txtStartId.Text, new TimeSpan(0, drivingMinutes, 0), averageSpeed);
            InMemoryFeatureLayer routingLayer = (InMemoryFeatureLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["RoutingLayer"];

            routingLayer.InternalFeatures.Remove("ServiceArea");
            if (polygonShape.Validate(ShapeValidationMode.Simple).IsValid)
            {
                routingLayer.InternalFeatures.Add("ServiceArea", new Feature(polygonShape));
                routingLayer.Open();
                winformsMap1.CurrentExtent = routingLayer.GetBoundingBox();
                routingLayer.Close();
            }

            winformsMap1.Overlays["RoutingOverlay"].Lock.IsDirty = true;

            winformsMap1.Refresh();
        }
Beispiel #3
0
        /// <summary>
        /// Setup the map with the ThinkGeo Cloud Maps overlay. Also, add the feature layer to the map
        /// </summary>
        protected override void OnAppearing()
        {
            base.OnAppearing();
            // It is important to set the map unit first to either feet, meters or decimal degrees.
            mapView.MapUnit = GeographyUnit.Meter;

            // Create the background world maps using vector tiles requested from the ThinkGeo Cloud Service.
            ThinkGeoCloudVectorMapsOverlay thinkGeoCloudVectorMapsOverlay = new ThinkGeoCloudVectorMapsOverlay("9ap16imkD_V7fsvDW9I8r8ULxgAB50BX_BnafMEBcKg~", "vtVao9zAcOj00UlGcK7U-efLANfeJKzlPuDB9nw7Bp4K4UxU_PdRDg~~", ThinkGeoCloudVectorMapsMapType.Light);

            thinkGeoCloudVectorMapsOverlay.VectorTileCache = new FileVectorTileCache(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "cache"), "CloudMapsVector");
            mapView.Overlays.Add(thinkGeoCloudVectorMapsOverlay);

            // Create a new overlay that will hold our new layer and add it to the map.
            LayerOverlay inMemoryOverlay = new LayerOverlay();

            mapView.Overlays.Add(inMemoryOverlay);

            // Create a new layer that we will pull features from to populate the in memory layer.
            ShapeFileFeatureLayer shapeFileLayer = new ShapeFileFeatureLayer(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Data/Shapefile/Frisco_Mosquitos.shp"));

            shapeFileLayer.FeatureSource.ProjectionConverter = new ProjectionConverter(2276, 3857);
            shapeFileLayer.Open();

            // Get all the features from the above layer.
            Collection <Feature> features = shapeFileLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns);

            shapeFileLayer.Close();

            // Create the in memory layer and add it to the map
            InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();

            inMemoryOverlay.Layers.Add("Frisco Mosquitos", inMemoryFeatureLayer);

            // Loop through all the features in the first layer and add them to the in memeory layer.  We use a shortcut called internal
            // features that is supported in the in memory layer instead of going through the edit tools
            foreach (Feature feature in features)
            {
                inMemoryFeatureLayer.InternalFeatures.Add(feature);
            }

            // Create a text style for the label and give it a mask for use below.
            TextStyle textStyle = new TextStyle("Trap: [TrapID]", new GeoFont("ariel", 14), GeoBrushes.Black);

            textStyle.Mask           = new AreaStyle(GeoPens.Black, GeoBrushes.White);
            textStyle.MaskMargin     = new DrawingMargin(2, 2, 2, 2);
            textStyle.YOffsetInPixel = -10;

            // Create an point style and add the text style from above on zoom level 1 and then apply it to all zoom levels up to 20.
            inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle   = new PointStyle(PointSymbolType.Circle, 12, GeoBrushes.Red, GeoPens.White);
            inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle    = textStyle;
            inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            // Open the layer and set the map view current extent to the bounding box of the layer.
            inMemoryFeatureLayer.Open();
            mapView.CurrentExtent = inMemoryFeatureLayer.GetBoundingBox();

            //Refresh the map.
            mapView.Refresh();
        }
Beispiel #4
0
        private void Form_Load(object sender, EventArgs e)
        {
            // It is important to set the map unit first to either feet, meters or decimal degrees.
            mapView.MapUnit = GeographyUnit.Meter;

            // Create the background world maps using vector tiles requested from the ThinkGeo Cloud Service.
            ThinkGeoCloudVectorMapsOverlay thinkGeoCloudVectorMapsOverlay = new ThinkGeoCloudVectorMapsOverlay("itZGOI8oafZwmtxP-XGiMvfWJPPc-dX35DmESmLlQIU~", "bcaCzPpmOG6le2pUz5EAaEKYI-KSMny_WxEAe7gMNQgGeN9sqL12OA~~", ThinkGeoCloudVectorMapsMapType.Light);

            mapView.Overlays.Add(thinkGeoCloudVectorMapsOverlay);

            // Create a new overlay that will hold our new layer and add it to the map.
            LayerOverlay inMemoryOverlay = new LayerOverlay();

            mapView.Overlays.Add(inMemoryOverlay);

            // Create a new layer that we will pull features from to populate the in memory layer.
            ShapeFileFeatureLayer shapeFileLayer = new ShapeFileFeatureLayer(@"../../../Data/Shapefile/Frisco_Mosquitos.shp");

            shapeFileLayer.FeatureSource.ProjectionConverter = new ProjectionConverter(2276, 3857);
            shapeFileLayer.Open();

            // Get all the features from the above layer.
            Collection <Feature> features = shapeFileLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns);

            shapeFileLayer.Close();

            // Create the in memory layer and add it to the map
            InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();

            inMemoryOverlay.Layers.Add("Frisco Mosquitos", inMemoryFeatureLayer);

            // Loop through all the features in the first layer and add them to the in memeory layer.  We use a shortcut called internal
            // features that is supported in the in memory layer instead of going through the edit tools
            foreach (Feature feature in features)
            {
                inMemoryFeatureLayer.InternalFeatures.Add(feature);
            }

            // Create a text style for the label and give it a mask for use below.
            TextStyle textStyle = new TextStyle("Trap: [TrapID]", new GeoFont("ariel", 14), GeoBrushes.Black);

            textStyle.Mask           = new AreaStyle(GeoPens.Black, GeoBrushes.White);
            textStyle.MaskMargin     = new DrawingMargin(2, 2, 2, 2);
            textStyle.YOffsetInPixel = -10;

            // Create an point style and add the text style from above on zoom level 1 and then apply it to all zoom levels up to 20.
            inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle   = new PointStyle(PointSymbolType.Circle, 12, GeoBrushes.Red, GeoPens.White);
            inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle    = textStyle;
            inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            // Open the layer and set the map view current extent to the bounding box of the layer.
            inMemoryFeatureLayer.Open();
            mapView.CurrentExtent = inMemoryFeatureLayer.GetBoundingBox();

            //Refresh the map.
            mapView.Refresh();
        }
        private bool IsHydrographyLayerVisiable()
        {
            if (boundingBoxPreviewLayer != null)
            {
                if (boundingBoxPreviewLayer.GetBoundingBox().Intersects(map.CurrentExtent))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #6
0
        private void TabSearchResult_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (searchResult != null)
            {
                // Clear the result layer,radius layer, markers and add geometry of best matching place.
                nearbysMarkerOverlay.Markers.Clear();
                resultGeometryFeatureLayer.InternalFeatures.Clear();
                seachRadiusFeatureLayer.InternalFeatures.Clear();

                AddSearchPointToMap(searchPoint);
                if (tabSearchResult.SelectedIndex == 0) // Nearby Addresses Tab
                {
                    AddSearchRadius(Convert.ToDouble(maxSearchIntersectionRadius.Text, CultureInfo.InvariantCulture));

                    for (int i = 0; i < serachedPlaces.Count; i++)
                    {
                        if (serachedPlaces[i] != searchResult.BestMatch)
                        {
                            AddMarkerToMap(serachedPlaces[i], i);
                        }
                    }
                }
                else if (tabSearchResult.SelectedIndex == 1) // Nearby Intersections Tab
                {
                    AddSearchRadius(Convert.ToDouble(maxSearchIntersectionRadius.Text, CultureInfo.InvariantCulture));

                    for (int i = 0; i < serachedIntersetions.Count; i++)
                    {
                        if (serachedIntersetions[i] != searchResult.BestMatch)
                        {
                            AddMarkerToMap(serachedIntersetions[i], i);
                        }
                    }
                }
                else if (tabSearchResult.SelectedIndex == 2) // Nearby Places Tab
                {
                    AddSearchRadius(Convert.ToDouble(maxSearchIntersectionRadius.Text, CultureInfo.InvariantCulture));

                    for (int i = 0; i < serachedAddress.Count; i++)
                    {
                        if (serachedAddress[i] != searchResult.BestMatch)
                        {
                            AddMarkerToMap(serachedAddress[i], i);
                        }
                    }
                }
                wpfMap.CurrentExtent = seachRadiusFeatureLayer.GetBoundingBox();
                wpfMap.Refresh();
            }
        }
Beispiel #7
0
        /// <summary>
        /// Draw the result of an optimized routing request on the map
        /// </summary>
        private void DrawOptimizedRoute(CloudRoutingOptimizationResult optimizedRoutingResult)
        {
            // Get the routing feature layer from the MapView
            InMemoryFeatureLayer routingLayer = (InMemoryFeatureLayer)mapView.FindFeatureLayer("Routing Layer");

            // Clear the previous features from the routing layer
            routingLayer.InternalFeatures.Clear();

            // Create a collection to hold the route segments. These include information like distance, duration, warnings, and instructions for turn-by-turn routing
            List <CloudRoutingSegment> routeSegments = new List <CloudRoutingSegment>();

            //// CloudRoutingOptimizationResult.TspResult.VisitSequences is an ordered array of integers
            //// Each integer corresponds to the index of the corresponding waypoint in the original set of waypoints passed into the query
            //// For example, if the second element in 'VisitSequences' is '3', the second stop on the route is originalWaypointArray[3]

            int index = 0;

            // Add the route visit points and route segments to the map
            foreach (int waypointIndex in optimizedRoutingResult.TspResult.VisitSequences)
            {
                Dictionary <string, string> columnValues = new Dictionary <string, string>();

                // Get the order of the stops and label the point
                // '0' represents the start/end point of the route for a round trip route, so we change the label to indicate that for readability
                columnValues.Add("SequenceNumber", (index == 0 || index == optimizedRoutingResult.TspResult.VisitSequences.Count - 1 ? "Start/End Point" : "Stop " + index));
                PointShape waypoint = routingWaypoints[waypointIndex];

                // Add the point to the map
                routingLayer.InternalFeatures.Add(new Feature(waypoint, columnValues));

                // Increment the index for labeling purposes
                index++;
            }
            foreach (CloudRoutingRoute route in optimizedRoutingResult.TspResult.Routes)
            {
                routingLayer.InternalFeatures.Add(new Feature(route.Shape));
                routeSegments.AddRange(route.Segments);
            }

            //// Set the data source for the list box to the route segments
            lsbRouteSegments.ItemsSource = routeSegments;

            //// Set the map extent to the newly displayed route
            routingLayer.Open();
            mapView.CurrentExtent = RectangleShape.ScaleUp(routingLayer.GetBoundingBox(), 20).GetBoundingBox();
            routingLayer.Close();
            mapView.Refresh();
        }
Beispiel #8
0
        /// <summary>
        /// Draw the result of a Cloud Routing request on the map
        /// </summary>
        private void DrawRoute(CloudRoutingGetRouteResult routingResult)
        {
            // Get the routing feature layer from the MapView
            InMemoryFeatureLayer routingLayer = (InMemoryFeatureLayer)mapView.FindFeatureLayer("Routing Layer");

            // Clear the previous features from the routing layer
            routingLayer.InternalFeatures.Clear();

            // Create a collection to hold the route segments. These include information like distance, duration, warnings, and instructions for turn-by-turn routing
            List <CloudRoutingSegment> routeSegments = new List <CloudRoutingSegment>();

            int index = 0;

            // Add the route waypoints and route segments to the map
            foreach (CloudRoutingWaypoint waypoint in routingResult.RouteResult.Waypoints)
            {
                Dictionary <string, string> columnValues = new Dictionary <string, string>();

                // Get the order of the stops and label the point
                // '0' represents the start/end point of the route for a round trip route, so we change the label to indicate that for readability
                columnValues.Add("SequenceNumber", (index == 0 ? "Start Point" : "Stop " + index));
                PointShape routeWaypoint = new PointShape(waypoint.Coordinate);

                // Add the point to the map
                routingLayer.InternalFeatures.Add(new Feature(routeWaypoint, columnValues));

                // Increment the index for labeling purposes
                index++;
            }
            foreach (CloudRoutingRoute route in routingResult.RouteResult.Routes)
            {
                routingLayer.InternalFeatures.Add(new Feature(route.Shape));
                routeSegments.AddRange(route.Segments);
            }

            // Set the data source for the list box to the route segments
            lsbRouteSegments.ItemsSource = routeSegments;

            // Set the map extent to the newly displayed route
            routingLayer.Open();
            mapView.CurrentExtent = RectangleShape.ScaleUp(routingLayer.GetBoundingBox(), 20).GetBoundingBox();

            routingLayer.Close();
            mapView.Refresh();
        }
Beispiel #9
0
        /// <summary>
        /// Setup the map with the ThinkGeo Cloud Maps overlay. Also, add the railway and subLineLayer layers into a
        /// grouped LayerOverlay and display them on the map.
        /// </summary>
        protected override void OnAppearing()
        {
            base.OnAppearing();
            // Set the map's unit of measurement to meters(Spherical Mercator)
            mapView.MapUnit = GeographyUnit.Meter;

            // Add Cloud Maps as a background overlay
            var thinkGeoCloudVectorMapsOverlay = new ThinkGeoCloudVectorMapsOverlay("9ap16imkD_V7fsvDW9I8r8ULxgAB50BX_BnafMEBcKg~", "vtVao9zAcOj00UlGcK7U-efLANfeJKzlPuDB9nw7Bp4K4UxU_PdRDg~~", ThinkGeoCloudVectorMapsMapType.Light);

            thinkGeoCloudVectorMapsOverlay.VectorTileCache = new FileVectorTileCache(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "cache"), "CloudMapsVector");
            mapView.Overlays.Add(thinkGeoCloudVectorMapsOverlay);

            InMemoryFeatureLayer railway      = new InMemoryFeatureLayer();
            InMemoryFeatureLayer subLineLayer = new InMemoryFeatureLayer();
            LayerOverlay         layerOverlay = new LayerOverlay();

            // Add the rail line feature to the railway layer
            railway.InternalFeatures.Add(new Feature("LineString (-10776730.91861553490161896 3925750.69222266925498843, -10778989.31895966082811356 3915278.00731692276895046, -10781766.12723691388964653 3909228.15506267035380006, -10782065.98029803484678268 3907458.59967381786555052, -10781867.48601813986897469 3905465.21030976390466094)"));

            // Style railway layer
            railway.ZoomLevelSet.ZoomLevel01.DefaultLineStyle    = LineStyle.CreateSimpleLineStyle(GeoColors.Red, 2, false);
            railway.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            // Style the subLineLayer
            subLineLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle    = LineStyle.CreateSimpleLineStyle(GeoColors.Green, 2, false);
            subLineLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            // Add railway to the layerOverlay
            layerOverlay.Layers.Add("railway", railway);

            // Add subLineLayer to the layerOverlay
            layerOverlay.Layers.Add("subLineLayer", subLineLayer);

            // Set the map extent to the railway layer bounding box
            railway.Open();
            mapView.CurrentExtent = railway.GetBoundingBox();
            railway.Close();

            // Add LayerOverlay to Map
            mapView.Overlays.Add("layerOverlay", layerOverlay);

            mapView.Refresh();
        }
Beispiel #10
0
        private void Form_Load(object sender, EventArgs e)
        {
            // Set the map's unit of measurement to meters(Spherical Mercator)
            mapView.MapUnit = GeographyUnit.Meter;

            // Add Cloud Maps as a background overlay
            var thinkGeoCloudVectorMapsOverlay = new ThinkGeoCloudVectorMapsOverlay("itZGOI8oafZwmtxP-XGiMvfWJPPc-dX35DmESmLlQIU~", "bcaCzPpmOG6le2pUz5EAaEKYI-KSMny_WxEAe7gMNQgGeN9sqL12OA~~", ThinkGeoCloudVectorMapsMapType.Light);

            mapView.Overlays.Add(thinkGeoCloudVectorMapsOverlay);

            InMemoryFeatureLayer railway      = new InMemoryFeatureLayer();
            InMemoryFeatureLayer subLineLayer = new InMemoryFeatureLayer();
            LayerOverlay         layerOverlay = new LayerOverlay();

            // Add the rail line feature to the railway layer
            railway.InternalFeatures.Add(new Feature("LineString (-10776730.91861553490161896 3925750.69222266925498843, -10778989.31895966082811356 3915278.00731692276895046, -10781766.12723691388964653 3909228.15506267035380006, -10782065.98029803484678268 3907458.59967381786555052, -10781867.48601813986897469 3905465.21030976390466094)"));

            // Style railway layer
            railway.ZoomLevelSet.ZoomLevel01.DefaultLineStyle    = LineStyle.CreateSimpleLineStyle(GeoColors.Red, 2, false);
            railway.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            // Style the subLineLayer
            subLineLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle    = LineStyle.CreateSimpleLineStyle(GeoColors.Green, 2, false);
            subLineLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            // Add railway to the layerOverlay
            layerOverlay.Layers.Add("railway", railway);

            // Add subLineLayer to the layerOverlay
            layerOverlay.Layers.Add("subLineLayer", subLineLayer);

            // Set the map extent to the railway layer bounding box
            railway.Open();
            mapView.CurrentExtent = railway.GetBoundingBox();
            railway.Close();

            // Add LayerOverlay to Map
            mapView.Overlays.Add("layerOverlay", layerOverlay);
        }
Beispiel #11
0
        private void btnRoute_Click(object sender, EventArgs e)
        {
            Algorithm         algorithm     = new AStarAlgorithm();
            RoutingSource     routingSource = new CustomRoutingSource(new ShapeFileFeatureSource(@"..\..\App_Data\Austinstreets.shp"));
            Collection <Road> pathIDs       = algorithm.GetShortestPath(routingSource, txtStartId.Text, txtEndId.Text);

            Collection <Feature> features = new Collection <Feature>();
            Dictionary <string, ShapeFileFeatureSource> featureSources = new Dictionary <string, ShapeFileFeatureSource>();

            for (int i = 0; i < pathIDs.Count; i++)
            {
                FeatureSource featureSource = routingSource.GetFeatureSourceByroadId(pathIDs[i].Id);
                featureSource.Open();
                features.Add(featureSource.GetFeatureById(routingSource.GetFeatureIdByroadId(pathIDs[i].Id).ToString(), ReturningColumnsType.NoColumns));
                featureSource.Close();
            }

            winformsMap1.Overlays["RoutingOverlay"].Lock.EnterWriteLock();
            try
            {
                InMemoryFeatureLayer inmemoryLayer = (InMemoryFeatureLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["RoutingLayer"];
                inmemoryLayer.InternalFeatures.Clear();

                foreach (Feature feature in features)
                {
                    inmemoryLayer.InternalFeatures.Add(feature);
                }

                inmemoryLayer.Open();
                winformsMap1.CurrentExtent = inmemoryLayer.GetBoundingBox();
                inmemoryLayer.Close();
            }
            finally
            {
                winformsMap1.Overlays["RoutingOverlay"].Lock.ExitWriteLock();
            }

            winformsMap1.Refresh();
        }
Beispiel #12
0
        /// <summary>
        /// Draw reprojected features on the map
        /// </summary>
        private void ClearMapAndAddFeatures(Collection <Feature> reprojectedFeatures)
        {
            // Get the layer we prepared from the MapView
            InMemoryFeatureLayer reprojectedFeatureLayer = (InMemoryFeatureLayer)mapView.FindFeatureLayer("Reprojected Features Layer");

            // Clear old features from the feature layer and add the newly reprojected features
            reprojectedFeatureLayer.InternalFeatures.Clear();
            foreach (Feature sphericalMercatorFeature in reprojectedFeatures)
            {
                reprojectedFeatureLayer.InternalFeatures.Add(sphericalMercatorFeature);
            }

            // Set the map extent to zoom into the feature and refresh the map
            reprojectedFeatureLayer.Open();
            mapView.CurrentExtent = reprojectedFeatureLayer.GetBoundingBox();

            ZoomLevelSet standardZoomLevelSet = new ZoomLevelSet();

            mapView.ZoomToScale(standardZoomLevelSet.ZoomLevel18.Scale);

            reprojectedFeatureLayer.Close();
            mapView.Refresh();
        }
Beispiel #13
0
        private void Route()
        {
            RtgRoutingSource routingSource = new RtgRoutingSource(Path.Combine(rootPath, "DallasCounty-4326.shortest.rtg"));
            FeatureSource    featureSource = new ShapeFileFeatureSource(Path.Combine(rootPath, "DallasCounty-4326.shp"));
            RoutingEngine    routingEngine = new RoutingEngine(routingSource, featureSource);

            float                averageSpeed   = float.Parse(txtAverageSpeed.Text);
            int                  drivingMinutes = int.Parse(txtDrivingMinutes.Text);
            SpeedUnit            speedUnit      = GetSpeedUnit();
            PolygonShape         polygonShape   = routingEngine.GenerateServiceArea(txtStartId.Text, new TimeSpan(0, drivingMinutes, 0), averageSpeed, speedUnit);
            InMemoryFeatureLayer routingLayer   = (InMemoryFeatureLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["RoutingLayer"];

            routingLayer.InternalFeatures.Remove("ServiceArea");
            if (polygonShape.Validate(ShapeValidationMode.Simple).IsValid)
            {
                routingLayer.InternalFeatures.Add("ServiceArea", new Feature(polygonShape));
                routingLayer.Open();
                winformsMap1.CurrentExtent = routingLayer.GetBoundingBox();
                routingLayer.Close();
            }

            winformsMap1.Refresh(winformsMap1.Overlays["RoutingOverlay"]);
        }
        private void mapView_Loaded(object sender, RoutedEventArgs e)
        {
            //Add a base map (ThinkGeo's online World Map Kit).
            mapView.MapUnit      = GeographyUnit.Meter;
            mapView.ZoomLevelSet = new ThinkGeoCloudMapsZoomLevelSet();

            // Please input your ThinkGeo Cloud Client ID / Client Secret to enable the background map.
            // Create background world map with vector tile requested from ThinkGeo Cloud Service.
            ThinkGeoCloudVectorMapsOverlay thinkGeoCloudVectorMapsOverlay = new ThinkGeoCloudVectorMapsOverlay(SampleHelper.ThinkGeoCloudId, SampleHelper.ThinkGeoCloudSecret, ThinkGeoCloudVectorMapsMapType.Light);

            mapView.Overlays.Add(thinkGeoCloudVectorMapsOverlay);

            //Build up the test data.
            InMemoryFeatureLayer testData = setupTestData();

            //Make test line red in color.
            testData.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyle.CreateSimpleLineStyle(GeoColors.Red, 6, false);
            //Make test point dark green in color.
            testData.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyle.CreateSimpleCircleStyle(GeoColors.DarkGreen, 12);
            //Apply the above styles to all zoom levels.
            testData.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            //Create a MapShapeLayer that we can style individually and which will hold the results of the shortest line and split lines.
            MapShapeLayer results = new MapShapeLayer();

            //Add the test data and results layers to a new layer overlay so they will show on top of the base map.
            LayerOverlay layerOverlay = new LayerOverlay();

            layerOverlay.Layers.Add("TestData", testData);
            layerOverlay.Layers.Add("Results", results);
            mapView.Overlays.Add("layerOverlay", layerOverlay);

            //Zoom into the test data area.
            mapView.CurrentExtent = testData.GetBoundingBox();
            mapView.Refresh();
        }
Beispiel #15
0
        /// <summary>
        /// Get elevation data using the ElevationCloudClient and update the UI
        /// </summary>
        private async Task PerformElevationQuery(BaseShape queryShape)
        {
            // Get feature layers from the MapView
            LayerOverlay         elevationPointsOverlay = (LayerOverlay)mapView.Overlays["Elevation Features Overlay"];
            InMemoryFeatureLayer drawnShapesLayer       = (InMemoryFeatureLayer)elevationPointsOverlay.Layers["Drawn Shape Layer"];
            InMemoryFeatureLayer elevationPointsLayer   = (InMemoryFeatureLayer)elevationPointsOverlay.Layers["Elevation Points Layer"];

            // Clear the existing shapes from the map
            elevationPointsLayer.Open();
            elevationPointsLayer.Clear();
            elevationPointsLayer.Close();
            drawnShapesLayer.Open();
            drawnShapesLayer.Clear();
            drawnShapesLayer.Close();

            // Add the drawn shape to the map
            drawnShapesLayer.InternalFeatures.Add(new Feature(queryShape));

            // Set options from the UI and run the query using the ElevationCloudClient
            Collection <CloudElevationPointResult> elevationPoints = new Collection <CloudElevationPointResult>();
            int projectionInSrid = 3857;

            // Show a loading graphic to let users know the request is running
            loadingIndicator.IsRunning = true;
            loadingLayout.IsVisible    = true;

            // The point interval distance determines how many elevation points are retrieved for line and area queries
            int pointIntervalDistance = (int)intervalDistance.Value;

            switch (queryShape.GetWellKnownType())
            {
            case WellKnownType.Point:
                PointShape drawnPoint = (PointShape)queryShape;
                double     elevation  = await elevationCloudClient.GetElevationOfPointAsync(drawnPoint.X, drawnPoint.Y, projectionInSrid);

                // The API for getting the elevation of a single point returns a double, so we manually create a CloudElevationPointResult to use as a data source for the Elevations list
                elevationPoints.Add(new CloudElevationPointResult(elevation, drawnPoint));

                // Update the UI with the average, highest, and lowest elevations
                txtAverageElevation.Text = $"Average Elevation: {elevation:0.00} feet";
                txtHighestElevation.Text = $"Highest Elevation: {elevation:0.00} feet";
                txtLowestElevation.Text  = $"Lowest Elevation: {elevation:0.00} feet";
                break;

            case WellKnownType.Line:
                LineShape drawnLine = (LineShape)queryShape;
                var       result    = await elevationCloudClient.GetElevationOfLineAsync(drawnLine, projectionInSrid, pointIntervalDistance, DistanceUnit.Meter, DistanceUnit.Feet);

                elevationPoints = result.ElevationPoints;

                // Update the UI with the average, highest, and lowest elevations
                txtAverageElevation.Text = $"Average Elevation: {result.AverageElevation:0.00} feet";
                txtHighestElevation.Text = $"Highest Elevation: {result.HighestElevationPoint.Elevation:0.00} feet";
                txtLowestElevation.Text  = $"Lowest Elevation: {result.LowestElevationPoint.Elevation:0.00} feet";
                break;

            case WellKnownType.Polygon:
                PolygonShape drawnPolygon = (PolygonShape)queryShape;
                result = await elevationCloudClient.GetElevationOfAreaAsync(drawnPolygon, projectionInSrid, pointIntervalDistance, DistanceUnit.Meter, DistanceUnit.Feet);

                elevationPoints = result.ElevationPoints;

                // Update the UI with the average, highest, and lowest elevations
                txtAverageElevation.Text = $"Average Elevation: {result.AverageElevation:0.00} feet";
                txtHighestElevation.Text = $"Highest Elevation: {result.HighestElevationPoint.Elevation:0.00} feet";
                txtLowestElevation.Text  = $"Lowest Elevation: {result.LowestElevationPoint.Elevation:0.00} feet";
                break;

            default:
                break;
            }

            // Add the elevation result points to the map and list box
            foreach (CloudElevationPointResult elevationPoint in elevationPoints)
            {
                elevationPointsLayer.InternalFeatures.Add(new Feature(elevationPoint.Point));
            }
            lsbElevations.ItemsSource = elevationPoints;

            // Hide the loading graphic
            loadingIndicator.IsRunning = false;
            loadingLayout.IsVisible    = false;

            // Set the map extent to the elevation query feature
            drawnShapesLayer.Open();
            mapView.CenterAt(drawnShapesLayer.GetBoundingBox().GetCenterPoint());
            drawnShapesLayer.Close();
            mapView.Refresh();
        }
Beispiel #16
0
        /// <summary>
        /// Get features from the WorldMapsQuery service based on the UI parameters
        /// </summary>
        private async void PerformWorldMapsQuery()
        {
            // Get the feature layers from the MapView
            LayerOverlay         queriedFeaturesOverlay = (LayerOverlay)mapView.Overlays["Queried Features Overlay"];
            InMemoryFeatureLayer queryShapeFeatureLayer = (InMemoryFeatureLayer)queriedFeaturesOverlay.Layers["Query Shape Layer"];
            InMemoryFeatureLayer queriedFeaturesLayer   = (InMemoryFeatureLayer)queriedFeaturesOverlay.Layers["Queried Features Layer"];

            // Show an error if trying to query with no query shape
            if (queryShapeFeatureLayer.InternalFeatures.Count == 0)
            {
                await DisplayAlert("Alert", "Please draw a shape to use for the query", "OK");

                return;
            }

            // Set the MapsQuery parameters based on the drawn query shape and the UI
            BaseShape queryShape       = queryShapeFeatureLayer.InternalFeatures[0].GetShape();
            int       projectionInSrid = 3857;
            string    queryLayer       = ((string)cboQueryLayer.SelectedItem).ToLower();

            CloudMapsQueryResult result = new CloudMapsQueryResult();

            // Show a loading graphic to let users know the request is running
            loadingIndicator.IsRunning = true;
            loadingLayout.IsVisible    = true;

            // Perform the world maps query
            try
            {
                switch ((string)cboQueryType.SelectedItem)
                {
                case "Containing":
                    result = await mapsQueryCloudClient.GetFeaturesContainingAsync(queryLayer, queryShape, projectionInSrid, new CloudMapsQuerySpatialQueryOptions()
                    {
                        MaxResults = Convert.ToInt32(maxResults.Text)
                    });

                    break;

                case "Nearest":
                    result = await mapsQueryCloudClient.GetFeaturesNearestAsync(queryLayer, queryShape, projectionInSrid, Convert.ToInt32(maxResults.Text));

                    break;

                case "Intersecting":
                    result = await mapsQueryCloudClient.GetFeaturesIntersectingAsync(queryLayer, queryShape, projectionInSrid, new CloudMapsQuerySpatialQueryOptions()
                    {
                        MaxResults = Convert.ToInt32(maxResults.Text)
                    });

                    break;

                case "Overlapping":
                    result = await mapsQueryCloudClient.GetFeaturesOverlappingAsync(queryLayer, queryShape, projectionInSrid, new CloudMapsQuerySpatialQueryOptions()
                    {
                        MaxResults = Convert.ToInt32(maxResults.Text)
                    });

                    break;

                case "Within":
                    result = await mapsQueryCloudClient.GetFeaturesWithinAsync(queryLayer, queryShape, projectionInSrid, new CloudMapsQuerySpatialQueryOptions()
                    {
                        MaxResults = Convert.ToInt32(maxResults.Text)
                    });

                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                // Handle any errors returned from the maps query service
                if (ex is ArgumentException)
                {
                    await DisplayAlert("Error", ex.Message, "OK");

                    mapView.Refresh();
                    return;
                }
                else
                {
                    await DisplayAlert("Alert", ex.Message, "OK");

                    mapView.Refresh();
                    return;
                }
            }
            finally
            {
                // Hide the loading graphic
                loadingIndicator.IsRunning = false;
                loadingLayout.IsVisible    = false;
            }

            if (result.Features.Count > 0)
            {
                // Add any features found by the query to the map
                foreach (Feature feature in result.Features)
                {
                    queriedFeaturesLayer.InternalFeatures.Add(feature);
                }

                // Set the map extent to the extent of the query results
                queriedFeaturesLayer.Open();
                mapView.CurrentExtent = queriedFeaturesLayer.GetBoundingBox();
                queriedFeaturesLayer.Close();
            }
            else
            {
                await DisplayAlert("Alert", "No features found in the selected area", "OK");
            }

            // Refresh and redraw the map
            mapView.Refresh();
        }
Beispiel #17
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Proj4Projection proj4 = new Proj4Projection();

            proj4.ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(2178);
            proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(2178);
            //proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
            proj4.Open();

            //WorldStreetsAndImageryProjection x = new WorldStreetsAndImageryProjection();

            //WpfMap.MapUnit = ThinkGeo.MapSuite.GeographyUnit.DecimalDegree;
            WpfMap.MapUnit       = ThinkGeo.MapSuite.GeographyUnit.Meter;
            WpfMap.CurrentExtent = new RectangleShape(6534300.78, 5593416.28, 6534296.12, 5593426.45);
            //var x = new WorldStreetsAndImageryOverlay()
            //WpfMap.Overlays.Add(x);
            WpfMap.Refresh();

            InMemoryFeatureLayer inMemoryFeatureLayer = CreateInMemoryFeatureLayerFromTextFile(@"..\..\data\FriscoHotels.txt");

            inMemoryFeatureLayer.FeatureSource.Projection = proj4;
            LayerOverlay layerOverlay = new LayerOverlay();

            layerOverlay.TileType = TileType.SingleTile;
            layerOverlay.Layers.Add(inMemoryFeatureLayer);
            WpfMap.Overlays.Add(layerOverlay);

            //LayerOverlay layerOverlay = new LayerOverlay();
            //layerOverlay.TileType = TileType.SingleTile;

            //var polygonLayer = new InMemoryFeatureLayer();
            //Feature feature2 = new Feature(new PolygonShape("POLYGON((20.030485999999996 50.00571917079107,20.030485999999996 49.998476,20.03997000000004 49.998476,20.03997000000004 49.998476,20.040292010620078 50.00568354029431,20.030485999999996 50.00571917079107))"));
            //polygonLayer.Open();
            //polygonLayer.EditTools.BeginTransaction();
            //polygonLayer.EditTools.Add(feature2);
            ////layerOverlay.Layers.Add(inMemoryFeatureLayer);
            //layerOverlay.Layers.Add(polygonLayer);
            //WpfMap.Overlays.Add(layerOverlay);
            //polygonLayer.EditTools.CommitTransaction();
            //polygonLayer.Close();

            InMemoryFeatureLayer inMemoryLayer = new InMemoryFeatureLayer();

            inMemoryLayer.FeatureSource.Projection = proj4;
            inMemoryLayer.InternalFeatures.Add("Polygon", new Feature(BaseShape.CreateShapeFromWellKnownData("POLYGON((6534300.78 5593416.28, 6534296.12 5593426.45, 6534280.56 5593419.19, 6534283.49 5593412.92, 6534285.3 5593409.04, 6534300.78 5593416.28))")));

            inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(100, GeoColor.StandardColors.RoyalBlue);
            inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color     = GeoColor.StandardColors.Blue;
            inMemoryLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            LayerOverlay layerOverlay2 = new LayerOverlay();

            layerOverlay2.TileType = TileType.SingleTile;
            layerOverlay2.Layers.Add(inMemoryLayer);
            //WpfMap.Overlays.Add(layerOverlay);


            inMemoryLayer.Open();
            WpfMap.CurrentExtent = inMemoryLayer.GetBoundingBox();
            inMemoryLayer.Close();

            WpfMap.Refresh();
        }
Beispiel #18
0
        /// <summary>
        /// Update the UI based on the search results from the reverse geocode
        /// </summary>
        private void DisplaySearchResults(PointShape searchPoint, int searchRadius, CloudReverseGeocodingResult searchResult)
        {
            // Get the 'Search Radius' layer from the MapView
            InMemoryFeatureLayer searchRadiusFeatureLayer = (InMemoryFeatureLayer)mapView.FindFeatureLayer("Search Radius");

            // Clear the existing features and add new features showing the area that was searched by the reverse geocode
            searchRadiusFeatureLayer.Clear();
            searchRadiusFeatureLayer.InternalFeatures.Add(new Feature(new EllipseShape(searchPoint, searchRadius)));
            searchRadiusFeatureLayer.InternalFeatures.Add(new Feature(searchPoint));

            // Get the 'Result Feature' layer and clear it
            InMemoryFeatureLayer selectedResultItemFeatureLayer = (InMemoryFeatureLayer)mapView.FindFeatureLayer("Result Feature Geometry");

            selectedResultItemFeatureLayer.Clear();

            // If a match was found for the geocode, update the UI
            if (searchResult?.BestMatchLocation != null)
            {
                // Get the 'Best Match' PopupOverlay from the MapView and clear it
                PopupOverlay bestMatchPopupOverlay = (PopupOverlay)mapView.Overlays["Best Match Popup Overlay"];
                bestMatchPopupOverlay.Popups.Clear();

                // Get the location of the 'Best Match' found within the search radius
                PointShape bestMatchLocation = searchResult.BestMatchLocation.LocationFeature.GetShape().GetClosestPointTo(searchPoint, GeographyUnit.Meter);
                if (bestMatchLocation == null)
                {
                    bestMatchLocation = searchResult.BestMatchLocation.LocationFeature.GetShape().GetCenterPoint();
                }

                // Create a popup to display the best match, and add it to the PopupOverlay
                Popup bestMatchPopup = new Popup();
                bestMatchPopup.Content  = "Best Match: " + searchResult.BestMatchLocation.LocationName;
                bestMatchPopup.Position = bestMatchLocation;
                bestMatchPopupOverlay.Popups.Add(bestMatchPopup);

                // Sort the locations found into three groups (Addresses, Places, Roads) based on their LocationCategory
                Collection <CloudReverseGeocodingLocation> nearbyLocations = new Collection <CloudReverseGeocodingLocation>(searchResult.NearbyLocations);
                Collection <CloudReverseGeocodingLocation> nearbyAddresses = new Collection <CloudReverseGeocodingLocation>();
                Collection <CloudReverseGeocodingLocation> nearbyPlaces    = new Collection <CloudReverseGeocodingLocation>();
                Collection <CloudReverseGeocodingLocation> nearbyRoads     = new Collection <CloudReverseGeocodingLocation>();
                foreach (CloudReverseGeocodingLocation foundLocation in nearbyLocations)
                {
                    if (foundLocation.LocationCategory.ToLower().Contains("addresspoint"))
                    {
                        nearbyAddresses.Add(foundLocation);
                    }
                    else if (nameof(CloudLocationCategories.Aeroway).Equals(foundLocation.LocationCategory) ||
                             nameof(CloudLocationCategories.Road).Equals(foundLocation.LocationCategory) ||
                             nameof(CloudLocationCategories.Rail).Equals(foundLocation.LocationCategory) ||
                             nameof(CloudLocationCategories.Waterway).Equals(foundLocation.LocationCategory))
                    {
                        nearbyRoads.Add(foundLocation);
                    }
                    else if (!nameof(CloudLocationCategories.Intersection).Equals(foundLocation.LocationCategory))
                    {
                        nearbyPlaces.Add(foundLocation);
                    }
                }

                // Set the data sources for the addresses, roads, and places list boxes
                lsbAddresses.ItemsSource = nearbyAddresses;
                lsbRoads.ItemsSource     = nearbyRoads;
                lsbPlaces.ItemsSource    = nearbyPlaces;

                lsbPlaces.IsVisible = true;

                txtSearchResultsBestMatch.Text = "Best Match: " + searchResult.BestMatchLocation.Address;
            }
            else
            {
                txtSearchResultsBestMatch.Text = "No address or place matches found for this location";
            }

            // Set the map extent to show the results of the search
            mapView.CurrentExtent = RectangleShape.ScaleUp(searchRadiusFeatureLayer.GetBoundingBox(), 20).GetBoundingBox();
            mapView.Refresh();
        }
Beispiel #19
0
        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            string address = txtAddressName.Text.Trim();

            if (string.IsNullOrEmpty(address))
            {
                MessageBox.Show("Please enter address.");
                return;
            }

            // Initialize geocoder
            Geocoder streetGeocoder = new Geocoder();

            streetGeocoder.MatchingPlugIns.Add(new StreetMatchingPlugin(@"..\..\Data\GeoCoderIndex", MatchMode.ExactMatch));
            try
            {
                streetGeocoder.Open();

                // Get the ShapeFileFeatureLayer which includes the street data.
                FeatureLayer roadFeatureLayer = ((LayerOverlay)Map1.Overlays[roadOverlayName]).Layers[0] as FeatureLayer;
                roadFeatureLayer.Open();

                // Get the marker overlay to display the searched results.
                SimpleMarkerOverlay markerOverlay = Map1.Overlays[markerOverlayName] as SimpleMarkerOverlay;
                markerOverlay.Markers.Clear();

                Collection <SearchResult> searchedResult = new Collection <SearchResult>();
                // Geocoder the address input, such as "6701 PECAN".
                Collection <GeocoderMatch> matchedRoads = streetGeocoder.Match(address);

                Proj4Projection projection = new Proj4Projection();
                projection.InternalProjectionParametersString = Proj4Projection.GetWgs84ParametersString();
                projection.ExternalProjectionParametersString = "+proj=lcc +lat_1=32.1333333333333 +lat_2=33.9666666666667 +lat_0=31.6666666666667 +lon_0=-98.5 +x_0=600000 +y_0=2000000 +ellps=GRS80 +datum=NAD83 +units=us-ft +no_defs";
                projection.Open();

                foreach (GeocoderMatch geocoderMatched in matchedRoads)
                {
                    // Display the searched result as marker.
                    BaseShape  streetCenter = new Feature(geocoderMatched.NameValuePairs["CentroidPoint"]).GetShape();
                    PointShape center       = projection.ConvertToExternalProjection(streetCenter) as PointShape;
                    markerOverlay.Markers.Add(new Marker(center)
                    {
                        ImageSource = new BitmapImage(new Uri("/Resources/AQUA.png", UriKind.RelativeOrAbsolute)),
                        Width       = 20,
                        Height      = 34,
                        YOffset     = -17,
                        ToolTip     = geocoderMatched.NameValuePairs["Street"]
                    });

                    // Get the feature id of the street where the searched result locates.
                    string featureId = geocoderMatched.NameValuePairs["UID"];

                    // Get the street where the searched result locates.
                    Feature feature = roadFeatureLayer.QueryTools.GetFeatureById(featureId, new[] { "ROAD_NAME" });
                    searchedResult.Add(GetSearchResult(feature, geocoderMatched));
                }

                projection.Close();
                roadFeatureLayer.Close();
                searchResults.ItemsSource = searchedResult;

                // Set the highlight layer into the current extent.
                InMemoryFeatureLayer highlightRoadLayer = ((LayerOverlay)Map1.Overlays[roadHighlightOverlayName]).Layers[0] as InMemoryFeatureLayer;
                if (highlightRoadLayer.InternalFeatures.Count > 0)
                {
                    Map1.CurrentExtent = highlightRoadLayer.GetBoundingBox();
                    Map1.ZoomOut();
                }

                Map1.Refresh();
            }
            finally
            {
                streetGeocoder.Close();
            }
        }