示例#1
0
        /// <summary>
        ///     Queries for the features that satisfies the attribute and/or spatial query as specified by an
        ///     <paramref name="filter" /> object
        ///     and executes the specified <paramref name="action" /> on each feature returned from the query.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="filter">The attribute and/or spatial requirement that the features must satisify.</param>
        /// <param name="action">The action to take for each feature in the cursor.</param>
        /// <param name="recycling">if set to <c>true</c> when a recycling memory for the features is used.</param>
        /// <returns>
        ///     Returns a <see cref="int" /> representing the number of features affected by the action.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">action</exception>
        /// <exception cref="ArgumentNullException">action</exception>
        public static int Fetch(this IFeatureClass source, IQueryFilter filter, Func <IFeature, bool> action, bool recycling)
        {
            if (source == null)
            {
                return(0);
            }
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            int recordsAffected = 0;

            using (ComReleaser cr = new ComReleaser())
            {
                IFeatureCursor cursor = source.Search(filter, recycling);
                cr.ManageLifetime(cursor);

                foreach (var feature in cursor.AsEnumerable())
                {
                    if (!action(feature))
                    {
                        return(recordsAffected);
                    }

                    recordsAffected++;
                }
            }

            return(recordsAffected);
        }
示例#2
0
        /// <summary>
        ///     Queries for the features that satisfies the attribute and/or spatial query as specified by an
        ///     <paramref name="filter" /> object.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="filter">The attribute and/or spatial requirement that the features must satisify.</param>
        /// <returns>
        ///     Returns a <see cref="List{IFeature}" /> representing the results of the query projected to the type.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">filter</exception>
        public static IList <IFeature> Fetch(this IFeatureClass source, IQueryFilter filter)
        {
            if (source == null)
            {
                return(null);
            }

            using (ComReleaser cr = new ComReleaser())
            {
                IFeatureCursor cursor = source.Search(filter, false);
                cr.ManageLifetime(cursor);

                return(cursor.AsEnumerable().ToList());
            }
        }
示例#3
0
        /// <summary>
        ///     Queries for the features that have the specified object ids.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="oids">The list of object ids.</param>
        /// <returns>
        ///     Returns a <see cref="List{IFeature}" /> representing the features returned from the query.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">oids</exception>
        public static IList <IFeature> Fetch(this IFeatureClass source, params int[] oids)
        {
            if (source == null)
            {
                return(null);
            }
            if (oids == null)
            {
                throw new ArgumentNullException("oids");
            }

            using (ComReleaser cr = new ComReleaser())
            {
                IFeatureCursor cursor = source.GetFeatures(oids, false);
                cr.ManageLifetime(cursor);

                return(cursor.AsEnumerable().ToList());
            }
        }
示例#4
0
        /// <summary>
        ///     Queries for the features that satisfies the attribute and/or spatial query as specified by an
        ///     <paramref name="filter" /> object and projects the results into a new form.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <param name="source">The source.</param>
        /// <param name="filter">The attribute and/or spatial requirement that the features must satisify.</param>
        /// <param name="selector">Projects each element of a sequence into a new form.</param>
        /// <returns>
        ///     Returns a <see cref="List{TResult}" /> representing the results of the query projected to the type.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     filter
        ///     or
        ///     selector
        /// </exception>
        public static IList <TResult> Fetch <TResult>(this IFeatureClass source, IQueryFilter filter, Func <IFeature, TResult> selector)
        {
            if (source == null)
            {
                return(null);
            }
            if (selector == null)
            {
                throw new ArgumentNullException("selector");
            }

            using (ComReleaser cr = new ComReleaser())
            {
                IFeatureCursor cursor = source.Search(filter, false);
                cr.ManageLifetime(cursor);

                return(cursor.AsEnumerable().Select(selector).ToList());
            }
        }