public static DbGeography CreatePoint(double lat, double lon, int srid = 4326) { string wkt = String.Format("POINT({1} {0})", lat, lon); wkt = wkt.Replace(",", "."); return(DbGeography.PointFromText(wkt, srid)); }
private static DbGeography GetRandomPointInZone(DbGeography validZone, Random rnd) { DbGeography pos = null; double minlat = double.MaxValue; double maxlat = double.MinValue; double minlon = double.MaxValue; double maxlon = double.MinValue; for (int i = 1; i <= validZone.PointCount; i++) { var point = validZone.PointAt(i); if (point.Latitude != null && minlat > point.Latitude) minlat = (double)point.Latitude; if (point.Longitude != null && minlon > point.Longitude) minlon = (double)point.Longitude; if (point.Latitude != null && maxlat < point.Latitude) maxlat = (double)point.Latitude; if (point.Longitude != null && maxlon < point.Longitude) maxlon = (double)point.Longitude; } int retry = 0; while (pos == null || !pos.Intersects(validZone)) //Aquí comprobamos que la posición aleatoria está dentro de la zona. { var latitude = GetRandomDouble(rnd, minlat, maxlat); var longitude = GetRandomDouble(rnd, minlon, maxlon); var wkt = String.Format("POINT({0} {1})", longitude.ToString(CultureInfo.InvariantCulture), latitude.ToString(CultureInfo.InvariantCulture)); pos = DbGeography.PointFromText(wkt, 4326); retry++; if (retry > 1000) throw new Exception("Parece un bucle infinito, tras 1000 reintentos no se ha podido obtener una posición dentro de la zona válida"); } return pos; }
/// <summary> /// Create a GeoLocation point based on latitude and longitude /// </summary> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <returns></returns> public static DbGeography CreatePoint(double latitude, double longitude) { var text = string.Format("POINT({0} {1})", longitude, latitude); // 4326 is most common coordinate system used by GPS/Maps return(DbGeography.PointFromText(text, 4326)); }
private static DbGeography CreatePoint(double latitude, double longitude) { var point = string.Format(CultureInfo.InvariantCulture.NumberFormat, "POINT({0} {1})", longitude, latitude); // 4326 is most common coordinate system used by GPS/Maps return(DbGeography.PointFromText(point, 4326)); }
public static DbGeography MakeDbGeographyFromLatLon(double longitude, double latitude, int coordinateSystemId) { var geography = DbGeography.PointFromText($"POINT({longitude} {latitude})", coordinateSystemId); return(geography); }
public static DbGeography MakeDbGeographyFromLatLon(double longitude, double latitude, int coordinateSystemId) { var geography = DbGeography.PointFromText(string.Format("POINT({0} {1})", longitude, latitude), coordinateSystemId); return(geography); }
public static DbGeography RetornarLocation(decimal latitude, decimal longitude) { var text = string.Format("POINT({0} {1})", longitude, latitude); // 4326 is most common coordinate system used by GPS/Maps return(DbGeography.PointFromText(text.Replace(',', '.'), 4326)); }
public static DbGeography ToPoint(Double latitude, Double longitude) { String lon = NormalizeLongitude(longitude).ToString(CultureInfo.InvariantCulture); String lat = NormalizeLatitude(latitude).ToString(CultureInfo.InvariantCulture); return(DbGeography.PointFromText(string.Format("POINT({0} {1})", lon, lat), DbGeography.DefaultCoordinateSystemId)); }
/// <summary> /// Create a GeoLocation point based on latitude and longitude /// </summary> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <param name="coordinateSystemId">The identifier of the coordinate system that the new DbGeography value should use.</param> /// <returns></returns> public static DbGeography CreatePoint(double latitude, double longitude, int coordinateSystemId = 4326) { var text = $"POINT({longitude} {latitude})"; // 4326 is most common coordinate system used by GPS/Maps return(DbGeography.PointFromText(text, coordinateSystemId)); }
internal void StoreHeatmapPoints(IEnumerable <PictureDTO> pictures, FilterResultDTO.CaracteristicType filterType) { ApplicationDbContext db = new ApplicationDbContext(); foreach (var picture in pictures.GroupBy(x => x.panoID).Select(g => g.First()).ToList()) { var lat = picture.location.lat.ToString(CultureInfo.InvariantCulture); var lon = picture.location.lng.ToString(CultureInfo.InvariantCulture); var geo = DbGeography.PointFromText(string.Format("POINT({0} {1})", lon, lat), 4326); var density = (float?)(picture.filterResults.FirstOrDefault(r => r.Type == filterType).Density); var newPoint = new HeatmapPointModel() { ID = picture.panoID, coordinates = geo, TreesDensity = filterType == FilterResultDTO.CaracteristicType.Trees ? density : null, CracksDensity = filterType == FilterResultDTO.CaracteristicType.Cracks ? density : null }; var oldPoint = db.HeatmapPointModel.FirstOrDefault(p => p.ID == newPoint.ID); if (oldPoint != null) { oldPoint.TreesDensity = newPoint.TreesDensity ?? oldPoint.TreesDensity; oldPoint.CracksDensity = newPoint.CracksDensity ?? oldPoint.TreesDensity; db.Entry <HeatmapPointModel>(oldPoint).State = System.Data.Entity.EntityState.Modified; } else { db.HeatmapPointModel.Add(newPoint); } } db.SaveChanges(); db.Dispose(); }
internal ACTransit.DataAccess.RestroomFinder.Restroom ToDataAccess() { return(new ACTransit.DataAccess.RestroomFinder.Restroom { ACTRoute = ACTRoute, Address = Address, City = City, Country = Country, DrinkingWater = DrinkingWater, Geo = DbGeography.PointFromText(String.Format("POINT({0} {1})", LongDec, LatDec), 4326), LatDec = LatDec, LongDec = LongDec, Note = Note, WeekdayHours = WeekdayHours, SaturdayHours = SaturdayHours, SundayHours = SundayHours, NearestIntersection = NearestIntersection, RestroomName = RestroomName, RestroomId = RestroomId, RestroomType = RestroomType, IsToiletAvailable = IsToiletAvailable, State = State, Zip = Zip, IsPublic = IsPublic, AverageRating = AverageRating, AddDateTime = DateTime.Now, StatusListId = Active ? (Approved ? (int)RestroomEnums.RestroomApprovalStatus.Approved : (int)RestroomEnums.RestroomApprovalStatus.Pending) : (int)RestroomEnums.RestroomApprovalStatus.InActive, ToiletGenderId = ToiletGenderId, AddressChanged = AddressChanged, LabelId = LabelId, }); }
private User FillUserByViewModel(RegisterVeiwModel register) { var user = new User() { Status = 1, Roles = "User", Wallet = 0, Username = register.Username.ToLower().Trim(), Password = register.Password.Encrypt(), Dateofbirth = register.PersianDateofbirth.ToMiladiDate(), Biography = register.Biography, Email = register.Email, Gender = register.Gender, Location = register.Location, Name = register.Name, Phone = register.Phone, PersianDateofbirth = register.PersianDateofbirth }; if (register.leafletViewwModel.Lat != null && register.leafletViewwModel.Lng != null) { string strPointWellKnownText = string.Format(CultureInfo.InvariantCulture.NumberFormat, "POINT({0} {1})", register.leafletViewwModel.Lng, register.leafletViewwModel.Lat); DbGeography oDbGeography = DbGeography.PointFromText (pointWellKnownText: strPointWellKnownText, coordinateSystemId: 4326); user.GeoLocation = oDbGeography; } return(user); }
internal ACTransit.DataAccess.RestroomFinder.Restroom ToDataAccessFrom(ACTransit.DataAccess.RestroomFinder.Restroom restroom) { restroom.ACTRoute = ACTRoute; restroom.Address = Address; restroom.City = City; restroom.Country = Country; restroom.DrinkingWater = DrinkingWater; restroom.Geo = DbGeography.PointFromText(String.Format("POINT({0} {1})", LongDec, LatDec), 4326); restroom.LatDec = LatDec; restroom.LongDec = LongDec; restroom.Note = Note; restroom.WeekdayHours = WeekdayHours; restroom.SaturdayHours = SaturdayHours; restroom.SundayHours = SundayHours; restroom.NearestIntersection = NearestIntersection; restroom.RestroomName = RestroomName; restroom.RestroomType = RestroomType; restroom.IsToiletAvailable = IsToiletAvailable; restroom.State = State; restroom.Zip = Zip; restroom.IsPublic = IsPublic; restroom.AverageRating = AverageRating; restroom.UpdDateTime = DateTime.Now; restroom.StatusListId = Active?(Approved ? (int)RestroomEnums.RestroomApprovalStatus.Approved : (int)RestroomEnums.RestroomApprovalStatus.Pending):(int)RestroomEnums.RestroomApprovalStatus.InActive; restroom.ToiletGenderId = ToiletGenderId; restroom.AddressChanged = AddressChanged; restroom.LabelId = LabelId; return(restroom); }
public JsonResult GetNearPoints(string lat, string lng) { string result = string.Empty; var text = string.Format(CultureInfo.InvariantCulture.NumberFormat, "POINT({0} {1})", lng, lat); DbGeography sourcePoint = DbGeography.PointFromText(text, 4326); using (SeguricelEntities db = new SeguricelEntities()) { var matches = db.Contrato .Where(x => x.UbicacionGeografica.Distance(sourcePoint) < 15000) .OrderBy(x => x.UbicacionGeografica.Distance(sourcePoint)) .Select(x => new { Edificio = x.NombreCompleto, Latitud = x.UbicacionGeografica.Latitude, Longitud = x.UbicacionGeografica.Longitude, Distancia = x.UbicacionGeografica.Distance(sourcePoint) }); foreach (var location in matches) { string mtoK = MetersToKms(location.Distancia).ToString(); result += string.Format("{0};{1};{2};{3:n1}/", location.Edificio, location.Latitud.ToString().Replace(",", "."), location.Longitud.ToString().Replace(",", "."), mtoK); } } return(Json(result)); }
public static DbGeography PointFromLatLng(double lat, double lng) { return(DbGeography.PointFromText( "POINT(" + lng.ToString(CultureInfo.InvariantCulture) + " " + lat.ToString(CultureInfo.InvariantCulture) + ")", SridGoogleMaps)); }
/// <summary> /// Create a GeoLocation point based on latitude and longitude /// </summary> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <returns></returns> public static DbGeography CreatePoint(double latitude, double longitude) { string lat = latitude.ToString(CultureInfo.InvariantCulture); string lon = longitude.ToString(CultureInfo.InvariantCulture); var text = string.Format("POINT({0} {1})", lon, lat); return(DbGeography.PointFromText(text, 4326)); }
public static DbGeography getCircle(Models.Coordinates coords, double km) { string textPoint = String.Format("POINT ({0} {1})", coords.Lng, coords.Lat); DbGeography point = DbGeography.PointFromText(textPoint, DbGeography.DefaultCoordinateSystemId); //4326 = [WGS84] DbGeography targetCircle = point.Buffer(km); return(targetCircle); }
private static DbGeography GetDbGeographyFromPoint(JToken geometry) { JArray coordinates = geometry.SelectToken("coordinates").Value<JArray>(); double x = coordinates[0].Value<double>(); double y = coordinates[1].Value<double>(); string pointText = string.Concat( "POINT(", x.ToString(culture), " ", y.ToString(culture), ")"); return DbGeography.PointFromText(pointText, 4326); }
public async Task <IEnumerable <TrackingPoint> > GetNearestPoints(int tripId, IPoint point, int count) { var data = await this.FindBy(a => a.TripId == tripId) .OrderBy(p => p.Location.Distance( DbGeography.PointFromText("POINT(" + point.Longitude + " " + point.Latitude + ")", 4326))) .Take(count) .ToListAsync(); return(data.Select(d => this.ObjectMapper.Map <TrackingPoint>(d))); }
public static DbGeography PointFromGeoPoint(StockServer.BL.Model.Geolocation geoPoint) { var nfi = new NumberFormatInfo { NumberDecimalSeparator = "." }; string text = $"POINT({geoPoint.Longitude.ToString(nfi)} {geoPoint.Latitude.ToString(nfi)})"; return(DbGeography.PointFromText(text, DEFAULT_COORDINATE_SYSTEM)); }
public static VehicleTracking.DataRepository.Tracking ToEntity(this VehicleTracking.Common.DTO.Tracking dto) { var entity = new VehicleTracking.DataRepository.Tracking(); entity.TrackingID = dto.ID; entity.VehicleID = dto.VehicleID; entity.TrackingTime = dto.Time; entity.Location = DbGeography.PointFromText($"Point({dto.Long} {dto.Lat})", 4326); // 4326 represents WGS84 Datum projection system. Google Map uses this projection system. Usage of Geography type will open possibilities to execute geographical queries directly on database. return(entity); }
public Place ToDALModel(PlaceEntity place) { Place placeDAL = new Place() { Name = place.Name, Location = DbGeography.PointFromText(String.Format("POINT({0} {1})", place.Location.Longitude.ToString().Replace(',', '.'), place.Location.Latitude.ToString().Replace(',', '.')), 4326) }; return(placeDAL); }
/// <summary> /// Create a GeoLocation point based on latitude and longitude /// </summary> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <returns></returns> public static DbGeography CreatePoint(double latitude, double longitude) { // в русском языке по умолчанию разделители десятичных знаков - запятые // POINT (lon lat) var text = $"POINT({longitude.ToString(CultureInfo.InvariantCulture)} " + $"{latitude.ToString(CultureInfo.InvariantCulture)})"; // 4326 is most common coordinate system used by GPS/Maps return(DbGeography.PointFromText(text, CoordinateSystem)); }
public DbGeography CreatePoint(double?lat, double?lon, int srid = 4326) { if (lat.HasValue && lon.HasValue) { string wkt = String.Format("POINT({0} {1})", lon, lat); return(DbGeography.PointFromText(wkt, srid)); } return(null); }
private double GetDistance(double lat1, double lng1, double lat2, double lng2) { int srid = 4326; string wkt = $"POINT({lat1} {lng1})"; var geoPointA = DbGeography.PointFromText($"POINT({lat1} {lng1})", srid); var geoPointB = DbGeography.PointFromText($"POINT({lat2} {lng2})", srid); var distance = geoPointA.Distance(geoPointB); return(distance ?? 0); }
public bool Edit(LeafletViewModel leaflet) { var me = GetCurentUser(); string strPointWellKnownText = string.Format(CultureInfo.InvariantCulture.NumberFormat, "POINT({0} {1})", leaflet.Lng, leaflet.Lat); DbGeography oDbGeography = DbGeography.PointFromText (pointWellKnownText: strPointWellKnownText, coordinateSystemId: 4326); me.GeoLocation = oDbGeography; me.Location = leaflet.Address; return(_userRepository.Update(me)); }
private static DbGeography CreateDbGeography(double?latitude, double?longitude) { if (latitude == null || longitude == null) { return(null); } var text = string.Format(CultureInfo.InvariantCulture.NumberFormat, "POINT({0} {1})", longitude, latitude); // 4326 is most common coordinate system used by GPS/Maps return(DbGeography.PointFromText(text, 4326)); }
/// <summary> /// Create a GeoLocation point based on latitude and longitude /// </summary> /// <param name="latitudeLongitude"> /// String should be two values either single comma or space delimited /// 45.710030,-121.516153 /// 45.710030 -121.516153 /// </param> /// <returns></returns> public static DbGeography CreatePoint(string latitudeLongitude) { var tokens = latitudeLongitude.Split(',', ' '); if (tokens.Length != 2) { throw new ArgumentException(Resources.InvalidLocationStringPassed); } var text = string.Format("POINT({0} {1})", tokens[1], tokens[0]); return(DbGeography.PointFromText(text, 4326)); }
private void SetupActiveTourAndNextPOI(int userID, int userTourID, int nextPOIID) { var activeTour = new UserTour { Id = userTourID }; var nextPOI = new POI { Id = nextPOIID, Coordinates = DbGeography.PointFromText("POINT(34 3)", 4326) }; _userTourRepoMock.Setup(m => m.GetActiveTour(userID)).Returns(activeTour); _userPoiRepoMock.Setup(m => m.GetNextPOI(activeTour)).Returns(nextPOI); }
/// <summary> /// Create a GeoLocation point based on latitude and longitude /// </summary> /// <param name="latitudeLongitude"> /// String should be two values either single comma or space delimited /// 45.710030,-121.516153 /// 45.710030 -121.516153 /// </param> /// <returns></returns> public static DbGeography CreatePoint(string latitudeLongitude) { var tokens = latitudeLongitude.Split(',', ' '); if (tokens.Length != 2) { throw new ArgumentException("Invalid location string passed"); } var text = $"POINT({tokens[1]} {tokens[0]})"; return(DbGeography.PointFromText(text, CoordinateSystem)); }