public async void QueryHandHoles100MeterRadiusFromJ1_ShouldReturn4HandHandholes()
        {
            // Setup
            var stops     = new RouteNodeKindEnum[] { RouteNodeKindEnum.CentralOfficeSmall };
            var interests = new RouteNodeKindEnum[] { RouteNodeKindEnum.HandHole };

            var nearestNodeQuery = new FindNearestRouteNodes(TestRouteNetwork.J_1, 10, 100, stops, interests);

            // Act
            var nearestNodeQueryResult = await _queryDispatcher.HandleAsync <FindNearestRouteNodes, Result <FindNearestRouteNodesResult> >(nearestNodeQuery);

            // Assert
            nearestNodeQueryResult.IsSuccess.Should().BeTrue();

            // We should get 4 hand holes back
            nearestNodeQueryResult.Value.RouteNetworkTraces.Count().Should().Be(4);
            nearestNodeQueryResult.Value.RouteNetworkElements.Count().Should().Be(4);
            nearestNodeQueryResult.Value.RouteNetworkElements.Count(r => r.RouteNodeInfo.Kind == RouteNodeKindEnum.HandHole).Should().Be(4);

            // Check trace for handhole HH_10
            var handHole10Trace = nearestNodeQueryResult.Value.RouteNetworkTraces[TestRouteNetwork.HH_10];

            handHole10Trace.Name.Should().Be("HH-10");
            handHole10Trace.RouteNetworkSegmentIds.Length.Should().Be(3);
            handHole10Trace.RouteNetworkSegmentGeometries.Length.Should().Be(3);
            handHole10Trace.RouteNetworkSegmentIds[0].Should().Be(TestRouteNetwork.S13);
            handHole10Trace.RouteNetworkSegmentIds[1].Should().Be(TestRouteNetwork.S5);
            handHole10Trace.RouteNetworkSegmentIds[2].Should().Be(TestRouteNetwork.S6);
            handHole10Trace.Distance.Should().BeInRange(94, 96);
        }
        internal RouteNode(Guid routeNodeId, string name, RouteNodeKindEnum nodeKind, RouteNodeFunctionKindEnum functionKind, RouteNetwork.Events.Model.Geometry geometry, LocationInfo locationInfo) : this()
        {
            // Check that we got some valid geometry
            if (geometry == null)
            {
                throw new ArgumentException("Cannot create route node with id: " + routeNodeId + " because Geometry is null, which is not allowed.");
            }

            if (geometry.GeoJsonType == null)
            {
                throw new ArgumentException("Cannot create route node with id: " + routeNodeId + " because Geometry.GeoJsonType is null, which is not allowed.");
            }

            if (geometry.GeoJsonType.ToLower() != "point")
            {
                throw new ArgumentException("Cannot create route node with id: " + routeNodeId + " because Geometry.GeoJsonType is: " + geometry.GeoJsonType + ", which is not allowed in route nodes. Expected Point.");
            }

            if (geometry.GeoJsonCoordinates == null)
            {
                throw new ArgumentException("Cannot create route node with id: " + routeNodeId + " because Geometry.GeoJsonCoordinates is null, which is not allowed.");
            }

            // Try parse geojson
            var reader = new NetTopologySuite.IO.GeoJsonReader();

            try
            {
                var point = reader.Read <Point>("{ \"type\": \"Point\", \"coordinates\": " + geometry.GeoJsonCoordinates + "}");

                if (point == null)
                {
                    throw new ArgumentException("Error parsing geometry: " + geometry);
                }
            }
            catch (Exception ex)
            {
                throw new ArgumentException("Error parsing geometry: " + geometry + " Got exception from NetTopologySuite: " + ex.Message, ex);
            }


            // Create domain event
            var routeNodeAdded = new RouteNodePlanned()
            {
                Id               = routeNodeId,
                Name             = name,
                NodeKind         = nodeKind,
                NodeFunctionKind = functionKind,
                InitialGeometry  = geometry,
                LocationInfo     = locationInfo
            };

            RaiseEvent(routeNodeAdded, false);
        }
Exemple #3
0
        /// <summary>
        /// Add a new node to the route network
        /// </summary>
        /// <param name="routeNodeId"></param>
        /// <param name="name"></param>
        /// <param name="nodeKind"></param>
        /// <param name="functionKind"></param>
        /// <param name="geometry"></param>
        /// <param name="locationInfo"></param>
        public void AddRouteNode(Guid routeNodeId, string name, RouteNodeKindEnum nodeKind, RouteNodeFunctionKindEnum functionKind, RouteNetwork.Events.Model.Geometry geometry, LocationInfo locationInfo)
        {
            // Id check
            if (routeNodeId == null || routeNodeId == Guid.Empty)
            {
                throw new ArgumentException("Id cannot be null or empty");
            }

            // Check that node not already exists
            if (routeNetworkState.CheckIfRouteNodeIdExists(routeNodeId))
            {
                throw new ArgumentException("A route node with id: " + routeNodeId + " already exists");
            }

            // Check that we got some valid geometry
            if (geometry == null)
            {
                throw new ArgumentException("Cannot create route node with id: " + routeNodeId + " because Geometry is null, which is not allowed.");
            }

            if (geometry.GeoJsonType == null)
            {
                throw new ArgumentException("Cannot create route node with id: " + routeNodeId + " because Geometry.GeoJsonType is null, which is not allowed.");
            }

            if (geometry.GeoJsonType.ToLower() != "point")
            {
                throw new ArgumentException("Cannot create route node with id: " + routeNodeId + " because Geometry.GeoJsonType is: " + geometry.GeoJsonType + ", which is not allowed in route nodes. Expected Point.");
            }

            if (geometry.GeoJsonCoordinates == null)
            {
                throw new ArgumentException("Cannot create route node with id: " + routeNodeId + " because Geometry.GeoJsonCoordinates is null, which is not allowed.");
            }

            // Try parse geojson
            var point = GeometryConversionHelper.ConvertFromPointGeoJson(geometry.GeoJsonCoordinates);

            // Create domain event
            var routeNodePlanned = new RouteNodePlanned()
            {
                Id               = routeNodeId,
                Name             = name,
                NodeKind         = nodeKind,
                NodeFunctionKind = functionKind,
                InitialGeometry  = geometry,
                LocationInfo     = locationInfo
            };

            RaiseEvent(routeNodePlanned, false);
        }
Exemple #4
0
        private void CreateNode(string name, int xCoord, int yCoord, RouteNodeKindEnum nodeKind, RouteNodeFunctionKindEnum nodeFunction)
        {
            var fixture = new Fixture();

            var addNodeCmd = fixture.Build <AddNodeCommand>()
                             .With(x => x.Name, name)
                             .With(x => x.Geometry, new Geometry("Point", "[" + xCoord + "," + yCoord + "]"))
                             .With(x => x.NodeKind, nodeKind)
                             .With(x => x.NodeFunctionKind, nodeFunction)
                             .Create();

            _bus.Send(addNodeCmd);

            _nodesByName[name] = _queryService.GetRouteNodeInfo(addNodeCmd.Id);
        }
        public async void QueryHandHoles30MeterRadiusFromJ1_ShouldReturn3HandHandholes()
        {
            // Setup
            var stops     = new RouteNodeKindEnum[] { RouteNodeKindEnum.CentralOfficeSmall };
            var interests = new RouteNodeKindEnum[] { RouteNodeKindEnum.HandHole };

            var nearestNodeQuery = new FindNearestRouteNodes(TestRouteNetwork.J_1, 10, 30, stops, interests);

            // Act
            var nearestNodeQueryResult = await _queryDispatcher.HandleAsync <FindNearestRouteNodes, Result <FindNearestRouteNodesResult> >(nearestNodeQuery);

            // Assert
            nearestNodeQueryResult.IsSuccess.Should().BeTrue();

            // We should get 4 hand holes back
            nearestNodeQueryResult.Value.RouteNetworkTraces.Count().Should().Be(3);
            nearestNodeQueryResult.Value.RouteNetworkElements.Count().Should().Be(3);
        }