private async void GetFeaturesFromQuery()
        {
            // Create a service feature table to get features from
            ServiceFeatureTable featTable = new ServiceFeatureTable(new Uri(FeatureLayerUrl));

            // Create a query to get all features in the table
            QueryParameters queryParams = new QueryParameters();

            queryParams.WhereClause = "1=1";

            // Query the table to get all features
            FeatureQueryResult featureResult = await featTable.QueryFeaturesAsync(queryParams);

            // Create a new feature collection table from the result features
            FeatureCollectionTable collectTable = new FeatureCollectionTable(featureResult);

            // Create a feature collection and add the table
            FeatureCollection featCollection = new FeatureCollection();

            featCollection.Tables.Add(collectTable);

            // Create a layer to display the feature collection, add it to the map's operational layers
            FeatureCollectionLayer featCollectionTable = new FeatureCollectionLayer(featCollection);

            _myMapView.Map.OperationalLayers.Add(featCollectionTable);
        }
        private async void GetFeaturesFromQuery()
        {
            // Create a service feature table to get features from.
            ServiceFeatureTable featTable = new ServiceFeatureTable(new Uri(FeatureLayerUrl));

            // Create a query to get all features in the table.
            QueryParameters queryParams = new QueryParameters
            {
                WhereClause = "1=1"
            };

            // Query the table to get all features.
            FeatureQueryResult featureResult = await featTable.QueryFeaturesAsync(queryParams);

            // Create a new feature collection table from the result features.
            FeatureCollectionTable collectTable = new FeatureCollectionTable(featureResult);

            // Create a feature collection and add the table.
            FeatureCollection featCollection = new FeatureCollection();

            featCollection.Tables.Add(collectTable);

            // Create a layer to display the feature collection, add it to the map's operational layers.
            FeatureCollectionLayer featureCollectionLayer = new FeatureCollectionLayer(featCollection);

            _myMapView.Map.OperationalLayers.Add(featureCollectionLayer);

            // Zoom to the extent of the feature collection layer.
            await featureCollectionLayer.LoadAsync();

            await _myMapView.SetViewpointGeometryAsync(featureCollectionLayer.FullExtent, 50);
        }
        private async void GetFeaturesFromQuery()
        {
            try
            {
                // Create a service feature table to get features from
                ServiceFeatureTable featTable = new ServiceFeatureTable(new Uri(FeatureLayerUrl));

                // Create a query to get all features in the table
                QueryParameters queryParams = new QueryParameters
                {
                    WhereClause = "1=1"
                };

                // Query the table to get all features
                FeatureQueryResult featureResult = await featTable.QueryFeaturesAsync(queryParams);

                // Create a new feature collection table from the result features
                FeatureCollectionTable collectTable = new FeatureCollectionTable(featureResult);

                // Create a feature collection and add the table
                FeatureCollection featCollection = new FeatureCollection();
                featCollection.Tables.Add(collectTable);

                // Create a layer to display the feature collection, add it to the map's operational layers
                FeatureCollectionLayer featCollectionTable = new FeatureCollectionLayer(featCollection);
                MyMapView.Map.OperationalLayers.Add(featCollectionTable);
            }
            catch (Exception e)
            {
                await new MessageDialog2(e.ToString(), "Error").ShowAsync();
            }
        }
Exemple #4
0
        private async void LoadByFeatureCollectionLayer()
        {
            FeatureCollection      featCollection = new FeatureCollection();
            FeatureCollectionLayer layer          = new FeatureCollectionLayer(featCollection);

            if (layer.Layers != null)
            {
                layer.Layers.Select(x => x.RenderingMode = FeatureRenderingMode.Dynamic);
            }
            MyMapView.Map.OperationalLayers.Add(layer);


            foreach (var tab in MyGeoPackage.GeoPackageFeatureTables)// Where(x => x.TableName.Contains("polygon")).ToList();
            {
                var queryPts = new QueryParameters();

                //queryPts.Geometry = MyMapView.VisibleArea;
                //queryPts.WhereClause = @" 1 = 1 ";
                var featureResult = await tab.QueryFeaturesAsync(queryPts);

                FeatureCollectionTable collectTable = new FeatureCollectionTable(featureResult);

                featCollection.Tables.Add(collectTable);
            }
        }
Exemple #5
0
        private async Task CalculateViewshed(MapPoint location)
        {
            // Create new geoprocessing task
            var viewshedTask = new GeoprocessingTask(new Uri(ViewshedUrl));

            // Create input collection that contains the requested location
            var     inputFeatures = new FeatureCollectionTable(new List <Field>(), GeometryType.Point, MyMapView.SpatialReference);
            Feature inputFeature  = inputFeatures.CreateFeature();

            inputFeature.Geometry = location;
            await inputFeatures.AddFeatureAsync(inputFeature);

            // Create parameters that are passed to the used geoprocessing task
            GeoprocessingParameters viewshedParameters =
                new GeoprocessingParameters(GeoprocessingExecutionType.SynchronousExecute);

            // Request output features in same SpatialReference as view.
            viewshedParameters.OutputSpatialReference = MyMapView.SpatialReference;

            // Add input location to geoprocessing parameters
            viewshedParameters.Inputs.Add("Input_Observation_Point", new GeoprocessingFeatures(inputFeatures));

            // Create job that handles the communication between the application and the geoprocessing task
            var viewshedJob = viewshedTask.CreateJob(viewshedParameters);

            try
            {
                // Execute analysis and wait for the results
                GeoprocessingResult analysisResult = await viewshedJob.GetResultAsync();

                // Get results from the outputs
                GeoprocessingFeatures viewshedResultFeatures = analysisResult.Outputs["Viewshed_Result"] as GeoprocessingFeatures;

                // Add all the results as a graphics to the map
                IFeatureSet viewshedAreas = viewshedResultFeatures.Features;
                foreach (var feature in viewshedAreas)
                {
                    _resultOverlay.Graphics.Add(new Graphic(feature.Geometry));
                }
            }
            catch (Exception ex)
            {
                if (viewshedJob.Status == JobStatus.Failed && viewshedJob.Error != null)
                {
                    MessageBox.Show("Executing geoprocessing failed. " + viewshedJob.Error.Message, "Geoprocessing error");
                }
                else
                {
                    MessageBox.Show("An error occurred. " + ex.ToString(), "Sample error");
                }
            }
            finally
            {
                SetBusy(false);
            }
        }
        private async void SaveFeatureCollectionFromQuery()
        {
            Debug.WriteLine("Creating feature collection from the service...");

            // Create a service feature table to get features from
            ServiceFeatureTable featTable = new ServiceFeatureTable(new Uri(FeatureLayerUrl));

            // Create a query to get all features in the table
            QueryParameters queryParams = new QueryParameters();

            queryParams.WhereClause = "1=1";

            // Query the table to get all features
            FeatureQueryResult featureResult = await featTable.QueryFeaturesAsync(queryParams);

            // Create a new feature collection table from the result features
            FeatureCollectionTable collectTable = new FeatureCollectionTable(featureResult);

            // Create a feature collection and add the table
            FeatureCollection featCollection = new FeatureCollection();

            featCollection.Tables.Add(collectTable);


            var tokenServiceUri = new Uri("https://www.arcgis.com/sharing/rest");  // url for generating token

            AuthenticationManager authManager = AuthenticationManager.Current;
            var cred = await authManager.GenerateCredentialAsync(tokenServiceUri, "*******", "*******");

            // Open a portal item containing a feature collection
            ArcGISPortal portal = await ArcGISPortal.CreateAsync(tokenServiceUri, cred);

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

            str.Add("Save Feature collection");


            FeatureCollectionLayer featCollectionTable = new FeatureCollectionLayer(featCollection);
            await featCollectionTable.LoadAsync();

            MyMapView.Map.OperationalLayers.Add(featCollectionTable);

            Debug.WriteLine("Create a feature layer named, Feature Collection to Portal, and saving to portal...");

            try
            {
                await featCollection.SaveAsAsync(portal, null, "Feature Collection to Portal", "FeatureCollection", str);

                MessageBox.Show("Feature Collection saved to portal");
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #7
0
        private async void AddFeature(MapPoint mapClickPoint)
        {
            // Grab the feature collection from the operational layers and create a feature collection layer
            _featCollectionLayer = (FeatureCollectionLayer)MyMapView.Map.OperationalLayers[0];

            // Get the points table from the feature collection layer and add to the feature collection table for editing
            _featCollectionTable = (FeatureCollectionTable)_featCollectionLayer.Layers[1].FeatureTable;

            // Create a feature
            Feature f = _featCollectionTable.CreateFeature();

            // Populate the feature's geometry with the map point coords
            f.Geometry = mapClickPoint;

            // Add the feature to the feature collection table
            await _featCollectionTable.AddFeatureAsync(f);
        }
        private async void GetFeaturesFromQuery()
        {
            // Create a service feature table to get features from
            ServiceFeatureTable featTable = new ServiceFeatureTable(new Uri(FeatureLayerUrl));

            // Create a query to get all features in the table
            QueryParameters queryParams = new QueryParameters();
            queryParams.WhereClause = "1=1";

            // Query the table to get all features
            FeatureQueryResult featureResult = await featTable.QueryFeaturesAsync(queryParams);

            // Create a new feature collection table from the result features
            FeatureCollectionTable collectTable = new FeatureCollectionTable(featureResult);

            // Create a feature collection and add the table
            FeatureCollection featCollection = new FeatureCollection();
            featCollection.Tables.Add(collectTable);

            // Create a layer to display the feature collection, add it to the map's operational layers
            FeatureCollectionLayer featCollectionTable = new FeatureCollectionLayer(featCollection);
            MyMapView.Map.OperationalLayers.Add(featCollectionTable);
        }
        private async void CreateNewFeatureCollection()
        {
            // Create the schema for a points table (one text field to contain a name attribute).
            List <Field> pointFields = new List <Field>();
            Field        placeField  = new Field(FieldType.Text, "Place", "Place Name", 50);

            pointFields.Add(placeField);

            // Create the schema for a lines table (one text field to contain a name attribute).
            List <Field> lineFields    = new List <Field>();
            Field        boundaryField = new Field(FieldType.Text, "Boundary", "Boundary Name", 50);

            lineFields.Add(boundaryField);

            // Create the schema for a polygon table (one text field to contain a name attribute).
            List <Field> polyFields = new List <Field>();
            Field        areaField  = new Field(FieldType.Text, "AreaName", "Area Name", 50);

            polyFields.Add(areaField);

            // Instantiate FeatureCollectionTables with schema and geometry type.
            FeatureCollectionTable pointsTable = new FeatureCollectionTable(pointFields, GeometryType.Point, SpatialReferences.Wgs84);
            FeatureCollectionTable linesTable  = new FeatureCollectionTable(lineFields, GeometryType.Polyline, SpatialReferences.Wgs84);
            FeatureCollectionTable polysTable  = new FeatureCollectionTable(polyFields, GeometryType.Polygon, SpatialReferences.Wgs84);

            // Set rendering for each table.
            pointsTable.Renderer = CreateRenderer(GeometryType.Point);
            linesTable.Renderer  = CreateRenderer(GeometryType.Polyline);
            polysTable.Renderer  = CreateRenderer(GeometryType.Polygon);

            // Create a new point feature, provide geometry and attribute values.
            Feature pointFeature = pointsTable.CreateFeature();

            pointFeature.SetAttributeValue(placeField, "Current location");
            MapPoint point1 = new MapPoint(-79.497238, 8.849289, SpatialReferences.Wgs84);

            pointFeature.Geometry = point1;

            // Create a new line feature, provide geometry and attribute values.
            Feature lineFeature = linesTable.CreateFeature();

            lineFeature.SetAttributeValue(boundaryField, "AManAPlanACanalPanama");
            MapPoint point2 = new MapPoint(-80.035568, 9.432302, SpatialReferences.Wgs84);

            lineFeature.Geometry = new Polyline(new[] { point1, point2 });

            // Create a new polygon feature, provide geometry and attribute values.
            Feature polyFeature = polysTable.CreateFeature();

            polyFeature.SetAttributeValue(areaField, "Restricted area");
            MapPoint point3 = new MapPoint(-79.337936, 8.638903, SpatialReferences.Wgs84);
            MapPoint point4 = new MapPoint(-79.11409, 8.895422, SpatialReferences.Wgs84);

            polyFeature.Geometry = new Polygon(new[] { point1, point3, point4 });

            // Add the new features to the appropriate feature collection table.
            await pointsTable.AddFeatureAsync(pointFeature);

            await linesTable.AddFeatureAsync(lineFeature);

            await polysTable.AddFeatureAsync(polyFeature);

            // Create a feature collection and add the feature collection tables.
            FeatureCollection featuresCollection = new FeatureCollection();

            featuresCollection.Tables.Add(pointsTable);
            featuresCollection.Tables.Add(linesTable);
            featuresCollection.Tables.Add(polysTable);

            // Create a FeatureCollectionLayer.
            FeatureCollectionLayer collectionLayer = new FeatureCollectionLayer(featuresCollection);

            // When the layer loads, zoom the map view to the extent of the feature collection.
            collectionLayer.Loaded += (s, e) => _myMapView.SetViewpointAsync(new Viewpoint(collectionLayer.FullExtent));

            // Add the layer to the Map's Operational Layers collection.
            _myMapView.Map.OperationalLayers.Add(collectionLayer);
        }
        private async void CreateNewFeatureCollection()
        {
            // Create the schema for a points table (one text field to contain a name attribute)
            List <Field> pointFields = new List <Field>();
            Field        placeField  = new Field(FieldType.Text, "Place", "Place Name", 50);

            pointFields.Add(placeField);

            // Create the schema for a lines table (one text field to contain a name attribute)
            List <Field> lineFields    = new List <Field>();
            Field        boundaryField = new Field(FieldType.Text, "Boundary", "Boundary Name", 50);

            lineFields.Add(boundaryField);

            // Create the schema for a polygon table (one text field to contain a name attribute)
            List <Field> polyFields = new List <Field>();
            Field        areaField  = new Field(FieldType.Text, "AreaName", "Area Name", 50);

            polyFields.Add(areaField);

            // Instantiate FeatureCollectionTables with schema and geometry type
            FeatureCollectionTable pointsTable = new FeatureCollectionTable(pointFields, GeometryType.Point, SpatialReferences.Wgs84);
            FeatureCollectionTable linesTable  = new FeatureCollectionTable(lineFields, GeometryType.Polyline, SpatialReferences.Wgs84);
            FeatureCollectionTable polysTable  = new FeatureCollectionTable(polyFields, GeometryType.Polygon, SpatialReferences.Wgs84);

            // Set rendering for each table
            pointsTable.Renderer = CreateRenderer(GeometryType.Point);
            linesTable.Renderer  = CreateRenderer(GeometryType.Polyline);
            polysTable.Renderer  = CreateRenderer(GeometryType.Polygon);

            // Create a new point feature, provide geometry and attribute values
            Feature pointFeature = pointsTable.CreateFeature();

            pointFeature.SetAttributeValue(placeField, "Current location");
            MapPoint point1 = new MapPoint(-79.497238, 8.849289, SpatialReferences.Wgs84);

            pointFeature.Geometry = point1;

            // Create a new line feature, provide geometry and attribute values
            Feature lineFeature = linesTable.CreateFeature();

            lineFeature.SetAttributeValue(boundaryField, "AManAPlanACanalPanama");
            MapPoint point2 = new MapPoint(-80.035568, 9.432302, SpatialReferences.Wgs84);
            Polyline line   = new Polyline(new MapPoint[] { point1, point2 });

            lineFeature.Geometry = line;

            // Create a new polygon feature, provide geometry and attribute values
            Feature polyFeature = polysTable.CreateFeature();

            polyFeature.SetAttributeValue(areaField, "Restricted area");
            MapPoint point3 = new MapPoint(-79.337936, 8.638903, SpatialReferences.Wgs84);
            MapPoint point4 = new MapPoint(-79.11409, 8.895422, SpatialReferences.Wgs84);
            Polygon  poly   = new Polygon(new MapPoint[] { point1, point3, point4 });

            polyFeature.Geometry = poly;

            try
            {
                // Add the new features to the appropriate feature collection table
                await pointsTable.AddFeatureAsync(pointFeature);

                await linesTable.AddFeatureAsync(lineFeature);

                await polysTable.AddFeatureAsync(polyFeature);

                // Create a feature collection and add the feature collection tables
                FeatureCollection featuresCollection = new FeatureCollection();
                featuresCollection.Tables.Add(pointsTable);
                featuresCollection.Tables.Add(linesTable);
                featuresCollection.Tables.Add(polysTable);

                // Create a FeatureCollectionLayer
                FeatureCollectionLayer collectionLayer = new FeatureCollectionLayer(featuresCollection);

                // When the layer loads, zoom the map centered on the feature collection
                await collectionLayer.LoadAsync();

                await _myMapView.SetViewpointCenterAsync(collectionLayer.FullExtent.GetCenter(), 1000000);

                // Add the layer to the Map's Operational Layers collection
                _myMapView.Map.OperationalLayers.Add(collectionLayer);
            }
            catch (Exception e)
            {
                new AlertDialog.Builder(this).SetMessage(e.ToString()).SetTitle("Error").Show();
            }
        }
        private async Task CalculateViewshed(MapPoint location)
        {
            // This function will define a new geoprocessing task that performs a custom viewshed analysis based upon a
            // user click on the map and then display the results back as a polygon fill graphics overlay. If there
            // is a problem with the execution of the geoprocessing task an error message will be displayed

            // Create new geoprocessing task using the url defined in the member variables section
            GeoprocessingTask myViewshedTask = await GeoprocessingTask.CreateAsync(new Uri(_viewshedUrl));

            // Create a new feature collection table based upon point geometries using the current map view spatial reference
            FeatureCollectionTable myInputFeatures = new FeatureCollectionTable(new List <Field>(), GeometryType.Point, MyMapView.SpatialReference);

            // Create a new feature from the feature collection table. It will not have a coordinate location (x,y) yet
            Feature myInputFeature = myInputFeatures.CreateFeature();

            // Assign a physical location to the new point feature based upon where the user clicked in the map view
            myInputFeature.Geometry = location;

            // Add the new feature with (x,y) location to the feature collection table
            await myInputFeatures.AddFeatureAsync(myInputFeature);

            // Create the parameters that are passed to the used geoprocessing task
            GeoprocessingParameters myViewshedParameters =
                new GeoprocessingParameters(GeoprocessingExecutionType.SynchronousExecute)
            {
                // Request the output features to use the same SpatialReference as the map view
                OutputSpatialReference = MyMapView.SpatialReference
            };

            // Add an input location to the geoprocessing parameters
            myViewshedParameters.Inputs.Add("Input_Observation_Point", new GeoprocessingFeatures(myInputFeatures));

            // Create the job that handles the communication between the application and the geoprocessing task
            GeoprocessingJob myViewshedJob = myViewshedTask.CreateJob(myViewshedParameters);

            try
            {
                // Execute analysis and wait for the results
                GeoprocessingResult myAnalysisResult = await myViewshedJob.GetResultAsync();

                // Get the results from the outputs
                GeoprocessingFeatures myViewshedResultFeatures = (GeoprocessingFeatures)myAnalysisResult.Outputs["Viewshed_Result"];

                // Add all the results as a graphics to the map
                IFeatureSet myViewshedAreas = myViewshedResultFeatures.Features;
                foreach (Feature myFeature in myViewshedAreas)
                {
                    _resultOverlay.Graphics.Add(new Graphic(myFeature.Geometry));
                }
            }
            catch (Exception ex)
            {
                // Display an error message if there is a problem
                if (myViewshedJob.Status == JobStatus.Failed && myViewshedJob.Error != null)
                {
                    MessageBox.Show("Executing geoprocessing failed. " + myViewshedJob.Error.Message, "Geoprocessing error");
                }
                else
                {
                    MessageBox.Show("An error occurred. " + ex.ToString(), "Sample error");
                }
            }
            finally
            {
                // Indicate that the geoprocessing is not running
                SetBusy(false);
            }
        }
Exemple #12
0
        private async void ExecuteGPService()
        {
            //加载DEM并且缩放到该区域
            Map    map          = new Map(Basemap.CreateTopographic());
            string pathToRaster = @"D:\work\github\ExecuteGPK\LasVegasNED13_geoid1.tif";
            var    myRaster     = new Raster(pathToRaster);
            // create a RasterLayer using the Raster
            var newRasterLayer = new RasterLayer(myRaster);

            map.OperationalLayers.Add(newRasterLayer);
            Viewpoint viewPoint = new Viewpoint(36.131, -115.144, 800000);

            myMapView.Map = map;
            await myMapView.SetViewpointAsync(viewPoint, TimeSpan.FromSeconds(2));

            StartLocalServer();
            LocalGeoprocessingService localServiceGP = new LocalGeoprocessingService(@"D:\work\github\ExecuteGPK\InterpolateShape.gpk");

            localServiceGP.ServiceType = GeoprocessingServiceType.SynchronousExecute;
            // Handle the status changed event to check when it's loaded
            localServiceGP.StatusChanged += async(svc, args) =>
            {
                // If service started successfully, create a gp task
                if (args.Status == LocalServerStatus.Started)
                {
                    // Get the URL for the specific geoprocessing tool
                    var gpSvcUrl = (svc as LocalGeoprocessingService).Url.AbsoluteUri + "/InterpolateShape";
                    // Create the geoprocessing task
                    GeoprocessingTask       gpRouteTask = new GeoprocessingTask(new Uri(gpSvcUrl));
                    GeoprocessingParameters para        = new GeoprocessingParameters(GeoprocessingExecutionType.SynchronousExecute);
                    // Create the schema for a lines table (one text field to contain a name attribute)
                    var     inputFeatures = new FeatureCollectionTable(new List <Field>(), GeometryType.Polyline, myMapView.SpatialReference);
                    Feature inputFeature  = inputFeatures.CreateFeature();
                    var     geometry      = await myMapView.SketchEditor.StartAsync(SketchCreationMode.Polyline, false);

                    inputFeature.Geometry = geometry;
                    await inputFeatures.AddFeatureAsync(inputFeature);

                    para.Inputs.Add("inputLine", new GeoprocessingFeatures(inputFeatures));
                    para.ReturnZ = true;
                    para.OutputSpatialReference = myMapView.SpatialReference;

                    GeoprocessingJob routeJob = gpRouteTask.CreateJob(para);

                    try
                    {
                        // Execute analysis and wait for the results
                        GeoprocessingResult geoprocessingResult = await routeJob.GetResultAsync();

                        GeoprocessingFeatures resultFeatures               = geoprocessingResult.Outputs["outputLine"] as GeoprocessingFeatures;
                        IFeatureSet           interpolateShapeResult       = resultFeatures.Features;
                        Esri.ArcGISRuntime.Geometry.Polyline elevationLine = interpolateShapeResult.First().Geometry as Esri.ArcGISRuntime.Geometry.Polyline;
                        MapPoint startPoint = elevationLine.Parts[0].Points[0];
                        int      count      = elevationLine.Parts[0].PointCount;
                        MapPoint stopPoint  = elevationLine.Parts[0].Points[count - 1];
                        double   chazhi     = stopPoint.Z - startPoint.Z;
                        MessageBox.Show("终点的Z值为: " + stopPoint.Z.ToString() + ",起点的Z值为: " + startPoint.Z.ToString());
                    }
                    catch (Exception ex)
                    {
                        if (routeJob.Status == JobStatus.Failed && routeJob.Error != null)
                        {
                            MessageBox.Show("Executing geoprocessing failed. " + routeJob.Error.Message, "Geoprocessing error");
                        }
                        else
                        {
                            MessageBox.Show("An error occurred. " + ex.ToString(), "Sample error");
                        }
                    }
                    // Create parameters, run the task, process results, etc.
                    // ...
                }
            };
            // Start the local geoprocessing service
            await localServiceGP.StartAsync();
        }
        private async Task CalculateViewshed(MapPoint location)
        {
            // This function will define a new geoprocessing task that performs a custom viewshed analysis based upon a
            // user click on the map and then display the results back as a polygon fill graphics overlay. If there
            // is a problem with the execution of the geoprocessing task an error message will be displayed.

            // Create new geoprocessing task using the URL defined in the member variables section.
            GeoprocessingTask viewshedTask = await GeoprocessingTask.CreateAsync(new Uri(ViewshedServiceUrl));

            // Create a new feature collection table based upon point geometries using the current map view spatial reference.
            FeatureCollectionTable inputFeatures = new FeatureCollectionTable(new List <Field>(), GeometryType.Point, _myMapView.SpatialReference);

            // Create a new feature from the feature collection table. It will not have a coordinate location (x,y) yet.
            Feature inputFeature = inputFeatures.CreateFeature();

            // Assign a physical location to the new point feature based upon where the user clicked in the map view.
            inputFeature.Geometry = location;

            // Add the new feature with (x,y) location to the feature collection table.
            await inputFeatures.AddFeatureAsync(inputFeature);

            // Create the parameters that are passed to the used geoprocessing task.
            GeoprocessingParameters viewshedParameters = new GeoprocessingParameters(GeoprocessingExecutionType.SynchronousExecute)
            {
                OutputSpatialReference = _myMapView.SpatialReference
            };

            // Add an input location to the geoprocessing parameters.
            viewshedParameters.Inputs.Add("Input_Observation_Point", new GeoprocessingFeatures(inputFeatures));

            // Create the job that handles the communication between the application and the geoprocessing task.
            GeoprocessingJob viewshedJob = viewshedTask.CreateJob(viewshedParameters);

            try
            {
                // Execute analysis and wait for the results.
                GeoprocessingResult analysisResult = await viewshedJob.GetResultAsync();

                // Get the results from the outputs.
                GeoprocessingFeatures viewshedResultFeatures = (GeoprocessingFeatures)analysisResult.Outputs["Viewshed_Result"];

                // Add all the results as a graphics to the map.
                foreach (Feature feature in viewshedResultFeatures.Features)
                {
                    _resultOverlay.Graphics.Add(new Graphic(feature.Geometry));
                }
            }
            catch (Exception ex)
            {
                // Display an error message if there is a problem.
                if (viewshedJob.Status == JobStatus.Failed && viewshedJob.Error != null)
                {
                    // Report error
                    UIAlertController alert = UIAlertController.Create("Geoprocessing Error", viewshedJob.Error.Message, UIAlertControllerStyle.Alert);
                    alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
                    PresentViewController(alert, true, null);
                }
                else
                {
                    // Report error
                    UIAlertController alert = UIAlertController.Create("Sample Error", ex.ToString(), UIAlertControllerStyle.Alert);
                    alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
                    PresentViewController(alert, true, null);
                }
            }
        }
        private async void RenderSymbols(Dictionary <string, object> info, bool initialize = false)
        {
            FeatureCollectionTable dTable;
            FeatureCollectionTable uTable;

            DictionaryRenderer  dRend;
            UniqueValueRenderer uRend;

            string[] codes = Newtonsoft.Json.JsonConvert.DeserializeObject <string[]>(info["codes"].ToString());
            int      page  = int.Parse(info["page"].ToString());

            if (initialize)
            {
                // Create the default symbol
                SimpleMarkerSymbol sms = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Colors.Red, 12)
                {
                    Outline = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Colors.Black, 1)
                };

                // Create the Dictionary and Unique Value renderers
                dRend = new DictionaryRenderer(DictionarySymbolStyle.OpenAsync("mil2525c_b2", StylePath).Result);
                uRend = new UniqueValueRenderer(new[] { FieldName }, null, "MilSymbol", sms);

                // Create the fields for the Feature Collection table
                Field[] fields = { new Field(FieldType.Text, FieldName, FieldName, 15) };

                // Create the Feature Collection Tables
                dTable = new FeatureCollectionTable(fields, GeometryType.Point, SpatialReferences.WebMercator)
                {
                    Renderer = dRend
                };
                uTable = new FeatureCollectionTable(fields, GeometryType.Point, SpatialReferences.WebMercator)
                {
                    Renderer = uRend
                };

                // Add the tables to the feature collection
                FeatureCollection collection = new FeatureCollection(new[] { dTable, uTable });

                // Add the collection to the map
                MyMapView.Map.OperationalLayers.Add(new FeatureCollectionLayer(collection));
            }
            else
            {
                // Get the feature collection from the map
                FeatureCollection collection = (MyMapView.Map.OperationalLayers.First() as FeatureCollectionLayer).FeatureCollection;

                // Get the tables from the collection
                dTable = collection.Tables.First();
                uTable = collection.Tables.Last();

                // Clear the records from the table and overlay
                QueryParameters query = new QueryParameters {
                    WhereClause = "1=1"
                };
                await dTable.DeleteFeaturesAsync(dTable.QueryFeaturesAsync(query).Result);

                await uTable.DeleteFeaturesAsync(uTable.QueryFeaturesAsync(query).Result);

                MyMapView.GraphicsOverlays.First().Graphics.Clear();

                // Clear the symbols from the unique value renderer
                (uTable.Renderer as UniqueValueRenderer)?.UniqueValues.Clear();
            }

            // Show the Page #
            MapPoint   titleLocation = new MapPoint(AOI.GetCenter().X, AOI.Extent.YMax + 25);
            TextSymbol titleBar      = new TextSymbol
            {
                Text                = string.Format("Page: {0}", page),
                Color               = Colors.Black,
                BackgroundColor     = Colors.DodgerBlue,
                FontWeight          = Esri.ArcGISRuntime.Symbology.FontWeight.Bold,
                Size                = 50,
                HorizontalAlignment = Esri.ArcGISRuntime.Symbology.HorizontalAlignment.Center,
                VerticalAlignment   = Esri.ArcGISRuntime.Symbology.VerticalAlignment.Bottom,
                OutlineColor        = Colors.Black,
                OutlineWidth        = 2
            };

            MyMapView.GraphicsOverlays.First().Graphics.Add(new Graphic(titleLocation, titleBar));

            int rows = codes.Length / Columns;

            double rowMargin = (AOI.XMax - AOI.XMin) / (Columns - 1);
            double colMargin = (AOI.YMax - AOI.YMin) / rows;

            int count = 0;

            for (double x = AOI.XMin; x < AOI.XMax; x += rowMargin)
            {
                if (count >= codes.Length)
                {
                    break;
                }

                for (double y = AOI.YMax; y > AOI.YMin; y -= colMargin)
                {
                    if (count >= codes.Length)
                    {
                        break;
                    }

                    string code = codes[count];

                    if (code.Length != 15)
                    {
                        System.Diagnostics.Debug.WriteLine(string.Format("Possible invalid code: {0}", code));
                    }
                    else
                    {
                        // Create features with the sidc code
                        Feature dFeature = dTable.CreateFeature(new Dictionary <string, object> {
                            { FieldName, code }
                        }, new MapPoint(x, y, SpatialReferences.WebMercator));
                        Feature uFeature = uTable.CreateFeature(new Dictionary <string, object> {
                            { FieldName, code }
                        }, new MapPoint(x + (rowMargin * 0.5), y, SpatialReferences.WebMercator));

                        // Create a label to display the code
                        TextSymbol label = new TextSymbol
                        {
                            Text            = code,
                            FontWeight      = Esri.ArcGISRuntime.Symbology.FontWeight.Bold,
                            Color           = Colors.DarkGoldenrod,
                            BackgroundColor = Colors.Black,
                            FontFamily      = "Consolas",
                            Size            = 16
                        };

                        MapPoint labelPoint = new MapPoint(x + (rowMargin * 0.25), y - (colMargin * 0.25), SpatialReferences.WebMercator);
                        MyMapView.GraphicsOverlays.First().Graphics.Add(new Graphic(labelPoint, label));

                        // Add the feature to the table
                        await dTable.AddFeatureAsync(dFeature);

                        await uTable.AddFeatureAsync(uFeature);

                        // Triple the size of the Unique Value symbol
                        MultilayerPointSymbol symbol = (MultilayerPointSymbol)(dTable.Renderer as DictionaryRenderer).GetSymbol(dFeature);
                        symbol.Size *= 3;

                        // Add the military symbol to the unique value renderer
                        UniqueValue uval = new UniqueValue(code, code, symbol, code);
                        (uTable.Renderer as UniqueValueRenderer).UniqueValues.Add(uval);
                    }

                    count++;

                    System.Diagnostics.Debug.WriteLine(string.Format(@"Processed feature {0} for {1}...", count, codes.Length));
                }
            }
        }
        private async void CreateNewFeatureCollection()
        {
            // Create the schema for a points table (one text field to contain a name attribute)
            List<Field> pointFields = new List<Field>();
            Field placeField = new Field(FieldType.Text, "Place", "Place Name", 50);
            pointFields.Add(placeField);

            // Create the schema for a lines table (one text field to contain a name attribute)
            List<Field> lineFields = new List<Field>();
            Field boundaryField = new Field(FieldType.Text, "Boundary", "Boundary Name", 50);
            lineFields.Add(boundaryField);

            // Create the schema for a polygon table (one text field to contain a name attribute)
            List<Field> polyFields = new List<Field>();
            Field areaField = new Field(FieldType.Text, "AreaName", "Area Name", 50);
            polyFields.Add(areaField);

            // Instantiate FeatureCollectionTables with schema and geometry type
            FeatureCollectionTable pointsTable = new FeatureCollectionTable(pointFields, GeometryType.Point, SpatialReferences.Wgs84);
            FeatureCollectionTable linesTable = new FeatureCollectionTable(lineFields, GeometryType.Polyline, SpatialReferences.Wgs84);
            FeatureCollectionTable polysTable = new FeatureCollectionTable(polyFields, GeometryType.Polygon, SpatialReferences.Wgs84);

            // Set rendering for each table
            pointsTable.Renderer = CreateRenderer(GeometryType.Point);
            linesTable.Renderer = CreateRenderer(GeometryType.Polyline);
            polysTable.Renderer = CreateRenderer(GeometryType.Polygon);

            // Create a new point feature, provide geometry and attribute values
            Feature pointFeature = pointsTable.CreateFeature();
            pointFeature.SetAttributeValue(placeField, "Current location");
            MapPoint point1 = new MapPoint(-79.497238, 8.849289, SpatialReferences.Wgs84);
            pointFeature.Geometry = point1;

            // Create a new line feature, provide geometry and attribute values
            Feature lineFeature = linesTable.CreateFeature();
            lineFeature.SetAttributeValue(boundaryField, "AManAPlanACanalPanama");
            MapPoint point2 = new MapPoint(-80.035568, 9.432302, SpatialReferences.Wgs84);
            Polyline line = new Polyline(new MapPoint[] { point1, point2 });
            lineFeature.Geometry = line;

            // Create a new polygon feature, provide geometry and attribute values
            Feature polyFeature = polysTable.CreateFeature();
            polyFeature.SetAttributeValue(areaField, "Restricted area");
            MapPoint point3 = new MapPoint(-79.337936, 8.638903, SpatialReferences.Wgs84);
            MapPoint point4 = new MapPoint(-79.11409, 8.895422, SpatialReferences.Wgs84);
            Polygon poly = new Polygon(new MapPoint[] { point1, point3, point4 });
            polyFeature.Geometry = poly;

            // Add the new features to the appropriate feature collection table 
            await pointsTable.AddFeatureAsync(pointFeature);
            await linesTable.AddFeatureAsync(lineFeature);
            await polysTable.AddFeatureAsync(polyFeature);

            // Create a feature collection and add the feature collection tables
            FeatureCollection featuresCollection = new FeatureCollection();
            featuresCollection.Tables.Add(pointsTable);
            featuresCollection.Tables.Add(linesTable);
            featuresCollection.Tables.Add(polysTable);

            // Create a FeatureCollectionLayer 
            FeatureCollectionLayer collectionLayer = new FeatureCollectionLayer(featuresCollection);

            // When the layer loads, zoom the map view to the extent of the feature collection
            collectionLayer.Loaded += CollectionLayer_Loaded;
            // Add the layer to the Map's Operational Layers collection
            MyMapView.Map.OperationalLayers.Add(collectionLayer);
        }
        private async Task CalculateViewshed(MapPoint location)
        {
            // This function will define a new geoprocessing task that performs a custom viewshed analysis based upon a 
            // user click on the map and then display the results back as a polygon fill graphics overlay. If there
            // is a problem with the execution of the geoprocessing task an error message will be displayed 

            // Create new geoprocessing task using the url defined in the member variables section
            var myViewshedTask = new GeoprocessingTask(new Uri(_viewshedUrl));

            // Create a new feature collection table based upon point geometries using the current map view spatial reference
            var myInputFeatures = new FeatureCollectionTable(new List<Field>(), GeometryType.Point, MyMapView.SpatialReference);

            // Create a new feature from the feature collection table. It will not have a coordinate location (x,y) yet
            Feature myInputFeature = myInputFeatures.CreateFeature();

            // Assign a physical location to the new point feature based upon where the user clicked in the map view
            myInputFeature.Geometry = location;

            // Add the new feature with (x,y) location to the feature collection table
            await myInputFeatures.AddFeatureAsync(myInputFeature);

            // Create the parameters that are passed to the used geoprocessing task
            GeoprocessingParameters myViewshedParameters =
                new GeoprocessingParameters(GeoprocessingExecutionType.SynchronousExecute);

            // Request the output features to use the same SpatialReference as the map view
            myViewshedParameters.OutputSpatialReference = MyMapView.SpatialReference;

            // Add an input location to the geoprocessing parameters
            myViewshedParameters.Inputs.Add("Input_Observation_Point", new GeoprocessingFeatures(myInputFeatures));

            // Create the job that handles the communication between the application and the geoprocessing task
            var myViewshedJob = myViewshedTask.CreateJob(myViewshedParameters);

            try
            {
                // Execute analysis and wait for the results
                GeoprocessingResult myAnalysisResult = await myViewshedJob.GetResultAsync();

                // Get the results from the outputs
                GeoprocessingFeatures myViewshedResultFeatures = myAnalysisResult.Outputs["Viewshed_Result"] as GeoprocessingFeatures;

                // Add all the results as a graphics to the map
                IFeatureSet myViewshedAreas = myViewshedResultFeatures.Features;
                foreach (var myFeature in myViewshedAreas)
                {
                    _resultOverlay.Graphics.Add(new Graphic(myFeature.Geometry));
                }
            }
            catch (Exception ex)
            {
                // Display an error message if there is a problem
                if (myViewshedJob.Status == JobStatus.Failed && myViewshedJob.Error != null)
                {
                    var message = new MessageDialog("Executing geoprocessing failed. " + myViewshedJob.Error.Message, "Geoprocessing error");
                    await message.ShowAsync();
                }
                else
                {
                    var message = new MessageDialog("An error occurred. " + ex.ToString(), "Sample error");
                    await message.ShowAsync();
                }
            }
            finally
            {
                // Indicate that the geoprocessing is not running
                SetBusy(false);
            }
        }
Exemple #17
0
        private async void CreateFeatureCollectionLayerFromNYTimesArticles()
        {
            // Read the NY Times data from the text file and get back a list of each article.
            // The format of each record/article will look like:
            // [Article summary]~[Article abstract]~[Country name]~[Url to the NY times article]~[Url to an image about the NY times article]~[Date of NY Times news article]
            // Ex:
            // Netanyahu not happy with Cohen~A spokesman for Prime Minister Benjamin Netanyahu disagrees with Roger Cohen’s “pessimism.”~Israel~https://www.nytimes.com/2018/01/02/opinion/israel-future.html~https://www.nytimes.com/images/2017/12/29/opinion/29cohenWeb/29cohenWeb-thumbLarge.jpg~20180102
            List <string> myNYTimesArticles = ReadTextFile3(_NEWSFILE);

            // Get the collection of all the layers in the map.
            var myMapAllLayers = MyMapView.Map.AllLayers;

            // Create a place holder for the world countries feature layer.
            FeatureLayer myFeatureLayer = null;

            // Loop through all of the layers.
            foreach (var myLayer in myMapAllLayers)
            {
                // Get the Id of the layer.
                string myLayerName = myLayer.Id;

                // If the layer id matches world countries set that to the feature layer.
                if (myLayerName == "WorldCountries")
                {
                    myFeatureLayer = (FeatureLayer)myLayer;
                }
            }

            // Get the feature table from the world countries shape file feature layer.
            FeatureTable myFeatureTable = myFeatureLayer.FeatureTable;

            // Create a new query parameters.
            QueryParameters myQueryParameters = new QueryParameters();

            // Define the where clause for the query parameters. It will select all the records in the world countries shape file feature table.
            myQueryParameters.WhereClause = "1 = 1";

            // Execute the feature query and get the results back. It will select all the records in the world countries shape file feature table.
            FeatureQueryResult myFeatureQueryResult = await myFeatureTable.QueryFeaturesAsync(myQueryParameters);

            // Create the schema for the polygon feature collection table.
            List <Field> myFeatureCollectionAttributeFields = new List <Field>();

            // Create a field for the feature collection layer. It will contain a text field called area name that is the county name.
            Field myAreaNameField = new Field(FieldType.Text, "AreaName", "Area Name", 50);

            // Add the country name field to the list of fields that will be added to the feature collection table.
            myFeatureCollectionAttributeFields.Add(myAreaNameField);

            // Create the feature collection table based on the list of attribute fields, a polygons feature type
            FeatureCollectionTable myFeatureCollectionTable = new FeatureCollectionTable(myFeatureCollectionAttributeFields, GeometryType.Polygon, SpatialReferences.Wgs84);

            // Create the outline symbol for the country fill symbol.
            SimpleLineSymbol mySimpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.DarkBlue, 2);

            // Create the fill symbol for the country. Solid yellow, with dark blue outline.
            SimpleFillSymbol mySimpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.Yellow, mySimpleLineSymbol);

            // Set the renderer of the feature collection table to be the simple fill symbol.
            myFeatureCollectionTable.Renderer = new SimpleRenderer(mySimpleFillSymbol);

            // Loop through each feature in the returned feature query results of the world countries shape file
            foreach (Feature myFeature in myFeatureQueryResult)
            {
                // Get the geometry (aka shape) for one feature.
                Geometry myGeometry = myFeature.Geometry;

                // Get the value (aka. the text for the record of a specific field).
                var myValue = (string)myFeature.Attributes["NAME"];

                // Loop through each NY Times article.
                foreach (string oneNYTimesArticle in myNYTimesArticles)
                {
                    // Remove an embedded double quotes that may be in or surrounding the country name in the NY Times data base.
                    char[] charsToTrim = { '"' };
                    string country     = oneNYTimesArticle.Split('~')[2].Trim(charsToTrim);

                    // Find a match from the shape file country feature and the NY Times country name in the article.
                    if ((string)myValue == country)
                    {
                        // Create a new polygon feature, provide geometry and attribute values.
                        Feature polyFeature = myFeatureCollectionTable.CreateFeature();
                        polyFeature.SetAttributeValue(myAreaNameField, country);
                        polyFeature.Geometry = myGeometry;

                        // Add the new features to the appropriate feature collection table.
                        await myFeatureCollectionTable.AddFeatureAsync(polyFeature);

                        // Once we have found a matching country in the subset news article file that matches a shape file record
                        // there is no need to find another one since we have just created a record in the FeatureCollectionTable.
                        break;
                    }
                }
            }

            // Create a feature collection and add the feature collection tables
            FeatureCollection myFeatureCollection = new FeatureCollection();

            myFeatureCollection.Tables.Add(myFeatureCollectionTable);

            // Create a FeatureCollectionLayer
            FeatureCollectionLayer myFeatureCollectionLayer = new FeatureCollectionLayer(myFeatureCollection);

            myFeatureCollectionLayer.Id   = "Joined"; // might not be needed
            myFeatureCollectionLayer.Name = "JoinedFCL";

            // When the layer loads, zoom the map centered on the feature collection
            await myFeatureCollectionLayer.LoadAsync();

            // Add the layer to the Map's Operational Layers collection
            MyMapView.Map.OperationalLayers.Add(myFeatureCollectionLayer);
        }