#pragma warning disable 1998
        public async Task<bool> Extract(OsmEntityContext entityContext, ParkingArea target)
#pragma warning restore 1998
        {
            target.Operator = entityContext.Entity.Tags.ValueOrDefault("operator");

            return true;
        }
        public IObservable<ParkingArea> Extract(IMongoQuery query)
        {
            return Observable.Create<ParkingArea>(async observer =>
            {
                var totalEntitiesToProcess  = serverProvider.Database.OsmCompoundQueryCount(query);
                var operationCounter        = new OperationCounter(log, string.Format("OSM Parking Area Extraction from {0}",query), totalEntitiesToProcess);
                var cursor                  = serverProvider.Database.OsmCompoundQuery(query);

                foreach (var entity in cursor)
                {
                    var entityContext   = new OsmEntityContext(serverProvider.Database, entity);
                    var parkingArea     = new ParkingArea() { Id = Guid.NewGuid(), Source = ParkingAreaSource.Maps, Confidence = configuration.Model.Confidence };
                    var isValid         = true;

                    foreach (var extractionRule in extractionRules)
                    {
                        var continueExtraction = await extractionRule.Extract(entityContext, parkingArea);

                        if (!continueExtraction)
                        {
                            log.Info("Entity {0} was dropped from extraction by rule {1}", entity, extractionRule.GetType().Name.Replace("Extraction", string.Empty).Replace("Rule", string.Empty));
                            isValid = false;
                            break;
                        }
                    }

                    if (isValid)
                    {
                        observer.OnNext(parkingArea);
                    }

                    operationCounter.Increment();
                }
            });
        }
#pragma warning disable 1998
        public async Task<bool> Extract(OsmEntityContext entityContext, ParkingArea target)
#pragma warning restore 1998
        {
            target.IsLit        = entityContext.Entity.Tags.EntryAsBool("lit");
            target.IsCovered    = entityContext.Entity.Tags.EntryAsBool("covered");
            target.IsSupervised = entityContext.Entity.Tags.EntryAsBool("supervised");

            return true;
        }
#pragma warning disable 1998
        public async Task<bool> Extract(OsmEntityContext entityContext, ParkingArea target)
#pragma warning restore 1998
        {
            if (entityContext.Entity.Tags.ContainsKey("FIXME"))
            {
                return false;
            }

            return true;
        }
#pragma warning disable 1998
        public async Task<bool> Extract(OsmEntityContext entityContext, ParkingArea target)
#pragma warning restore 1998
        {
            var capacity = entityContext.Entity.Tags.EntryAsInt("capacity",entityContext.Entity.Tags.EntryAsInt("capacity:disabled"));

            if ( capacity < 1 )
            {
                capacity = (int)(MathUtil.SquareDegreesToSquareMeters(target.Location.Area.Value) / configuration.Model.AreaPerParkingSpace);
            }

            target.Capacity = capacity;
            return true;
        }
#pragma warning disable 1998
        public async Task<bool> Extract(OsmEntityContext entityContext, ParkingArea target)
#pragma warning restore 1998
        {
            if (entityContext.Entity.Tags.ContainsKey("vehicle") && !entityContext.Entity.Tags.EntryAsBool("vehicle"))
            {
                return false;
            }

            if (entityContext.Entity.Tags.ContainsKey("motor_vehicle") && !entityContext.Entity.Tags.EntryAsBool("motor_vehicle"))
            {
                return false;
            }

            return true;
        }
#pragma warning disable 1998
        public async Task<bool> Extract(OsmEntityContext entityContext, ParkingArea target)
#pragma warning restore 1998
        {
            var containement = ParkingContainementType.Unknown;

            if (entityContext.Entity.Tags.EntryEquals("parking", "surface"))
            {
                containement = ParkingContainementType.Surface;
            }

            if (entityContext.Entity.Tags.ContainsKey("building"))
            {
                containement = ParkingContainementType.Building;
            }

            target.ContainementType = containement;

            return true;
        }
#pragma warning disable 1998
        public async Task<bool> Extract(OsmEntityContext entityContext, ParkingArea target)
#pragma warning restore 1998
        {
            if ( entityContext.Entity.Tags.EntryAsInt("capacity:disabled") > 0 )
            {
                target.IsDisabledParking = true;
            }

            if (entityContext.Entity.Tags.EntryEquals("parking_space", "disabled"))
            {
                target.IsDisabledParking = true;
            }

            if (entityContext.Entity.Tags.EntryAsBool("wheelchair"))
            {
                target.IsDisabledParking = true;
            }

            return true;
        }
示例#9
0
        public static ParkingAreaDto FromModel(ParkingArea parkingArea,Vector referencePoint,Func<double,double> conversionFunction = null )
        {
            conversionFunction = conversionFunction ?? ShapeDto.DefaultToDtoConversionFunction;

            return new ParkingAreaDto()
            {
                Id                  = parkingArea.Id,
                Location            = new MultiPolygonDto(parkingArea.Location,conversionFunction),
                Distance            = conversionFunction((referencePoint - parkingArea.Location.Center).Length()),

                IsDisabledParking   = parkingArea.IsDisabledParking,
                IsCovered           = parkingArea.IsCovered,
                IsLit               = parkingArea.IsLit,
                IsSupervised        = parkingArea.IsSupervised,
                Source              = parkingArea.Source,
                AccessType          = parkingArea.AccessType,
                ContainementType    = parkingArea.ContainementType,
                Operator            = parkingArea.Operator,
                Confidence          = parkingArea.Confidence,    
                Capacity            = parkingArea.Capacity,
            };
        }
#pragma warning disable 1998
        public async Task<bool> Extract(OsmEntityContext entityContext, ParkingArea target)
#pragma warning restore 1998
        {
            var accessType = ParkingAreaAccessType.Public;

            if (entityContext.Entity.Tags.EntryEquals("access", "customers"))
            {
                accessType = ParkingAreaAccessType.Customers;
            }

            if (entityContext.Entity.Tags.EntryAsBool("fee"))
            {
                accessType = ParkingAreaAccessType.Paid;
            }

            if (entityContext.Entity.Tags.EntryAsBool("visitor"))
            {
                accessType = ParkingAreaAccessType.Visitor;
            }

            target.AccessType = accessType;
            return true;
        }
#pragma warning disable 1998
        public async Task<bool> Extract(OsmEntityContext entityContext, ParkingArea target)
#pragma warning restore 1998
        {
            var singleNode = entityContext.Entity as OsmNode;

            if ( singleNode != null )
            {
                target.Location = new MultiPolygon(new[] { new Polygon(singleNode.Location,MathUtil.MetersToDegrees(configuration.Model.NodeRadius))});
                return true;
            }

            var polygonList = new List<Polygon>();
            BuildPolygons(entityContext.EntityTree,polygonList);

            var resultPolygonList = new List<Polygon>();

            foreach( var polygon in polygonList)
            {
                if ( polygon.IsSelfIntersecting )
                {
                    resultPolygonList.Add(ConvexHull.CreateConvexHull(polygon.Vertices));
                }
                else
                {
                    resultPolygonList.Add(polygon);
                }
            }

            if ( resultPolygonList.Any() )
            {
                target.Location = new MultiPolygon(resultPolygonList.ToArray());
                return true;
            }

            return false;
        }