private async void Initialize() { // Create a new map to display in the map view with a streets basemap. Map streetMap = new Map(Basemap.CreateStreetsVector()); // Get the path to the downloaded shapefile. string filepath = DataManager.GetDataFolder("d98b3e5293834c5f852f13c569930caa", "TrailBikeNetwork.shp"); try { // Open the shapefile. ShapefileFeatureTable myShapefile = await ShapefileFeatureTable.OpenAsync(filepath); // Read metadata about the shapefile and display it in the UI. _shapefileMetadata = myShapefile.Info; // Create a feature layer to display the shapefile. _featureLayer = new FeatureLayer(myShapefile); // Zoom the map to the extent of the shapefile. _myMapView.SpatialReferenceChanged += MapView_SpatialReferenceChanged; // Add the feature layer to the map. streetMap.OperationalLayers.Add(_featureLayer); // Show the map in the MapView. _myMapView.Map = streetMap; } catch (Exception e) { new UIAlertView("Error", e.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show(); } }
private void initAsync() { FeatureLayer shapeFile = this.layer as FeatureLayer; if (shapeFile != null) { ShapefileFeatureTable myShapefile = shapeFile.FeatureTable as ShapefileFeatureTable; if (myShapefile != null) { ShapefileInfo fileInfo = myShapefile.Info; string x = ""; foreach (Field field in myShapefile.Fields) { x += field.Name; x += "\n"; } info.Text = x; InfoPanel.DataContext = fileInfo; //ShapefileThumbnailImage.Source = // await Esri.ArcGISRuntime.UI.RuntimeImageExtensions.ToImageSourceAsync(fileInfo.Thumbnail); } } }
private async void Initialize() { // Create a new map to display in the map view with a streets basemap _myMapView.Map = new Map(Basemap.CreateStreets()); // Get the path to the downloaded shapefile string filepath = GetShapefilePath(); try { // Open the shapefile ShapefileFeatureTable myShapefile = await ShapefileFeatureTable.OpenAsync(filepath); // Create a feature layer to display the shapefile FeatureLayer newFeatureLayer = new FeatureLayer(myShapefile); // Add the feature layer to the map _myMapView.Map.OperationalLayers.Add(newFeatureLayer); // Zoom the map to the extent of the shapefile await _myMapView.SetViewpointGeometryAsync(newFeatureLayer.FullExtent, 50); } catch (Exception e) { new AlertDialog.Builder(this).SetMessage(e.ToString()).SetTitle("Error").Show(); } }
private async void Initialize() { // Create a new map to display in the map view with a streets basemap Map streetMap = new Map(Basemap.CreateStreetsVector()); // Get the path to the downloaded shapefile string filepath = GetShapefilePath(); // Open the shapefile ShapefileFeatureTable myShapefile = await ShapefileFeatureTable.OpenAsync(filepath); // Read metadata about the shapefile and display it in the UI ShapefileInfo fileInfo = myShapefile.Info; InfoPanel.DataContext = fileInfo; // Display the shapefile thumbnail in an image control ShapefileThumbnailImage.Source = await Esri.ArcGISRuntime.UI.RuntimeImageExtensions.ToImageSourceAsync(fileInfo.Thumbnail); // Create a feature layer to display the shapefile FeatureLayer newFeatureLayer = new FeatureLayer(myShapefile); await newFeatureLayer.LoadAsync(); // Zoom the map to the extent of the shapefile MyMapView.SpatialReferenceChanged += async(s, e) => { await MyMapView.SetViewpointGeometryAsync(newFeatureLayer.FullExtent); }; // Add the feature layer to the map streetMap.OperationalLayers.Add(newFeatureLayer); // Show the map in the MapView MyMapView.Map = streetMap; }
private async void Initialize() { // Create a new map to display in the map view with a streets basemap MyMapView.Map = new Map(BasemapStyle.ArcGISStreets); // Get the path to the downloaded shapefile string filepath = GetShapefilePath(); try { // Open the shapefile ShapefileFeatureTable myShapefile = await ShapefileFeatureTable.OpenAsync(filepath); // Create a feature layer to display the shapefile FeatureLayer newFeatureLayer = new FeatureLayer(myShapefile); // Add the feature layer to the map MyMapView.Map.OperationalLayers.Add(newFeatureLayer); // Zoom the map to the extent of the shapefile await MyMapView.SetViewpointGeometryAsync(newFeatureLayer.FullExtent, 50); } catch (Exception e) { await Application.Current.MainPage.DisplayAlert("Error", e.ToString(), "OK"); } }
// 数据/导入shapefile文件; private async void AddSHP_Click(object sender, RoutedEventArgs e) { System.Windows.Forms.OpenFileDialog ofdlg = new System.Windows.Forms.OpenFileDialog(); ofdlg.Multiselect = true; ofdlg.Filter = "Shapefile文件(*.shp)|*.shp"; ofdlg.Title = "打开Shapefile文件"; if (ofdlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { for (int i = 0; i < ofdlg.FileNames.Length; i++) { String fPath = ofdlg.FileNames.GetValue(i).ToString(); // 新建图层 ShapefileFeatureTable myShapefile = await ShapefileFeatureTable.OpenAsync(fPath); FeatureLayer newFeaturelayer = new FeatureLayer(myShapefile) { SelectionColor = System.Drawing.Color.Cyan, SelectionWidth = 5 }; Esri.ArcGISRuntime.UI.Controls.MapView mapView = (Esri.ArcGISRuntime.UI.Controls.MapView) this.FindName("myMapView"); if (mapView != null) { myMapLayersList.Add(newFeaturelayer); mapView.Map.OperationalLayers.Add(newFeaturelayer); await mapView.SetViewpointGeometryAsync(newFeaturelayer.FullExtent); // 获取文件名 String layerName = System.IO.Path.GetFileName(fPath); // 新建checkbox并入栈 myTableOfContent.addLayersList(layerName); } } } }
private async void Initialize() { // Create a new map to display in the map view with a streets basemap Map streetMap = new Map(Basemap.CreateStreets()); // Get the path to the downloaded shapefile string filepath = GetShapefilePath(); // Open the shapefile ShapefileFeatureTable myShapefile = await ShapefileFeatureTable.OpenAsync(filepath); // Read metadata about the shapefile and display it in the UI _shapefileMetadata = myShapefile.Info; // Create a feature layer to display the shapefile FeatureLayer newFeatureLayer = new FeatureLayer(myShapefile); await newFeatureLayer.LoadAsync(); // Zoom the map to the extent of the shapefile _myMapView.SpatialReferenceChanged += async(s, e) => { await _myMapView.SetViewpointGeometryAsync(newFeatureLayer.FullExtent); }; // Add the feature layer to the map streetMap.OperationalLayers.Add(newFeatureLayer); // Show the map in the MapView _myMapView.Map = streetMap; }
private async void Initialize() { // Create a new map to display in the map view with a streets basemap _myMapView.Map = new Map(Basemap.CreateStreets()); // Get the path to the downloaded shapefile // string filepath = GetShapefilePath(); try { // Open the shapefile //ArcGISRuntimeEnvironment.SetLicense(licenseKey); ShapefileFeatureTable myShapefile = await ShapefileFeatureTable.OpenAsync(filepath); // ArcGISRuntimeEnvironment.SetLicense(licenseKey); // Create a feature layer to display the shapefile FeatureLayer newFeatureLayer = new FeatureLayer(myShapefile); // Add the feature layer to the map _myMapView.Map.OperationalLayers.Add(newFeatureLayer); //ArcGISRuntimeEnvironment.SetLicense(licenseKey); // Zoom the map to the extent of the shapefile await _myMapView.SetViewpointGeometryAsync(newFeatureLayer.FullExtent, 50); } catch (Exception ex) { Console.WriteLine("Unable to initialize the ArcGIS Runtime with the client ID provided: " + ex.Message); } }
private async void Initialize() { // Create a new map to display in the map view with a streets basemap. Map streetMap = new Map(Basemap.CreateStreetsVector()); // Get the path to the downloaded shapefile. string filepath = DataManager.GetDataFolder("d98b3e5293834c5f852f13c569930caa", "TrailBikeNetwork.shp"); // Open the shapefile. ShapefileFeatureTable myShapefile = await ShapefileFeatureTable.OpenAsync(filepath); // Read metadata about the shapefile and display it in the UI. _shapefileMetadata = myShapefile.Info; // Create a feature layer to display the shapefile. FeatureLayer newFeatureLayer = new FeatureLayer(myShapefile); // Zoom the map to the extent of the shapefile. _myMapView.SpatialReferenceChanged += async(s, e) => { await _myMapView.SetViewpointGeometryAsync(newFeatureLayer.FullExtent); }; // Add the feature layer to the map. streetMap.OperationalLayers.Add(newFeatureLayer); // Show the map in the MapView. _myMapView.Map = streetMap; }
private async void Initialize() { // Create a new map to display in the map view with a streets basemap. _myMapView.Map = new Map(Basemap.CreateStreetsVector()); // Get the path to the downloaded shapefile. string filepath = DataManager.GetDataFolder("d98b3e5293834c5f852f13c569930caa", "Public_Art.shp"); try { // Open the shapefile. ShapefileFeatureTable myShapefile = await ShapefileFeatureTable.OpenAsync(filepath); // Create a feature layer to display the shapefile. FeatureLayer newFeatureLayer = new FeatureLayer(myShapefile); // Add the feature layer to the map. _myMapView.Map.OperationalLayers.Add(newFeatureLayer); // Zoom the map to the extent of the shapefile. await _myMapView.SetViewpointGeometryAsync(newFeatureLayer.FullExtent, 50); } catch (Exception e) { new UIAlertView("Error", e.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show(); } }
private async void Initialize() { // Create a new map to display in the map view with a streets basemap Map streetMap = new Map(Basemap.CreateStreets()); // Get the path to the downloaded shapefile string filepath = GetShapefilePath(); try { // Open the shapefile ShapefileFeatureTable myShapefile = await ShapefileFeatureTable.OpenAsync(filepath); // Read metadata about the shapefile and display it in the UI ShapefileInfo fileInfo = myShapefile.Info; InfoPanel.BindingContext = fileInfo; // Read the thumbnail image data into a byte array Stream imageStream = await fileInfo.Thumbnail.GetEncodedBufferAsync(); byte[] imageData = new byte[imageStream.Length]; imageStream.Read(imageData, 0, imageData.Length); // Create a new image source from the thumbnail data ImageSource streamImageSource = ImageSource.FromStream(() => new MemoryStream(imageData)); // Create a new image to display the thumbnail Image image = new Image() { Source = streamImageSource, Margin = new Thickness(10) }; // Show the thumbnail image in a UI control ShapefileThumbnailImage.Source = image.Source; // Create a feature layer to display the shapefile FeatureLayer newFeatureLayer = new FeatureLayer(myShapefile); await newFeatureLayer.LoadAsync(); // Zoom the map to the extent of the shapefile MyMapView.SpatialReferenceChanged += async(s, e) => { await MyMapView.SetViewpointGeometryAsync(newFeatureLayer.FullExtent); }; // Add the feature layer to the map streetMap.OperationalLayers.Add(newFeatureLayer); // Show the map in the MapView MyMapView.Map = streetMap; } catch (Exception e) { await((Page)Parent).DisplayAlert("Error", e.ToString(), "OK"); } }
private async void Initialize() { Map myMap = new Map(BasemapType.TopographicVector, 43.3, -73.2, 8); /* * try * { * if(LocalServer.Instance.Status == LocalServerStatus.Started) * { * await LocalServer.Instance.StopAsync(); * } * * string tempDataPathRoot = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.Windows)).FullName; * string tempDataPath = System.IO.Path.Combine(tempDataPathRoot, "EsriSamples", "AppData"); * await LocalServer.Instance.StartAsync(); * * } * catch (Exception ex) * { * var localServerTypeInfo = typeof(LocalMapService).GetTypeInfo(); * var localServerVersion = FileVersionInfo.GetVersionInfo(localServerTypeInfo.Assembly.Location); * * MessageBox.Show($"Please ensure that local server {localServerVersion.FileVersion} is installed prior to usung this app. Thx bro.\n{ex}"); * return; * } */ sfFeatTable = await ShapefileFeatureTable.OpenAsync("C://Users//benja//Desktop//ColumbiaCounty//ColumbiaCounty.shp"); // Create feature layer using this feature table. Make it slightly transparent. newFeatureLayer = new FeatureLayer(sfFeatTable) { Opacity = 0.6, // Work around service setting. MaxScale = 10 }; // Create a new renderer for the States Feature Layer. SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Black, 1); SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.Transparent, lineSymbol); // Set States feature layer renderer. newFeatureLayer.Renderer = new SimpleRenderer(fillSymbol); // Add feature layer to the map. myMap.OperationalLayers.Add(newFeatureLayer); MyMapView.Map = myMap; try { await MyMapView.SetViewpointGeometryAsync(newFeatureLayer.FullExtent, 50); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }
private async void showBtn_Click(object sender, RoutedEventArgs e) { ShapefileFeatureTable myShapefile = await ShapefileFeatureTable.OpenAsync(rasterResultPath); FeatureLayer newFeaturelayer = new FeatureLayer(myShapefile); MainWindow.myMapLayersList.Add(newFeaturelayer); myMapView.Map.OperationalLayers.Add(newFeaturelayer); await myMapView.SetViewpointGeometryAsync(newFeaturelayer.FullExtent); String layerName = System.IO.Path.GetFileName(rasterResultPath); ((TableOfContent)w.FindName("myTableOfContent")).addLayersList(layerName); }
private async void Initialize() { // Create the map with topographic basemap Map myMap = new Map(Basemap.CreateTopographic()); // Create the point for the map's initial viewpoint MapPoint point = new MapPoint(-11662054, 4818336, SpatialReference.Create(3857)); // Create a viewpoint for the point Viewpoint viewpoint = new Viewpoint(point, 200000); // Set the initial viewpoint myMap.InitialViewpoint = viewpoint; // Create a shapefile feature table from the shapefile path ShapefileFeatureTable myFeatureTable = new ShapefileFeatureTable(GetShapefilePath()); // Create a layer from the feature table _shapefileFeatureLayer = new FeatureLayer(myFeatureTable); // Add the layer to the map myMap.OperationalLayers.Add(_shapefileFeatureLayer); // Create the symbology for the alternate renderer SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Red, 1.0); SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, System.Drawing.Color.Yellow, lineSymbol); // Create the alternate renderer _alternateRenderer = new SimpleRenderer(fillSymbol); try { // Wait for the layer to load so that it will be assigned a default renderer await _shapefileFeatureLayer.LoadAsync(); // Hold a reference to the default renderer (to enable switching between the renderers) _defaultRenderer = _shapefileFeatureLayer.Renderer; // Add the map to the mapview _myMapView.Map = myMap; // Enable changing symbology now that sample is loaded _myRendererButton.Enabled = true; } catch (Exception e) { new AlertDialog.Builder(this).SetMessage(e.ToString()).SetTitle("Error").Show(); } }
private async void Initialize() { // Create the point for the map's initial viewpoint. MapPoint point = new MapPoint(-11662054, 4818336, SpatialReference.Create(3857)); // Create and show a map with topographic basemap. Map myMap = new Map(Basemap.CreateTopographic()) { InitialViewpoint = new Viewpoint(point, 200000) }; // Get the path to the shapefile. string shapefilePath = DataManager.GetDataFolder("d98b3e5293834c5f852f13c569930caa", "Subdivisions.shp"); // Create a shapefile feature table from the shapefile path. ShapefileFeatureTable featureTable = new ShapefileFeatureTable(shapefilePath); // Create a layer from the feature table. _shapefileFeatureLayer = new FeatureLayer(featureTable); // Add the layer to the map. myMap.OperationalLayers.Add(_shapefileFeatureLayer); // Create the symbology for the alternate renderer. SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Red, 1.0); SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, System.Drawing.Color.Yellow, lineSymbol); // Create the alternate renderer. _alternateRenderer = new SimpleRenderer(fillSymbol); try { // Wait for the layer to load so that it will be assigned a default renderer. await _shapefileFeatureLayer.LoadAsync(); // Hold a reference to the default renderer (to enable switching between the renderers). _defaultRenderer = _shapefileFeatureLayer.Renderer; // Add the map to the mapview. _myMapView.Map = myMap; // Enable changing symbology now that sample is loaded. _changeRendererButton.Enabled = true; } catch (Exception e) { new UIAlertView("Error", e.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show(); } }
async private void Page_Loaded(object sender, RoutedEventArgs e) { map1.Map = new Map(); string folder = Windows.ApplicationModel.Package.Current.InstalledLocation.Path; string filename = @"Assets\NOA\bnd-political-boundary-a.shp"; string filepath = Path.Combine(folder, filename); ShapefileFeatureTable shapefile = await ShapefileFeatureTable.OpenAsync(filepath); FeatureLayer featurelayer = new FeatureLayer(shapefile); map1.Map.OperationalLayers.Add(featurelayer); await map1.SetViewpointGeometryAsync(featurelayer.FullExtent); }
private async void Initialize() { // Create a new map to display in the map view with a streets basemap Map myMap = new Map(Basemap.CreateStreets()); string file_shapefile_location = parent.FullName + "\\Data\\Public_Art.shp"; try { ShapefileFeatureTable myShapefile = await ShapefileFeatureTable.OpenAsync(file_shapefile_location); // Create a feature layer to display the shapefile FeatureLayer newFeatureLayer = new FeatureLayer(myShapefile); string file_to_stylx = parent.FullName + "\\Data\\style.stylx"; symbolStyle = await SymbolStyle.OpenAsync(file_to_stylx); IList <String> stringList = new List <string>(); stringList.Add("shoppingcenter01"); stringList.Add("marker01"); SimpleRenderer simpleRenderer = new SimpleRenderer(await symbolStyle.GetSymbolAsync(stringList)); newFeatureLayer.Renderer = simpleRenderer; // Add the feature layer to the map myMap.OperationalLayers.Add(newFeatureLayer); // Zoom the map to the extent of the shapefile MyMapView.Map = myMap; await MyMapView.SetViewpointGeometryAsync(newFeatureLayer.FullExtent); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private async void Initialize() { // Create the map with topographic basemap Map myMap = new Map(Basemap.CreateTopographic()); // Create the point for the map's initial viewpoint MapPoint point = new MapPoint(-11662054, 4818336, SpatialReference.Create(3857)); // Create a viewpoint for the point Viewpoint viewpoint = new Viewpoint(point, 200000); // Set the initial viewpoint myMap.InitialViewpoint = viewpoint; // Create a shapefile feature table from the shapefile path ShapefileFeatureTable myFeatureTable = new ShapefileFeatureTable(await GetShapefilePath()); // Create a layer from the feature table _shapefileFeatureLayer = new FeatureLayer(myFeatureTable); // Wait for the layer to load await _shapefileFeatureLayer.LoadAsync(); // Add the layer to the map myMap.OperationalLayers.Add(_shapefileFeatureLayer); // Create the symbology for the alternate renderer SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Colors.Red, 1.0); SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Colors.Yellow, lineSymbol); // Create the alternate renderer _alternateRenderer = new SimpleRenderer(fillSymbol); // Hold a reference to the default renderer (to enable switching between the renderers) _defaultRenderer = _shapefileFeatureLayer.Renderer; // Add the map to the mapview MyMapView.Map = myMap; // Enable changing symbology now that sample is loaded MyRendererButton.IsEnabled = true; }
private async void Initialize() { // Create a new map to display in the map view with a streets basemap _myMapView.Map = new Map(Basemap.CreateStreetsVector()); // Get the path to the downloaded shapefile string filepath = GetShapefilePath(); // Open the shapefile ShapefileFeatureTable myShapefile = await ShapefileFeatureTable.OpenAsync(filepath); // Create a feature layer to display the shapefile FeatureLayer newFeatureLayer = new FeatureLayer(myShapefile); // Add the feature layer to the map _myMapView.Map.OperationalLayers.Add(newFeatureLayer); // Zoom the map to the extent of the shapefile await _myMapView.SetViewpointGeometryAsync(newFeatureLayer.FullExtent); }
public async Task <ShapefileFeatureTable> InitLayerTable(string _layerNm) { string shapeNm = ""; try { string[] ary = _layerNm.Split('^'); shapeNm = ary[0]; //레이어테이블명 string shapefilePath = Path.Combine(BizUtil.GetDataFolder("shape", shapeNm + ".shp")); ShapefileFeatureTable layerTable = await ShapefileFeatureTable.OpenAsync(shapefilePath); return(layerTable); } catch (Exception ex) { Console.WriteLine(ex.Message); return(null); } }
private async void Initialize() { // Create a new map to display in the map view with a streets basemap Map streetMap = new Map(BasemapStyle.ArcGISStreets); // Get the path to the downloaded shapefile string filepath = GetShapefilePath(); try { // Open the shapefile ShapefileFeatureTable myShapefile = await ShapefileFeatureTable.OpenAsync(filepath); // Read metadata about the shapefile and display it in the UI _shapefileMetadata = myShapefile.Info; // Create a feature layer to display the shapefile FeatureLayer newFeatureLayer = new FeatureLayer(myShapefile); await newFeatureLayer.LoadAsync(); // Zoom the map to the extent of the shapefile _myMapView.SpatialReferenceChanged += async(s, e) => { await _myMapView.SetViewpointGeometryAsync(newFeatureLayer.FullExtent); }; // Add the feature layer to the map streetMap.OperationalLayers.Add(newFeatureLayer); // Show the map in the MapView _myMapView.Map = streetMap; } catch (Exception e) { new AlertDialog.Builder(this).SetMessage(e.ToString()).SetTitle("Error").Show(); } }
private async void LoadTheShapefile() { try { // Get the path to the downloaded shape file. string myShapefilePath = _SHAPEFILEPATH; // Open the shape file. ShapefileFeatureTable myShapefileFeatureTable = await ShapefileFeatureTable.OpenAsync(myShapefilePath); // Create a feature layer to display the shape file. FeatureLayer myFeatureLayer = new FeatureLayer(myShapefileFeatureTable); // Set the Id of the feature layer for the shape file so we can find it later. myFeatureLayer.Id = "WorldCountries"; // Add the feature layer to the map. MyMapView.Map.OperationalLayers.Add(myFeatureLayer); } catch (Exception e) { MessageBox.Show(e.ToString(), "Error loading the shape file."); } }
private async void Initialize() { //MyMapView.Map = new Map(Basemap.CreateImagery()); MyMapView.Map = new Map(new SpatialReference(3375)); //MyMapView.InteractionOptions = new MapViewInteractionOptions { IsZoomEnabled = false }; // Open the shapefile ShapefileFeatureTable myShapefile = await ShapefileFeatureTable.OpenAsync(shapeFilePath); // Create a feature layer to display the shapefile FeatureLayer newFeatureLayer = new FeatureLayer(myShapefile); // Add the feature layer to the map MyMapView.Map.OperationalLayers.Add(newFeatureLayer); await myShapefile.LoadAsync(); //Get mosaic dataset names in the SQLite database. var names = MosaicDatasetRaster.GetNames(rasterMapMosaicPath); var rasterName = names[0]; //Create a raster from a mosaic dataset Raster mapRaster = new MosaicDatasetRaster(rasterMapMosaicPath, "RasterMapTable"); // Create a RasterLayer to display the Raster RasterLayer rasterMapLayer = new RasterLayer(mapRaster); MyMapView.Map.OperationalLayers.Add(rasterMapLayer); rasterMapLayer.MinScale = 100000; rasterMapLayer.MaxScale = 2000; await rasterMapLayer.LoadAsync(); MyMapView.Map.MinScale = 3000000; MyMapView.Map.MaxScale = 2000; MyMapView.GraphicsOverlays.Add(graphicsOverlay); // Add a graphic at JFK to serve as the origin. start = new MapPoint(564968.155634, 431946.116905, new SpatialReference(3168)); mapPoints.Add(start); SimpleMarkerSymbol startMarker = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Cross, System.Drawing.Color.Blue, 15); //PictureMarkerSymbol markerSym = new PictureMarkerSymbol(new Uri("C:\\Users\\mfathin.CSYSINT\\Documents\\Visual Studio 2017\\Projects\\ArcGISControl\\ArcGISControl\\Icon\\icons8-man-filled-100.PNG")); // markerSym.Opacity = 0.5; _startLocationGraphic = new Graphic(start, startMarker); // Create the graphic for the destination. _endLocationGraphic = new Graphic { Symbol = startMarker }; // Create the graphic for the path. _pathGraphic = new Graphic { Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Blue, 1) }; graphic1 = new Graphic { Symbol = startMarker }; // Add the graphics to the overlay. graphicsOverlay.Graphics.Add(_startLocationGraphic); graphicsOverlay.Graphics.Add(_endLocationGraphic); graphicsOverlay.Graphics.Add(graphic1); graphicsOverlay.Graphics.Add(_pathGraphic); //// Update end location when the user taps. MyMapView.GeoViewTapped += MyMapViewOnGeoViewTapped; await MyMapView.SetViewpointAsync(new Viewpoint(start, 4000000)); // Update the extent to encompass all of the symbols //SetExtent(); // Add the graphics overlay to the map view //MyMapView.GraphicsOverlays.Add(_overlay); plotButton.Click += (sender, e) => { TryPlot(); }; TrueCalculation(); }
private void Update(ShapefileFeatureTable sf, CancellationToken ct, IProgress <int> p) { Task.Run(async() => { var directory = Globals.Model.Assets.PathTo("BasinShapefile"); if (String.IsNullOrWhiteSpace(directory)) { MessageBox.Show("You need to have imported a basin shapefile."); Clear(); return; } var file = Directory.EnumerateFiles(directory, "*.shp").FirstOrDefault(); if (String.IsNullOrWhiteSpace(file)) { MessageBox.Show("Error reading the basin shapefile."); Clear(); return; } var ci = Globals.Model.EcosystemVitality.FetchIndicator <ConnectivityIndicator>(); var reaches = ci?.Reaches; if (reaches == null) { MessageBox.Show( "You must import a river network for the Connectivity Indicator in Ecosystem Vitality."); Clear(); return; } var bsf = await ShapefileFeatureTable.OpenAsync(file); var allQuery = new QueryParameters { Geometry = bsf.Extent, SpatialRelationship = SpatialRelationship.Contains }; ConservationAreaIndicator.TotalProtectedArea = 0; ConservationAreaIndicator.TotalArea = 0; foreach (var mapFeature in await bsf.QueryFeaturesAsync(allQuery)) { if (ct.IsCancellationRequested) { Clear(); return; } ConservationAreaIndicator.TotalArea += GeometryEngine.AreaGeodetic(mapFeature.Geometry); var areaFeatures = await sf.QueryFeaturesAsync(new QueryParameters { Geometry = mapFeature.Geometry, SpatialRelationship = SpatialRelationship.Contains }); foreach (var feature in areaFeatures) { ConservationAreaIndicator.TotalProtectedArea += GeometryEngine.AreaGeodetic(feature.Geometry); if (ct.IsCancellationRequested) { Clear(); return; } } } p.Report(25); // todo: this is not an efficient algorithm var pb = new PolylineBuilder(new SpatialReference(Model.Attributes.Wkid)); foreach (var reach in reaches) { pb.AddPart( reach.Nodes.Select(node => new MapPoint(node.Location.Longitude, node.Location.Latitude))); } var mapGeometry = pb.ToGeometry(); ConservationAreaIndicator.TotalLength = GeometryEngine.Length(mapGeometry); if (ct.IsCancellationRequested) { Clear(); return; } var lengthFeatures = await sf.QueryFeaturesAsync(new QueryParameters { Geometry = sf.Extent, SpatialRelationship = SpatialRelationship.Contains }); var tpl = 0.0; var reachNumber = 0; foreach (var reach in reaches) { var poly = new PolylineBuilder(new SpatialReference(Model.Attributes.Wkid)); poly.AddPart(reach.Nodes.Select(node => new MapPoint(node.Location.Longitude, node.Location.Latitude))); var pg = poly.ToGeometry(); foreach (var feature in lengthFeatures) { var intersection = GeometryEngine.Intersection(pg, feature.Geometry) as Polyline; if (intersection?.Parts.Count > 0) { tpl += GeometryEngine.Length(pg); } if (ct.IsCancellationRequested) { Clear(); return; } } p.Report(25 + (int)(75.0 * reachNumber++ / reaches.Count)); } ConservationAreaIndicator.TotalProtectedLength = tpl; }, ct).Wait(ct); }
private async Task Import() { var dialog = new OpenFileDialog { Title = "Add conservation area shapefile", Filter = "GIS Shapefile (*.shp)|*.shp", DefaultExt = ".shp" }; if (dialog.ShowDialog() != true) { return; } var filename = dialog.FileName; var rawAssetName = Path.GetFileNameWithoutExtension(filename); if (ConservationAreaIndicator.AssetNames.Contains(rawAssetName)) { MessageBox.Show("You have already added a shapefile by that name."); return; } _assetName = rawAssetName; int i = 1; while (Model.Assets.Exists(_assetName)) { _assetName = $"{rawAssetName}_{i++}"; } ConservationAreaIndicator.AssetNames.Add(_assetName); Model.Assets.Create(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename), _assetName); try { var sf = await ShapefileFeatureTable.OpenAsync(filename); if (!sf.HasGeometry) { MessageBox.Show($"Shapefile {filename} does not have a geometry."); Clear(); return; } var directory = Globals.Model.Assets.PathTo("BasinShapefile"); if (String.IsNullOrWhiteSpace(directory)) { MessageBox.Show("You need to have imported a basin shapefile."); Clear(); return; } var ci = Globals.Model.EcosystemVitality.FetchIndicator <ConnectivityIndicator>(); if (ci?.Reaches == null) { MessageBox.Show( "You must import a river network for the Connectivity Indicator in Ecosystem Vitality."); Clear(); return; } var progress = new ProgressDialog { Label = $"Processing conservation areas", Owner = Application.Current.MainWindow, IsCancellable = true, IsIndeterminate = false }; progress.Execute((ct, p) => Update(sf, ct, p)); } catch (Exception ex) { MessageBox.Show($"Open of shapefile {filename} failed: {ex.Message}"); Clear(); } }
private async Task ImportFromShapefile() { var dialog = new OpenFileDialog { Title = "Open shapefile with Spatial Unit locations", Filter = "Shapefile (*.shp)|*.shp", DefaultExt = ".shp" }; if (dialog.ShowDialog() != true) { return; } var filename = dialog.FileName; var sf = await ShapefileFeatureTable.OpenAsync(filename); var qp = new QueryParameters(); var esi = Model.EcosystemServices.FetchIndicators <EcosystemServicesIndicator>().ToList(); var res = await sf.QueryFeaturesAsync(qp); foreach (var r in res) { Trace.WriteLine($"{r.Geometry}"); if (!(r.Geometry is MapPoint point)) { if (!(r.Geometry is Polygon polygon)) { continue; } point = polygon.Extent.GetCenter(); } var name = r.Attributes.FirstOrDefault(x => x.Key.ToLowerInvariant() == "name").Value as String; var success = false; foreach (var es in esi) { foreach (var su in es.SpatialUnits) { if (su.Name.ToLowerInvariant() != name?.ToLowerInvariant()) { continue; } su.Location.Latitude = point.Y; su.Location.Longitude = point.X; su.Location.Wkid = point.SpatialReference.Wkid; success = true; } } if (success) { continue; } var wkid = point.SpatialReference.Wkid; if (wkid == 0) { wkid = 4326; // WGS84 } SpatialUnit nsu = null; switch (Indicator.EvidenceLevel) { case Confidence.F1: nsu = new F1SpatialUnit { Name = name, NonCompliant = false, Location = { Latitude = point.Y, Longitude = point.X, Wkid = wkid } }; break; case Confidence.F2: nsu = new F2SpatialUnit { Name = name, Location = { Latitude = point.Y, Longitude = point.X, Wkid = wkid } }; break; case Confidence.F3Sharp: nsu = new F3SharpSpatialUnit { Name = name, Location = { Latitude = point.Y, Longitude = point.X, Wkid = wkid } }; break; case Confidence.F3Fuzzy: nsu = new F3FuzzySpatialUnit { Name = name, Location = { Latitude = point.Y, Longitude = point.X, Wkid = wkid } }; break; default: throw new ArgumentException("Unknown evidence level."); } Indicator.SpatialUnits.Add(nsu); if (String.IsNullOrWhiteSpace(nsu.Name)) { nsu.Name = $"SU [{Indicator.SpatialUnits.IndexOf(nsu) + 1}]"; } } }
/// <summary> /// Shape 레이어 보이기/끄기 - Shape버전 /// </summary> /// <param name="_mapView"></param> /// <param name="layer"></param> /// <param name="chk"></param> public async void ShowShapeLayer(MapView _mapView, string _layerNm, bool chk) { try { // 0.해당레이어 가져오기 string filterExp = ""; string layerNm = ""; try { string[] ary = _layerNm.Split(','); layerNm = ary[0]; //레이어테이블명 filterExp = ary[1]; //필터표현식 } catch (Exception) { } FeatureLayer layer = layers[_layerNm]; //Type memberType = this.GetType(); // 1.레이어 ON if (chk) { if (_mapView.Map.OperationalLayers.Contains(layer)) { //on상태 아무것도 안함 } else { if (layer != null && layer.LoadStatus == LoadStatus.Loaded) //레이어객체 있으면 단순추가 { _mapView.Map.OperationalLayers.Add(layer); } else //레이어객체 없으면 Shape 로딩 { string shapefilePath = Path.Combine(BizUtil.GetDataFolder("shape", layerNm + ".shp")); try { ShapefileFeatureTable layerTable = await ShapefileFeatureTable.OpenAsync(shapefilePath); layer = new FeatureLayer(layerTable); /////// 신규레이어 생성 /////// layers[_layerNm] = layer; /////// 딕셔너리에 자동으로 저장되지는 않을것임 /////// layer.Renderer = uniqueValueRenderer.Clone(); //렌더러는 레이어 각각 할당해야하므로 렌더러복사하여 할당 _mapView.Map.OperationalLayers.Add(layer); } catch (Exception) { //throw e; } } } // 필터링 인수있으면 하위시설물으로 필터 if (!FmsUtil.IsNull(filterExp)) { layer.DefinitionExpression = filterExp; } } // 2.레이어 OFF else { if (_mapView.Map.OperationalLayers.Contains(layer)) { _mapView.Map.OperationalLayers.Remove(layer); } else { //off상태 아무것도 안함 } // 필터링 인수있으면 하위시설물으로 필터 리셋 if (!FmsUtil.IsNull(filterExp)) { layer.DefinitionExpression = ""; } } } catch (Exception) { MessageBox.Show("레이어가 존재하지 않습니다."); } }
private async Task ImportFromShapefile() { var dialog = new OpenFileDialog { Title = "Open shapefile with station locations", Filter = "Shapefile (*.shp)|*.shp", DefaultExt = ".shp" }; if (dialog.ShowDialog() != true) { return; } var filename = dialog.FileName; var sf = await ShapefileFeatureTable.OpenAsync(filename); var qp = new QueryParameters(); var res = await sf.QueryFeaturesAsync(qp); foreach (var r in res) { Trace.WriteLine($"{r.Geometry}"); if (!(r.Geometry is MapPoint point)) { if (!(r.Geometry is Polygon polygon)) { continue; } point = polygon.Extent.GetCenter(); } var name = r.Attributes.FirstOrDefault(x => x.Key.ToLowerInvariant() == "name").Value as String; var success = false; foreach (var station in FlowDeviation.Stations) { if (station.Name.ToLowerInvariant() != name?.ToLowerInvariant()) { continue; } station.Location.Latitude = point.Y; station.Location.Longitude = point.X; station.Location.Wkid = point.SpatialReference.Wkid; success = true; } if (success) { continue; } var wkid = point.SpatialReference.Wkid; if (wkid == 0) { wkid = 4326; // WGS84 } var ns = new Station { Name = name, Location = { Latitude = point.Y, Longitude = point.X, Wkid = wkid } }; FlowDeviation.Stations.Add(ns); if (String.IsNullOrWhiteSpace(ns.Name)) { ns.Name = $"STATION [{FlowDeviation.Stations.IndexOf(ns) + 1}]"; } } }
/// <summary> /// Shape 레이어 보이기/끄기 - Shape버전 /// </summary> /// <param name="_mapView"></param> /// <param name="layer"></param> /// <param name="chk"></param> public async void ShowShapeLayerFilter(MapView _mapView, string _layerNm, bool chk, string _FTR_IDN) { try { // 0.해당레이어 가져오기 string filterExp = ""; string shapeNm = ""; try { string[] ary = _layerNm.Split('^'); shapeNm = ary[0]; //레이어테이블명 filterExp = "FTR_CDE='" + ary[1] + "'"; //필터표현식 } catch (Exception) { } //FTR_IDN 필터추가 if (!FmsUtil.IsNull(_FTR_IDN)) { if (FmsUtil.IsNull(filterExp)) { filterExp += "FTR_IDN LIKE '%' || " + _FTR_IDN + " || '%'"; } else { filterExp += " AND FTR_IDN LIKE '%' || " + _FTR_IDN + " || '%'"; } } FeatureLayer layer = layers[_layerNm]; //Type memberType = this.GetType(); // 1.레이어 ON if (chk) { // 필터링 인수있으면 하위시설물(관리번호, 전체)으로 필터 layer.DefinitionExpression = filterExp; if (_mapView.Map.OperationalLayers.Contains(layer)) { //on상태 아무것도 안함 } else { if (layer != null && layer.LoadStatus == LoadStatus.Loaded) //레이어객체 있으면 단순추가 { _mapView.Map.OperationalLayers.Add(layer); } else //레이어객체 없으면 Shape 로딩 { string shapefilePath = Path.Combine(BizUtil.GetDataFolder("shape", shapeNm + ".shp")); try { ShapefileFeatureTable layerTable = await ShapefileFeatureTable.OpenAsync(shapefilePath); layer = new FeatureLayer(layerTable); /////// 신규레이어 생성 /////// layer.DefinitionExpression = filterExp; // 필터링 인수있으면 하위시설물(관리번호, 전체)으로 필터 layers[_layerNm] = layer; /////// 딕셔너리에 자동으로 저장되지는 않을것임 /////// layer.Renderer = CmmRun.uniqueValueRenderer.Clone(); //렌더러는 레이어 각각 할당해야하므로 렌더러복사하여 할당 _mapView.Map.OperationalLayers.Add(layer); } catch (Exception e) { Messages.ShowErrMsgBox(e.Message); } } } // Zoom the map to the extent of the shapefile. //await _mapView.SetViewpointGeometryAsync(layer.FullExtent, 50); } // 2.레이어 OFF else { if (_mapView.Map.OperationalLayers.Contains(layer)) { _mapView.Map.OperationalLayers.Remove(layer); } else { //off상태 아무것도 안함 } // 필터링 인수있으면 하위시설물으로 필터 리셋 layer.DefinitionExpression = ""; } } catch (Exception) { MessageBox.Show("레이어가 존재하지 않습니다."); } }