コード例 #1
0
        public async Task <WardWithDistrict> GetWardIdByLocation(string coordinateString)
        {
            Geometry geom = GeoJsonHelper.ParseStringToGeoMetry(coordinateString);

            geom.SRID = 4326;
            geom      = geom.Buffer(-0.0000261);
            WardWithDistrict result = null;

            try
            {
                var ward = await _unitOfWork.Repository <Ward>().GetAll().Where(x => x.Geom.Contains(geom)).FirstOrDefaultAsync();

                if (ward != null && CheckSystemzone(geom))
                {
                    result = new WardWithDistrict()
                    {
                        Id           = ward.Id,
                        Name         = ward.Name,
                        DistrictName = ward.District?.Name
                    };
                }
                return(result);
            }
            catch (Exception e)
            {
                throw new CrudException(HttpStatusCode.BadRequest, "Get Ward Id by Location error", e.InnerException?.Message);
            }
        }
コード例 #2
0
        public async Task <CustomFeatureCollection> GetWardForMap(string coordinateString)
        {
            try
            {
                var      result = new CustomFeatureCollection();
                Geometry geom   = GeoJsonHelper.ParseStringToGeoMetry(coordinateString);

                geom.SRID = 4326;
                var wards = await _unitOfWork.Repository <Ward>().GetAll().Where(x => geom.Contains(x.Geom)).ToListAsync();

                foreach (var item in wards)
                {
                    Feature ft = new Feature
                    {
                        Geometry = item.Geom
                    };
                    ft.Properties.F3 = item.Id;
                    ft.Properties.F2 = item.Name;
                    result.Features.Add(ft);
                }

                return(result);
            }
            catch (Exception e)
            {
                throw new CrudException(HttpStatusCode.BadRequest, "Get boundary wards Error!!!", e.InnerException?.Message);
            }
        }
コード例 #3
0
        public async Task <ListStreetSegmentResponse> GetStreetSegmentInRadius(string coor)
        {
            Geometry geom   = null;
            var      radius = _unitOfWork.Repository <Config>().GetAll().Where(x => x.Active && x.Name.Equals("BuildingRadius")).Select(x => x.Value).FirstOrDefault();// unit: meter StreetSegmentRadius

            try
            {
                geom = GeoJsonHelper.ParseStringToGeoMetry(coor);
                // s = c0/360; c0 = 40075.017
                var list = await _unitOfWork.Repository <StreetSegment>().GetAll().Where(x => (x.Geom.Distance(geom) * 40075.017 * 1000 / 360) <= radius).Select(x => new StreetSegmentResponse
                {
                    Name       = x.Name,
                    Geom       = x.Geom,
                    CreateDate = x.CreateDate,
                    ModifyDate = x.ModifyDate,
                    WardId     = x.WardId,
                    Id         = x.Id
                }).ToListAsync();

                return(new ListStreetSegmentResponse
                {
                    ListStreetSegment = list
                });
            }
            catch (Exception e)
            {
                throw new CrudException(HttpStatusCode.BadRequest, "Get Street Segment by Building Location Error!!!", e.InnerException?.Message);
            }
        }
コード例 #4
0
        public async Task <CheckBuidlingResponse> CheckBuildingInCampus(string coordinateString, Guid id)
        {
            Geometry geom = GeoJsonHelper.ParseStringToGeoMetry(coordinateString);
            CheckBuidlingResponse result = new CheckBuidlingResponse();
            bool isValid = true;

            try
            {
                var systemzones = await _unitOfWork.Repository <SystemZone>().GetAll().Where(x => x.AccountId == id).ToListAsync();

                var isInSystemzone  = systemzones.Any(x => x.Geom.Contains(geom));
                var isValidBuilding = !_unitOfWork.Repository <Building>().GetAll().Any(x => x.Geom.Intersects(geom));
                isValid = isValidBuilding && isInSystemzone;

                if (isValid)
                {
                    result.IsValid = true;
                    var campus = await _unitOfWork.Repository <Campus>().GetAll()
                                 .Where(x => x.Geom.Contains(geom))
                                 .Select(x => new CheckBuidlingResponse {
                        Id = x.Id, Name = x.Name
                    })
                                 .FirstOrDefaultAsync();

                    if (campus != null)
                    {
                        result.Name = campus.Name;
                        result.Id   = campus.Id;
                    }
                    else
                    {
                        var isIntersect = _unitOfWork.Repository <Campus>().GetAll()
                                          .Any(x => x.Geom.Intersects(geom));
                        if (isIntersect)
                        {
                            return(null);
                        }
                        else
                        {
                            result.Id = -1;
                        }
                    }
                }
                else
                {
                    return(null);
                }
                return(result);
            }
            catch (Exception e)
            {
                throw new CrudException(HttpStatusCode.BadRequest, "Check Building in Campus error", e.InnerException?.Message);
            }
        }
コード例 #5
0
        public bool CheckCampus(string coordinateString)
        {
            Geometry geom    = GeoJsonHelper.ParseStringToGeoMetry(coordinateString);
            bool     isValid = true;

            try
            {
                isValid = !_unitOfWork.Repository <Campus>().GetAll().Any(x => x.Geom.Intersects(geom));
                if (isValid)
                {
                    isValid = !_unitOfWork.Repository <Building>().GetAll().Any(x => x.Geom.Intersects(geom.Boundary));
                }
                return(isValid);
            }
            catch (Exception e)
            {
                throw new CrudException(HttpStatusCode.BadRequest, "Check New Campus error", e.InnerException?.Message);
            }
        }
コード例 #6
0
        public async Task <CustomFeatureCollection> GetStoreForMap(string coordinateString, int role)
        {
            try
            {
                Geometry geom = GeoJsonHelper.ParseStringToGeoMetry(coordinateString);
                CustomFeatureCollection result = new CustomFeatureCollection();
                geom.SRID = 4326;
                dynamic stores;
                if (role == 0 || role == 2)
                {
                    stores = await _unitOfWork.Repository <Store>().GetAll().Where(x => geom.Contains(x.Geom) && x.Status != (int?)Status.Deleted &&
                                                                                   x.Status != (int?)Status.Reject &&
                                                                                   x.Status != (int?)Status.WaitingUpdate && x.FloorAreaId == null).
                             Select(x => new { x.Geom, SegmentName = x.Brand.Segment.Name, x.Id, x.Status, x.Name }).AsNoTracking()
                             .ToListAsync();
                }
                else
                {
                    stores = await _unitOfWork.Repository <Store>().GetAll().Where(x => geom.Contains(x.Geom) && x.Status == (int?)Status.Surveyed || x.Status == (int?)Status.WaitingUpdate)
                             .Select(x => new { x.Geom, SegmentName = x.Brand.Segment.Name, x.Id, x.Status, x.Name }).AsNoTracking()
                             .ToListAsync();
                }

                foreach (var item in stores)
                {
                    Feature ft = new Feature
                    {
                        Geometry = item.Geom
                    };
                    ft.Properties.F1 = item.SegmentName;
                    ft.Properties.F2 = item.Name;
                    ft.Properties.F4 = item.Id;
                    ft.Properties.F3 = item.Status;
                    result.Features.Add(ft);
                }
                return(result);
            }
            catch (Exception e)
            {
                throw new CrudException(HttpStatusCode.BadRequest, "Get Store Error!!!", e.InnerException?.Message);
            }
        }
コード例 #7
0
        public async Task <CustomFeatureCollection> GetBuildingForMap(string coordinateString, int role)
        {
            try
            {
                Geometry geom = GeoJsonHelper.ParseStringToGeoMetry(coordinateString);
                CustomFeatureCollection result = new CustomFeatureCollection();
                geom.SRID = 4326;
                dynamic buildings;
                // List<Building> buildings = null;
                if (role == 0 || role == 2)
                {
                    buildings = await _unitOfWork.Repository <Building>().GetAll().Where(x => geom.Contains(x.Geom) && x.Status != (int?)Status.Deleted && x.Status != (int?)Status.WaitingUpdate && x.Status != (int?)Status.Reject).Select(x => new { x.Name, Type = x.Type.Name, x.Status, x.Id, x.Geom }).AsNoTracking().ToListAsync();
                }
                else
                {
                    buildings = await _unitOfWork.Repository <Building>().GetAll().Where(x => geom.Contains(x.Geom) && (x.Status == (int?)Status.Surveyed || x.Status == (int?)Status.WaitingUpdate)).Select(x => new { x.Name, Type = x.Type.Name, x.Status, x.Id, x.Geom }).AsNoTracking().ToListAsync();
                }

                foreach (var item in buildings)
                {
                    Feature ft = new Feature
                    {
                        Geometry = item.Geom,
                    };
                    ft.Properties.F1 = item.Type;
                    ft.Properties.F2 = item.Name;
                    ft.Properties.F3 = item.Status;
                    ft.Properties.F4 = item.Id;
                    ft.Properties.F5 = item.Geom.Centroid.AsText();
                    result.Features.Add(ft);
                }
                return(result);
            }
            catch (Exception e)
            {
                throw new CrudException(HttpStatusCode.BadRequest, "Get building Error!!!", e.InnerException?.Message);
            }
        }