コード例 #1
0
        public void SearchGeoIntersects()
        {
            var connection = TestConfiguration.GetConnection();
            var dbSet      = new MongoDbSet <SearchGeoModel>();

            dbSet.SetConnection(connection);

            dbSet.AddRange(new SearchGeoModel[]
            {
                new SearchGeoModel {
                    Description = "New York", PrimaryCoordinates = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(
                        new GeoJson2DGeographicCoordinates(-74.005974, 40.712776)
                        )
                },
                new SearchGeoModel {
                    Description = "Adelaide", PrimaryCoordinates = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(
                        new GeoJson2DGeographicCoordinates(138.600739, -34.928497)
                        )
                },
                new SearchGeoModel {
                    Description = "Sydney", PrimaryCoordinates = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(
                        new GeoJson2DGeographicCoordinates(151.209290, -33.868820)
                        )
                },
                new SearchGeoModel {
                    Description = "Melbourne", PrimaryCoordinates = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(
                        new GeoJson2DGeographicCoordinates(144.963058, -37.813629)
                        )
                },
                new SearchGeoModel {
                    Description = "Darwin", PrimaryCoordinates = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(
                        new GeoJson2DGeographicCoordinates(-95.582413, 37.095142)
                        )
                },
                new SearchGeoModel {
                    Description = "Brisbane", PrimaryCoordinates = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(
                        new GeoJson2DGeographicCoordinates(153.025131, -27.469770)
                        )
                }
            });
            dbSet.SaveChanges();

            var results = dbSet.SearchGeoIntersecting(e => e.PrimaryCoordinates, new GeoJsonPolygon <GeoJson2DGeographicCoordinates>(
                                                          new GeoJsonPolygonCoordinates <GeoJson2DGeographicCoordinates>(
                                                              new GeoJsonLinearRingCoordinates <GeoJson2DGeographicCoordinates>(
                                                                  new[]
            {
                new GeoJson2DGeographicCoordinates(115.860458, -31.950527),                                        //Perth
                new GeoJson2DGeographicCoordinates(147.327194, -42.882137),                                        //Hobart
                new GeoJson2DGeographicCoordinates(153.399994, -28.016666),                                        //Gold Coast

                new GeoJson2DGeographicCoordinates(115.860458, -31.950527)                                         //Wrap back to first point
            }
                                                                  )
                                                              )
                                                          )).ToArray();

            Assert.AreEqual(3, results.Count());
            Assert.IsTrue(results.Any(e => e.Description == "Adelaide"));
            Assert.IsTrue(results.Any(e => e.Description == "Melbourne"));
            Assert.IsTrue(results.Any(e => e.Description == "Sydney"));
        }