コード例 #1
0
        Filter evaluate(string input)
        {
            Dictionary <string, int> priority = new Dictionary <string, int>();

            priority["and"] = 2;
            priority["or"]  = 2;
            priority["not"] = 2;
            priority[">"]   = 1;
            priority["<"]   = 1;
            priority["="]   = 1;
            priority["<>"]  = 1;
            var            list    = input.Split(' ');
            Stack <string> stack   = new Stack <string>();
            List <string>  postfix = new List <string>();

            foreach (var item in list)
            {
                if (item != "" && item != "<>" && item != "not" && item != "(" && item != ")" && item != ">" && item != "<" && item != "=" && item != "and" && item != "or")
                {
                    postfix.Add(item);
                }
                else if (item == "(")
                {
                    stack.Push(item);
                }
                else if (item == ")")
                {
                    string op = stack.Pop();
                    while (op != "(")
                    {
                        postfix.Add(op);
                        op = stack.Pop();
                    }
                }
                else
                {
                    while (true)
                    {
                        if (stack.Count == 0 || stack.Peek() == "(" || priority[item] < priority[stack.Peek()])
                        {
                            stack.Push(item);
                            break;
                        }
                        else
                        {
                            postfix.Add(stack.Pop());
                        }
                    }
                }
            }
            while (stack.Count != 0)
            {
                postfix.Add(stack.Pop());
            }
            var s = new System.Collections.Stack();

            for (int i = 0; i < postfix.Count; i++)
            {
                if (postfix[i] == ">")
                {
                    double value  = double.Parse(s.Pop() as string);
                    string name   = s.Pop() as string;
                    Filter filter = new Filter_Larger(name, value);
                    s.Push(filter);
                }
                else if (postfix[i] == "<")
                {
                    double value  = double.Parse(s.Pop() as string);
                    string name   = s.Pop() as string;
                    Filter filter = new Filter_Less(name, value);
                    s.Push(filter);
                }
                else if (postfix[i] == "=")
                {
                    string str = s.Pop() as string;
                    double temp;
                    bool   isNum = Double.TryParse(str, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out temp);
                    object value = str;
                    if (isNum)
                    {
                        value = temp;
                    }
                    string name   = s.Pop() as string;
                    Filter filter = new Filter_Equals(name, value);
                    s.Push(filter);
                }
                else if (postfix[i] == "<>")
                {
                    string str = s.Pop() as string;
                    double temp;
                    bool   isNum = Double.TryParse(str, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out temp);
                    object value = str;
                    if (isNum)
                    {
                        value = temp;
                    }
                    string name   = s.Pop() as string;
                    Filter filter = new Filter_Not(new Filter_Equals(name, value));
                    s.Push(filter);
                }
                else if (postfix[i] == "and")
                {
                    Filter filter1 = s.Pop() as Filter;
                    Filter filter2 = s.Pop() as Filter;
                    Filter filter  = new Filter_And(new List <Filter> {
                        filter1, filter2
                    });
                    s.Push(filter);
                }
                else if (postfix[i] == "or")
                {
                    Filter filter1 = s.Pop() as Filter;
                    Filter filter2 = s.Pop() as Filter;
                    Filter filter  = new Filter_Or(new List <Filter> {
                        filter1, filter2
                    });
                    s.Push(filter);
                }
                else if (postfix[i] == "not")
                {
                    Filter filter = s.Pop() as Filter;
                    s.Push(new Filter_Not(filter));
                }
                else
                {
                    s.Push(postfix[i]);
                }
            }
            Filter result = s.Pop() as Filter;

            return(result);
        }
コード例 #2
0
ファイル: support.cs プロジェクト: gisdevelope/MercuryGIS
        public static Style createRankStyle(FeatureSource featuresource, string attributename, int num, Color startcolor, Color endcolor)
        {
            Schema         schema = featuresource.schema;
            SymbolizerType sign   = SymbolizerType.POINT;

            switch (schema.geometryType)
            {
            case OSGeo.OGR.wkbGeometryType.wkbPoint:
                sign = SymbolizerType.POINT;
                break;

            case OSGeo.OGR.wkbGeometryType.wkbLineString:
                sign = SymbolizerType.LINE;
                break;

            case OSGeo.OGR.wkbGeometryType.wkbPolygon:
                sign = SymbolizerType.POLYGON;
                break;
            }
            FieldDefn fielddefn = null;

            if (schema.fields.TryGetValue(attributename, out fielddefn) || attributename.Equals("FeatureID"))
            {
                FieldType type = FieldType.OFTString;
                if (!attributename.Equals("FeatureID"))
                {
                    type = fielddefn.GetFieldType();
                }
                if (type == FieldType.OFTInteger || type == FieldType.OFTReal || attributename.Equals("FeatureID"))
                {
                    double maxvalue = double.MinValue;
                    double minvalue = double.MaxValue;
                    foreach (GisSmartTools.Data.Feature feature in featuresource.features.featureList)
                    {
                        double value = 0;
                        if (type == FieldType.OFTInteger || attributename.Equals("FeatureID"))
                        {
                            value = (int)feature.GetArrtributeByName(attributename);
                        }
                        if (type == FieldType.OFTReal)
                        {
                            value = (double)feature.GetArrtributeByName(attributename);
                        }
                        if (value > maxvalue)
                        {
                            maxvalue = value;
                        }
                        if (value < minvalue)
                        {
                            minvalue = value;
                        }
                    }
                    if (num == 0)
                    {
                        return(null);
                    }
                    double x = (maxvalue - minvalue) / num;
                    //逐个创建对应的rule
                    Color[]           colorarray    = Utils.GetLinearColorList(startcolor, endcolor, num);
                    double            temp_minvalue = minvalue;
                    double            temp_maxvalue = minvalue + x;
                    List <RenderRule> rulelist      = new List <RenderRule>();
                    // Printer.printnode("min=" + minvalue + " max=" + maxvalue, "");

                    for (int i = 0; i < num; i++)
                    {
                        RenderRule           rule       = RenderRule.createDefaultRule(sign, colorarray[i]);
                        Filter_Larger        larger     = new Filter_Larger(attributename, temp_minvalue);
                        Filter_Less          less       = new Filter_Less(attributename, temp_maxvalue);
                        List <Filter.Filter> filterlist = new List <Filter.Filter>();
                        filterlist.Add(larger); filterlist.Add(less);
                        Filter_And andfilter = new Filter_And(filterlist);
                        rule.filter = andfilter;
                        rulelist.Add(rule);
                        // Printer.printnode("temp_" + i, "min=" + temp_minvalue + " max=" + temp_maxvalue);
                        temp_minvalue += x; temp_maxvalue += x;
                    }
                    Style rankstyle = new Style("RankStyle", StyleType.RANKSTYLE, RenderRule.createDefaultRule(sign, startcolor));
                    rankstyle.rulelist = rulelist;
                    Printer.printnode("rulist,count=", "" + rulelist.Count);
                    return(rankstyle);
                }
            }
            return(null);
        }