async public Task <IFeature> NextFeature() { if (_edgeCursor == null && _edgeFcs != null && _edgeFcIndex < _edgeFcs.Count) { IFeatureClass fc = _edgeFcs[_edgeFcIndex++]; _fcid = await _fdb.FeatureClassID(await _fdb.DatasetID(fc.Dataset.DatasetName), fc.Name); if (_fcid < 0) { return(await NextFeature()); } if (fc.Name == _networkName + "_ComplexEdges") { _fcid = -1; } IQueryFilter f = (IQueryFilter)_filter.Clone(); if (f.SubFields != "*") { f.AddField(fc.IDFieldName); f.AddField(fc.ShapeFieldName); } _edgeCursor = await fc.GetFeatures(f); if (_edgeCursor == null) { return(await NextFeature()); } } if (_edgeCursor != null) { IFeature feature = await _edgeCursor.NextFeature(); if (feature != null) { feature.Fields.Add(new FieldValue("NETWORK#FCID", _fcid)); return(feature); } _edgeCursor.Dispose(); _edgeCursor = null; return(await NextFeature()); } if (_nodeCursor == null && _nodeFc != null) { _nodeCursor = await _nodeFc.GetFeatures(_filter); } if (_nodeCursor != null) { return(await _nodeCursor.NextFeature()); } return(null); }
async public Task <IFeatureCursor> GetFeatures(IQueryFilter filter) { if (filter is ISpatialFilter) { if (this.SpatialReference != null && ((ISpatialFilter)filter).FilterSpatialReference != null && !((ISpatialFilter)filter).FilterSpatialReference.Equals(this.SpatialReference)) { filter = (ISpatialFilter)filter.Clone(); ((ISpatialFilter)filter).Geometry = GeometricTransformerFactory.Transform2D(((ISpatialFilter)filter).Geometry, ((ISpatialFilter)filter).FilterSpatialReference, this.SpatialReference); ((ISpatialFilter)filter).FilterSpatialReference = null; } } if (_dataset.Source != null) { if (_dataset.Source.IsValid) { if (filter is DistinctFilter) { return(new GeoJsonDistinctFeatureCursor(await _dataset.Source?.GetFeatures(this.GeometryType), (DistinctFilter)filter)); } return(new GeoJsonFeatureCursor(this, await _dataset.Source?.GetFeatures(this.GeometryType), filter)); } else if (_dataset.Source.LastException != null) { throw new Exception(_dataset.Source.LastException.AllMessages()); } } // Dataset is not intializalized return(new GeoJsonFeatureCursor(this, new IFeature[0], filter)); }
static public IQueryFilter AppendWhereClause(this IQueryFilter queryFilter, string appendFilter) { if (String.IsNullOrWhiteSpace(appendFilter)) { return(queryFilter); } if (queryFilter == null) { return(new QueryFilter() { WhereClause = appendFilter }); } var result = queryFilter.Clone() as IQueryFilter; if (result != null) { result.WhereClause = queryFilter.WhereClause.AppendWhereClause(appendFilter); } return(result); }
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); } }
public OgcSpatialFeatureCursor(OgcSpatialFeatureclass fc, IQueryFilter filter) : base((fc != null) ? fc.SpatialReference : null, (filter != null) ? filter.FeatureSpatialReference : null) { if (fc == null || fc.Dataset == null) { return; } _idField = fc.IDFieldName; if (filter is ISpatialFilter) { _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 = GeometricTransformer.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; } _spatialfilter = (ISpatialFilter)filter; } DbCommand command = ((OgcSpatialDataset)fc.Dataset).SelectCommand( fc, filter, out _shapeField); if (command == null) { return; } _conn = ((OgcSpatialDataset)fc.Dataset).ProviderFactory.CreateConnection(); _conn.ConnectionString = fc.Dataset.ConnectionString; command.Connection = _conn; if (_conn.State != ConnectionState.Closed) { try { _conn.Close(); } catch { } } _conn.Open(); //command.Prepare(); _reader = command.ExecuteReader(); } catch (Exception ex) { if (_fc != null) { _fc.LastException = ex; } if (_conn != null && _conn.State != ConnectionState.Closed) { _conn.Close(); _conn = null; } } }