Exemple #1
0
        internal async void ApplyRulePackage()
        {
            await DownloadRulePackage(SelectedRulePackage);  //Download the rule package selected.

            await QueuedTask.Run(async() =>
            {
                //Get the build footprint layer's currect renderer.
                CIMSimpleRenderer renderer = (CIMSimpleRenderer)Module1.BuildingFootprintLayer.GetRenderer();

                //Get the rule package attributes and mapping to Feature layer from the dictionary
                var attributeExpressionMapping =
                    SelectedRulePackage.RpkAttributeExpressionMapping[SelectedRulePackage.Title];

                //Create the array of CIMPrimitiveOverrides. This is where the field\attribute mapping for the rulepackage is done.
                var primitiveOverrides = attributeExpressionMapping.Select(kvp => new CIMPrimitiveOverride
                {
                    PrimitiveName = SelectedRulePackage.Title,
                    PropertyName  = kvp.Key,
                    Expression    = kvp.Value
                }).ToArray();

                //Full path of the rule package path
                var rulePkgPath = Path.Combine(_rulePkgPath, SelectedRulePackage.Name);

                //Creating a procedural symbol using the rulepaackage
                var symbolReference = SymbolFactory.ConstructProceduralSymbol(rulePkgPath,
                                                                              Module1.BuildingFootprintLayer, primitiveOverrides);

                //CIMPolygonSymbol needed to create a style item.
                CIMPolygonSymbol polygonSymbol = symbolReference.Symbol as CIMPolygonSymbol;

                //Set symbol's real world setting to be the same as that of the feature layer
                polygonSymbol.SetRealWorldUnits(Module1.BuildingFootprintLayer.UsesRealWorldSymbolSizes);

                //Set the current renderer to the new procedural symbol's CIMSymbolReference
                renderer.Symbol = polygonSymbol.MakeSymbolReference();

                //Set the Building footprint layer's render.
                Module1.BuildingFootprintLayer.SetRenderer(renderer);

                //Create a style project item.
                await CreateStyleItem();
                if (BuildingStyleProjectItem != null && !BuildingStyleProjectItem.IsReadOnly())
                {
                    await AddStyleItemToStyle(BuildingStyleProjectItem, polygonSymbol); //Building footprint's procedural symbol is added to the BuildingStyle
                }
            });
        }