public static IQueryable <GridUnitEntity> GetWithinRadius(this IQueryable <GridUnitEntity> gridUnits, double radiusInDegrees, LngLat lngLat, IGeometryFactory geometryFactory)
        {
            var centerCoordinate = new Coordinate(lngLat.Lng, lngLat.Lat);
            var centerPoint      = geometryFactory.CreatePoint(centerCoordinate);
            var searchArea       = centerPoint.Buffer(radiusInDegrees).Reverse();

            var queryable = gridUnits.Where(x => !x.Boundary.Disjoint(searchArea));

            return(queryable);
        }
Beispiel #2
0
 public HTMLGenerator(string outputPath, LayerUsage layerUsage, LngLat center, int minZoom, int maxZoom, int sourceZoom, string mapTypeName) : this(outputPath, layerUsage, center, minZoom, maxZoom, sourceZoom)
 {
     this.mapTypeName = mapTypeName;
 }
Beispiel #3
0
        public async Task <List <CatchmentGeoJson> > GetAllWithinRadiusOfPointGeoJson(double radiusInDegrees, LngLat lngLat)
        {
            //var catchmentEntities = await this.GetCatchmentEntitiesWithinRadiusWithoutGridding(radiusInDegrees, lngLat); // 29s
            var catchmentEntities = await this.GetCatchmentEntitiesWithinRadiusViaGridding(radiusInDegrees, lngLat);

            var catchments = catchmentEntities
                             .Select(x => x.ToAppTypeGeoJson())
                             .ToList();

            return(catchments);
        }
        // Removed because with gridding, this can't be an extension for a single table,
        // it needs three tables (Catchments, GridUnits, and CatchmentGridUnits) to work
        // public static IQueryable<CatchmentEntity> GetCatchmentsContainingPoint(this IQueryable<CatchmentEntity> catchments, LngLat lngLat, IGeometryFactory geometryFactory)
        // {
        //     var coordinate = new Coordinate(lngLat.Lng, lngLat.Lat);
        //     var point = geometryFactory.CreatePoint(coordinate);

        //     var queryable = catchments.Where(x => x.Boundary.Contains(point));
        //     return queryable;
        // }

        public static IQueryable <CatchmentEntity> GetCatchmentsWithStringInNameAndWithinRadius(this IQueryable <CatchmentEntity> catchments, string nameContains, double radiusDegrees, LngLat lngLat, IGeometryFactory geometryFactory)
        {
            var centerCoordinate = new Coordinate(lngLat.Lng, lngLat.Lat);
            var center           = geometryFactory.CreatePoint(centerCoordinate);
            var searchArea       = center.Buffer(radiusDegrees).Boundary;

            var queryable = catchments
                            .GetContainingName(nameContains)
                            .GetWithinRadius(radiusDegrees, lngLat, geometryFactory)
            ;

            return(queryable);
        }
Beispiel #5
0
        public async Task <List <CatchmentIdentity> > GetAllCatchmentIdentitiesContainingPoint(LngLat lngLat)
        {
            var catchmentEntities = await this.GetCatchmentEntitiesContainingPoint(lngLat);

            var catchmentIdentityList = catchmentEntities
                                        .Select(x => CatchmentIdentity.From(x.Identity))
                                        .ToList();

            return(catchmentIdentityList);
        }
Beispiel #6
0
        public async Task <List <Catchment> > GetFilteredByNameAndRadius(string nameContains, double radiusDegrees, LngLat lngLat)
        {
            var geometryFactory = await this.GeometryFactoryProvider.GetGeometryFactoryAsync();

            var catchments = await this.ExecuteInContextAsync(async dbContext =>
            {
                var output = await dbContext.Catchments
                             .GetCatchmentsWithStringInNameAndWithinRadius(nameContains, radiusDegrees, lngLat, geometryFactory)
                             .Select(x => x.ToAppType())
                             .ToListAsync(); // Execute now to avoid disposing DbContext.

                return(output);
            });

            return(catchments);
        }
Beispiel #7
0
        private Task <List <CatchmentEntity> > GetCatchmentEntitiesWithinRadiusViaGridding(double radiusInDegrees, LngLat lngLat)
        {
            var gettingCatchmentEntities = this.ExecuteInContextAsyncWithGeometryFactory(async(dbContext, geometryFactory) =>
            {
                var relevantGridUnitIdentityValues = await dbContext.GridUnits
                                                     .GetWithinRadius(radiusInDegrees, lngLat, geometryFactory)
                                                     .Select(x => x.GUID)
                                                     .ToListAsync();

                var catchmentsWithinRadius = dbContext.Catchments
                                             .GetWithinRadius(radiusInDegrees, lngLat, geometryFactory);

                var catchmentsWithinRadiusViaGridding = await DatabaseCatchmentsRepository <TDbContext> .GetCatchmentsBasedOnGridUnitList(dbContext, relevantGridUnitIdentityValues, catchmentsWithinRadius)
                                                        .ToListAsync();

                return(catchmentsWithinRadiusViaGridding);
            });

            return(gettingCatchmentEntities);
        }
Beispiel #8
0
        private Task <List <CatchmentEntity> > GetCatchmentEntitiesWithinRadiusWithoutGridding(double radiusInDegrees, LngLat lngLat)
        {
            var gettingCatchmentEntiies = this.ExecuteInContextAsyncWithGeometryFactory(async(dbContext, geometryFactory) =>
            {
                var output = await dbContext.Catchments
                             .GetWithinRadius(radiusInDegrees, lngLat, geometryFactory)
                             .ToListAsync(); // Execute now to avoid disposing DbContext.

                return(output);
            });

            return(gettingCatchmentEntiies);
        }
Beispiel #9
0
        // Methods for getting catchments for a point (e.g. for anomaly catchment assignment or goastbusters)
        private async Task <List <CatchmentEntity> > GetCatchmentEntitiesContainingPoint(LngLat lngLat)
        {
            var catchmentEntities = await this.ExecuteInContextAsyncWithGeometryFactory(async (dbContext, geometryFactory) =>
            {
                var coordinate = lngLat.ToCoordinate();

                var point = geometryFactory.CreatePoint(coordinate);

                var relevantGridUnitIdentityValues = await dbContext.GridUnits
                                                     .Where(x => x.Boundary.Contains(point))
                                                     .Select(x => x.GUID)
                                                     .ToListAsync();

                IQueryable <CatchmentEntity> result;
                if (relevantGridUnitIdentityValues.IsEmpty())
                {
                    // Search all catchments. This may take a while.
                    result = dbContext.Catchments
                             .Where(x => x.Boundary.Contains(point));
                }
                else
                {
                    result = from catchment in dbContext.Catchments
                             join catchmentGridUnit in dbContext.CatchmentGridUnits
                             on catchment.Identity equals catchmentGridUnit.CatchmentIdentity
                             where relevantGridUnitIdentityValues.Contains(catchmentGridUnit.GridUnitIdentity)
                             where catchment.Boundary.Contains(point)
                             select catchment;
                }

                return(await result.ToListAsync());
            });

            return(catchmentEntities);
        }
        /// <summary>
        /// Uses <see cref="ToCoordinateXIsLongitude(LngLat)"/> as the default.
        /// </summary>
        public static Coordinate ToCoordinate(this LngLat lngLat)
        {
            var coordinate = lngLat.ToCoordinateXIsLongitude();

            return(coordinate);
        }
        public static Coordinate ToCoordinateXIsLongitude(this LngLat lngLat)
        {
            var coordinate = new Coordinate(lngLat.Lng, lngLat.Lat);

            return(coordinate);
        }