示例#1
0
        /// <summary>
        /// Downloads records and yields them as a lazy sequence of features of the specified type.  Possibly throws RestException.
        /// </summary>
        /// <typeparam name="T">The type the record should be mapped to.</typeparam>
        /// <param name="layerId">The layer ID of the feature layer or table.</param>
        /// <param name="whereClause">The where clause.  If set to null, returns all features.</param>
        /// <param name="extraParameters">The query string that describes any additional query parameters (i.e. outSR=4326).  Each parameter must be url encoded.</param>
        /// <param name="keepQuerying">If set to true, repetitively queries the server until all features have been returned.</param>
        /// <param name="degreeOfParallelism">The maximum number of concurrent requests.</param>
        /// <returns></returns>
        public IEnumerable <T> Download <T>(int layerId, string whereClause = null, string extraParameters = null, bool keepQuerying = false, int degreeOfParallelism = 1) where T : Feature
        {
            var layer          = GetLayer(layerId);
            var returnGeometry = typeof(T).HasGeometry();

            var featureSet = Esri.GetFeatureSet(ServiceArgs, layerId, returnGeometry, layer.hasZ, whereClause, extraParameters, null);

            foreach (var g in featureSet.features)
            {
                yield return(ToFeature <T>(g, layer));
            }

            var objectIds = featureSet.features.Select(g => Convert.ToInt32(g.attributes[layer.GetObjectIdFieldName()])).ToArray();

            if (!keepQuerying || objectIds.Length == 0)
            {
                yield break;
            }

            var remainingObjectIds = Esri.GetOIDSet(ServiceArgs, layerId, whereClause, extraParameters).objectIds.Except(objectIds);

            foreach (var f in Download <T>(layer, remainingObjectIds, returnGeometry, whereClause, extraParameters, objectIds.Length, degreeOfParallelism))
            {
                yield return(f);
            }
        }
示例#2
0
 private IEnumerable <T> Download <T>(Layer layer, IEnumerable <int> objectIds, bool returnGeometry, string whereClause, string extraParameters, int batchSize, int degreeOfParallelism) where T : Feature
 {
     return(objectIds.Partition(batchSize)
            .AsParallel()
            .AsOrdered()
            .WithDegreeOfParallelism(degreeOfParallelism < 1 ? 1 : degreeOfParallelism)
            .SelectMany(ids => Esri.GetFeatureSet(ServiceArgs, layer.id, returnGeometry, layer.hasZ, whereClause, extraParameters, ids).features
                        .Select(g => ToFeature <T>(g, layer))));
 }