//apply filter

        private void applyFilter(Filter filter)
        {
            BitmapSource source = (BitmapSource)this.originalImage.Source;

            if (filter is ConvolutionFilter)
            {
                Bitmap            originalBitmap    = source.ConvertToBitmap();
                ConvolutionFilter convolutionFilter = (ConvolutionFilter)filter;

                bool parsed = false;
                if (this.offsetTextField.Text.Replace(" ", "").Length != 0)
                {
                    float offset = 0;
                    parsed = (float.TryParse(this.offsetTextField.Text.Replace(" ", ""), out offset));
                    if (parsed == false)
                    {
                        MessageBox.Show("Enter valid offset / offset value", "Invalid parameters", MessageBoxButton.OK, MessageBoxImage.Information);
                        return;
                    }
                    convolutionFilter.Offset = offset;
                }

                if (this.factorTextField.Text.Replace(" ", "").Length != 0)
                {
                    float factor = 0;
                    parsed = parsed && (float.TryParse(this.factorTextField.Text.Replace(" ", ""), out factor));
                    if (parsed == false)
                    {
                        MessageBox.Show("Enter valid offset / offset value", "Invalid parameters", MessageBoxButton.OK, MessageBoxImage.Information);
                        return;
                    }
                    convolutionFilter.Factor = factor;
                }

                Bitmap      filteredBitmap = originalBitmap.ConvolutionFilter(convolutionFilter);
                BitmapImage bitmapImage    = filteredBitmap.BitmapToImageSource();
                this.filteredImage.Source = bitmapImage;
            }
            else     //function filter
            {
                FunctionFilter functionFilter = (FunctionFilter)filter;
                if (functionFilter is IFunctionFilterOffset)
                {
                    IFunctionFilterOffset factorFunctionFilter = (IFunctionFilterOffset)functionFilter;
                    float coeff  = 0;
                    bool  parsed = (float.TryParse(this.coeffTextField.Text.Replace(" ", ""), out coeff));

                    if (parsed == false)
                    {
                        MessageBox.Show("Enter valid coefficient value", "Invalid parameters", MessageBoxButton.OK, MessageBoxImage.Information);
                        return;
                    }

                    factorFunctionFilter.Offset = coeff;
                }

                WriteableBitmap writeableBitmap = functionFilter.ApplyFunctionFilter((BitmapImage)this.originalImage.Source);
                this.filteredImage.Source = writeableBitmap;
            }
        }
Exemple #2
0
        private void PropertyForm_ChartLabelRenderer_MaxValues_Load(object sender, EventArgs e)
        {
            if (_fc != null && _fieldNames != null)
            {
                double sum = 0D;
                foreach (string fieldName in _fieldNames)
                {
                    if (_fc.FindField(fieldName) == null)
                    {
                        continue;
                    }

                    object minObj = FunctionFilter.QueryScalar(
                        _fc,
                        new FunctionFilter("MIN", fieldName, "fieldMin"),
                        "fieldMin");
                    object maxObj = FunctionFilter.QueryScalar(
                        _fc,
                        new FunctionFilter("MAX", fieldName, "fieldMax"),
                        "fieldMax");

                    double max;
                    if (minObj != null && maxObj != null)
                    {
                        max = Math.Max(Math.Abs(Convert.ToDouble(minObj)), Math.Abs(Convert.ToDouble(maxObj)));
                        lstMaxValues.Items.Add(
                            new ListViewItem(new string[] { fieldName, max.ToString() }));
                        sum += max;
                    }
                }
                lstMaxValues.Items.Add(
                    new ListViewItem(new string[] { "*Sum", sum.ToString() }));
            }
        }
Exemple #3
0
 public void Create_IfTheFunctionParameterIsNull_ShouldThrowAnArgumentNullException()
 {
     try
     {
         FunctionFilter.Create(null);
     }
     catch (ArgumentNullException argumentNullException)
     {
         if (argumentNullException.ParamName.Equals("filterFunction", StringComparison.Ordinal))
         {
             throw;
         }
     }
 }
Exemple #4
0
        public void ShouldFilter_ShouldInvokeThePassedFunction()
        {
            var invoked = false;

            var functionFilter = new FunctionFilter(content =>
            {
                invoked = true;
                return(false);
            });

            Assert.IsFalse(invoked);

            functionFilter.ShouldFilter(Mock.Of <IContent>());

            Assert.IsTrue(invoked);
        }
Exemple #5
0
        public IFeatureCursor GetFeatures(IQueryFilter filter)
        {
            if (filter == null)
            {
                return(null);
            }

            if (filter is IBufferQueryFilter)
            {
                ISpatialFilter sFilter = BufferQueryFilter.ConvertToSpatialFilter(filter as IBufferQueryFilter);
                if (sFilter == null)
                {
                    return(null);
                }
                return(GetFeatures(sFilter));
            }

            #region IDistrictFilter ?
            if (filter is IDistinctFilter)
            {
                if (filter.SubFields.Contains(":"))
                {
                    string[] fn = filter.SubFields.Split(':');

                    IFeatureLayerJoin join = _joins[fn[0]];
                    if (join != null)
                    {
                        using (join = (IFeatureLayerJoin)join.Clone())
                        {
                            join.Init(String.Empty);
                            filter         = new DistinctFilter(fn[1]);
                            filter.OrderBy = fn[1];
                            return(new FeatureCursorWrapper(join.PerformQuery(filter)));
                        }
                    }
                    return(null);
                }
                else
                {
                    return(_fc.GetFeatures(filter));
                }
            }
            #endregion

            #region IFunctionFilter ?
            if (filter is IFunctionFilter)
            {
                if (filter.SubFields.Contains(":"))
                {
                    string[] fn = filter.SubFields.Split(':');

                    IFeatureLayerJoin join = _joins[fn[0]];
                    if (join != null)
                    {
                        using (join = (IFeatureLayerJoin)join.Clone())
                        {
                            join.Init(String.Empty);
                            filter = new FunctionFilter(((IFunctionFilter)filter).Function, fn[1], ((IFunctionFilter)filter).Alias);
                            return(new FeatureCursorWrapper(join.PerformQuery(filter)));
                        }
                    }
                    return(null);
                }
                else
                {
                    return(_fc.GetFeatures(filter));
                }
            }
            #endregion

            bool hasInnerJoin = false;
            if (_joins != null)
            {
                foreach (IFeatureLayerJoin join in _joins)
                {
                    if (join.JoinType == joinType.LeftInnerJoin)
                    {
                        hasInnerJoin = true;
                        break;
                    }
                }
            }
            if ((!filter.SubFields.Contains(":") && !filter.SubFields.Contains("*") && hasInnerJoin == false && !filter.WhereClause.Contains(":")) || _joins == null || _joins.Count == 0)
            {
                return(_fc.GetFeatures(filter));
            }

            Dictionary <string, UniqueList <string> > fieldNames = new Dictionary <string, UniqueList <string> >();
            fieldNames.Add(String.Empty, new UniqueList <string>());
            fieldNames[String.Empty].Add(this.IDFieldName);

            string[] names = filter.SubFields.Replace(" ", ",").Split(',');

            foreach (string fieldname in filter.SubFields.Replace(" ", ",").Split(','))
            {
                if (fieldname == "*")
                {
                    fieldNames[String.Empty] = new UniqueList <string>();
                    fieldNames[String.Empty].Add("*");
                    foreach (IFeatureLayerJoin join in _joins)
                    {
                        fieldNames[join.JoinName] = new UniqueList <string>();
                        fieldNames[join.JoinName].Add("*");
                    }
                    break;
                }
                if (fieldname.Contains(":"))
                {
                    string[] fn = fieldname.Split(':');

                    IFeatureLayerJoin join = _joins[fn[0]];
                    if (join != null)
                    {
                        fieldNames[String.Empty].Add(join.Field);

                        if (!fieldNames.ContainsKey(fn[0]))
                        {
                            fieldNames.Add(fn[0], new UniqueList <string>());
                        }
                        fieldNames[fn[0]].Add(fn[1].Trim());
                    }
                }
                else
                {
                    fieldNames[String.Empty].Add(fieldname.Trim());
                }
            }

            foreach (IFeatureLayerJoin join in _joins)
            {
                if (join.JoinType == joinType.LeftInnerJoin)
                {
                    if (!fieldNames.Keys.Contains(join.JoinName))
                    {
                        fieldNames.Add(join.JoinName, new UniqueList <string>()
                        {
                            join.JoinFields[0].name
                        });
                        fieldNames[String.Empty].Add(join.Field);
                    }
                }
            }

            filter           = (IQueryFilter)filter.Clone();
            filter.SubFields = fieldNames[String.Empty].ToString(',');

            #region CrossTable Where Clause ?
            if (!String.IsNullOrEmpty(filter.WhereClause) && filter.WhereClause.Contains(":"))
            {
                string where = filter.WhereClause.ToLower();
                bool isCrossTableQuery = false;
                foreach (IField field in this.Fields.ToEnumerable())
                {
                    if (field.name.Contains(":") && where.Contains("[" + field.name.ToLower() + "]"))
                    {
                        IFeatureLayerJoin join = _joins[field.name.Split(':')[0]];
                        if (join != null)
                        {
                            isCrossTableQuery = true;
                            if (!fieldNames.ContainsKey(join.JoinName))
                            {
                                fieldNames.Add(join.JoinName, new UniqueList <string>());
                            }
                            fieldNames[join.JoinName].Add(field.name.Split(':')[1].Trim());
                            filter.AddField(join.Field);
                            //filter.AddField(field.name);
                        }
                    }
                    else if (!field.name.Contains(":") && where.Contains(field.name.ToLower()))  // select all fields in the where clause (because you need them in table.Select(...)
                    {
                        filter.AddField(field.name);
                    }
                }
                if (isCrossTableQuery)
                {
                    where = filter.WhereClause;
                    filter.WhereClause = String.Empty;
                    IFeatureCursor cursor = new FeatureCursor(_fc.GetFeatures(filter), (FeatureLayerJoins)_joins.Clone(), fieldNames);

                    DataTable tab  = gView.Framework.Data.FeatureCursor.ToDataTable(cursor);
                    DataRow[] rows = null;
                    try
                    {
                        rows = tab.Select(where, filter.OrderBy);
                    }
                    catch
                    {
                    }
                    return(new gView.Framework.Data.FeatureCursor.DataRowCursor(rows));
                }
            }
            #endregion

            if (fieldNames.Keys.Count <= 1)
            {
                fieldNames = null;
            }

            try
            {
                return(new FeatureCursor(_fc.GetFeatures(filter), (FeatureLayerJoins)_joins.Clone(), fieldNames));
            }
            catch
            {
                return(null);
            }
        }
        private void PropertyForm_QuantityRenderer_Wizard_Load(object sender, EventArgs e)
        {
            if (_fc == null || _renderer == null ||
                String.IsNullOrEmpty(_renderer.ValueField))
            {
                return;
            }

            _minSymbol = RendererFunctions.CreateStandardSymbol(_fc.GeometryType);
            //_midSymbol = RendererFunctions.CreateStandardSymbol(_fc.GeometryType);
            _maxSymbol = RendererFunctions.CreateStandardSymbol(_fc.GeometryType);

            IField field = _fc.FindField(_renderer.ValueField);

            if (field == null)
            {
                return;
            }
            switch (field.type)
            {
            case FieldType.ID:
            case FieldType.integer:
                numMin.DataType           = numMax.DataType =
                    numStepWidth.DataType = NumericTextBox.NumericDataType.intType;
                break;

            case FieldType.smallinteger:
                numMin.DataType           = numMax.DataType =
                    numStepWidth.DataType = NumericTextBox.NumericDataType.shortType;
                break;

            case FieldType.biginteger:
                numMin.DataType           = numMax.DataType =
                    numStepWidth.DataType = NumericTextBox.NumericDataType.longType;
                break;

            case FieldType.Float:
                numMin.DataType           = numMax.DataType =
                    numStepWidth.DataType = NumericTextBox.NumericDataType.floatType;
                break;

            case FieldType.Double:
                numMin.DataType           = numMax.DataType =
                    numStepWidth.DataType = NumericTextBox.NumericDataType.doubleType;
                break;
            }

            object minObj = FunctionFilter.QueryScalar(
                _fc,
                new FunctionFilter("MIN", _renderer.ValueField, "fieldMin"),
                "fieldMin");
            object maxObj = FunctionFilter.QueryScalar(
                _fc,
                new FunctionFilter("MAX", _renderer.ValueField, "fieldMax"),
                "fieldMax");

            if (minObj != null)
            {
                numMin.Double = Convert.ToDouble(minObj);
            }
            if (maxObj != null)
            {
                numMax.Double = Convert.ToDouble(maxObj);
            }

            btnFixStepCount.Checked = true;
            numStepCount.Double     = 10;
            numStepWidth.Double     = (double)((int)((numMax.Double - numMin.Double) / 10));
        }
Exemple #7
0
 public void Create_ShouldReturnAFunctionFilter()
 {
     Assert.IsTrue(FunctionFilter.Create(content => false) is FunctionFilter);
 }