Exemplo n.º 1
0
        public ArithmeticPostAggregator(string name, ArithmeticFunction fn, IEnumerable <IPostAggregationSpec> fields, string ordering = null)
        {
            Name     = name;
            Fields   = fields;
            Ordering = ordering;

            switch (fn)
            {
            case ArithmeticFunction.Plus:
                Fn = "+";
                break;

            case ArithmeticFunction.Minus:
                Fn = "-";
                break;

            case ArithmeticFunction.Multiply:
                Fn = "*";
                break;

            case ArithmeticFunction.Divide:
                Fn = "/";
                break;

            case ArithmeticFunction.Quotient:
                Fn = "quotient";
                break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parse binary expression.
        /// </summary>
        private IExpression GetBinaryExpression(ArithmeticFunction func, params TokenType[] tokenTypes)
        {
            IExpression expr = func();

            while (Match(tokenTypes))
            {
                Token       op    = Previous();
                IExpression right = func();

                return(new BinaryExpr(expr, op, right));
            }

            return(expr);
        }
Exemplo n.º 3
0
        private string WriteTerm(Term term)
        {
            string             displayString = "";
            ArgumentCollection args          = null;

            if (term is Constant)
            {
                if (((Constant)term).Value != null)
                {
                    if (((Constant)term).Value.ToString() == string.Empty)
                    {
                        displayString = "&lt;empty string&gt;";
                    }
                    else
                    {
                        displayString = ((Constant)term).Value.ToString();
                    }
                }
                else
                {
                    displayString = "&lt;null&gt;";
                }
            }

            else if (term is UserFunction || term is ObjectReference)
            {
                Binding termBinding = null;

                if (term is UserFunction)
                {
                    termBinding = ((UserFunction)term).Binding;
                }
                else
                {
                    termBinding = ((ObjectReference)term).Binding;
                }

                if (termBinding is XMLDocumentBinding)
                {
                    XMLDocumentBinding binding = termBinding as XMLDocumentBinding;
                    displayString = binding.DocumentType;
                }
                else if (termBinding is DatabaseBinding)
                {
                    DatabaseBinding binding = termBinding as DatabaseBinding;
                    displayString = binding.DatasetName;
                }
                else if (termBinding is ClassBinding)
                {
                    ClassBinding binding = termBinding as ClassBinding;
                    displayString = binding.TypeName;
                }
                else if (termBinding is XMLDocumentFieldBinding)
                {
                    XMLDocumentFieldBinding binding = termBinding as XMLDocumentFieldBinding;
                    displayString = binding.DocumentBinding.DocumentType + ":" + binding.DocumentBinding.Selector.Alias + "/" + binding.Field.Alias;

                    if (binding.Argument != null)
                    {
                        if (binding.MemberName.ToLower() == "setstring")
                        {
                            displayString += " = {0}";
                        }

                        args = new ArgumentCollection();
                        args.Add(binding.Argument);
                    }
                }
                else if (termBinding is DatabaseColumnBinding)
                {
                    DatabaseColumnBinding binding = termBinding as DatabaseColumnBinding;
                    displayString = binding.DatabaseBinding.DatasetName + "." + binding.DatabaseBinding.TableName + "." + binding.ColumnName;

                    if (binding.Argument != null)
                    {
                        args = new ArgumentCollection();
                        args.Add(binding.Argument);
                    }
                }
                else if (termBinding is DataRowBinding)
                {
                    DataRowBinding binding = termBinding as DataRowBinding;
                    displayString = binding.DisplayName;
                }
                else if (termBinding is ClassMemberBinding)
                {
                    ClassMemberBinding binding = termBinding as ClassMemberBinding;
                    displayString = binding.ClassBinding.ImplementingType.FullName + "." + binding.MemberName;
                    args          = binding.Arguments;
                }
            }
            else if (term is ArithmeticFunction)
            {
                ArithmeticFunction f = term as ArithmeticFunction;
                args = new ArgumentCollection();
                args.Add(f.LeftArgument);
                args.Add(f.RightArgument);
            }
            else if (term is Assert)
            {
                args = new ArgumentCollection();
                args.Add(((Assert)term).Facts);
            }
            else if (term is Retract)
            {
                args = new ArgumentCollection();
                args.Add(((Retract)term).Facts);
            }
            else if (term is Update)
            {
                args = new ArgumentCollection();
                args.Add(((Update)term).Facts);
            }
            else if (term is Halt)
            {
                args = new ArgumentCollection();
                args.Add(((Halt)term).ClearAgenda);
            }

            ArrayList argsToDisplay = new ArrayList();

            if (args != null)
            {
                foreach (Term t in args)
                {
                    argsToDisplay.Add(WriteTerm(t));
                }
            }

            string format = "";

            if (term.VocabularyLink != null)
            {
                VocabularyDefinition vd = vdefs[term.VocabularyLink.DefinitionId] as VocabularyDefinition;
                format = vd.GetFormatString().Format;

                // Added to fix halt documentation CD 20140328
                if (format == "halt choices")
                {
                    format = "{0}";
                    if (displayString == "True")
                    {
                        argsToDisplay.Add("clear all rules firings");
                    }
                    else
                    {
                        argsToDisplay.Add("do not clear");
                    }
                }
            }
            else
            {
                format = displayString;
            }

            displayString = TryStringFormat(format, argsToDisplay.ToArray());

            return("<span class='TableData'>" + displayString + "</span>");
        }
        static void Main(string[] args)
        {
            ESRI.ArcGIS.esriSystem.AoInitialize aoInit;

            #region Initialize License
            try
            {
                Console.WriteLine("Obtaining license");
                ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
                aoInit = new AoInitializeClass();
                esriLicenseStatus licStatus = aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeBasic);
                Console.WriteLine("Ready with license.");
            }
            catch (Exception exc)
            {
                // If it fails at this point, shutdown the test and ignore any subsequent errors.
                Console.WriteLine(exc.Message);
                return;
            }
            #endregion

            try
            {
                // Specify input directory and dataset name.
                string inputWorkspace = @"C:\Data";
                string inputDatasetName = "8bitSampleImage.tif";
                // Specify output filename.
                string outputDataset = @"c:\Temp\testArithmaticCS.afr";

                // Open the Raster Dataset
                Type factoryType = Type.GetTypeFromProgID("esriDataSourcesRaster.RasterWorkspaceFactory");
                IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                IWorkspace workspace = workspaceFactory.OpenFromFile(inputWorkspace, 0);
                IRasterWorkspace rasterWorkspace = (IRasterWorkspace)workspace;
                IRasterDataset myRasterDataset = rasterWorkspace.OpenRasterDataset(inputDatasetName);

                // Create the Function Arguments object
                IArithmeticFunctionArguments rasterFunctionArguments =
                    (IArithmeticFunctionArguments)new ArithmeticFunctionArguments();                
                // Set the parameters for the function:
                // Specify the operation as addition (esriRasterPlus)
                rasterFunctionArguments.Operation = esriRasterArithmeticOperation.esriRasterPlus;
                // Specify the first operand, i.e. the Raster Dataset opened above.
                rasterFunctionArguments.Raster = myRasterDataset;
                // For the second operand, create an array of double values
                // containing the scalar value to be used as the second operand 
                // to each band of the input dataset.
                // The number of values in the array should equal the number 
                // of bands of the input dataset.
                double[] scalars = { 128.0, 128.0, 128.0 };
                // Create a new Scalar object and specify
                // the array as its value.
                IScalar scalarVals = new ScalarClass();
                scalarVals.Value = scalars;
                // Specify the scalar object as the second operand.
                rasterFunctionArguments.Raster2 = scalarVals;

                // Create the Raster Function object.
                IRasterFunction rasterFunction = new ArithmeticFunction();
                rasterFunction.PixelType = rstPixelType.PT_USHORT;

                // Create the Function Raster Dataset Object.
                IFunctionRasterDataset functionRasterDataset = new FunctionRasterDataset();

                // Create a name object for the Function Raster Dataset.
                IFunctionRasterDatasetName functionRasterDatasetName =
                    (IFunctionRasterDatasetName)new FunctionRasterDatasetName();

                // Specify the output filename for the new dataset (including 
                // the .afr extension at the end).
                functionRasterDatasetName.FullName = outputDataset;
                functionRasterDataset.FullName = (IName)functionRasterDatasetName;
                // Initialize the new Function Raster Dataset with the Raster Function 
                // and its arguments.
                functionRasterDataset.Init(rasterFunction, rasterFunctionArguments);

                // QI for the Temporary Dataset interface
                ITemporaryDataset myTempDset = (ITemporaryDataset)functionRasterDataset;
                // and make it a permanent dataset. This creates the afr file.
                myTempDset.MakePermanent();

                // Report
                Console.WriteLine("Success.");
                Console.WriteLine("Press any key...");
                Console.ReadKey();

                // Shutdown License
                aoInit.Shutdown();
            }
            catch (Exception exc)
            {
                // Report
                Console.WriteLine("Exception Caught while creating Function Raster Dataset. " + exc.Message);
                Console.WriteLine("Failed.");
                Console.WriteLine("Press any key...");
                Console.ReadKey();

                // Shutdown License
                aoInit.Shutdown();
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            ESRI.ArcGIS.esriSystem.AoInitialize aoInit;

            #region Initialize License
            try
            {
                Console.WriteLine("Obtaining license");
                ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
                aoInit = new AoInitializeClass();
                esriLicenseStatus licStatus = aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeBasic);
                Console.WriteLine("Ready with license.");
            }
            catch (Exception exc)
            {
                // If it fails at this point, shutdown the test and ignore any subsequent errors.
                Console.WriteLine(exc.Message);
                return;
            }
            #endregion

            try
            {
                // Specify input directory and dataset name.
                string inputWorkspace   = @"C:\Data";
                string inputDatasetName = "8bitSampleImage.tif";
                // Specify output filename.
                string outputDataset = @"c:\Temp\testArithmaticCS.afr";

                // Open the Raster Dataset
                Type factoryType = Type.GetTypeFromProgID("esriDataSourcesRaster.RasterWorkspaceFactory");
                IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                IWorkspace        workspace        = workspaceFactory.OpenFromFile(inputWorkspace, 0);
                IRasterWorkspace  rasterWorkspace  = (IRasterWorkspace)workspace;
                IRasterDataset    myRasterDataset  = rasterWorkspace.OpenRasterDataset(inputDatasetName);

                // Create the Function Arguments object
                IArithmeticFunctionArguments rasterFunctionArguments =
                    (IArithmeticFunctionArguments) new ArithmeticFunctionArguments();
                // Set the parameters for the function:
                // Specify the operation as addition (esriRasterPlus)
                rasterFunctionArguments.Operation = esriRasterArithmeticOperation.esriRasterPlus;
                // Specify the first operand, i.e. the Raster Dataset opened above.
                rasterFunctionArguments.Raster = myRasterDataset;
                // For the second operand, create an array of double values
                // containing the scalar value to be used as the second operand
                // to each band of the input dataset.
                // The number of values in the array should equal the number
                // of bands of the input dataset.
                double[] scalars = { 128.0, 128.0, 128.0 };
                // Create a new Scalar object and specify
                // the array as its value.
                IScalar scalarVals = new ScalarClass();
                scalarVals.Value = scalars;
                // Specify the scalar object as the second operand.
                rasterFunctionArguments.Raster2 = scalarVals;

                // Create the Raster Function object.
                IRasterFunction rasterFunction = new ArithmeticFunction();
                rasterFunction.PixelType = rstPixelType.PT_USHORT;

                // Create the Function Raster Dataset Object.
                IFunctionRasterDataset functionRasterDataset = new FunctionRasterDataset();

                // Create a name object for the Function Raster Dataset.
                IFunctionRasterDatasetName functionRasterDatasetName =
                    (IFunctionRasterDatasetName) new FunctionRasterDatasetName();

                // Specify the output filename for the new dataset (including
                // the .afr extension at the end).
                functionRasterDatasetName.FullName = outputDataset;
                functionRasterDataset.FullName     = (IName)functionRasterDatasetName;
                // Initialize the new Function Raster Dataset with the Raster Function
                // and its arguments.
                functionRasterDataset.Init(rasterFunction, rasterFunctionArguments);

                // QI for the Temporary Dataset interface
                ITemporaryDataset myTempDset = (ITemporaryDataset)functionRasterDataset;
                // and make it a permanent dataset. This creates the afr file.
                myTempDset.MakePermanent();

                // Report
                Console.WriteLine("Success.");
                Console.WriteLine("Press any key...");
                Console.ReadKey();

                // Shutdown License
                aoInit.Shutdown();
            }
            catch (Exception exc)
            {
                // Report
                Console.WriteLine("Exception Caught while creating Function Raster Dataset. " + exc.Message);
                Console.WriteLine("Failed.");
                Console.WriteLine("Press any key...");
                Console.ReadKey();

                // Shutdown License
                aoInit.Shutdown();
            }
        }
 internal static int Compute(ArithmeticFunction op, int x, int y)
 {
    return s_map[op](x, y);
 }
Exemplo n.º 7
0
 public ArithmeticPostAggregator(string name, ArithmeticFunction fn, string ordering = null, params IPostAggregationSpec[] fields)
     : this(name, fn, fields, ordering)
 {
 }