async public Task <ISelectionSet> Select(IQueryFilter filter) { filter.SubFields = this.IDFieldName; filter.AddField("FDB_SHAPE"); filter.AddField("FDB_OID"); IFeatureCursor cursor = await _fdb.Query(this, filter); IFeature feat; SpatialIndexedIDSelectionSet selSet = new SpatialIndexedIDSelectionSet(this.Envelope); while ((feat = await cursor.NextFeature()) != null) { //long nid = 0; foreach (FieldValue fv in feat.Fields) { //if (fv.Name == "FDB_NID") //{ // nid = Convert.ToInt64(fv.Value); // break; //} } selSet.AddID(feat.OID, feat.Shape); } cursor.Dispose(); return(selSet); }
public ISelectionSet Select(IQueryFilter filter) { filter.SubFields = this.IDFieldName; filter.AddField("FDB_OID"); filter.AddField("FDB_SHAPE"); IFeatureCursor cursor = (IFeatureCursor)_fdb.Query(this, filter); IFeature feat; SpatialIndexedIDSelectionSet selSet = new SpatialIndexedIDSelectionSet(this.Envelope); while ((feat = cursor.NextFeature) != null) { int nid = 0; foreach (FieldValue fv in feat.Fields) { //if (fv.Name == "FDB_NID") //{ // nid = (int)fv.Value; // break; //} } selSet.AddID(feat.OID, feat.Shape); } cursor.Dispose(); return(selSet); }
public void PrepareQueryFilter(IFeatureLayer layer, IQueryFilter filter) { if (layer.FeatureClass == null) { return; } if (!String.IsNullOrEmpty(_valueField1) && layer.FeatureClass.FindField(_valueField1) != null) { filter.AddField(_valueField1); } if (!String.IsNullOrEmpty(_valueField2) && layer.FeatureClass.FindField(_valueField2) != null) { filter.AddField(_valueField2); } if (!String.IsNullOrEmpty(_valueField3) && layer.FeatureClass.FindField(_valueField3) != null) { filter.AddField(_valueField3); } if (layer.FeatureClass.FindField(_symbolRotation.RotationFieldName) != null) { filter.AddField(_symbolRotation.RotationFieldName); } }
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); }
public void PrepareFilter(IFeatureClass fc, IQueryFilter queryFilter) { // prepare filter for drawing // must add OID queryFilter.AddField(fc.OIDFieldName); m_ShapeType = fc.ShapeType; if (m_ShapeType == esriGeometryType.esriGeometryPoint) { if (m_sRotationField != null) { if (m_sRotationField != "") { queryFilter.AddField(m_sRotationField); } } } // save the fc and the query filter so that multiple cursors can be built in DrawSymbols m_pFeatureClass = fc; m_pQueryFilter = queryFilter; // prepare filters on constituent renderers so I can use SymbolByFeature in Draw if (m_pShapePatternRend != null) m_pShapePatternRend.PrepareFilter(fc, queryFilter); if (m_pColorRend1 != null) m_pColorRend1.PrepareFilter(fc, queryFilter); if (m_pColorRend2 != null) m_pColorRend2.PrepareFilter(fc, queryFilter); if (m_pSizeRend != null) m_pSizeRend.PrepareFilter(fc, queryFilter); // if we're combining colors from two (sequential) quantitative schemes, build color matrix now // this gives flexibility to extend in future // in current impl. we determine combined color based on two colors, one from each constituent // ClassBreaksRenderer. so, we could determine color on demand when drawing. but, by creating // the color matrix here and storing for later use, we leave open the possibility of swapping in // different logic for determining combined colors based on all known colors in each constituent // renderer, not just the colors for the given feature if ((m_pColorRend1 != null) & (m_pColorRend2 != null)) { if (! (m_eColorCombinationMethod == EColorCombinationType.enuComponents)) BuildColorMatrix(); } //implementation of IExportSupport AddExportFields(fc, queryFilter); }
public void PrepareQueryFilter(IDisplay display, IFeatureLayer layer, IQueryFilter filter) { if (layer.FeatureClass == null) { return; } if (_useExpression) { ExtractExpressionFields(); foreach (string fieldname in _expressionFields) { if (layer.FeatureClass.FindField(fieldname) != null) { filter.AddField(fieldname); } } } else { if (layer.FeatureClass.FindField(_fieldname) != null) { filter.AddField(_fieldname); } } if (_sizeField != String.Empty) { filter.AddField(_sizeField); } if (_fontField != String.Empty) { filter.AddField(_fontField); } if (layer.FeatureClass.FindField(_symbolRotation.RotationFieldName) != null) { filter.AddField(_symbolRotation.RotationFieldName); } _clipEnvelope = new Envelope(display.DisplayTransformation.TransformedBounds(display)); if (display.GeometricTransformer != null) { object e = display.GeometricTransformer.InvTransform2D(display.Envelope); if (e is IGeometry) { _clipEnvelope = ((IGeometry)e).Envelope; } } }
public void PrepareFilter(IFeatureClass fc, IQueryFilter queryFilter) { //if (queryFilter == null) // queryFilter = new QueryFilterClass(); queryFilter = m_pQueryFilter; queryFilter.AddField(fc.OIDFieldName); //m_ShapeType = fc.ShapeType; queryFilter.AddField(m_strOriRenderField); queryFilter.AddField(m_strUncernRenderField); // save the fc and the query filter so that multiple cursors can be built in DrawSymbols m_pFeatureClass = fc; m_pQueryFilter = queryFilter; }
protected override void ConfigureQueryFilter(int tableIndex, IQueryFilter queryFilter) { base.ConfigureQueryFilter(tableIndex, queryFilter); ITable table = InvolvedTables[tableIndex]; foreach (QueryFilterHelper[] rule in _rules) { if (rule[tableIndex] == null) { continue; } string subFields = rule[tableIndex].SubFields; if (string.IsNullOrEmpty(subFields)) { continue; } foreach (string fieldName in ExpressionUtils.GetExpressionFieldNames( table, subFields)) { queryFilter.AddField(fieldName); // .AddField checks for multiple entries ! } } }
/// <summary> /// Adapts IQueryFilter so that it conforms to the needs of the test /// </summary> protected virtual void ConfigureQueryFilter(int tableIndex, [NotNull] IQueryFilter queryFilter) { Assert.ArgumentNotNull(queryFilter, nameof(queryFilter)); ITable table = InvolvedTables[tableIndex]; string constraint = GetConstraint(tableIndex); queryFilter.AddField(table.OIDFieldName); var featureClass = table as IFeatureClass; // add shape field if (featureClass != null) { queryFilter.AddField(featureClass.ShapeFieldName); } // add subtype field var subtypes = table as ISubtypes; if (subtypes != null) { if (subtypes.HasSubtype) { queryFilter.AddField(subtypes.SubtypeFieldName); } } // add where clause fields if (constraint != null) { foreach ( string fieldName in ExpressionUtils.GetExpressionFieldNames(table, constraint)) { queryFilter.AddField(fieldName); // .AddField checks for multiple entries ! } queryFilter.WhereClause = constraint; } else { queryFilter.WhereClause = constraint; } }
public void PrepareQueryFilter(IFeatureLayer layer, IQueryFilter filter) { if (layer.FeatureClass == null) { return; } if (layer.FeatureClass.FindField(_valueField) != null) { filter.AddField(_valueField); } if (layer.FeatureClass.FindField(_symbolRotation.RotationFieldName) != null) { filter.AddField(_symbolRotation.RotationFieldName); } }
public ISelectionSet Select(IQueryFilter filter) { filter.SubFields = this.IDFieldName; filter.AddField("FDB_SHAPE"); filter.AddField("FDB_OID"); using (IFeatureCursor cursor = (IFeatureCursor)_fdb.Query(this, filter)) { IFeature feat; SpatialIndexedIDSelectionSet selSet = new SpatialIndexedIDSelectionSet(this.Envelope); while ((feat = cursor.NextFeature) != null) { selSet.AddID(feat.OID, feat.Shape); } return(selSet); } }
virtual public ISelectionSet Select(IQueryFilter filter) { FeatureCache.RemoveFeatureCollection(_selectionGUID); if (this.IDFieldName != String.Empty && this.FindField(this.IDFieldName) != null) { filter.SubFields = this.IDFieldName; filter.AddField(this.ShapeFieldName); filter.AddField(this.IDFieldName); using (IFeatureCursor cursor = this.GetFeatures(_selectionGUID, filter)) { if (cursor != null) { IFeature feat; IDSelectionSet selSet = new IDSelectionSet(); while ((feat = cursor.NextFeature) != null) { selSet.AddID(feat.OID); } return(selSet); } } } else { int count = 0; using (IFeatureCursor cursor = this.GetFeatures(_selectionGUID, filter)) { if (cursor == null) { return(null); } IFeature feature; while ((feature = cursor.NextFeature) != null) { count++; } } return(new QueryFilteredSelectionSet(filter, count)); } return(null); }
protected override void ConfigureQueryFilter(int tableIndex, IQueryFilter queryFilter) { base.ConfigureQueryFilter(tableIndex, queryFilter); foreach (string field in _fieldInfos.Keys) { queryFilter.AddField(field); } }
public void PrepareQueryFilter(IFeatureLayer layer, IQueryFilter filter) { if (!(_symbol is ISymbolCollection) || ((ISymbolCollection)_symbol).Symbols.Count < 2) { _actualCartoMethod = CartographicMethod.Simple; } else { _actualCartoMethod = _cartoMethod; } if (_rotate && layer.FeatureClass.FindField(_symbolRotation.RotationFieldName) != null) { filter.AddField(_symbolRotation.RotationFieldName); } }
protected override void ConfigureQueryFilter(int tableIndex, IQueryFilter queryFilter) { if (_flipExpressions != null) { ITable table = InvolvedTables[tableIndex]; foreach (string fieldName in ExpressionUtils.GetExpressionFieldNames(table, _flipExpressions[tableIndex])) { // .AddField checks for multiple entries ! queryFilter.AddField(fieldName); } } base.ConfigureQueryFilter(tableIndex, queryFilter); }
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); } }
protected override void ConfigureQueryFilter(int tableIndex, IQueryFilter queryFilter) { base.ConfigureQueryFilter(tableIndex, queryFilter); ITable table = InvolvedTables[tableIndex]; foreach (QaConnectionRuleHelper ruleHelper in _ruleHelpers) { if (ruleHelper.MainRuleFilterHelpers[tableIndex] == null) { continue; } string constraint = ruleHelper.MainRuleFilterHelpers[tableIndex].Constraint; foreach ( string fieldName in ExpressionUtils.GetExpressionFieldNames(table, constraint)) { queryFilter.AddField(fieldName); // .AddField checks for multiple entries ! } } }
public IFeatureCursor GetFeatures(IQueryFilter filter /*, gView.Framework.Data.getFeatureQueryType type*/) { if (_fdb == null) { return(null); } if (filter != null) { filter.AddField("FDB_OID"); } if (filter is IRowIDFilter) { filter.fieldPostfix = filter.fieldPrefix = "\""; return(_fdb.QueryIDs(this, filter.SubFieldsAndAlias, ((IRowIDFilter)filter).IDs, filter.FeatureSpatialReference)); } else { return(_fdb.Query(this, filter)); } }
virtual public DbCommand SelectCommand(OgcSpatialFeatureclass fc, IQueryFilter filter, out string shapeFieldName, string functionName = "", string functionField = "", string functionAlias = "") { shapeFieldName = String.Empty; filter.fieldPostfix = filter.fieldPrefix = "\""; if (filter.SubFields == "*") { filter.SubFields = ""; foreach (IField field in fc.Fields.ToEnumerable()) { filter.AddField(field.name); } filter.AddField(fc.IDFieldName); filter.AddField(fc.ShapeFieldName); } else { filter.AddField(fc.IDFieldName); } string where = ""; if (filter is ISpatialFilter) { ISpatialFilter sFilter = filter as ISpatialFilter; if (sFilter.Geometry is IEnvelope) { where = fc.ShapeFieldName + " && " + gView.Framework.OGC.OGC.Envelope2box2(sFilter.Geometry as IEnvelope, fc.SpatialReference); } else if (sFilter.Geometry != null) { where = fc.ShapeFieldName + " && " + gView.Framework.OGC.OGC.Envelope2box2(sFilter.Geometry.Envelope, fc.SpatialReference); } filter.AddField(fc.ShapeFieldName); } if (!String.IsNullOrWhiteSpace(functionName) && !String.IsNullOrWhiteSpace(functionField)) { filter.SubFields = ""; filter.AddField(functionName + "(" + filter.fieldPrefix + functionField + filter.fieldPostfix + ")"); } string filterWhereClause = (filter is IRowIDFilter) ? ((IRowIDFilter)filter).RowIDWhereClause : filter.WhereClause; //if (where != "" && filterWhereClause != "") //{ // where += " AND "; //} where = String.IsNullOrWhiteSpace(where) ? filterWhereClause : where + (String.IsNullOrWhiteSpace(filterWhereClause) ? "" : $" AND ({ filterWhereClause })"); StringBuilder fieldNames = new StringBuilder(); foreach (string fieldName in filter.SubFields.Split(' ')) { if (fieldNames.Length > 0) { fieldNames.Append(","); } if (fieldName == "\"" + fc.ShapeFieldName + "\"") { fieldNames.Append("ST_AsBinary(\"" + fc.ShapeFieldName + "\") as temp_geometry"); shapeFieldName = "temp_geometry"; } else { fieldNames.Append(fieldName); } } string limit = String.Empty, orderBy = String.Empty; if (!String.IsNullOrWhiteSpace(filter.OrderBy)) { orderBy = " order by " + filter.OrderBy; } if (filter.Limit > 0) { limit = " limit " + filter.Limit; } if (filter.BeginRecord > 1) // Default in QueryFilter is one!!! { limit += " offset " + Math.Max(0, filter.BeginRecord - 1); } DbCommand command = ((OgcSpatialDataset)fc.Dataset).ProviderFactory.CreateCommand(); command.CommandText = ("SELECT " + fieldNames + " FROM " + DbTableName(fc.Name) + ((where != "") ? " WHERE " + where : "") + orderBy + limit).Trim(); return(command); }
public SdeFeatureCursor(SdeDataset dataset, ITableClass tc, IQueryFilter filter) : base((tc is IFeatureClass) && ((IFeatureClass)tc).SpatialReference != null ? ((IFeatureClass)tc).SpatialReference : filter.ContextLayerDefaultSpatialReference, (filter != null) ? filter.FeatureSpatialReference : null) { try { if (filter != null && !filter.SubFields.Contains("*")) { filter.AddField(tc.IDFieldName, false); } filter.fieldPrefix = tc.Name + "."; filter.fieldPostfix = ""; if (filter is ISpatialFilter && (((ISpatialFilter)filter).SpatialRelation != spatialRelation.SpatialRelationMapEnvelopeIntersects)) { if (tc is IFeatureClass) { filter.AddField(((IFeatureClass)tc).ShapeFieldName); } _spatialFilter = (ISpatialFilter)filter; } Int32 err_no = 0; _dataset = dataset; if (_dataset == null) { return; } //_connection = _dataset.AllocConnection(); _connection = new ArcSdeConnection(dataset.ConnectionString); if (!_connection.Open(this._dataset)) { return; } _queryInfo = new SdeQueryInfo(_connection, tc, filter); if (_queryInfo.ErrorMessage != "") { Dispose(); return; } //if (Wrapper10.SE_stream_create(_connection.SeConnection, ref _stream) != 0) //{ // Dispose(); // return; //} //_connection.ResetStream(); _stream = _connection.CreateStream(); // SE_stream_set_state sollte auch aufgerufen werden (siehe mapsde.c von UMN) if (Wrapper10.SE_stream_set_state( _stream.SeStream, CONST.SE_DEFAULT_STATE_ID, CONST.SE_DEFAULT_STATE_ID, CONST.SE_STATE_DIFF_NOCHECK) != 0) { Dispose(); return; } if ((err_no = Wrapper10.SE_stream_query_with_info(_stream.SeStream, _queryInfo.SeQueryInfo)) != 0) { Dispose(); return; } if (_queryInfo.IsSpatial) { SE_FILTER se_filter = _queryInfo.Filter_Shape; if ((err_no = Wrapper10.SE_stream_set_spatial_constraints(_stream.SeStream, CONST.SE_SPATIAL_FIRST, false, 1, ref se_filter)) != 0) { _errMsg = Wrapper10.GetErrorMsg(_connection.SeConnection, err_no); Dispose(); return; } } else { /* * SE_FILTER se_filter = _queryInfo.Filter_Id; * if (Wrapper10.SE_stream_set_spatial_constraints(_stream, CONST.SE_SPATIAL_FIRST, false, 1, ref se_filter) != 0) * { * Release(); * return; * } * */ } if (Wrapper10.SE_stream_execute(_stream.SeStream) != 0) { Dispose(); return; } _queryFields = _queryInfo.QueryFields; _queryInfo.Dispose(); _queryInfo = null; } catch (Exception ex) { _errMsg = ex.Message + "\n" + ex.StackTrace; Dispose(); } }
virtual public DbCommand SelectCommand(OgcSpatialFeatureclass fc, IQueryFilter filter, out string shapeFieldName) { shapeFieldName = String.Empty; filter.fieldPostfix = filter.fieldPrefix = "\""; if (filter.SubFields == "*") { filter.SubFields = ""; foreach (IField field in fc.Fields.ToEnumerable()) { filter.AddField(field.name); } filter.AddField(fc.IDFieldName); filter.AddField(fc.ShapeFieldName); } else { filter.AddField(fc.IDFieldName); } string where = ""; if (filter is ISpatialFilter) { ISpatialFilter sFilter = filter as ISpatialFilter; if (sFilter.Geometry is IEnvelope) { where = fc.ShapeFieldName + " && " + gView.Framework.OGC.OGC.Envelope2box2(sFilter.Geometry as IEnvelope, fc.SpatialReference); } else if (sFilter.Geometry != null) { where = fc.ShapeFieldName + " && " + gView.Framework.OGC.OGC.Envelope2box2(sFilter.Geometry.Envelope, fc.SpatialReference); } filter.AddField(fc.ShapeFieldName); } string filterWhereClause = (filter is IRowIDFilter) ? ((IRowIDFilter)filter).RowIDWhereClause : filter.WhereClause; if (where != "" && filterWhereClause != "") { where += " AND "; } where += filterWhereClause; StringBuilder fieldNames = new StringBuilder(); foreach (string fieldName in filter.SubFields.Split(' ')) { if (fieldNames.Length > 0) { fieldNames.Append(","); } if (fieldName == "\"" + fc.ShapeFieldName + "\"") { fieldNames.Append("ST_AsBinary(\"" + fc.ShapeFieldName + "\") as temp_geometry"); shapeFieldName = "temp_geometry"; } else { fieldNames.Append(fieldName); } } DbCommand command = ((OgcSpatialDataset)fc.Dataset).ProviderFactory.CreateCommand(); command.CommandText = "SELECT " + fieldNames + " FROM " + DbTableName(fc.Name) + ((where != "") ? " WHERE " + where : ""); return(command); }
async static public Task <FeatureCursor> Create(EventTableConnection etconn, IQueryFilter filter, IFeatureClass fc) { var cursor = new FeatureCursor(etconn, filter); cursor._etcon = etconn; if (etconn != null) { CommonDbConnection conn = new CommonDbConnection(); conn.ConnectionString2 = etconn.DbConnectionString.ConnectionString; string appendWhere = String.Empty; if (filter is ISpatialFilter && ((ISpatialFilter)filter).Geometry != null) { if (!(((ISpatialFilter)filter).Geometry is Envelope)) { cursor._addShape = true; filter.AddField("#SHAPE#"); cursor._spatialFilter = (ISpatialFilter)filter; } IEnvelope env = ((ISpatialFilter)filter).Geometry.Envelope; appendWhere = etconn.XFieldName + ">=" + env.minx.ToString(_nhi) + " AND " + etconn.XFieldName + "<=" + env.maxx.ToString(_nhi) + " AND " + etconn.YFieldName + ">=" + env.miny.ToString(_nhi) + " AND " + etconn.YFieldName + "<=" + env.maxy.ToString(_nhi); } if (filter is IRowIDFilter) { IRowIDFilter idFilter = (IRowIDFilter)filter; appendWhere = idFilter.RowIDWhereClause; } string where = (filter != null) ? filter.WhereClause : String.Empty; if (!String.IsNullOrEmpty(where)) { where += (String.IsNullOrEmpty(appendWhere) ? String.Empty : " AND (" + appendWhere + ")"); } else { where = appendWhere; } StringBuilder sb = new StringBuilder(); sb.Append(filter.SubFieldsAndAlias); foreach (string fieldname in filter.SubFields.Split(' ')) { if (fieldname == "#SHAPE#") { if (sb.Length > 0) { sb.Append(","); } sb.Append(cursor._etcon.XFieldName + "," + cursor._etcon.YFieldName); cursor._addShape = true; } if (fieldname == "*") { cursor._addShape = true; } } string fields = sb.ToString().Replace(",#SHAPE#", "").Replace("#SHAPE#,", "").Replace("#SHAPE#", ""); //_tab = conn.Select(sb.ToString(), etconn.TableName, where); //_addShape = _tab.Columns.Contains(_etcon.XFieldName) && // _tab.Columns.Contains(_etcon.YFieldName); var limits = conn.LimitResults(filter, fc); var dataReaderResult = await conn.DataReaderAsync("select " + limits.top + fields + " from " + etconn.TableName + (String.IsNullOrEmpty(where) ? String.Empty : " WHERE " + where) + limits.limit); cursor._dbReader = dataReaderResult.reader; cursor._dbConnection = dataReaderResult.connection; } return(cursor); }
public override DbCommand SelectCommand(gView.Framework.OGC.DB.OgcSpatialFeatureclass fc, IQueryFilter filter, out string shapeFieldName, string functionName = "", string functionField = "", string functionAlias = "") { shapeFieldName = String.Empty; DbCommand command = this.ProviderFactory.CreateCommand(); filter.fieldPrefix = "["; filter.fieldPostfix = "]"; if (filter.SubFields == "*") { filter.SubFields = ""; foreach (IField field in fc.Fields.ToEnumerable()) { filter.AddField(field.name); } filter.AddField(fc.IDFieldName); filter.AddField(fc.ShapeFieldName); } else { filter.AddField(fc.IDFieldName); } string where = String.Empty; if (filter is ISpatialFilter && ((ISpatialFilter)filter).Geometry != null) { ISpatialFilter sFilter = filter as ISpatialFilter; if (sFilter.SpatialRelation == spatialRelation.SpatialRelationMapEnvelopeIntersects /*|| sFilter.Geometry is IEnvelope*/) { IEnvelope env = sFilter.Geometry.Envelope; where = fc.ShapeFieldName + ".Filter("; where += "geography::STGeomFromText('POLYGON(("; where += Math.Max(-179.99, env.minx).ToString(_nhi) + " "; where += Math.Max(-89.99, env.miny).ToString(_nhi) + ","; where += Math.Min(179.99, env.maxx).ToString(_nhi) + " "; where += Math.Max(-89.99, env.miny).ToString(_nhi) + ","; where += Math.Min(179.99, env.maxx).ToString(_nhi) + " "; where += Math.Min(89.99, env.maxy).ToString(_nhi) + ","; where += Math.Max(-179.99, env.minx).ToString(_nhi) + " "; where += Math.Min(89.99, env.maxy).ToString(_nhi) + ","; where += Math.Max(-179.99, env.minx).ToString(_nhi) + " "; where += Math.Max(-89.99, env.miny).ToString(_nhi) + "))',4326))=1"; } else if (sFilter.Geometry != null) { IEnvelope env = sFilter.Geometry.Envelope; where = fc.ShapeFieldName + ".STIntersects("; where += "geography::STGeomFromText('POLYGON(("; where += Math.Max(-180.0, env.minx).ToString(_nhi) + " "; where += Math.Max(-89.99, env.miny).ToString(_nhi) + ","; where += Math.Max(-180.0, env.minx).ToString(_nhi) + " "; where += Math.Min(89.99, env.maxy).ToString(_nhi) + ","; where += Math.Min(180.0, env.maxx).ToString(_nhi) + " "; where += Math.Min(89.99, env.maxy).ToString(_nhi) + ","; where += Math.Min(180.0, env.maxx).ToString(_nhi) + " "; where += Math.Max(-89.99, env.miny).ToString(_nhi) + ","; where += Math.Max(-180.0, env.minx).ToString(_nhi) + " "; where += Math.Max(-89.99, env.miny).ToString(_nhi) + "))',4326))=1"; } filter.AddField(fc.ShapeFieldName); } if (!String.IsNullOrWhiteSpace(functionName) && !String.IsNullOrWhiteSpace(functionField)) { filter.SubFields = ""; filter.AddField(functionName + "(" + filter.fieldPrefix + functionField + filter.fieldPostfix + ")"); } string filterWhereClause = (filter is IRowIDFilter) ? ((IRowIDFilter)filter).RowIDWhereClause : filter.WhereClause; StringBuilder fieldNames = new StringBuilder(); foreach (string fieldName in filter.SubFields.Split(' ')) { if (fieldNames.Length > 0) { fieldNames.Append(","); } if (fieldName == "[" + fc.ShapeFieldName + "]") { fieldNames.Append(fc.ShapeFieldName + ".STAsBinary() as temp_geometry"); shapeFieldName = "temp_geometry"; } else { fieldNames.Append(fieldName); } } string limit = String.Empty, top = String.Empty, orderBy = String.Empty; if (!String.IsNullOrWhiteSpace(filter.OrderBy)) { orderBy = " order by " + filter.OrderBy; } if (filter.Limit > 0) { if (String.IsNullOrEmpty(fc.IDFieldName) && String.IsNullOrWhiteSpace(orderBy)) { top = "top(" + filter.Limit + ") "; } else { if (String.IsNullOrWhiteSpace(orderBy)) { orderBy = " order by " + filter.fieldPrefix + fc.IDFieldName + filter.fieldPostfix; } limit = " offset " + Math.Max(0, filter.BeginRecord - 1) + " rows fetch next " + filter.Limit + " rows only"; } } command.CommandText = "SELECT " + limit + fieldNames + " FROM " + fc.Name; if (!String.IsNullOrEmpty(where)) { command.CommandText += " WHERE " + where + ((filterWhereClause != "") ? $" AND ({ filterWhereClause })" : ""); } else if (!String.IsNullOrEmpty(filterWhereClause)) { command.CommandText += " WHERE " + filterWhereClause; } command.CommandText += orderBy + limit; return(command); }
public override DbCommand SelectCommand(gView.Framework.OGC.DB.OgcSpatialFeatureclass fc, IQueryFilter filter, out string shapeFieldName, string functionName = "", string functionField = "", string functionAlias = "") { shapeFieldName = String.Empty; DbCommand command = this.ProviderFactory.CreateCommand(); filter.fieldPrefix = "["; filter.fieldPostfix = "]"; if (filter.QuerySubFields.Contains("*")) { // var subFieldFunctions = filter.QuerySubFields.Where(f => f.IsSubFieldFunction()); filter.SubFields = ""; foreach (IField field in fc.Fields.ToEnumerable()) { filter.AddField(field.name); } filter.AddField(fc.IDFieldName); filter.AddField(fc.ShapeFieldName); //foreach(var subFieldFunction in subFieldFunctions) //{ // filter.AddField(subFieldFunction); //} } else { filter.AddField(fc.IDFieldName); } string where = String.Empty; if (filter is ISpatialFilter && ((ISpatialFilter)filter).Geometry != null) { ISpatialFilter sFilter = filter as ISpatialFilter; int srid = 0; try { if (fc.SpatialReference != null && fc.SpatialReference.Name.ToLower().StartsWith("epsg:")) { srid = Convert.ToInt32(fc.SpatialReference.Name.Split(':')[1]); } } catch { } if (sFilter.SpatialRelation == spatialRelation.SpatialRelationMapEnvelopeIntersects /*|| sFilter.Geometry is IEnvelope*/) { IEnvelope env = sFilter.Geometry.Envelope; where = fc.ShapeFieldName + ".Filter("; where += "geometry::STGeomFromText('POLYGON(("; where += env.minx.ToString(_nhi) + " "; where += env.miny.ToString(_nhi) + ","; where += env.minx.ToString(_nhi) + " "; where += env.maxy.ToString(_nhi) + ","; where += env.maxx.ToString(_nhi) + " "; where += env.maxy.ToString(_nhi) + ","; where += env.maxx.ToString(_nhi) + " "; where += env.miny.ToString(_nhi) + ","; where += env.minx.ToString(_nhi) + " "; where += env.miny.ToString(_nhi) + "))'," + srid + "))=1"; } else if (sFilter.Geometry != null) { IEnvelope env = sFilter.Geometry.Envelope; where = fc.ShapeFieldName + ".STIntersects("; where += "geometry::STGeomFromText('POLYGON(("; where += env.minx.ToString(_nhi) + " "; where += env.miny.ToString(_nhi) + ","; where += env.minx.ToString(_nhi) + " "; where += env.maxy.ToString(_nhi) + ","; where += env.maxx.ToString(_nhi) + " "; where += env.maxy.ToString(_nhi) + ","; where += env.maxx.ToString(_nhi) + " "; where += env.miny.ToString(_nhi) + ","; where += env.minx.ToString(_nhi) + " "; where += env.miny.ToString(_nhi) + "))'," + srid + "))=1"; } filter.AddField(fc.ShapeFieldName); } if (!String.IsNullOrWhiteSpace(functionName) && !String.IsNullOrWhiteSpace(functionField)) { filter.SubFields = ""; filter.AddField(functionName + "(" + filter.fieldPrefix + functionField + filter.fieldPostfix + ")"); } string filterWhereClause = (filter is IRowIDFilter) ? ((IRowIDFilter)filter).RowIDWhereClause : filter.WhereClause; StringBuilder fieldNames = new StringBuilder(); foreach (string fieldName in filter.QuerySubFields) { if (fieldNames.Length > 0) { fieldNames.Append(","); } if (fieldName == "[" + fc.ShapeFieldName + "]") { fieldNames.Append(fc.ShapeFieldName + ".STAsBinary() as temp_geometry"); shapeFieldName = "temp_geometry"; } else { fieldNames.Append(fieldName); } } string limit = String.Empty, top = String.Empty, orderBy = String.Empty; if (!String.IsNullOrWhiteSpace(filter.OrderBy)) { orderBy = " order by " + filter.OrderBy; } if (filter.Limit > 0) { if (String.IsNullOrEmpty(fc.IDFieldName) && String.IsNullOrWhiteSpace(orderBy)) { top = "top(" + filter.Limit + ") "; } else { if (String.IsNullOrWhiteSpace(orderBy)) { orderBy = " order by " + filter.fieldPrefix + fc.IDFieldName + filter.fieldPostfix; } limit = " offset " + Math.Max(0, filter.BeginRecord - 1) + " rows fetch next " + filter.Limit + " rows only"; } } string fcName = fc.Name; if (fc is SdeFeatureClass && !String.IsNullOrWhiteSpace(((SdeFeatureClass)fc).MultiVersionedViewName)) { fcName = ((SdeFeatureClass)fc).MultiVersionedViewName; // ToDo: filterWhereClause? SDE_STATE_ID=0?? } command.CommandText = "SELECT " + top + fieldNames + " FROM " + fcName; if (!String.IsNullOrEmpty(where)) { command.CommandText += " WHERE " + where + ((filterWhereClause != "") ? $" AND ({ filterWhereClause })" : ""); } else if (!String.IsNullOrEmpty(filterWhereClause)) { command.CommandText += " WHERE " + filterWhereClause; } command.CommandText += orderBy + limit; return(command); }
public override DbCommand SelectCommand(gView.Framework.OGC.DB.OgcSpatialFeatureclass fc, IQueryFilter filter, out string shapeFieldName) { shapeFieldName = String.Empty; DbCommand command = this.ProviderFactory.CreateCommand(); filter.fieldPrefix = "["; filter.fieldPostfix = "]"; if (filter.SubFields == "*") { filter.SubFields = ""; foreach (IField field in fc.Fields.ToEnumerable()) { filter.AddField(field.name); } filter.AddField(fc.IDFieldName); filter.AddField(fc.ShapeFieldName); } else { filter.AddField(fc.IDFieldName); } string where = String.Empty; if (filter is ISpatialFilter && ((ISpatialFilter)filter).Geometry != null) { ISpatialFilter sFilter = filter as ISpatialFilter; if (sFilter.SpatialRelation == spatialRelation.SpatialRelationMapEnvelopeIntersects || sFilter.Geometry is IEnvelope) { IEnvelope env = sFilter.Geometry.Envelope; where = fc.ShapeFieldName + ".Filter("; where += "geography::STGeomFromText('POLYGON(("; where += Math.Max(-179.99, env.minx).ToString(_nhi) + " "; where += Math.Max(-89.99, env.miny).ToString(_nhi) + ","; where += Math.Min(179.99, env.maxx).ToString(_nhi) + " "; where += Math.Max(-89.99, env.miny).ToString(_nhi) + ","; where += Math.Min(179.99, env.maxx).ToString(_nhi) + " "; where += Math.Min(89.99, env.maxy).ToString(_nhi) + ","; where += Math.Max(-179.99, env.minx).ToString(_nhi) + " "; where += Math.Min(89.99, env.maxy).ToString(_nhi) + ","; where += Math.Max(-179.99, env.minx).ToString(_nhi) + " "; where += Math.Max(-89.99, env.miny).ToString(_nhi) + "))',4326))=1"; } else if (sFilter.Geometry != null) { IEnvelope env = sFilter.Geometry.Envelope; where = fc.ShapeFieldName + ".STIntersects("; where += "geography::STGeomFromText('POLYGON(("; where += Math.Max(-180.0, env.minx).ToString(_nhi) + " "; where += Math.Max(-89.99, env.miny).ToString(_nhi) + ","; where += Math.Max(-180.0, env.minx).ToString(_nhi) + " "; where += Math.Min(89.99, env.maxy).ToString(_nhi) + ","; where += Math.Min(180.0, env.maxx).ToString(_nhi) + " "; where += Math.Min(89.99, env.maxy).ToString(_nhi) + ","; where += Math.Min(180.0, env.maxx).ToString(_nhi) + " "; where += Math.Max(-89.99, env.miny).ToString(_nhi) + ","; where += Math.Max(-180.0, env.minx).ToString(_nhi) + " "; where += Math.Max(-89.99, env.miny).ToString(_nhi) + "))',4326))=1"; } filter.AddField(fc.ShapeFieldName); } string filterWhereClause = (filter is IRowIDFilter) ? ((IRowIDFilter)filter).RowIDWhereClause : filter.WhereClause; StringBuilder fieldNames = new StringBuilder(); foreach (string fieldName in filter.SubFields.Split(' ')) { if (fieldNames.Length > 0) { fieldNames.Append(","); } if (fieldName == "[" + fc.ShapeFieldName + "]") { fieldNames.Append(fc.ShapeFieldName + ".STAsBinary() as temp_geometry"); shapeFieldName = "temp_geometry"; } else { fieldNames.Append(fieldName); } } command.CommandText = "SELECT " + fieldNames + " FROM " + fc.Name; if (!String.IsNullOrEmpty(where)) { command.CommandText += " WHERE " + where + ((filterWhereClause != "") ? " AND " + filterWhereClause : ""); } else if (!String.IsNullOrEmpty(filterWhereClause)) { command.CommandText += " WHERE " + filterWhereClause; } //command.CommandText = "SELECT " + fieldNames + " FROM " + table + ((filterWhereClause != "") ? " WHERE " + filterWhereClause : ""); return(command); }
public FeatureCursor(EventTableConnection etconn, IQueryFilter filter) : base( (etconn != null ? etconn.SpatialReference : null), (filter != null ? filter.FeatureSpatialReference : null)) { _etcon = etconn; if (etconn != null) { CommonDbConnection conn = new CommonDbConnection(); conn.ConnectionString2 = etconn.DbConnectionString.ConnectionString; string appendWhere = String.Empty; if (filter is ISpatialFilter && ((ISpatialFilter)filter).Geometry != null) { if (!(((ISpatialFilter)filter).Geometry is Envelope)) { _addShape = true; filter.AddField("#SHAPE#"); _spatialFilter = (ISpatialFilter)filter; } IEnvelope env = ((ISpatialFilter)filter).Geometry.Envelope; appendWhere = etconn.XFieldName + ">=" + env.minx.ToString(_nhi) + " AND " + etconn.XFieldName + "<=" + env.maxx.ToString(_nhi) + " AND " + etconn.YFieldName + ">=" + env.miny.ToString(_nhi) + " AND " + etconn.YFieldName + "<=" + env.maxy.ToString(_nhi); } if (filter is IRowIDFilter) { IRowIDFilter idFilter = (IRowIDFilter)filter; appendWhere = idFilter.RowIDWhereClause; } string where = (filter != null) ? filter.WhereClause : String.Empty; if (!String.IsNullOrEmpty(where)) { where += (String.IsNullOrEmpty(appendWhere) ? String.Empty : " AND (" + appendWhere + ")"); } else { where = appendWhere; } StringBuilder sb = new StringBuilder(); sb.Append(filter.SubFieldsAndAlias); foreach (string fieldname in filter.SubFields.Split(' ')) { if (fieldname == "#SHAPE#") { if (sb.Length > 0) { sb.Append(","); } sb.Append(_etcon.XFieldName + "," + _etcon.YFieldName); _addShape = true; } if (fieldname == "*") { _addShape = true; } } string fields = sb.ToString().Replace(",#SHAPE#", "").Replace("#SHAPE#,", "").Replace("#SHAPE#", ""); //_tab = conn.Select(sb.ToString(), etconn.TableName, where); //_addShape = _tab.Columns.Contains(_etcon.XFieldName) && // _tab.Columns.Contains(_etcon.YFieldName); _dbReader = conn.DataReader("select " + fields + " from " + etconn.TableName + (String.IsNullOrEmpty(where) ? String.Empty : " WHERE " + where), out _dbConnection); } }
private void btnOK_Click(object sender, EventArgs e) { ExportMethodItem filterItem = (ExportMethodItem)cmbFeatures.SelectedItem; IQueryFilter filter = filterItem.QueryFilter; filter.SubFields = String.Empty; DataTable tab = new DataTable(); IField dataField = ((FieldItem)cmbDataFields.SelectedItem).Field; filter.AddField(dataField.name); tab.Columns.Add(new DataFieldColumn(dataField.name)); Fields seriesFields = new Fields(); foreach (SymbolsListView.SymbolListViewItem item in seriesListView.Items) { seriesFields.Add(((ITableClass)_layer.Class).Fields.FindField(item.Text)); filter.AddField(item.Text); IBrushColor brushColor = item.Symbol as IBrushColor; Color col = brushColor != null ? brushColor.FillColor : Color.Red; tab.Columns.Add(new SeriesDataColumn(item.Text) { Color = col, SeriesName = item.SubItems[1].Text }); } using (ICursor cursor = ((ITableClass)_layer.Class).Search(filterItem.QueryFilter)) { IRow row = null; while ((row = NextRow(cursor)) != null) { object dataValue = row[dataField.name]; if (dataValue == System.DBNull.Value) { continue; } DataRow dataRow = GetDataRow(tab, dataValue); for (int i = 1, to = tab.Columns.Count; i < to; i++) { double val = Convert.ToDouble((row[tab.Columns[i].ColumnName] == System.DBNull.Value ? 0D : row[tab.Columns[i].ColumnName])); dataRow[tab.Columns[i].ColumnName] = Convert.ToDouble(dataRow[tab.Columns[i].ColumnName]) + val; } } } DataFieldColumn dataCol = this.DataFieldCol(tab); List <SeriesDataColumn> serCols = this.SeriesColumns(tab); if (tab != null && tab.Rows.Count > 0 && dataCol != null && serCols != null) { Series[] ser = new Series[serCols.Count]; for (int i = 0; i < ser.Length; i++) { ser[i] = new Series(serCols[i].SeriesName); ser[i].Color = serCols[i].Color; } foreach (DataRow row in tab.Rows) { for (int i = 0; i < ser.Length; i++) { ser[i].Points.AddXY(row[dataCol.ColumnName], row[serCols[i].ColumnName]); } } for (int i = 0; i < ser.Length; i++) { _series.Add(ser[i]); } } }
public static bool ModifyFilter(IServiceMap map, ITableClass tClass, IQueryFilter filter) { if (filter == null || tClass == null) { return(false); } string subFields = filter.SubFields; if (subFields != "*") { filter.SubFields = String.Empty; foreach (string subField in subFields.Split(' ')) { string fname = subField; if (subFields.StartsWith(filter.fieldPrefix) && subFields.EndsWith(filter.fieldPostfix)) { fname = fname.Substring(filter.fieldPrefix.Length, fname.Length - filter.fieldPrefix.Length - filter.fieldPostfix.Length); } if (tClass.Fields != null) { if (tClass.FindField(fname) != null || (tClass is IFeatureClass && ((IFeatureClass)tClass).ShapeFieldName == fname)) { filter.AddField(fname); } } } } try { XmlDocument xmlFilter = new XmlDocument(); string xml = Xml.ToXml(tClass, filter); xmlFilter.LoadXml(xml); XmlNodeList propertyNames = xmlFilter.SelectNodes("//PropertyName"); foreach (XmlNode propertyName in propertyNames) { if (propertyName.InnerText == MergedObjectIDName) { XmlNode literal = propertyName.ParentNode.SelectSingleNode("Literal"); if (literal == null) { return(false); } long mergedID; if (!long.TryParse(literal.InnerText, out mergedID)) { return(false); } int classID = GetClassID(map, tClass), propertyClassID = GetClassID(mergedID); if (classID != propertyClassID) { propertyName.ParentNode.ParentNode.RemoveChild(propertyName.ParentNode); continue; } propertyName.InnerText = tClass.IDFieldName; literal.InnerText = GetObjectID(mergedID).ToString(); } else if (tClass.Fields.FindField(propertyName.InnerText) == null) { propertyName.ParentNode.ParentNode.RemoveChild( propertyName.ParentNode); } } // keine Properties übgrig geblieben sind -> nicht abfraten... if (propertyNames.Count > 0 && xmlFilter.SelectNodes("//PropertyName").Count == 0) { return(false); } IQueryFilter f = Xml.FromXml(tClass, xmlFilter.SelectSingleNode("Filter")); // Prüfen, ob vom Filter noch was übrig bleibt... if (!String.IsNullOrEmpty(filter.WhereClause) && String.IsNullOrEmpty(f.WhereClause)) { return(false); } filter.WhereClause = f.WhereClause; } catch { return(false); } return(true); }