/// <summary>
 /// Calculates the data statistics for a geodatabase table.
 /// </summary>
 /// <param name="table">The geodatabase table which statistics should be gathered.</param>
 /// <param name="field">The field which statistics should be gathered.</param>
 /// <returns>The calculated data statistics.</returns>
 internal async Task<DataStatisticsResult> CalculateStatistics(FeatureTable table, FieldInfo field)
 {
     var result = new DataStatisticsResult { TableName = table.Name, AttributeName = field.Alias };
     result.Count = table.RowCount;
     var filter = new QueryFilter { WhereClause = @"1=1" };
     var features = await table.QueryAsync(filter);
     var uniqueValues = new HashSet<object>();
     foreach (var feature in features)
     {
         var attributes = feature.Attributes;
         if (attributes.ContainsKey(field.Name))
         {
             var value = attributes[field.Name];
             if (!uniqueValues.Contains(value))
             {
                 uniqueValues.Add(value);
             }
         }
     }
     result.UniqueValueCount = uniqueValues.Count;
     return result;
 }
Exemple #2
0
        // Summary:
        //     Load features in a FeatureTable into a GraphicsLayer
        //
        async Task <IS3GraphicsLayer> featureTable2GraphicsLayer(FeatureTable table,
                                                                 int start = 0, int maxFeatures = 0, bool isShp = false)
        {
            if (table == null)
            {
                return(null);
            }

            if (_srEMap == null)
            {
                // The spatial reference in the first table is used as the project spatial reference.
                // All features on other layers will be projected to the spatial reference.
                _srEMap = table.SpatialReference;
                _map.SpatialReference = table.SpatialReference;
            }

            //// We cannot use the feature layer class because it typically
            //// has a different SpatialReferece object (coordinate system)
            //// other than the tiled layer (WKID = 3857 or 102100),
            //// and there is no easy way to reproject feature layer
            //// to another coordinate system.
            //// We can only use the feature layer when there is no tiled layer defined,
            //// which is not a usual case.
            //FeatureLayer fLayer = new FeatureLayer(table);
            //fLayer.ID = table.Name;
            //fLayer.DisplayName = table.Name;
            //_map.Layers.Add(fLayer);

            QueryFilter qf = new QueryFilter();

            qf.WhereClause = "1=1";
            IEnumerable <Feature> features = await table.QueryAsync(qf);

            IS3GraphicCollection graphics = new IS3GraphicCollection();

            int index = 0, count = 0;

            foreach (Feature f in features)
            {
                // jump to start position
                if (index++ < start)
                {
                    continue;
                }

                // Note:
                //     In ArcGIS Runtime SDK: User-defined coordinate system
                //     is not allowed when using ShapefileTable.OpenAsync().
                // Workaround:
                //     (1) Do not assign user-defined CS in shape file;
                //     (2) Assign CS dynamically here to _srEMap.
                //
                Geometry geometry = f.Geometry;
                if (isShp == true)
                {
                    geometry = ArcGISMappingUtility.ChangeSpatailReference(geometry, _srEMap);
                    if (geometry == null)
                    {
                        continue;
                    }
                }

                if (_srEMap != null && isShp == false && geometry.SpatialReference != _srEMap)
                {
                    geometry = GeometryEngine.Project(geometry, _srEMap);
                }

                // import the attributes
                IS3Graphic g = new IS3Graphic(geometry);
                foreach (KeyValuePair <string, object> item in f.Attributes.AsEnumerable())
                {
                    g.Attributes.Add(item);
                }
                graphics.Add(g);

                // Load max featuers
                if (maxFeatures != 0 && count++ == maxFeatures)
                {
                    break;
                }
            }

            IS3GraphicsLayer gLayer = new IS3GraphicsLayer();

            gLayer.DisplayName    = table.Name;
            gLayer.GraphicsSource = graphics;
            gLayer.geometryType   = (Core.Model.GeometryType)(int) table.GeometryType;

            return(gLayer);
        }
Exemple #3
0
        // Summary:
        //     Load features in a FeatureTable into a GraphicsLayer
        //
        async Task<IS3GraphicsLayer> featureTable2GraphicsLayer(FeatureTable table,
            int start = 0, int maxFeatures = 0, bool isShp = false)
        {
            if (table == null)
                return null;

            if (_srEMap == null)
            {
                // The spatial reference in the first table is used as the project spatial reference.
                // All features on other layers will be projected to the spatial reference.
                _srEMap = table.SpatialReference;
                _map.SpatialReference = table.SpatialReference;
            }

            //// We cannot use the feature layer class because it typically 
            //// has a different SpatialReferece object (coordinate system)
            //// other than the tiled layer (WKID = 3857 or 102100),
            //// and there is no easy way to reproject feature layer
            //// to another coordinate system.
            //// We can only use the feature layer when there is no tiled layer defined,
            //// which is not a usual case.
            //FeatureLayer fLayer = new FeatureLayer(table);
            //fLayer.ID = table.Name;
            //fLayer.DisplayName = table.Name;
            //_map.Layers.Add(fLayer);

            QueryFilter qf = new QueryFilter();
            qf.WhereClause = "1=1";
            IEnumerable<Feature> features = await table.QueryAsync(qf);
            IS3GraphicCollection graphics = new IS3GraphicCollection();

            int index = 0, count = 0;
            foreach (Feature f in features)
            {
                // jump to start position
                if (index++ < start)
                    continue;

                // Note:
                //     In ArcGIS Runtime SDK: User-defined coordinate system
                //     is not allowed when using ShapefileTable.OpenAsync().
                // Workaround:
                //     (1) Do not assign user-defined CS in shape file;
                //     (2) Assign CS dynamically here to _srEMap.
                //
                Geometry geometry = f.Geometry;
                if (isShp == true)
                {
                    geometry = ArcGISMappingUtility.ChangeSpatailReference(geometry, _srEMap);
                    if (geometry == null)
                        continue;
                }

                if (_srEMap != null && isShp == false && geometry.SpatialReference != _srEMap)
                    geometry = GeometryEngine.Project(geometry, _srEMap);

                // import the attributes
                IS3Graphic g = new IS3Graphic(geometry);
                foreach (KeyValuePair<string, object> item in f.Attributes.AsEnumerable())
                    g.Attributes.Add(item);
                graphics.Add(g);

                // Load max featuers
                if (maxFeatures != 0 && count++ == maxFeatures)
                    break;
            }

            IS3GraphicsLayer gLayer = new IS3GraphicsLayer();
            gLayer.DisplayName = table.Name;
            gLayer.GraphicsSource = graphics;
            gLayer.geometryType = (IS3.Core.Geometry.GeometryType)(int)table.GeometryType;

            return gLayer;
        }