コード例 #1
0
        private async Task PopulateDataGridAsync()
        {
            try
            {
                //create a new query and set the where clause to return all the features
                ESRI.ArcGIS.OperationsDashboard.Query findQuery =
                    new ESRI.ArcGIS.OperationsDashboard.Query()
                {
                    WhereClause    = "1=1",
                    ReturnGeometry = true
                };

                //execute the query on the data source configured for this widget and await for it
                QueryResult result = await this.DataSource.ExecuteQueryAsync(findQuery);

                if ((result != null) && (result.Features != null))
                {
                    //bind the feature grid to the features
                    FeatureGrid.ItemsSource = result.Features;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
        // ***********************************************************************************
        // * User selected a barrier layer... Get the barrier layer name and query
        // * for that layer
        // ***********************************************************************************
        private async void cmbBarriers_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ResourceLayer barriertType = (ResourceLayer)cmbBarriers.SelectedItem;

            if (barriertType.Name == "Select Barrier")
            {
                return;
            }


            var query = new ESRI.ArcGIS.OperationsDashboard.Query();

            query.ReturnGeometry = true;
            query.SpatialFilter  = _mapWidget.Map.Extent;
            query.WhereClause    = "1=1";
            query.Fields         = new string[] { "OBJECTID" };

            var result = await barriertType.DataSource.ExecuteQueryAsync(query);

            if (result == null || result.Features == null)
            {
                return;
            }
            else
            {
                queryBarrierType_ExecuteCompleted(result);
            }
        }
        // ***********************************************************************************
        // * User selected a facility type... query for that facility type
        // ***********************************************************************************
        private async void cmbFacility_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ResourceType resourceType = (ResourceType)cmbFacility.SelectedItem;

            if (resourceType.Name == "Select Type")
            {
                return;
            }

            _facilityType = resourceType.Name;
            FacilityType  = _facilityType;

            var query = new ESRI.ArcGIS.OperationsDashboard.Query();

            query.WhereClause    = _resourceTypeField + "='" + _facilityType + "'";
            query.ReturnGeometry = true;
            query.SpatialFilter  = _mapWidget.Map.Extent;
            query.Fields         = new string[] { "*" };

            ResourceLayer layer = (ResourceLayer)cmbLayers.SelectedItem;

            var result = await layer.DataSource.ExecuteQueryAsync(query);

            if (result == null || result.Features == null)
            {
                return;
            }
            else
            {
                queryResourceType_ExecuteCompleted(result);
            }
        }
コード例 #4
0
        public static async Task <GraphicsLayer> CreateCustomLayer(FeatureLayer featureLayer, OD.DataSource dataSource)
        {
            if (featureLayer == null || dataSource == null)
            {
                return(null);
            }

            GraphicsLayer customLayer = new GraphicsLayer();

            customLayer.DisplayName = "Edit - " + featureLayer.DisplayName;
            customLayer.Renderer    = featureLayer.Renderer;

            // Execute an async query
            OD.Query query = new OD.Query();
            query.ReturnGeometry = true;
            OD.QueryResult queryResult = await dataSource.ExecuteQueryAsync(query);

            if (queryResult.Canceled || queryResult.Features == null)
            {
                return(null);
            }

            CopyGraphics(queryResult.Features, customLayer.Graphics);
            return(customLayer);
        }
コード例 #5
0
        async void Map_ExtentChanged(object sender, ExtentEventArgs e)
        {
            try
            {
                if (callQuery)
                {
                    //Select features using polygon
                    IEnumerable <ESRI.ArcGIS.OperationsDashboard.DataSource> dataSources = OperationsDashboard.Instance.DataSources;
                    foreach (ESRI.ArcGIS.OperationsDashboard.DataSource d in dataSources)
                    {
                        //if (d.IsSelectable)
                        // {
                        System.Diagnostics.Debug.WriteLine(d.Name);
                        ESRI.ArcGIS.OperationsDashboard.Query query = new ESRI.ArcGIS.OperationsDashboard.Query();

                        query.SpatialFilter  = outdoorPoly;
                        query.ReturnGeometry = true;
                        query.Fields         = new string[] { d.ObjectIdFieldName };

                        ESRI.ArcGIS.OperationsDashboard.QueryResult result = await d.ExecuteQueryAsync(query);

                        //System.Diagnostics.Debug.WriteLine("Features : " + result.Features.Count);
                        if (result.Features.Count > 0)
                        {
                            // Get the array of IDs from the query results.
                            var resultOids = from feature in result.Features select System.Convert.ToInt32(feature.Attributes[d.ObjectIdFieldName]);

                            // Find the map layer in the map widget that contains the data source.
                            MapWidget mapW = MapWidget.FindMapWidget(d);
                            if (mapW != null)
                            {
                                // Get the feature layer in the map for the data source.
                                client.FeatureLayer featureL = mapW.FindFeatureLayer(d);

                                // NOTE: Can check here if the feature layer is selectable, using code shown above.
                                // For each result feature, find the corresponding graphic in the map by OID and select it.
                                foreach (client.Graphic feature in featureL.Graphics)
                                {
                                    int featureOid;
                                    int.TryParse(feature.Attributes[d.ObjectIdFieldName].ToString(), out featureOid);
                                    if (resultOids.Contains(featureOid))
                                    {
                                        feature.Select();
                                    }
                                }
                            }
                        }
                    }
                }
                callQuery = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in MapExent Changed: " + ex.Message);
            }
        }
コード例 #6
0
        async public void Update(OD.DataSource dataSource)
        {
            if (dataSource == null)
            {
                return;
            }
            if (SkipUpdates)
            {
                return;
            }
            if (InEditMode)
            {
                return;
            }

            // Execute an async query
            OD.Query query = new OD.Query()
            {
                SortField      = SortByFieldName1,
                SortOrder      = ESRI.ArcGIS.Client.Tasks.SortOrder.Ascending,
                ReturnGeometry = true
            };
            OD.QueryResult queryResult = await dataSource.ExecuteQueryAsync(query);

            if (queryResult.Canceled || queryResult.Features == null)
            {
                Items.Clear();
                return;
            }

            //hk - RESEARCH THIS APPROACH

            /*
             * List<ListItem> items = new List<ListItem>();
             * int i = 0;
             * foreach (var result in queryResult.Features)
             * {
             * items.Add(new ListItem(this, result, dataSource));
             * if (++i == ListWidget.MaxCount)
             *  break;
             * }
             */

            try
            {
                SetDataSource(dataSource);
                Update(queryResult.Features);
            }
            catch (Exception ex)
            {
                Log.TraceException("Updating " + dataSource.Name, ex);
            }
        }
コード例 #7
0
        // ***********************************************************************************
        // * ... Select facilities that intersect the affeced area on the map
        // ***********************************************************************************
        private async void selectFeaturesOnTheMap(ESRI.ArcGIS.Client.Geometry.Polygon geometry)
        {
            // Find the Selectable data sources provided by feature layers in the map widget.
            var dataSourcesFromSameWidget = OperationsDashboard.Instance.DataSources.Select((dataSource) =>
            {
                client.FeatureLayer fl = _mapWidget.FindFeatureLayer(dataSource);
                return(((fl != null) && (dataSource.IsSelectable)) ? fl : null);
            });

            IEnumerable <ESRI.ArcGIS.OperationsDashboard.DataSource> dataSources = OperationsDashboard.Instance.DataSources;

            foreach (ESRI.ArcGIS.OperationsDashboard.DataSource d in dataSources)
            {
                client.FeatureLayer featureL = _mapWidget.FindFeatureLayer(d);

                if (dataSourcesFromSameWidget.Contains(featureL))
                {
                    ESRI.ArcGIS.OperationsDashboard.Query query = new ESRI.ArcGIS.OperationsDashboard.Query();
                    query.SpatialFilter  = geometry;
                    query.ReturnGeometry = true;
                    query.Fields         = new string[] { d.ObjectIdFieldName };

                    ESRI.ArcGIS.OperationsDashboard.QueryResult result = await d.ExecuteQueryAsync(query);

                    if (result.Features.Count > 0)
                    {
                        // Get the array of IDs from the query results.
                        var resultOids = from feature in result.Features select System.Convert.ToInt32(feature.Attributes[d.ObjectIdFieldName]);

                        // For each result feature, find the corresponding graphic in the map.
                        foreach (client.Graphic feature in featureL.Graphics)
                        {
                            int featureOid;
                            int.TryParse(feature.Attributes[d.ObjectIdFieldName].ToString(), out featureOid);
                            if (resultOids.Contains(featureOid))
                            {
                                feature.Select();
                            }
                        }
                    }
                    else
                    if (d.IsSelectable == true)
                    {
                        featureL.ClearSelection();
                    }
                }
            }
        }
        // ***********************************************************************************
        // * Query the selected resource layer to get the different resource types...
        // ***********************************************************************************
        private async void queryResourceLayer(ESRI.ArcGIS.OperationsDashboard.DataSource dataSource)
        {
            var query = new ESRI.ArcGIS.OperationsDashboard.Query();

            query.WhereClause    = "1=1";
            query.ReturnGeometry = false;
            query.Fields         = new string[] { _resourceTypeField };

            var result = await dataSource.ExecuteQueryAsync(query);

            if (result == null || result.Features == null)
            {
                return;
            }
            else
            {
                queryResourceLayer_ExecuteCompleted(result);
            }
        }
        //Calculate a single statistic
        private async void CalculateOneStatistic(Statistic statistic)
        {
            //Construct the query
            opsDash.Query query = new opsDash.Query()
            {
                ReturnGeometry = false,
                WhereClause    = "1=1",
                Fields         = new string[] { Field }
            };

            //If map widget is valid and UseCurrentExtent = true, we will set the current extent into the query
            if (MapWidget == null)
            {
                query.SpatialFilter = null;
            }
            else
            {
                if (UseCurrentExtent == false)
                {
                    query.SpatialFilter = null;
                }
                else
                {
                    query.SpatialFilter = MapWidget.Map.Extent;
                }
            }

            //Create a query task, pass in the query and the type of statistic then start the task
            List <Task <opsDash.QueryResult> > queryTasks = new List <Task <opsDash.QueryResult> >();

            opsDash.QueryResult queryResult = await DataSource.ExecuteQueryStatisticAsync(statistic, query);

            //Query results are back. Check the results
            if (queryResult.Canceled)
            {
                return;
            }

            //There should only be one feature carrying the requested value
            if (queryResult.Features == null || queryResult.Features.Count != 1)
            {
                return;
            }

            //The feature should not be null and should have the field with the correct field name
            client.Graphic feature = queryResult.Features[0];

            //When we pan outside of the map extent and do the calculation, feature.Attributes[Field] will be null
            //Resetting all values to 0
            if (feature == null || feature.Attributes[Field] == null)
            {
                Max = Min = Avg = Sum = 0;
            }
            else
            {
                //Try to set the field into a double field
                double value = 0;
                Double.TryParse(feature.Attributes[Field].ToString(), out value);

                //Based on the requested, set the value to the output statsitic
                if (statistic == Statistic.Max)
                {
                    Max = value;
                }
                else if (statistic == Statistic.Average)
                {
                    Avg = value;
                }
                else if (statistic == Statistic.Min)
                {
                    Min = value;
                }
                else if (statistic == Statistic.Sum)
                {
                    Sum = value;
                }
            }

            //Update StatisticsLists, which in turn will trigger the UI to update
            UpdateControls();
        }
        // ***********************************************************************************
        // * User selected a barrier layer... Get the barrier layer name and query 
        // * for that layer
        // ***********************************************************************************
        private async void cmbBarriers_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ResourceLayer barriertType = (ResourceLayer)cmbBarriers.SelectedItem;
            if (barriertType.Name == "Select Barrier")
                return;


            var query = new ESRI.ArcGIS.OperationsDashboard.Query();
            query.ReturnGeometry = true;
            query.SpatialFilter = _mapWidget.Map.Extent;
            query.WhereClause = "1=1";
            query.Fields = new string[] { "OBJECTID" };

            var result = await barriertType.DataSource.ExecuteQueryAsync(query);
            if (result == null || result.Features == null)
                return;
            else
                queryBarrierType_ExecuteCompleted(result);
        }
        // ***********************************************************************************
        // * User selected a facility type... query for that facility type 
        // ***********************************************************************************
        private async void cmbFacility_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
                ResourceType resourceType = (ResourceType)cmbFacility.SelectedItem;

                if (resourceType.Name == "Select Type")
                    return;

                _facilityType = resourceType.Name;
                FacilityType = _facilityType;

                var query = new ESRI.ArcGIS.OperationsDashboard.Query();
                query.WhereClause = _resourceTypeField + "='" + _facilityType + "'";
                query.ReturnGeometry = true;
                query.SpatialFilter = _mapWidget.Map.Extent;
                query.Fields = new string[] {"*"};

                ResourceLayer layer = (ResourceLayer)cmbLayers.SelectedItem;

                var result = await layer.DataSource.ExecuteQueryAsync(query);
                if (result == null || result.Features == null)
                    return;
                else
                    queryResourceType_ExecuteCompleted(result);
        }
        // ***********************************************************************************
        // * Query the selected resource layer to get the different resource types... 
        // ***********************************************************************************
        private async void queryResourceLayer(ESRI.ArcGIS.OperationsDashboard.DataSource dataSource)
        {
            var query = new ESRI.ArcGIS.OperationsDashboard.Query();
            query.WhereClause = "1=1";
            query.ReturnGeometry = false;
            query.Fields = new string[] { _resourceTypeField };

            var result = await dataSource.ExecuteQueryAsync(query);
            if (result == null || result.Features == null)
                return;
            else
                queryResourceLayer_ExecuteCompleted(result);
        }
コード例 #13
0
    //Query for features from the target layers that intersect with the selected feature(s) from the source layer. 
    //We use the ExecuteQueryAsync method from OpsDashboard.DataSource to do the query
    private async void Select_IntersectSourceLayer(IEnumerable<Graphic> buffers = null)
    {
      IEnumerable<Graphic> sourceGraphics = SourceFeatures;

      if (buffers != null)
        sourceGraphics = buffers;

      foreach (OpsDashboard.DataSource targetDataSource in TargetDataSources)
      {
        foreach (Graphic sourceGraphic in sourceGraphics)
        {
          //Set up the query and query result
          OpsDashboard.Query query = new OpsDashboard.Query("", sourceGraphic.Geometry, true);

          //Run the query and check the result
          OpsDashboard.QueryResult result = await targetDataSource.ExecuteQueryAsync(query);
          if ((result == null) || (result.Canceled) || (result.Features == null) || (result.Features.Count < 1))
            continue;

          // Get the array of OIDs from the query results.
          var resultOids = from resultFeature in result.Features select Convert.ToInt32(resultFeature.Attributes[targetDataSource.ObjectIdFieldName]);
          // Get the feature layer in the map for the data source.
          FeatureLayer targetLayer = MapWidget.FindFeatureLayer(targetDataSource);
          if (targetLayer == null)
            return;
          
          //Clear any features that are currently selected
          targetLayer.ClearSelection();

          // For each graphic feature in featureLayer, use its OID to find the graphic feature from the result set.
          // Note that though the featureLayer's graphic feature and the result set's feature graphic feature share the same properties,
          // they are indeed different objects
          foreach (Graphic feature in targetLayer.Graphics)
          {
            int featureOid;
            int.TryParse(feature.Attributes[targetDataSource.ObjectIdFieldName].ToString(), out featureOid);

            //If the feature is in the query result set, select it
            if ((resultOids.Contains(featureOid)))
              feature.Select();
          }
        }
      }
    }
コード例 #14
0
    async public void Update(OD.DataSource dataSource)
    {
      if (dataSource == null)
        return;
      if (SkipUpdates)
        return;
      if (InEditMode)
        return;

      // Execute an async query
      OD.Query query = new OD.Query()
      {
        SortField = SortByFieldName1,
        SortOrder = ESRI.ArcGIS.Client.Tasks.SortOrder.Ascending,
        ReturnGeometry = true
      };
      OD.QueryResult queryResult = await dataSource.ExecuteQueryAsync(query);
      if (queryResult.Canceled || queryResult.Features == null)
      {
        Items.Clear();
        return;
      }

      //hk - RESEARCH THIS APPROACH
      /*
      List<ListItem> items = new List<ListItem>();
      int i = 0;
      foreach (var result in queryResult.Features)
      {
        items.Add(new ListItem(this, result, dataSource));
        if (++i == ListWidget.MaxCount)
          break;
      }
      */

      try
      {
        SetDataSource(dataSource);
        Update(queryResult.Features);
      }
      catch (Exception ex)
      {
        Log.TraceException("Updating " + dataSource.Name, ex);
      }

    }
コード例 #15
0
        async void Map_ExtentChanged(object sender, ExtentEventArgs e)
        {
            try
            {
                if (callQuery)
                {
                    //Select features using polygon
                    IEnumerable<ESRI.ArcGIS.OperationsDashboard.DataSource> dataSources = OperationsDashboard.Instance.DataSources;
                    foreach (ESRI.ArcGIS.OperationsDashboard.DataSource d in dataSources)
                    {
                        //if (d.IsSelectable)
                        // {
                        System.Diagnostics.Debug.WriteLine(d.Name);
                        ESRI.ArcGIS.OperationsDashboard.Query query = new ESRI.ArcGIS.OperationsDashboard.Query();

                        query.SpatialFilter = outdoorPoly;
                        query.ReturnGeometry = true;
                        query.Fields = new string[] { d.ObjectIdFieldName };

                        ESRI.ArcGIS.OperationsDashboard.QueryResult result = await d.ExecuteQueryAsync(query);
                        //System.Diagnostics.Debug.WriteLine("Features : " + result.Features.Count);
                        if (result.Features.Count > 0)
                        {

                            // Get the array of IDs from the query results.
                            var resultOids = from feature in result.Features select System.Convert.ToInt32(feature.Attributes[d.ObjectIdFieldName]);

                            // Find the map layer in the map widget that contains the data source.
                            MapWidget mapW = MapWidget.FindMapWidget(d);
                            if (mapW != null)
                            {
                                // Get the feature layer in the map for the data source.
                                client.FeatureLayer featureL = mapW.FindFeatureLayer(d);

                                // NOTE: Can check here if the feature layer is selectable, using code shown above.
                                // For each result feature, find the corresponding graphic in the map by OID and select it.
                                foreach (client.Graphic feature in featureL.Graphics)
                                {
                                    int featureOid;
                                    int.TryParse(feature.Attributes[d.ObjectIdFieldName].ToString(), out featureOid);
                                    if (resultOids.Contains(featureOid))
                                    {
                                        feature.Select();
                                    }
                                }
                            }
                        }
                    }
                }
                callQuery = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in MapExent Changed: " + ex.Message);
            }
        }
コード例 #16
0
    private async Task PopulateDataGridAsync()
    {
      try
      {
        //create a new query and set the where clause to return all the features
        ESRI.ArcGIS.OperationsDashboard.Query findQuery =
            new ESRI.ArcGIS.OperationsDashboard.Query()
        {
          WhereClause = "1=1",
          ReturnGeometry = true
        };

        //execute the query on the data source configured for this widget and await for it
        QueryResult result = await this.DataSource.ExecuteQueryAsync(findQuery);

        if ((result != null) && (result.Features != null))
          //bind the feature grid to the features
          FeatureGrid.ItemsSource = result.Features;
      }
      catch (Exception ex)
      {
        System.Diagnostics.Debug.WriteLine(ex.Message);
      }
    }
コード例 #17
0
    public static async Task<GraphicsLayer> CreateCustomLayer(FeatureLayer featureLayer, OD.DataSource dataSource)
    {
      if (featureLayer == null || dataSource == null)
        return null;

      GraphicsLayer customLayer = new GraphicsLayer();
      customLayer.DisplayName = "Edit - " + featureLayer.DisplayName;
      customLayer.Renderer = featureLayer.Renderer;

      // Execute an async query
      OD.Query query = new OD.Query();
      query.ReturnGeometry = true;
      OD.QueryResult queryResult = await dataSource.ExecuteQueryAsync(query);
      if (queryResult.Canceled || queryResult.Features == null)
        return null;

      CopyGraphics(queryResult.Features, customLayer.Graphics);
      return customLayer;
    }
コード例 #18
0
        // ***********************************************************************************
        // * ... Select facilities that intersect the affeced area on the map
        // ***********************************************************************************
        private async void selectFeaturesOnTheMap(ESRI.ArcGIS.Client.Geometry.Polygon geometry)
        {
            // Find the Selectable data sources provided by feature layers in the map widget.
            var dataSourcesFromSameWidget = OperationsDashboard.Instance.DataSources.Select((dataSource) =>
            {
                client.FeatureLayer fl = _mapWidget.FindFeatureLayer(dataSource);
                return ((fl != null) && (dataSource.IsSelectable)) ? fl : null;
            });

            IEnumerable<ESRI.ArcGIS.OperationsDashboard.DataSource> dataSources = OperationsDashboard.Instance.DataSources;
            foreach (ESRI.ArcGIS.OperationsDashboard.DataSource d in dataSources)
            {

                client.FeatureLayer featureL = _mapWidget.FindFeatureLayer(d);
  
                if (dataSourcesFromSameWidget.Contains(featureL))
                {
                    ESRI.ArcGIS.OperationsDashboard.Query query = new ESRI.ArcGIS.OperationsDashboard.Query();
                    query.SpatialFilter = geometry;
                    query.ReturnGeometry = true;
                    query.Fields = new string[] { d.ObjectIdFieldName };

                    ESRI.ArcGIS.OperationsDashboard.QueryResult result = await d.ExecuteQueryAsync(query);
                    if (result.Features.Count > 0)
                    {
                        // Get the array of IDs from the query results.
                        var resultOids = from feature in result.Features select System.Convert.ToInt32(feature.Attributes[d.ObjectIdFieldName]);

                        // For each result feature, find the corresponding graphic in the map.
                        foreach (client.Graphic feature in featureL.Graphics)
                        {
                            int featureOid;
                            int.TryParse(feature.Attributes[d.ObjectIdFieldName].ToString(), out featureOid);
                            if (resultOids.Contains(featureOid))
                                feature.Select();
                        }
                    }
                    else
                        if (d.IsSelectable == true)
                            featureL.ClearSelection();
                }
            }
        }