Example #1
0
        public List <GeographyPlace> GetNearestPlacesUsingGeography(double latitude, double longitude, double radius = 10, int limit = 10)
        {
            var         point                = DbGeography.FromText("POINT(" + longitude + " " + latitude + ")", 4326);
            var         topLeftLatitude      = 23.783726;
            var         topLeftLongitude     = 90.344245;
            var         bottomRightLatitude  = 23.685148;
            var         bottomRightLongitude = 90.492713;
            MapsContext context              = new MapsContext();
            var         datas                =
                context.GeographyPlaces.Where(x => x.Location.Distance(point) <= radius * 1000)
                .Take(limit)
                .OrderBy(x => x.Location.Distance(point));

            System.Data.Spatial.DbGeography polygon;
            try
            {
                polygon =
                    System.Data.Spatial.DbGeography.PolygonFromText(
                        "POLYGON((127.652 -26.244,127.652 -26.194,90.344245 23.783726,127.652 -26.244))",
                        4326);
            }
            catch (System.Exception ex)
            {
                throw;
            }
            //polygon.
            var result = datas.ToList();

            return(result);
        }
Example #2
0
 public static GeoLocation CreatePoint(DbGeography location)
 {
     var geoLocation = new GeoLocation();
     geoLocation.Latitude = location.Latitude.Value;
     geoLocation.Longitude = location.Longitude.Value;
     return geoLocation;
 }
        public virtual IQueryable<SupplierWithLocation> SuppliersWithinRangeUsingPoint(int? miles, DbGeography location)
        {
            var objectContext = ((IObjectContextAdapter)this).ObjectContext;
            objectContext.MetadataWorkspace.LoadFromAssembly(typeof(SupplierWithLocation).Assembly);

            return objectContext.CreateQuery<SupplierWithLocation>("[SpatialNorthwindContext].[SuppliersWithinRangeUsingPoint](@miles, @location)",
                                                                   new ObjectParameter("miles", miles),
                                                                   new ObjectParameter("location", location));
        }
Example #4
0
        internal SpatialGeography(DbGeography g, ICoordinateSystem coordinateSystem)
        {
            Debug.Assert(g!=null);
            if (g==null)
                throw new ArgumentNullException("g");

            _Geography=g;
            _CoordinateSystem=coordinateSystem;
        }
Example #5
0
        // Please set the following connection strings in app.config for this WebJob to run:
        // AzureWebJobsDashboard and AzureWebJobsStorage
        static void Main()
        {
            var host = new JobHost();

            Console.WriteLine("Subscriber Start");

            string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");

            SubscriptionClient Client = SubscriptionClient.CreateFromConnectionString(connectionString, "Storm", "StormSubcription");

            // Configure the callback options.
            OnMessageOptions options = new OnMessageOptions();

            options.AutoComplete = false;

            // options.AutoRenewTimeout = TimeSpan.FromMinutes(1);

            Client.OnMessage((message) =>
            {
                try
                {
                    var data = message.GetBody <string>();

                    WarnDataset warnDataset = JsonConvert.DeserializeObject <WarnDataset>(data);

                    System.Data.Entity.Spatial.DbGeography shape = DbGeography.PolygonFromText(warnDataset.SHAPE.ToString(), 4326);


                    //System.Data.Entity.Spatial.DbGeography shape= DbGeography.PolygonFromText("POLYGON ((-95.08 38.04, -95.08 37.86, -94.69 37.87, -94.66 38.03, -95.08 38.04))", 4326);

                    // This code will move to another project

                    using (var db = new DataLakeEntities())
                    {
                        int insertWeatherDatasets = db.uspInsertWarningData(warnDataset.WARNINGTYPE, warnDataset.MESSAGEID, shape, warnDataset.ZTIME_END, warnDataset.ZTIME_START, warnDataset.ID, warnDataset.ISSUEWFO);
                    }

                    // Remove message from subscription.
                    message.Complete();
                }

                catch (Exception ex)
                {
                    // Indicates a problem, unlock message in subscription.
                    message.Abandon();
                }
            }, options);



            Console.ReadLine();

            // The following code ensures that the WebJob will be running continuously
            host.RunAndBlock();
        }
        public void GetGeographyAsync_calls_GetGeography()
        {
            var mockDbSpatialDataReader = new Mock<DbSpatialDataReader> { CallBase = true };
            var dbGeography = new DbGeography();
            mockDbSpatialDataReader.Setup(m => m.GetGeography(0)).Returns((int ordinal) => dbGeography).Verifiable();

            var task = mockDbSpatialDataReader.Object.GetGeographyAsync(0, CancellationToken.None);

            mockDbSpatialDataReader.Verify(m => m.GetGeography(0), Times.Once());
            Assert.Same(dbGeography, task.Result);
        }
 private static ReadOnlySpatialValues CheckCompatible(DbGeography geographyValue)
 {
     DebugCheck.NotNull(geographyValue);
     if (geographyValue != null)
     {
         var expectedValue = geographyValue.ProviderValue as ReadOnlySpatialValues;
         if (expectedValue != null)
         {
             return expectedValue;
         }
     }
     throw new ArgumentException(Strings.Spatial_GeographyValueNotCompatibleWithSpatialServices, "geographyValue");
 }
 private static ReadOnlySpatialValues CheckCompatible(DbGeography geographyValue)
 {
     Debug.Assert(geographyValue != null, "Validate geographyValue is non-null before calling CheckCompatible");
     if (geographyValue != null)
     {
         var expectedValue = geographyValue.ProviderValue as ReadOnlySpatialValues;
         if (expectedValue != null)
         {
             return expectedValue;
         }
     }
     throw new ArgumentException(Strings.Spatial_GeographyValueNotCompatibleWithSpatialServices, "geographyValue");
 }
Example #9
0
 public override bool Intersects(DbGeography geographyValue, DbGeography otherGeography)
 {
     throw SpatialServicesUnavailable();
 }
Example #10
0
 public override double?GetLength(DbGeography geographyValue)
 {
     throw DefaultSpatialServices.SpatialServicesUnavailable();
 }
Example #11
0
 public override DbGeography Intersection(
     DbGeography geographyValue,
     DbGeography otherGeography)
 {
     throw DefaultSpatialServices.SpatialServicesUnavailable();
 }
Example #12
0
 public override bool SpatialEquals(DbGeography geographyValue, DbGeography otherGeography)
 {
     throw DefaultSpatialServices.SpatialServicesUnavailable();
 }
Example #13
0
 public override int?GetPointCount(DbGeography geographyValue)
 {
     throw SpatialServicesUnavailable();
 }
Example #14
0
 public override DbGeography GetStartPoint(DbGeography geographyValue)
 {
     throw SpatialServicesUnavailable();
 }
Example #15
0
 public override DbGeography Union(DbGeography geographyValue, DbGeography otherGeography)
 {
     throw SpatialServicesUnavailable();
 }
Example #16
0
 /// <summary> Computes the union of this DbGeography value and another DbGeography value. </summary>
 /// <returns>A new DbGeography value representing the union between this geography value and other.</returns>
 /// <param name="other">The geography value for which the union with this value should be computed.</param>
 public DbGeography Union(DbGeography other)
 {
     Check.NotNull(other, "other");
     return(_spatialProvider.Union(this, other));
 }
Example #17
0
 /// <summary> Computes the distance between the closest points in this DbGeography value and another DbGeography value. </summary>
 /// <returns>A double value that specifies the distance between the two closest points in this geography value and other.</returns>
 /// <param name="other">The geography value for which the distance from this value should be computed.</param>
 public double?Distance(DbGeography other)
 {
     Check.NotNull(other, "other");
     return(_spatialProvider.Distance(this, other));
 }
Example #18
0
 /// <summary> Determines whether this DbGeography value spatially intersects the specified DbGeography argument. </summary>
 /// <returns>true if other intersects this geography value; otherwise false.</returns>
 /// <param name="other">The geography value that should be compared with this geography value for intersection.</param>
 public bool Intersects(DbGeography other)
 {
     Check.NotNull(other, "other");
     return(_spatialProvider.Intersects(this, other));
 }
Example #19
0
 /// <summary> Determines whether this DbGeography is spatially disjoint from the specified DbGeography argument. </summary>
 /// <returns>true if other is disjoint from this geography value; otherwise false.</returns>
 /// <param name="other">The geography value that should be compared with this geography value for disjointness.</param>
 public bool Disjoint(DbGeography other)
 {
     Check.NotNull(other, "other");
     return(_spatialProvider.Disjoint(this, other));
 }
Example #20
0
 /// <summary> Determines whether this DbGeography is spatially equal to the specified DbGeography argument. </summary>
 /// <returns>true if other is spatially equal to this geography value; otherwise false.</returns>
 /// <param name="other">The geography value that should be compared with this geography value for equality.</param>
 public bool SpatialEquals(DbGeography other)
 {
     Check.NotNull(other, "other");
     return(_spatialProvider.SpatialEquals(this, other));
 }
Example #21
0
 public override DbGeography ElementAt(DbGeography geographyValue, int index)
 {
     throw DefaultSpatialServices.SpatialServicesUnavailable();
 }
Example #22
0
 public override DbGeography Buffer(DbGeography geographyValue, double distance)
 {
     throw SpatialServicesUnavailable();
 }
Example #23
0
 public override double Distance(DbGeography geographyValue, DbGeography otherGeography)
 {
     throw SpatialServicesUnavailable();
 }
Example #24
0
 /// <summary> Computes the symmetric difference of this DbGeography value and another DbGeography value. </summary>
 /// <returns>A new DbGeography value representing the symmetric difference between this geography value and other.</returns>
 /// <param name="other">The geography value for which the symmetric difference with this value should be computed.</param>
 public DbGeography SymmetricDifference(DbGeography other)
 {
     Check.NotNull(other, "other");
     return(_spatialProvider.SymmetricDifference(this, other));
 }
Example #25
0
 public override DbGeography SymmetricDifference(DbGeography geographyValue, DbGeography otherGeography)
 {
     throw SpatialServicesUnavailable();
 }
Example #26
0
 public override int?GetElementCount(DbGeography geographyValue)
 {
     throw DefaultSpatialServices.SpatialServicesUnavailable();
 }
Example #27
0
 public override bool?GetIsClosed(DbGeography geographyValue)
 {
     throw SpatialServicesUnavailable();
 }
 /// <summary>
 ///     Returns the number of points in the given <see cref="T:System.Data.Entity.Spatial.DbGeography" /> value, if it represents a linestring or linear ring.
 /// </summary>
 /// <returns>
 ///     The number of points in the given <see cref="T:System.Data.Entity.Spatial.DbGeography" /> value.
 /// </returns>
 /// <param name="geographyValue">The geography value, which need not represent a linestring or linear ring.</param>
 /// <exception cref="ArgumentNullException">
 ///     <paramref name="geographyValue" />
 ///     is null.
 /// </exception>
 /// <exception cref="ArgumentException">
 ///     <paramref name="geographyValue" />
 ///     is not compatible with this spatial services implementation.
 /// </exception>
 public abstract int? GetPointCount(DbGeography geographyValue);
Example #29
0
 public override DbGeography PointAt(DbGeography geographyValue, int index)
 {
     throw SpatialServicesUnavailable();
 }
 public static string DistanceFromMe(this Center center, DbGeography point)
 {
     return ( (center.Coordinates != null && point!=null )? 
         String.Format("{0:0.##} km", (center.Coordinates.Distance(point)) / 1000) : "-");
 }
Example #31
0
 public override DbGeography Difference(
     DbGeography geographyValue,
     DbGeography otherGeography)
 {
     throw DefaultSpatialServices.SpatialServicesUnavailable();
 }
Example #32
0
 public override bool Disjoint(DbGeography geographyValue, DbGeography otherGeography)
 {
     throw SpatialServicesUnavailable();
 }
Example #33
0
 public override int GetDimension(DbGeography geographyValue)
 {
     throw SpatialServicesUnavailable();
 }
Example #34
0
 public override DbGeography GetEndPoint(DbGeography geographyValue)
 {
     throw DefaultSpatialServices.SpatialServicesUnavailable();
 }
Example #35
0
 public override string GetSpatialTypeName(DbGeography geographyValue)
 {
     throw SpatialServicesUnavailable();
 }
Example #36
0
 public override bool GetIsEmpty(DbGeography geographyValue)
 {
     throw SpatialServicesUnavailable();
 }
 /// <summary>
 ///     Returns a point element of the given <see cref="T:System.Data.Entity.Spatial.DbGeography" /> value, if it represents a linestring or linear ring.
 /// </summary>
 /// <returns>The point in geographyValue at position index, if it represents a linestring or linear ring; otherwise null.</returns>
 /// <param name="geographyValue">The geography value, which need not represent a linestring or linear ring.</param>
 /// <param name="index">The position within the geography value from which the element should be taken.</param>
 /// <exception cref="ArgumentNullException">
 ///     <paramref name="geographyValue" />
 ///     is null.
 /// </exception>
 /// <exception cref="ArgumentException">
 ///     <paramref name="geographyValue" />
 ///     is not compatible with this spatial services implementation.
 /// </exception>
 public abstract DbGeography PointAt(DbGeography geographyValue, int index);
Example #38
0
 public override double?GetArea(DbGeography geographyValue)
 {
     throw SpatialServicesUnavailable();
 }
        private void PropertyDelegationHelper(
            Func<DbGeography, object> operation, 
            Expression<Action<DbSpatialServices>> verification)
        {
            var spatialProviderMock = new Mock<DbSpatialServices>();
            var geography = new DbGeography(spatialProviderMock.Object, DbGeography.FromText("POINT(1 1)"));
            var result = operation(geography);

            spatialProviderMock.Verify(verification, Times.Once());
        }
Example #40
0
 /// <summary> Determines whether this DbGeography is spatially disjoint from the specified DbGeography argument. </summary>
 /// <returns>true if other is disjoint from this geography value; otherwise false.</returns>
 /// <param name="other">The geography value that should be compared with this geography value for disjointness.</param>
 public bool Disjoint(DbGeography other)
 {
     Check.NotNull(other, "other");
     return _spatialProvider.Disjoint(this, other);
 }
Example #41
0
 /// <summary> Determines whether this DbGeography value spatially intersects the specified DbGeography argument. </summary>
 /// <returns>true if other intersects this geography value; otherwise false.</returns>
 /// <param name="other">The geography value that should be compared with this geography value for intersection.</param>
 public bool Intersects(DbGeography other)
 {
     Check.NotNull(other, "other");
     return _spatialProvider.Intersects(this, other);
 }
 public static Int32? NumRings(DbGeography geographyValue)
 {
     throw new NotSupportedException(Strings.ELinq_DbFunctionDirectCall);
 }
Example #43
0
 /// <summary> Determines whether this DbGeography is spatially equal to the specified DbGeography argument. </summary>
 /// <returns>true if other is spatially equal to this geography value; otherwise false.</returns>
 /// <param name="other">The geography value that should be compared with this geography value for equality.</param>
 public bool SpatialEquals(DbGeography other)
 {
     Check.NotNull(other, "other");
     return _spatialProvider.SpatialEquals(this, other);
 }
 public ParameterModel Geography(
     DbGeography defaultValue = null,
     string defaultValueSql = null,
     string name = null,
     string storeType = null,
     bool outParameter = false)
 {
     return BuildParameter(
         PrimitiveTypeKind.Geography,
         defaultValue,
         defaultValueSql,
         name: name,
         storeType: storeType,
         outParameter: outParameter);
 }
 /// <summary>
 /// Generates SQL to specify a constant geogrpahy default value being set on a column.
 /// This method just generates the actual value, not the SQL to set the default value.
 /// </summary>
 /// <param name="defaultValue"> The value to be set. </param>
 /// <returns> SQL representing the default value. </returns>
 protected virtual string Generate(DbGeography defaultValue)
 {
     return "'" + defaultValue + "'";
 }
 public static DbGeography BufferWithTolerance(DbGeography geographyValue, Double? distance, Double? tolerance, Boolean? relative)
 {
     throw new NotSupportedException(Strings.ELinq_DbFunctionDirectCall);
 }
Example #47
0
 /// <summary> Computes the symmetric difference of this DbGeography value and another DbGeography value. </summary>
 /// <returns>A new DbGeography value representing the symmetric difference between this geography value and other.</returns>
 /// <param name="other">The geography value for which the symmetric difference with this value should be computed.</param>
 public DbGeography SymmetricDifference(DbGeography other)
 {
     Check.NotNull(other, "other");
     return _spatialProvider.SymmetricDifference(this, other);
 }
 public static DbGeography RingN(DbGeography geographyValue, Int32? index)
 {
     throw new NotSupportedException(Strings.ELinq_DbFunctionDirectCall);
 }
 public static String AsTextZM(DbGeography geographyValue)
 {
     throw new NotSupportedException(Strings.ELinq_DbFunctionDirectCall);
 }
 public static DbGeography Reduce(DbGeography geographyValue, Double? tolerance)
 {
     throw new NotSupportedException(Strings.ELinq_DbFunctionDirectCall);
 }
 /// <summary>
 /// Generates code to specify the default value for a <see cref="DbGeography" /> column.
 /// </summary>
 /// <param name="defaultValue"> The value to be used as the default. </param>
 /// <returns> Code representing the default value. </returns>
 protected virtual string Generate(DbGeography defaultValue)
 {
     return "DbGeography.FromText(\"" + defaultValue.AsText() + "\", " + defaultValue.CoordinateSystemId + ")";
 }
 public static IQueryable<SupplierWithLocation> StaticSuppliersWithinRange(int? miles, DbGeography location)
 {
     throw new NotImplementedException("Should not be called by client code.");
 }
Example #53
0
 /// <summary> Computes the distance between the closest points in this DbGeography value and another DbGeography value. </summary>
 /// <returns>A double value that specifies the distance between the two closest points in this geography value and other.</returns>
 /// <param name="other">The geography value for which the distance from this value should be computed.</param>
 public double? Distance(DbGeography other)
 {
     Check.NotNull(other, "other");
     return _spatialProvider.Distance(this, other);
 }
 public static DbGeography EnvelopeCenter(DbGeography geographyValue)
 {
     throw new NotSupportedException(Strings.ELinq_DbFunctionDirectCall);
 }
Example #55
0
 /// <summary> Computes the union of this DbGeography value and another DbGeography value. </summary>
 /// <returns>A new DbGeography value representing the union between this geography value and other.</returns>
 /// <param name="other">The geography value for which the union with this value should be computed.</param>
 public DbGeography Union(DbGeography other)
 {
     Check.NotNull(other, "other");
     return _spatialProvider.Union(this, other);
 }
 public static Boolean? Filter(DbGeography geographyValue, DbGeography geographyOther)
 {
     throw new NotSupportedException(Strings.ELinq_DbFunctionDirectCall);
 }
        /// <summary>
        /// Returns the first <see cref="Rock.Model.Location"/> with a GeoFence that matches
        /// the specified GeoFence.
        /// </summary>
        /// <param name="fence">A <see cref="System.Data.Entity.Spatial.DbGeography"/> object that 
        ///  represents the GeoFence of the location to retrieve.</param>
        /// <returns>The <see cref="Rock.Model.Location"/> for the specified GeoFence. </returns>
        public Location GetByGeoFence( DbGeography fence )
        {

            // get the first address that has a GeoPoint or GeoFence that matches the value
            var result = Queryable()
                .Where( a => 
                    a.GeoFence != null &&
                    a.GeoFence.SpatialEquals( fence ) )
                .FirstOrDefault();

            if ( result == null )
            {
                // if the Location can't be found, save the new location to the database
                Location newLocation = new Location
                {
                    GeoFence = fence,
                    Guid = Guid.NewGuid()
                };

                // Create a new context/service so that save does not affect calling method's context
                var rockContext = new RockContext();
                var locationService = new LocationService( rockContext );
                locationService.Add( newLocation );
                rockContext.SaveChanges();

                // refetch it from the database to make sure we get a valid .Id
                return Get( newLocation.Guid );
            }

            return result;

        }
 public static Boolean? InstanceOf(DbGeography geographyValue, String geometryTypeName)
 {
     throw new NotSupportedException(Strings.ELinq_DbFunctionDirectCall);
 }
Example #59
0
 public override string AsGml(DbGeography geographyValue)
 {
     Check.NotNull <DbGeography>(geographyValue, nameof(geographyValue));
     return(DefaultSpatialServices.CheckCompatible(geographyValue).GML);
 }
Example #60
-1
        private void addReference(Placemark placemark, SharpKml.Dom.Point point, DbGeography coordinates)
        {
            LANDMARK landmark = new LANDMARK();
            LANDMARK_KNOWN_AS knowAsLandmark;

            knowAsLandmark = new LANDMARK_KNOWN_AS();

            knowAsLandmark.Known_As_Description = placemark.Name;
            landmark.Landmark_Coordinates = coordinates;
            knowAsLandmark.LANDMARK = landmark;
            knowAsLandmark.Known_As_ID = count = count + 1;

            DBLandmarkKnownAs db = new DBLandmarkKnownAs(context);
            db.Add(knowAsLandmark);

            if (placemark.Description != null)
            {
                string[] description = placemark.Description.Text.Split(';');

                for (int i = 0; i < description.Count(); i++)
                {
                    knowAsLandmark = new LANDMARK_KNOWN_AS();

                    knowAsLandmark.Known_As_Description = description[i];
                    landmark.Landmark_Coordinates = coordinates;
                    knowAsLandmark.Known_As_ID = count = count + 1;

                    knowAsLandmark.LANDMARK = landmark;

                    db = new DBLandmarkKnownAs(context);
                    db.Add(knowAsLandmark);
                }
            }
        }