Ejemplo n.º 1
0
        public void EditOperation(UtilityNetwork utilityNetwork, AssetType poleAssetType, Guid poleGlobalID, AssetType transformerBankAssetType, Guid transformerBankGlobalID)
        {
            #region Create a utility network association

            // Create edit operation

            EditOperation editOperation = new EditOperation();
            editOperation.Name = "Create structural attachment association";

            // Create a RowHandle for the pole

            Element   poleElement   = utilityNetwork.CreateElement(poleAssetType, poleGlobalID);
            RowHandle poleRowHandle = new RowHandle(poleElement, utilityNetwork);

            // Create a RowHandle for the transformer bank

            Element   transformerBankElement   = utilityNetwork.CreateElement(transformerBankAssetType, transformerBankGlobalID);
            RowHandle transformerBankRowHandle = new RowHandle(transformerBankElement, utilityNetwork);

            // Attach the transformer bank to the pole

            StructuralAttachmentAssociationDescription structuralAttachmentAssociationDescription = new StructuralAttachmentAssociationDescription(poleRowHandle, transformerBankRowHandle);
            editOperation.Create(structuralAttachmentAssociationDescription);
            editOperation.Execute();

            #endregion
        }
        private async void Initialize()
        {
            try
            {
                Configuration.IsEnabled = false;

                // Create and load the utility network.
                _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServiceUrl));

                // Build the choice lists for network attribute comparison.
                Attributes.ItemsSource = _utilityNetwork.Definition.NetworkAttributes.Where(netattr => !netattr.IsSystemDefined);
                Operators.ItemsSource  = Enum.GetValues(typeof(UtilityAttributeComparisonOperator));

                // Create a default starting location.
                UtilityNetworkSource networkSource = _utilityNetwork.Definition.GetNetworkSource(DeviceTableName);
                UtilityAssetGroup    assetGroup    = networkSource.GetAssetGroup(AssetGroupName);
                UtilityAssetType     assetType     = assetGroup.GetAssetType(AssetTypeName);
                Guid globalId = Guid.Parse(GlobalId);
                _startingLocation = _utilityNetwork.CreateElement(assetType, globalId);

                // Set the terminal for this location. (For our case, we use the 'Load' terminal.)
                _startingLocation.Terminal = _startingLocation.AssetType.TerminalConfiguration?.Terminals.FirstOrDefault(term => term.Name == "Load");

                // Get a default trace configuration from a tier to update the UI.
                UtilityDomainNetwork domainNetwork = _utilityNetwork.Definition.GetDomainNetwork(DomainNetworkName);
                UtilityTier          sourceTier    = domainNetwork.GetTier(TierName);

                // Set the trace configuration.
                _configuration = sourceTier.TraceConfiguration;

                // Set the default expression (if provided).
                if (sourceTier.TraceConfiguration.Traversability.Barriers is UtilityTraceConditionalExpression expression)
                {
                    ConditionBarrierExpression.Text = ExpressionToString(expression);
                    _initialExpression = expression;
                }

                // Setting DataContext will resolve the data-binding in XAML.
                Configuration.DataContext = _configuration;

                // Set the traversability scope.
                sourceTier.TraceConfiguration.Traversability.Scope = UtilityTraversabilityScope.Junctions;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.Message.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Configuration.IsEnabled = true;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This routine takes a row from the starting (or barrier) point table and converts it to a [Network] Element that we can use for tracing
        /// </summary>
        /// <param name="pointRow">The Row (either starting point or barrier point)</param>
        /// <param name="utilityNetwork">Utility Network to be used</param>
        /// <param name="definition">Utility Network definition to be used</param>
        /// <returns>newly created element</returns>
        private static Element GetElementFromPointRow(Row pointRow,
                                                      UtilityNetwork utilityNetwork, UtilityNetworkDefinition definition)
        {
            // Fetch the SourceID, AssetGroupCode, AssetType, GlobalID, and TerminalID values from the starting point row
            int    sourceID     = (int)pointRow[PointsSourceIDFieldName];
            int    assetGroupID = (int)pointRow[PointsAssetGroupFieldName];
            int    assetTypeID  = (int)pointRow[PointsAssetTypeFieldName];
            Guid   globalID     = new Guid(pointRow[PointsGlobalIDFieldName].ToString());
            int    terminalID   = (int)pointRow[PointsTerminalFieldName];
            double percentAlong = (double)pointRow[PointsPercentAlong];

            // Fetch the NetworkSource, AssetGroup, and AssetType objects
            NetworkSource networkSource = definition.GetNetworkSources().First(x => x.ID == sourceID);
            AssetGroup    assetGroup    = networkSource.GetAssetGroups().First(x => x.Code == assetGroupID);
            AssetType     assetType     = assetGroup.GetAssetTypes().First(x => x.Code == assetTypeID);

            // Fetch the Terminal object from the ID
            Terminal terminal = null;

            if (assetType.IsTerminalConfigurationSupported())
            {
                TerminalConfiguration terminalConfiguration = assetType.GetTerminalConfiguration();
                terminal = terminalConfiguration.Terminals.First(x => x.ID == terminalID);
            }

            // Create and return a FeatureElement object
            // If we have an edge, set the PercentAlongEdge property; otherwise set the Terminal property
            if (networkSource.Type == SourceType.Edge)
            {
                Element element = utilityNetwork.CreateElement(assetType, globalID);
                element.PercentAlongEdge = percentAlong;
                return(element);
            }
            else
            {
                Element element = utilityNetwork.CreateElement(assetType, globalID, terminal);
                return(element);
            }
        }
Ejemplo n.º 4
0
        private async void Initialize()
        {
            try
            {
                // Disable interaction until the data is loaded.
                _mainView.Visibility = ViewStates.Gone;

                // Create and load the utility network.
                _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServiceUrl));

                // Getthe attributes in the utility network.
                _attributes = _utilityNetwork.Definition.NetworkAttributes.Where(netattr => !netattr.IsSystemDefined);

                // Create a default starting location.
                UtilityNetworkSource networkSource = _utilityNetwork.Definition.GetNetworkSource(DeviceTableName);
                UtilityAssetGroup    assetGroup    = networkSource.GetAssetGroup(AssetGroupName);
                UtilityAssetType     assetType     = assetGroup.GetAssetType(AssetTypeName);
                Guid globalId = Guid.Parse(GlobalId);
                _startingLocation = _utilityNetwork.CreateElement(assetType, globalId);

                // Set the terminal for this location. (For our case, we use the 'Load' terminal.)
                _startingLocation.Terminal = _startingLocation.AssetType.TerminalConfiguration?.Terminals.FirstOrDefault(term => term.Name == "Load");

                // Get a default trace configuration from a tier to update the UI.
                UtilityDomainNetwork domainNetwork = _utilityNetwork.Definition.GetDomainNetwork(DomainNetworkName);
                _sourceTier = domainNetwork.GetTier(TierName);

                // Set the trace configuration.
                _configuration = _sourceTier.TraceConfiguration;

                // Set the default expression (if provided).
                if (_sourceTier.TraceConfiguration.Traversability.Barriers is UtilityTraceConditionalExpression expression)
                {
                    _initialExpression    = expression;
                    _expressionLabel.Text = ExpressionToString(_initialExpression);
                }

                // Set the traversability scope.
                _sourceTier.TraceConfiguration.Traversability.Scope = UtilityTraversabilityScope.Junctions;
            }
            catch (Exception ex)
            {
                new AlertDialog.Builder(this).SetMessage(ex.Message).SetTitle(ex.GetType().Name).Show();
            }
            finally
            {
                _mainView.Visibility = ViewStates.Visible;
            }
        }
        private async void Initialize()
        {
            try
            {
                // Disable interaction until the data is loaded.
                View.UserInteractionEnabled = false;

                // Create and load the utility network.
                _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServiceUrl));

                // Create a default starting location.
                UtilityNetworkSource networkSource = _utilityNetwork.Definition.GetNetworkSource(DeviceTableName);
                UtilityAssetGroup    assetGroup    = networkSource.GetAssetGroup(AssetGroupName);
                UtilityAssetType     assetType     = assetGroup.GetAssetType(AssetTypeName);
                Guid globalId = Guid.Parse(GlobalId);
                _startingLocation = _utilityNetwork.CreateElement(assetType, globalId);

                // Set the terminal for this location. (For our case, we use the 'Load' terminal.)
                _startingLocation.Terminal = _startingLocation.AssetType.TerminalConfiguration?.Terminals.FirstOrDefault(term => term.Name == "Load");

                // Get a default trace configuration from a tier to update the UI.
                UtilityDomainNetwork domainNetwork = _utilityNetwork.Definition.GetDomainNetwork(DomainNetworkName);
                _sourceTier = domainNetwork.GetTier(TierName);

                // Set the trace configuration.
                _configuration = _sourceTier.TraceConfiguration;

                // Set the default expression (if provided).
                if (_sourceTier.TraceConfiguration.Traversability.Barriers is UtilityTraceConditionalExpression expression)
                {
                    _expressionLabel.Text = ExpressionToString(expression);
                    _initialExpression    = expression;
                }

                // Set the traversability scope.
                _sourceTier.TraceConfiguration.Traversability.Scope = UtilityTraversabilityScope.Junctions;
            }
            catch (Exception ex)
            {
                new UIAlertView(ex.GetType().Name, ex.Message, (IUIAlertViewDelegate)null, "Error loading network", null).Show();
            }
            finally
            {
                View.UserInteractionEnabled = true;
            }
        }
Ejemplo n.º 6
0
        private async void Initialize()
        {
            try
            {
                ConfigureTable.IsEnabled = false;

                // Create and load the utility network.
                _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServiceUrl));

                // Build the choice lists for network attribute comparison.
                Attributes.ItemsSource = _utilityNetwork.Definition.NetworkAttributes.Where(i => i.IsSystemDefined == false).ToList();
                Operators.ItemsSource  = Enum.GetValues(typeof(UtilityAttributeComparisonOperator));

                // Create a default starting location.
                UtilityNetworkSource networkSource = _utilityNetwork.Definition.GetNetworkSource(DeviceTableName);
                UtilityAssetGroup    assetGroup    = networkSource.GetAssetGroup(AssetGroupName);
                UtilityAssetType     assetType     = assetGroup.GetAssetType(AssetTypeName);
                Guid globalId = Guid.Parse(GlobalId);
                _startingLocation = _utilityNetwork.CreateElement(assetType, globalId);

                // Set the terminal for this location. (For our case, we use the 'Load' terminal.)
                _startingLocation.Terminal = _startingLocation.AssetType.TerminalConfiguration?.Terminals.FirstOrDefault(term => term.Name == "Load");

                // Get a default trace configuration from a tier to update the UI.
                UtilityDomainNetwork domainNetwork = _utilityNetwork.Definition.GetDomainNetwork(DomainNetworkName);
                _sourceTier = domainNetwork.GetTier(TierName);

                if (_sourceTier.TraceConfiguration.Traversability.Barriers is UtilityTraceConditionalExpression expression)
                {
                    ConditionBarrierExpression.Text = ExpressionToString(expression);
                    _initialExpression = expression;
                }

                // Set the traversability scope.
                _sourceTier.TraceConfiguration.Traversability.Scope = UtilityTraversabilityScope.Junctions;
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "OK");
            }
            finally
            {
                ConfigureTable.IsEnabled = true;
            }
        }
        /// <summary>
        /// GetNetworkElementFromStartingPoint
        ///
        /// This routine takes a row from the starting point table and converts it to a NetworkElement that we can use for tracing
        ///
        /// </summary>
        ///

        private Element GetElementFromStartingPointRow(Row startingPointRow, UtilityNetwork utilityNetwork, UtilityNetworkDefinition definition)
        {
            // Fetch the SourceID, AssetGroupCode, AssetType, GlobalID, and TerminalID values from the starting point row

            object vSourceID = startingPointRow[StartingPointsSourceIDFieldName];
            int    sourceID  = (int)vSourceID;

            object vAssetGroupID = startingPointRow[StartingPointsAssetGroupFieldName];
            int    assetGroupID  = (int)vAssetGroupID;

            object vAssetTypeID = startingPointRow[StartingPointsAssetTypeFieldName];
            int    assetTypeID  = (int)vAssetTypeID;

            object vGlobalID = startingPointRow[StartingPointsGlobalIDFieldName];
            Guid   globalID  = new Guid(vGlobalID.ToString());

            object vTerminalID = startingPointRow[StartingPointsTerminalFieldName];
            int    terminalID  = (int)vTerminalID;

            // Fetch the NetworkSource, AssetGroup, and AssetType objects

            NetworkSource networkSource = definition.GetNetworkSources().First(x => x.ID == sourceID);
            AssetGroup    assetGroup    = networkSource.GetAssetGroups().First(x => x.Code == assetGroupID);
            AssetType     assetType     = assetGroup.GetAssetTypes().First(x => x.Code == assetTypeID);

            // Fetch the Terminal object from the ID
            Terminal terminal = null;

            if (assetType.IsTerminalConfigurationSupported())
            {
                TerminalConfiguration terminalConfiguration = assetType.GetTerminalConfiguration();
                terminal = terminalConfiguration.Terminals.First(x => x.ID == terminalID);
            }

            // Create and return a Element object

            return(utilityNetwork.CreateElement(assetType, globalID, terminal));
        }
Ejemplo n.º 8
0
        private async void OnGeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                _activityIndicator.StartAnimating();
                _statusLabel.Text = "Identifying trace locations...";

                // Identify the feature to be used.
                IEnumerable <IdentifyLayerResult> identifyResult = await _myMapView.IdentifyLayersAsync(e.Position, 10.0, false);

                ArcGISFeature feature = identifyResult?.FirstOrDefault()?.GeoElements?.FirstOrDefault() as ArcGISFeature;
                if (feature == null)
                {
                    return;
                }

                // Create element from the identified feature.
                UtilityElement element = _utilityNetwork.CreateElement(feature);

                if (element.NetworkSource.SourceType == UtilityNetworkSourceType.Junction)
                {
                    // Select terminal for junction feature.
                    IEnumerable <UtilityTerminal> terminals = element.AssetType.TerminalConfiguration?.Terminals;
                    if (terminals?.Count() > 1)
                    {
                        element.Terminal = await WaitForTerminal(terminals);
                    }
                    _statusLabel.Text = $"Terminal: {element.Terminal?.Name ?? "default"}";
                }
                else if (element.NetworkSource.SourceType == UtilityNetworkSourceType.Edge)
                {
                    // Compute how far tapped location is along the edge feature.
                    if (feature.Geometry is Polyline line)
                    {
                        line = GeometryEngine.RemoveZ(line) as Polyline;
                        element.FractionAlongEdge = GeometryEngine.FractionAlong(line, e.Location, -1);
                        _statusLabel.Text         = $"Fraction along edge: {element.FractionAlongEdge}";
                    }
                }

                // Check whether starting location or barrier is added to update the right collection and symbology.
                Symbol symbol = null;
                if (_startBarrierPicker.SelectedSegment == 0)
                {
                    _startingLocations.Add(element);
                    symbol = _startingPointSymbol;
                }
                else
                {
                    _barriers.Add(element);
                    symbol = _barrierPointSymbol;
                }

                // Add a graphic for the new utility element.
                Graphic traceLocationGraphic = new Graphic(feature.Geometry as MapPoint ?? e.Location, symbol);
                _myMapView.GraphicsOverlays.FirstOrDefault()?.Graphics.Add(traceLocationGraphic);
            }
            catch (Exception ex)
            {
                _statusLabel.Text = "Identifying locations failed...";
                new UIAlertView("Error", ex.Message, (IUIAlertViewDelegate)null, "OK", null).Show();
            }
            finally
            {
                if (_statusLabel.Text.Equals("Identifying trace locations..."))
                {
                    _statusLabel.Text = "Could not identify location.";
                }
                _activityIndicator.StopAnimating();
            }
        }
Ejemplo n.º 9
0
        private async void Initialize()
        {
            try
            {
                // Disable the UI.
                FilterOptions.Visibility = Visibility.Collapsed;

                // Create and load the utility network.
                _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServiceUrl));

                // Create a map with layers in this utility network.
                MyMapView.Map = new Map(Basemap.CreateStreetsNightVector());
                MyMapView.Map.OperationalLayers.Add(new FeatureLayer(new Uri($"{FeatureServiceUrl}/{LineLayerId}")));
                MyMapView.Map.OperationalLayers.Add(new FeatureLayer(new Uri($"{FeatureServiceUrl}/{DeviceLayerId}")));

                // Get a trace configuration from a tier.
                UtilityDomainNetwork domainNetwork = _utilityNetwork.Definition.GetDomainNetwork(DomainNetworkName) ?? throw new ArgumentException(DomainNetworkName);
                UtilityTier          tier          = domainNetwork.GetTier(TierName) ?? throw new ArgumentException(TierName);
                _configuration = tier.TraceConfiguration;

                // Create a trace filter.
                _configuration.Filter = new UtilityTraceFilter();

                // Get a default starting location.
                UtilityNetworkSource networkSource = _utilityNetwork.Definition.GetNetworkSource(NetworkSourceName) ?? throw new ArgumentException(NetworkSourceName);
                UtilityAssetGroup    assetGroup    = networkSource.GetAssetGroup(AssetGroupName) ?? throw new ArgumentException(AssetGroupName);
                UtilityAssetType     assetType     = assetGroup.GetAssetType(AssetTypeName) ?? throw new ArgumentException(AssetTypeName);
                Guid globalId = Guid.Parse(GlobalId);
                _startingLocation = _utilityNetwork.CreateElement(assetType, globalId);

                // Create a graphics overlay.
                GraphicsOverlay overlay = new GraphicsOverlay();
                MyMapView.GraphicsOverlays.Add(overlay);

                // Display starting location.
                IEnumerable <ArcGISFeature> elementFeatures = await _utilityNetwork.GetFeaturesForElementsAsync(new List <UtilityElement> {
                    _startingLocation
                });

                MapPoint startingLocationGeometry = elementFeatures.FirstOrDefault().Geometry as MapPoint;
                Symbol   symbol  = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Cross, System.Drawing.Color.LimeGreen, 25d);
                Graphic  graphic = new Graphic(startingLocationGeometry, symbol);
                overlay.Graphics.Add(graphic);

                // Set the starting viewpoint.
                await MyMapView.SetViewpointAsync(new Viewpoint(startingLocationGeometry, 3000));

                // Build the choice list for categories populated with the `Name` property of each `UtilityCategory` in the `UtilityNetworkDefinition`.
                Categories.ItemsSource  = _utilityNetwork.Definition.Categories;
                Categories.SelectedItem = _utilityNetwork.Definition.Categories.First();

                // Enable the UI.
                FilterOptions.Visibility = Visibility.Visible;
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.Message, ex.GetType().Name).ShowAsync();
            }
            finally
            {
                LoadingBar.Visibility = Visibility.Collapsed;
            }
        }
        private static void ExecuteTrace(Guid traceStartGuid, string geodatabasePath)
        {
            using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(geodatabasePath))))
            {
                IReadOnlyList <UtilityNetworkDefinition> utilityNetworkDefinitions = geodatabase.GetDefinitions <UtilityNetworkDefinition>();

                string utilityNetworkName = string.Empty;

                if (utilityNetworkDefinitions.Count < 0 || utilityNetworkDefinitions.Count > 1)
                {
                    return;
                }

                // Get utility network name from the dataset
                foreach (UtilityNetworkDefinition definition in utilityNetworkDefinitions)
                {
                    utilityNetworkName = definition.GetName();

                    Console.WriteLine($"Utility network name: {utilityNetworkName}");
                    definition.Dispose();
                }

                // Open utility network
                using (UtilityNetwork utilityNetwork = geodatabase.OpenDataset <UtilityNetwork>(utilityNetworkName))
                    using (UtilityNetworkDefinition utilityNetworkDefinition = utilityNetwork.GetDefinition())
                    {
                        using (NetworkSource networkSource = utilityNetworkDefinition.GetNetworkSource("ElectricDevice"))
                            using (AssetGroup assetGroup = networkSource.GetAssetGroup("Medium Voltage Transformer"))
                                using (AssetType assetType = assetGroup.GetAssetType("Overhead Single Phase"))
                                {
                                    DomainNetwork      domainNetwork      = utilityNetworkDefinition.GetDomainNetwork("Electric");
                                    Tier               sourceTier         = domainNetwork.GetTier("Electric Distribution");
                                    TraceConfiguration traceConfiguration = sourceTier.GetTraceConfiguration();

                                    // Get downstream side of the terminal
                                    Terminal terminal = null;
                                    if (assetType.IsTerminalConfigurationSupported())
                                    {
                                        TerminalConfiguration    terminalConfiguration = assetType.GetTerminalConfiguration();
                                        IReadOnlyList <Terminal> terminals             = terminalConfiguration.Terminals;
                                        terminal = terminals.First(t => !t.IsUpstreamTerminal);
                                    }

                                    // Create an element to begin a trace
                                    Element startingPointElement = utilityNetwork.CreateElement(assetType, traceStartGuid, terminal);

                                    List <Element> startingPoints = new List <Element>();
                                    startingPoints.Add(startingPointElement);


                                    // Get trace manager
                                    using (TraceManager traceManager = utilityNetwork.GetTraceManager())
                                    {
                                        // Set trace configurations
                                        TraceArgument traceArgument = new TraceArgument(startingPoints);
                                        traceArgument.Configuration = traceConfiguration;

                                        // Get downstream tracer
                                        Tracer tracer = traceManager.GetTracer <DownstreamTracer>();

                                        // Execuate downstream trace
                                        IReadOnlyList <Result> traceResults = tracer.Trace(traceArgument);

                                        // Display trace results in console
                                        foreach (Result result in traceResults)
                                        {
                                            if (result is ElementResult)
                                            {
                                                ElementResult           elementResult = result as ElementResult;
                                                IReadOnlyList <Element> elements      = elementResult.Elements;

                                                Console.WriteLine("Trace result elements:");
                                                foreach (Element element in elements)
                                                {
                                                    Console.WriteLine($"\t OID: {element.ObjectID}, Name:{element.AssetType.Name}");
                                                }
                                            }
                                            else if (result is FunctionOutputResult)
                                            {
                                                FunctionOutputResult           functionResult  = result as FunctionOutputResult;
                                                IReadOnlyList <FunctionOutput> functionOutputs = functionResult.FunctionOutputs;

                                                Console.WriteLine("Trace result function outputs:");
                                                foreach (FunctionOutput functionOut in functionOutputs)
                                                {
                                                    Console.WriteLine($"\t Function result:{functionOut.Value}, name: {functionOut.Function}");
                                                }
                                            }
                                            else if (result is AggregatedGeometryResult)
                                            {
                                                AggregatedGeometryResult aggResults = result as AggregatedGeometryResult;
                                                Polyline   aggregatedLine           = aggResults.Line as Polyline;
                                                Multipoint aggregatedPoint          = aggResults.Point as Multipoint;
                                                Polygon    aggregatedPolygon        = aggResults.Polygon as Polygon;
                                            }
                                        }
                                    }
                                }
                    }
            }
        }
        private async void OnGeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                IsBusy.Visibility = Visibility.Visible;
                Status.Text       = "Identifying trace locations...";

                // Identify the feature to be used.
                IEnumerable <IdentifyLayerResult> identifyResult = await MyMapView.IdentifyLayersAsync(e.Position, 10.0, false);

                ArcGISFeature feature = identifyResult?.FirstOrDefault()?.GeoElements?.FirstOrDefault() as ArcGISFeature;
                if (feature == null)
                {
                    return;
                }

                // Create element from the identified feature.
                UtilityElement element = _utilityNetwork.CreateElement(feature);

                if (element.NetworkSource.SourceType == UtilityNetworkSourceType.Junction)
                {
                    // Select terminal for junction feature.
                    IEnumerable <UtilityTerminal> terminals = element.AssetType.TerminalConfiguration?.Terminals;
                    if (terminals?.Count() > 1)
                    {
                        element.Terminal = await GetTerminalAsync(terminals);
                    }
                    Status.Text = $"Terminal: {element.Terminal?.Name ?? "default"}";
                }
                else if (element.NetworkSource.SourceType == UtilityNetworkSourceType.Edge)
                {
                    // Compute how far tapped location is along the edge feature.
                    if (feature.Geometry is Polyline line)
                    {
                        line = GeometryEngine.RemoveZ(line) as Polyline;
                        double fraction = GeometryEngine.FractionAlong(line, e.Location, -1);
                        if (double.IsNaN(fraction))
                        {
                            return;
                        }
                        element.FractionAlongEdge = fraction;
                        Status.Text = $"Fraction along edge: {element.FractionAlongEdge}";
                    }
                }

                // Check whether starting location or barrier is added to update the right collection and symbology.
                Symbol symbol = null;
                if (IsAddingStartingLocations.IsChecked.Value == true)
                {
                    _startingLocations.Add(element);
                    symbol = _startingPointSymbol;
                }
                else
                {
                    _barriers.Add(element);
                    symbol = _barrierPointSymbol;
                }

                // Add a graphic for the new utility element.
                Graphic traceLocationGraphic = new Graphic(feature.Geometry as MapPoint ?? e.Location, symbol);
                MyMapView.GraphicsOverlays.FirstOrDefault()?.Graphics.Add(traceLocationGraphic);
            }
            catch (Exception ex)
            {
                Status.Text = "Identifying locations failed.";
                MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                if (Status.Text.Equals("Identifying trace locations..."))
                {
                    Status.Text = "Could not identify location.";
                }
                IsBusy.Visibility = Visibility.Hidden;
            }
        }
Ejemplo n.º 12
0
        private async void Initialize()
        {
            try
            {
                // Disable the UI.
                _traceButton.Enabled = false;

                // Create and load the utility network.
                _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServiceUrl));

                // Create a map with layers in this utility network.
                _myMapView.Map = new Map(new Basemap(new Uri("https://www.arcgis.com/home/item.html?id=1970c1995b8f44749f4b9b6e81b5ba45")));
                _myMapView.Map.OperationalLayers.Add(new FeatureLayer(new Uri($"{FeatureServiceUrl}/{LineLayerId}")));
                _myMapView.Map.OperationalLayers.Add(new FeatureLayer(new Uri($"{FeatureServiceUrl}/{DeviceLayerId}")));

                // Get a trace configuration from a tier.
                UtilityDomainNetwork domainNetwork = _utilityNetwork.Definition.GetDomainNetwork(DomainNetworkName) ?? throw new ArgumentException(DomainNetworkName);
                UtilityTier          tier          = domainNetwork.GetTier(TierName) ?? throw new ArgumentException(TierName);
                _configuration = tier.TraceConfiguration;

                // Create a trace filter.
                _configuration.Filter = new UtilityTraceFilter();

                // Get a default starting location.
                UtilityNetworkSource networkSource = _utilityNetwork.Definition.GetNetworkSource(NetworkSourceName) ?? throw new ArgumentException(NetworkSourceName);
                UtilityAssetGroup    assetGroup    = networkSource.GetAssetGroup(AssetGroupName) ?? throw new ArgumentException(AssetGroupName);
                UtilityAssetType     assetType     = assetGroup.GetAssetType(AssetTypeName) ?? throw new ArgumentException(AssetTypeName);
                Guid globalId = Guid.Parse(GlobalId);
                _startingLocation = _utilityNetwork.CreateElement(assetType, globalId);

                // Create a graphics overlay.
                GraphicsOverlay overlay = new GraphicsOverlay();
                _myMapView.GraphicsOverlays.Add(overlay);

                // Display starting location.
                IEnumerable <ArcGISFeature> elementFeatures = await _utilityNetwork.GetFeaturesForElementsAsync(new List <UtilityElement> {
                    _startingLocation
                });

                MapPoint startingLocationGeometry = elementFeatures.FirstOrDefault().Geometry as MapPoint;
                Symbol   symbol  = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Cross, System.Drawing.Color.LimeGreen, 25d);
                Graphic  graphic = new Graphic(startingLocationGeometry, symbol);
                overlay.Graphics.Add(graphic);

                // Set the starting viewpoint.
                await _myMapView.SetViewpointAsync(new Viewpoint(startingLocationGeometry, 3000));

                // Build the choice list for categories populated with the `Name` property of each `UtilityCategory` in the `UtilityNetworkDefinition`.
                _utilityNetwork.Definition.Categories.ToList().ForEach(cat => _categoryDictionary.Add(cat.Name, cat));
                _categorySpinner.Adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerItem, _categoryDictionary.Keys.ToList());
                _categorySpinner.SetSelection(0);

                // Enable the UI.
                _traceButton.Enabled = true;
            }
            catch (Exception ex)
            {
                new AlertDialog.Builder(this).SetMessage(ex.Message).SetTitle(ex.GetType().Name).Show();
            }
            finally
            {
                _loadingBar.Visibility = Android.Views.ViewStates.Gone;
            }
        }
        private async void GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                _progressBar.Visibility = Android.Views.ViewStates.Visible;
                _status.Text            = "Identifying trace locations...";

                // Identify the feature to be used.
                IEnumerable <IdentifyLayerResult> identifyResult = await _myMapView.IdentifyLayersAsync(e.Position, 10.0, false);

                // Check that a results from a layer were identified from the user input.
                if (!identifyResult.Any())
                {
                    return;
                }

                // Identify the selected feature.
                IdentifyLayerResult layerResult = identifyResult?.FirstOrDefault();
                ArcGISFeature       feature     = layerResult?.GeoElements?.FirstOrDefault() as ArcGISFeature;

                // Check that a feature was identified from the layer.
                if (feature == null)
                {
                    return;
                }

                // Create element with `terminal` for junction feature or with `fractionAlong` for edge feature.
                UtilityElement element = null;

                // Select default terminal or display possible terminals for the junction feature.
                UtilityNetworkSource networkSource = _utilityNetwork.Definition.GetNetworkSource(feature.FeatureTable.TableName);

                // Check if the network source is a junction or an edge.
                if (networkSource.SourceType == UtilityNetworkSourceType.Junction)
                {
                    // Get the UtilityAssetGroup from the feature.
                    string            assetGroupFieldName = ((ArcGISFeatureTable)feature.FeatureTable).SubtypeField ?? "ASSETGROUP";
                    int               assetGroupCode      = Convert.ToInt32(feature.Attributes[assetGroupFieldName]);
                    UtilityAssetGroup assetGroup          = networkSource?.AssetGroups?.FirstOrDefault(g => g.Code == assetGroupCode);

                    // Get the UtilityAssetType from the feature.
                    int assetTypeCode          = Convert.ToInt32(feature.Attributes["ASSETTYPE"]);
                    UtilityAssetType assetType = assetGroup?.AssetTypes?.FirstOrDefault(t => t.Code == assetTypeCode);

                    // Get the list of terminals for the feature.
                    IEnumerable <UtilityTerminal> terminals = assetType?.TerminalConfiguration?.Terminals;

                    // If there is more than one terminal, prompt the user to select a terminal.
                    if (terminals.Count() > 1)
                    {
                        // Ask the user to choose the terminal.
                        UtilityTerminal terminal = await WaitForTerminal(terminals);

                        // Create a UtilityElement with the terminal.
                        element      = _utilityNetwork.CreateElement(feature, terminal);
                        _status.Text = $"Terminal: {terminal?.Name ?? "default"}";
                    }
                    else
                    {
                        element      = _utilityNetwork.CreateElement(feature, terminals.FirstOrDefault());
                        _status.Text = $"Terminal: {element.Terminal?.Name ?? "default"}";
                    }
                }
                else if (networkSource.SourceType == UtilityNetworkSourceType.Edge)
                {
                    element = _utilityNetwork.CreateElement(feature);

                    // Compute how far tapped location is along the edge feature.
                    if (feature.Geometry is Polyline line)
                    {
                        line = GeometryEngine.RemoveZ(line) as Polyline;

                        // Set how far the element is along the edge.
                        element.FractionAlongEdge = GeometryEngine.FractionAlong(line, e.Location, -1);

                        _status.Text = $"Fraction along edge: {element.FractionAlongEdge}";
                    }
                }

                // Check that the element can be added to the parameters.
                if (element == null)
                {
                    return;
                }

                // Build the utility trace parameters.
                if (_parameters == null)
                {
                    IEnumerable <UtilityElement> startingLocations = Enumerable.Empty <UtilityElement>();
                    _parameters = new UtilityTraceParameters(UtilityTraceType.Connected, startingLocations);
                }
                if (isAddingStart)
                {
                    _parameters.StartingLocations.Add(element);
                }
                else
                {
                    _parameters.Barriers.Add(element);
                }

                // Add a graphic for the new utility element.
                Graphic traceLocationGraphic = new Graphic(feature.Geometry as MapPoint ?? e.Location, isAddingStart ? _startingPointSymbol : _barrierPointSymbol);
                _myMapView.GraphicsOverlays.FirstOrDefault()?.Graphics.Add(traceLocationGraphic);
            }
            catch (Exception ex)
            {
                _status.Text = "Identifying locations failed...";
                CreateDialog(ex.Message);
            }
            finally
            {
                if (_status.Text.Equals("Identifying trace locations..."))
                {
                    _status.Text = "Could not identify location.";
                }
                _progressBar.Visibility = Android.Views.ViewStates.Invisible;
            }
        }
Ejemplo n.º 14
0
        private async void Initialize()
        {
            // As of ArcGIS Enterprise 10.8.1, using utility network functionality requires a licensed user. The following login for the sample server is licensed to perform utility network operations.
            AuthenticationManager.Current.ChallengeHandler = new ChallengeHandler(async(info) =>
            {
                try
                {
                    // WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
                    string sampleServer7User = "******";
                    string sampleServer7Pass = "******";

                    return(await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass));
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    return(null);
                }
            });

            try
            {
                // Disable the UI.
                FilterOptions.IsVisible = false;

                // Create and load the utility network.
                _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServiceUrl));

                // Create a map with layers in this utility network.
                MyMapView.Map = new Map(new Basemap(new Uri("https://www.arcgis.com/home/item.html?id=1970c1995b8f44749f4b9b6e81b5ba45")));
                MyMapView.Map.OperationalLayers.Add(new FeatureLayer(new Uri($"{FeatureServiceUrl}/{LineLayerId}")));
                MyMapView.Map.OperationalLayers.Add(new FeatureLayer(new Uri($"{FeatureServiceUrl}/{DeviceLayerId}")));

                // Get a trace configuration from a tier.
                UtilityDomainNetwork domainNetwork = _utilityNetwork.Definition.GetDomainNetwork(DomainNetworkName) ?? throw new ArgumentException(DomainNetworkName);
                UtilityTier          tier          = domainNetwork.GetTier(TierName) ?? throw new ArgumentException(TierName);
                _configuration = tier.TraceConfiguration;

                // Create a trace filter.
                _configuration.Filter = new UtilityTraceFilter();

                // Get a default starting location.
                UtilityNetworkSource networkSource = _utilityNetwork.Definition.GetNetworkSource(NetworkSourceName) ?? throw new ArgumentException(NetworkSourceName);
                UtilityAssetGroup    assetGroup    = networkSource.GetAssetGroup(AssetGroupName) ?? throw new ArgumentException(AssetGroupName);
                UtilityAssetType     assetType     = assetGroup.GetAssetType(AssetTypeName) ?? throw new ArgumentException(AssetTypeName);
                Guid globalId = Guid.Parse(GlobalId);
                _startingLocation = _utilityNetwork.CreateElement(assetType, globalId);

                // Create a graphics overlay.
                GraphicsOverlay overlay = new GraphicsOverlay();
                MyMapView.GraphicsOverlays.Add(overlay);

                // Display starting location.
                IEnumerable <ArcGISFeature> elementFeatures = await _utilityNetwork.GetFeaturesForElementsAsync(new List <UtilityElement> {
                    _startingLocation
                });

                MapPoint startingLocationGeometry = elementFeatures.FirstOrDefault().Geometry as MapPoint;
                Symbol   symbol  = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Cross, System.Drawing.Color.LimeGreen, 25d);
                Graphic  graphic = new Graphic(startingLocationGeometry, symbol);
                overlay.Graphics.Add(graphic);

                // Set the starting viewpoint.
                await MyMapView.SetViewpointAsync(new Viewpoint(startingLocationGeometry, 3000));

                // Build the choice list for categories populated with the `Name` property of each `UtilityCategory` in the `UtilityNetworkDefinition`.
                CategoryPicker.ItemsSource  = _utilityNetwork.Definition.Categories.ToList();
                CategoryPicker.SelectedItem = _utilityNetwork.Definition.Categories.First();

                // Enable the UI.
                FilterOptions.IsVisible = true;
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert(ex.GetType().Name, ex.Message, "OK");
            }
            finally
            {
                LoadingIndicator.IsVisible = false;
            }
        }
        private async void Initialize()
        {
            // As of ArcGIS Enterprise 10.8.1, using utility network functionality requires a licensed user. The following login for the sample server is licensed to perform utility network operations.
            AuthenticationManager.Current.ChallengeHandler = new ChallengeHandler(async(info) =>
            {
                try
                {
                    // WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
                    string sampleServer7User = "******";
                    string sampleServer7Pass = "******";
                    return(await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass));
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            });

            try
            {
                Configuration.IsEnabled = false;

                // Create and load the utility network.
                _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServiceUrl));

                // Build the choice lists for network attribute comparison.
                Attributes.ItemsSource = _utilityNetwork.Definition.NetworkAttributes.Where(netattr => !netattr.IsSystemDefined);
                Operators.ItemsSource  = Enum.GetValues(typeof(UtilityAttributeComparisonOperator));

                // Create a default starting location.
                UtilityNetworkSource networkSource = _utilityNetwork.Definition.GetNetworkSource(DeviceTableName);
                UtilityAssetGroup    assetGroup    = networkSource.GetAssetGroup(AssetGroupName);
                UtilityAssetType     assetType     = assetGroup.GetAssetType(AssetTypeName);
                Guid globalId = Guid.Parse(GlobalId);
                _startingLocation = _utilityNetwork.CreateElement(assetType, globalId);

                // Set the terminal for this location. (For our case, we use the 'Load' terminal.)
                _startingLocation.Terminal = _startingLocation.AssetType.TerminalConfiguration?.Terminals.FirstOrDefault(term => term.Name == "Load");

                // Get a default trace configuration from a tier to update the UI.
                UtilityDomainNetwork domainNetwork = _utilityNetwork.Definition.GetDomainNetwork(DomainNetworkName);
                UtilityTier          sourceTier    = domainNetwork.GetTier(TierName);

                // Set the trace configuration.
                _configuration = sourceTier.TraceConfiguration;

                // Set the default expression (if provided).
                if (sourceTier.TraceConfiguration.Traversability.Barriers is UtilityTraceConditionalExpression expression)
                {
                    ConditionBarrierExpression.Text = ExpressionToString(expression);
                    _initialExpression = expression;
                }

                // Setting DataContext will resolve the data-binding in XAML.
                Configuration.DataContext = _configuration;

                // Set the traversability scope.
                sourceTier.TraceConfiguration.Traversability.Scope = UtilityTraversabilityScope.Junctions;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.Message.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Configuration.IsEnabled = true;
            }
        }
Ejemplo n.º 16
0
        private async void Initialize()
        {
            // As of ArcGIS Enterprise 10.8.1, using utility network functionality requires a licensed user. The following login for the sample server is licensed to perform utility network operations.
            AuthenticationManager.Current.ChallengeHandler = new ChallengeHandler(async(info) =>
            {
                try
                {
                    // WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
                    string sampleServer7User = "******";
                    string sampleServer7Pass = "******";
                    return(await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass));
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            });

            try
            {
                // Disable interaction until the data is loaded.
                View.UserInteractionEnabled = false;

                // Create and load the utility network.
                _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServiceUrl));

                // Create a default starting location.
                UtilityNetworkSource networkSource = _utilityNetwork.Definition.GetNetworkSource(DeviceTableName);
                UtilityAssetGroup    assetGroup    = networkSource.GetAssetGroup(AssetGroupName);
                UtilityAssetType     assetType     = assetGroup.GetAssetType(AssetTypeName);
                Guid globalId = Guid.Parse(GlobalId);
                _startingLocation = _utilityNetwork.CreateElement(assetType, globalId);

                // Set the terminal for this location. (For our case, we use the 'Load' terminal.)
                _startingLocation.Terminal = _startingLocation.AssetType.TerminalConfiguration?.Terminals.FirstOrDefault(term => term.Name == "Load");

                // Get a default trace configuration from a tier to update the UI.
                UtilityDomainNetwork domainNetwork = _utilityNetwork.Definition.GetDomainNetwork(DomainNetworkName);
                _sourceTier = domainNetwork.GetTier(TierName);

                // Set the trace configuration.
                _configuration = _sourceTier.TraceConfiguration;

                // Set the default expression (if provided).
                if (_sourceTier.TraceConfiguration.Traversability.Barriers is UtilityTraceConditionalExpression expression)
                {
                    _expressionLabel.Text = ExpressionToString(expression);
                    _initialExpression    = expression;
                }

                // Set the traversability scope.
                _sourceTier.TraceConfiguration.Traversability.Scope = UtilityTraversabilityScope.Junctions;
            }
            catch (Exception ex)
            {
                new UIAlertView(ex.GetType().Name, ex.Message, (IUIAlertViewDelegate)null, "Error loading network", null).Show();
            }
            finally
            {
                View.UserInteractionEnabled = true;
            }
        }