private async void CalculateViewshed(MapPoint location) { // Get the file name MapPoint Point = (MapPoint)GeometryEngine.Project(location, SpatialReferences.Wgs84); RunCmd(Point.X, Point.Y); string filepath = "C:\\Users\\zia13430\\dest.tif"; // Load the raster file Raster myRasterFile = new Raster(filepath); // Create the layer RasterLayer myRasterLayer = new RasterLayer(myRasterFile); // Create a color map where values 0-149 are red and 150-249 are yellow. IEnumerable <Color> colors = new int[250] .Select((c, i) => i < 150 ? Color.Red : Color.Red); // Create a colormap renderer. ColormapRenderer colormapRenderer = new ColormapRenderer(colors); // Set the colormap renderer on the raster layer. myRasterLayer.Renderer = colormapRenderer; myRasterLayer.Opacity = 0.6; await MyMapView.SetViewpointAsync(new Viewpoint(Point, 75000), TimeSpan.FromSeconds(1)); //myMap.InitialViewpoint = ; // Add the layer to the map myMap.OperationalLayers.Clear(); myMap.OperationalLayers.Add(myRasterLayer); try { } catch (Exception ex) { MessageBox.Show("An error occurred. " + ex.ToString(), "Sample error"); } finally { // Indicate that the geoprocessing is not running SetBusy(false); } }
private async void Initialize() { // Add an imagery basemap. Map map = new Map(Basemap.CreateImagery()); // Load the raster file. Raster rasterFile = new Raster(_rasterPath); // Create the layer. RasterLayer rasterLayer = new RasterLayer(rasterFile); // Create a color map where values 0-149 are red and 150-249 are yellow. IEnumerable <Color> colors = new int[250] .Select((c, i) => i < 150 ? Color.Red : Color.Yellow); // Create a colormap renderer. ColormapRenderer colormapRenderer = new ColormapRenderer(colors); // Set the colormap renderer on the raster layer. rasterLayer.Renderer = colormapRenderer; // Add the layer to the map. map.OperationalLayers.Add(rasterLayer); // Add map to the mapview. MyMapView.Map = map; try { // Wait for the layer to load. await rasterLayer.LoadAsync(); // Set the viewpoint. await MyMapView.SetViewpointGeometryAsync(rasterLayer.FullExtent, 15); } catch (Exception e) { Debug.WriteLine(e.Message); MessageBox.Show(e.Message, "Error"); } }