示例#1
0
        async public Task <IFeatureCursor> GetFeatures(IQueryFilter filter)
        {
            _lastException = null;
            if (filter is IBufferQueryFilter)
            {
                ISpatialFilter sFilter = await BufferQueryFilter.ConvertToSpatialFilter(filter as IBufferQueryFilter);

                if (sFilter == null)
                {
                    return(null);
                }

                return(await GetFeatures(sFilter));
            }

            return(await OgcSpatialFeatureCursor.Create(this, filter));
        }
示例#2
0
        async public Task <ISelectionSet> Select(IQueryFilter filter)
        {
            filter.SubFields = this.IDFieldName;
            if (filter is ISpatialFilter)
            {
                filter.AddField(this.ShapeFieldName);
            }

            using (IFeatureCursor cursor = await OgcSpatialFeatureCursor.Create(this, filter))
            {
                IFeature feat;

                SpatialIndexedIDSelectionSet selSet = new SpatialIndexedIDSelectionSet(this.Envelope);
                while ((feat = await cursor.NextFeature()) != null)
                {
                    selSet.AddID(feat.OID, feat.Shape);
                }
                return(selSet);
            }
        }
示例#3
0
        async static public Task <IFeatureCursor> Create(OgcSpatialFeatureclass fc, IQueryFilter filter)
        {
            var featureCursor = new OgcSpatialFeatureCursor(fc, filter);

            if (fc == null || fc.Dataset == null)
            {
                return(featureCursor);
            }

            featureCursor._idField = fc.IDFieldName;
            if (filter is ISpatialFilter)
            {
                featureCursor._spatialfilter = (ISpatialFilter)filter;
            }

            try
            {
                if (fc.SpatialReference != null &&
                    filter is ISpatialFilter &&
                    ((ISpatialFilter)filter).FilterSpatialReference != null &&
                    !((ISpatialFilter)filter).FilterSpatialReference.Equals(fc.SpatialReference))
                {
                    filter = (ISpatialFilter)filter.Clone();

                    ((ISpatialFilter)filter).Geometry =
                        GeometricTransformerFactory.Transform2D(((ISpatialFilter)filter).Geometry,
                                                                ((ISpatialFilter)filter).FilterSpatialReference,
                                                                fc.SpatialReference);
                    ((ISpatialFilter)filter).FilterSpatialReference = null;
                    if (((ISpatialFilter)filter).SpatialRelation == spatialRelation.SpatialRelationMapEnvelopeIntersects &&
                        ((ISpatialFilter)filter).Geometry != null)
                    {
                        ((ISpatialFilter)filter).Geometry = ((ISpatialFilter)filter).Geometry.Envelope;
                    }

                    featureCursor._spatialfilter = (ISpatialFilter)filter;
                }
                DbCommand command = ((OgcSpatialDataset)fc.Dataset).SelectCommand(
                    fc, filter, out featureCursor._shapeField);
                if (command == null)
                {
                    return(featureCursor);
                }

                featureCursor._subFields = filter.QuerySubFields.ToArray();

                featureCursor._conn = ((OgcSpatialDataset)fc.Dataset).ProviderFactory.CreateConnection();
                featureCursor._conn.ConnectionString = fc.Dataset.ConnectionString;

                command.Connection = featureCursor._conn;

                if (featureCursor._conn.State != ConnectionState.Closed)
                {
                    try
                    {
                        featureCursor._conn.Close();
                    }
                    catch { }
                }
                await featureCursor._conn.OpenAsync();

                command.SetCustomCursorTimeout();
                featureCursor._reader = await command.ExecuteReaderAsync();

                return(featureCursor);
            }
            catch (Exception ex)
            {
                if (featureCursor._fc != null)
                {
                    featureCursor._fc.LastException = ex;
                }

                if (featureCursor._conn != null && featureCursor._conn.State != ConnectionState.Closed)
                {
                    featureCursor._conn.Close();
                    featureCursor._conn = null;
                }

                fc.LastException = ex;

                return(null);
            }
        }