예제 #1
0
 public static void Seed(SpatialContext context, GeometryFactory factory)
 {
     context.AddRange(SpatialData.CreatePointEntities(factory));
     context.AddRange(SpatialData.CreateGeoPointEntities());
     context.AddRange(SpatialData.CreateLineStringEntities(factory));
     context.AddRange(SpatialData.CreatePolygonEntities(factory));
     context.AddRange(SpatialData.CreateMultiLineStringEntities(factory));
     context.SaveChanges();
 }
예제 #2
0
        static void Main()
        {
            using (var db = new SpatialContext())
            {
                db.Database.EnsureDeleted();
                db.Database.EnsureCreated();

                db.AddRange(
                    new Location {
                    Coordinates = new Point(0, 0)
                    {
                        SRID = 4326
                    }, City = "Sao Paulo"
                },
                    new Location {
                    Coordinates = new Point(1, 1)
                    {
                        SRID = 4326
                    }, City = "Aracaju"
                });
                db.SaveChanges();


                var aracajuLocation = new Point(1, 1)
                {
                    SRID = 4326
                };
                var nearestMesurements =
                    from m in db.Locations
                    where m.Coordinates.Distance(aracajuLocation) < 2
                    select m;

                foreach (var m in nearestMesurements)
                {
                    Console.WriteLine(m.City);
                }
            }

            Console.WriteLine();
            Console.ReadKey(intercept: true);
        }