diff --git a/README.md b/README.md index 59f305fd..5b56dd70 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ We have separate folders for the samples of individual modules: * `example` - Example project for general repository functionality (including geo-spatial functionality), Querydsl integration and advanced topics. * `aggregation` - Example project to showcase the MongoDB aggregation framework support. * `text-search` - Example project showing usage of MongoDB text search feature. +* `geo-json` - Example project showing usage of [GeoJSON](http://geojson.org) with MongoDB. ## Spring Data REST diff --git a/mongodb/geo-json/README.md b/mongodb/geo-json/README.md new file mode 100644 index 00000000..bbd65c2c --- /dev/null +++ b/mongodb/geo-json/README.md @@ -0,0 +1,81 @@ +# Spring Data MongoDB - GeoJSON examples + +This project contains samples of [GeoJSON](http://geojeson.org) specific features of Spring Data (MongoDB). + +## Support for GeoJSON types in domain classes + +Using [GeoJSON](http://geojeson.org) types in domain classes is straight forward. The `org.springframework.data.mongodb.core.geo` package contains types like `GeoJsonPoint` or `GeoJsonPolygon` which are extensions to the existing `org.springframework.data.geo` types. +Please read the [MongoDB manual on GeoJSON support](http://docs.mongodb.org/manual/core/2dsphere/#geospatial-indexes-store-geojson) to learn about requirements and restrictions. + +```java +public class Store { + + String id; + + /** + * location is stored in GeoJSON format. + * { + * "type" : "Point", + * "coordinates" : [ x, y ] + * } + */ + GeoJsonPoint location; +} +``` + + +## Support for GeoJSON types in repository methods + +Using GeoJson types as repository query parameters forces usage of the `$geometry` operator when creating the query. + +```java +public interface StoreRepository extends CrudRepository { + + List findByLocationWithin(Polygon polygon); + +} +``` + +```java + +/* + * { + * "location": { + * "$geoWithin": { + * "$geometry": { + * "type": "Polygon", + * "coordinates": [ + * [ + * [-73.992514,40.758934], + * [-73.961138,40.760348], + * [-73.991658,40.730006], + * [-73.992514,40.758934] + * ] + * ] + * } + * } + * } + * } + */ +repo.findByLocationWithin( + new GeoJsonPolygon( + new Point(-73.992514, 40.758934), + new Point(-73.961138, 40.760348), + new Point(-73.991658, 40.730006), + new Point(-73.992514, 40.758934))); + +/* + * { + * "location" : { + * "$geoWithin" : { + * "$polygon" : [ [ -73.992514, 40.758934 ] , [ -73.961138, 40.760348 ] , [ -73.991658, 40.730006 ] ] + * } + * } + * } + */ +repo.findByLocationWithin( + new Polygon( + new Point(-73.992514, 40.758934), + new Point(-73.961138, 40.760348), + new Point(-73.991658, 40.730006)); +``` diff --git a/mongodb/geo-json/pom.xml b/mongodb/geo-json/pom.xml new file mode 100644 index 00000000..92046615 --- /dev/null +++ b/mongodb/geo-json/pom.xml @@ -0,0 +1,34 @@ + + 4.0.0 + + + org.springframework.data.examples + spring-data-mongodb-examples + 1.0.0.BUILD-SNAPSHOT + + + spring-data-mongodb-geojson + Spring Data MongoDB - GeoJson specific features + + + + ${project.groupId} + spring-data-mongodb-utils + ${project.version} + test + + + + com.fasterxml.jackson.core + jackson-databind + + + + org.springframework.data + spring-data-mongodb + + + + + diff --git a/mongodb/geo-json/src/main/java/example/springdata/mongodb/Application.java b/mongodb/geo-json/src/main/java/example/springdata/mongodb/Application.java new file mode 100644 index 00000000..33456700 --- /dev/null +++ b/mongodb/geo-json/src/main/java/example/springdata/mongodb/Application.java @@ -0,0 +1,80 @@ +/* + * Copyright 2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package example.springdata.mongodb; + +import static com.fasterxml.jackson.databind.DeserializationFeature.*; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.data.geo.GeoModule; +import org.springframework.data.mongodb.core.geo.GeoJsonPoint; +import org.springframework.data.repository.init.AbstractRepositoryPopulatorFactoryBean; +import org.springframework.data.repository.init.Jackson2RepositoryPopulatorFactoryBean; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * @author Christoph Strobl + */ +@SpringBootApplication +public class App { + + public static void main(String[] args) { + SpringApplication.run(App.class, args); + } + + /** + * Read JSON data from disk and insert those stores. + * + * @return + */ + public @Bean AbstractRepositoryPopulatorFactoryBean repositoryPopulator() { + + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new GeoJsonModule()); + mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false); + + Jackson2RepositoryPopulatorFactoryBean factoryBean = new Jackson2RepositoryPopulatorFactoryBean(); + factoryBean.setResources(new Resource[] { new ClassPathResource("starbucks-in-nyc.json") }); + factoryBean.setMapper(mapper); + + return factoryBean; + + } + + /** + * Creates a new {@link GeoJsonModule} registering mixins for common and MongoDB geo-spatial types.
+ * This should be part of Spring Data MongoDB. + */ + static class GeoJsonModule extends GeoModule { + + private static final long serialVersionUID = 6239912797617786302L; + + public GeoJsonModule() { + super(); + + setMixInAnnotation(GeoJsonPoint.class, GeoJsonPointMixin.class); + } + } + + static abstract class GeoJsonPointMixin { + GeoJsonPointMixin(@JsonProperty("longitude") double x, @JsonProperty("latitude") double y) {} + } +} diff --git a/mongodb/geo-json/src/main/java/example/springdata/mongodb/Store.java b/mongodb/geo-json/src/main/java/example/springdata/mongodb/Store.java new file mode 100644 index 00000000..eddcca6a --- /dev/null +++ b/mongodb/geo-json/src/main/java/example/springdata/mongodb/Store.java @@ -0,0 +1,48 @@ +/* + * Copyright 2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package example.springdata.mongodb; + +import lombok.Data; + +import org.springframework.data.mongodb.core.geo.GeoJsonPoint; +import org.springframework.data.mongodb.core.mapping.Document; + +/** + * @author Christoph Strobl + */ +@Data +@Document(collection = "starbucks") +public class Store { + + String id; + String name; + String street; + String city; + + /** + * location is stored in GeoJSON format. + * + *
+	 * 
+	 * {
+	 *   "type" : "Point",
+	 *   "coordinates" : [ x, y ]
+	 * }
+	 * 
+	 * 
+ */ + GeoJsonPoint location; +} diff --git a/mongodb/geo-json/src/main/java/example/springdata/mongodb/StoreRepository.java b/mongodb/geo-json/src/main/java/example/springdata/mongodb/StoreRepository.java new file mode 100644 index 00000000..20ba3cbd --- /dev/null +++ b/mongodb/geo-json/src/main/java/example/springdata/mongodb/StoreRepository.java @@ -0,0 +1,30 @@ +/* + * Copyright 2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package example.springdata.mongodb; + +import java.util.List; + +import org.springframework.data.geo.Polygon; +import org.springframework.data.repository.CrudRepository; + +/** + * @author Christoph Strobl + */ +public interface StoreRepository extends CrudRepository { + + List findByLocationWithin(Polygon polygon); + +} diff --git a/mongodb/geo-json/src/main/resources/starbucks-in-nyc.json b/mongodb/geo-json/src/main/resources/starbucks-in-nyc.json new file mode 100644 index 00000000..52105370 --- /dev/null +++ b/mongodb/geo-json/src/main/resources/starbucks-in-nyc.json @@ -0,0 +1,1290 @@ +[ + { + "_class":"example.springdata.mongodb.Store", + "id":"16628", + "name":"26th & Broadway", + "street":"1140 Broadway", + "city":"New York", + "location" : { "latitude":40.743827, "longitude":-73.989015 } + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7427", + "name":"29th & Park-Park Ave. South", + "street":"424 Park Avenue South", + "city":"New York", + "location" : { "latitude":4.074426, "longitude":-73.983749} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7263", + "name":"43rd & 8th", + "street":"684 Eighth Avenue", + "city":"New York", + "location" : { "latitude":40.758001, "longitude":-73.988994} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7215", + "name":"1585 Broadway (47th)", + "street":"1585 Broadway", + "city":"New York", + "location" : { "latitude":40.759686, "longitude":-73.985235} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7393", + "name":"49th & 8th-World Wide Plaza", + "street":"325 W 49th St", + "city":"New York", + "location" : { "latitude":40.762176, "longitude":-73.987472} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7316", + "name":"31st & 7th", + "street":"370 7th Avenue", + "city":"New York", + "location" : { "latitude":40.74899, "longitude":-73.992372} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7540", + "name":"17th and Broadway (41 Union Square", + "street":"41 Union Square West", + "city":"New York", + "location" : { "latitude":40.737035, "longitude":-73.990558} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7611", + "name":"40th & Lexington (360 Lex)", + "street":"360 Lexington Avenue", + "city":"New York", + "location" : { "latitude":40.750332, "longitude":-73.977043} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"15461", + "name":"Jackson Square at Greenwich Ave", + "street":"122 Greenwich Avenue, (space A)", + "city":"New York", + "location" : { "latitude":40.738441, "longitude":-74.002217} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"852", + "name":"1656 Broadway", + "street":"1656 Broadway", + "city":"New York", + "location" : { "latitude":40.762092, "longitude":-73.983345} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"11738", + "name":"63rd & Broadway", + "street":"1889 Broadway", + "city":"New York", + "location" : { "latitude":40.771365, "longitude":-73.982591} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"817", + "name":"1st Avenue & 75th St.", + "street":"1445 First Avenue", + "city":"New York", + "location" : { "latitude":40.770031, "longitude":-73.954631} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"839", + "name":"Broadway @ 81st", + "street":"2252 Broadway", + "city":"New York", + "location" : { "latitude":40.784905, "longitude":-73.978696} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7378", + "name":"Union Square", + "street":"10 UNION SQUARE EAST", + "city":"New York", + "location" : { "latitude":40.735022, "longitude":-73.989848} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7547", + "name":"Sheridan Square (72 Grove Street)", + "street":"72 Grove Street", + "city":"New York", + "location" : { "latitude":40.73311, "longitude":-74.002707} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7216", + "name":"87th & Lexington", + "street":"120 EAST 87TH ST", + "city":"New York", + "location" : { "latitude":40.780139, "longitude":-73.955346} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7352", + "name":"86th & Columbus", + "street":"540 Columbus Avenue", + "city":"New York", + "location" : { "latitude":40.786704, "longitude":-73.972244} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7346", + "name":"SONY", + "street":"550 Madison Avenue, #A32", + "city":"New York", + "location" : { "latitude":40.761478, "longitude":-73.973501} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7317", + "name":"73rd & Columbus", + "street":"267-275 Columbus Ave", + "city":"New York", + "location" : { "latitude":40.777949, "longitude":-73.978175} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"14091", + "name":"Macy's 5th Floor - Herald Square", + "street":"151 W. 34th Street", + "city":"New York", + "location" : { "latitude":40.751148, "longitude":-73.990061} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7525", + "name":"135 E 57 Street (New World)", + "street":"135 East 57th Street", + "city":"New York", + "location" : { "latitude":40.760965, "longitude":-73.96921} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7608", + "name":"48th & Lexington", + "street":"511 Lexington Avenue", + "city":"New York", + "location" : { "latitude":40.755021, "longitude":-73.973223} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"75589", + "name":"Marriott Marquis-Lobby", + "street":"1535 Broadway", + "city":"New York", + "location" : { "latitude":40.757993, "longitude":-73.985633} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7373", + "name":"Grand Central Station", + "street":"107 E 43rd St, Space MC-72", + "city":"New York", + "location" : { "latitude":40.753291, "longitude":-73.977635} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"75847", + "name":"Hilton New York Marketplace", + "street":"1335 Avenue of the Americas", + "city":"New York", + "location" : { "latitude":40.762304, "longitude":-73.979184} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7342", + "name":"41st & 3rd", + "street":"639 3rd Avenue", + "city":"New York", + "location" : { "latitude":40.750195, "longitude":-73.974565} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"9241", + "name":"Park Avenue Plaza", + "street":"55 E 53rd St", + "city":"New York", + "location" : { "latitude":40.759285, "longitude":-73.973516} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7860", + "name":"Trump Tower", + "street":"725 5th Avenue", + "city":"New York", + "location" : { "latitude":40.762555, "longitude":-73.974236} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"16576", + "name":"36th St & Sixth Avenue", + "street":"977 Avenue of the Americas", + "city":"New York", + "location" : { "latitude":40.751005, "longitude":-73.986913} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"14441", + "name":"118th & Frederick Douglas Blvd.", + "street":"2195 Frederick Douglas Boulevard", + "city":"New York", + "location" : { "latitude":40.805915, "longitude":-73.954495} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"5114", + "name":"96th & Lexington Ave", + "street":"1491 Lexington Avenue", + "city":"New York", + "location" : { "latitude":40.785886, "longitude":-73.950919} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"15685", + "name":"69th & First", + "street":"1281 First Avenue", + "city":"New York", + "location" : { "latitude":40.765864, "longitude":-73.957431} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"10751", + "name":"Roosevelt Island", + "street":"455 Main Street", + "city":"New York", + "location" : { "latitude":40.759326, "longitude":-73.95289} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"10608", + "name":"Third & 60th", + "street":"1021 Third Avenue", + "city":"New York", + "location" : { "latitude":40.762394, "longitude":-73.965745} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"10693", + "name":"Bloomberg Building", + "street":"731 Lexington Avenue", + "city":"New York", + "location" : { "latitude":40.761401, "longitude":-73.967862} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7404", + "name":"57th & Lexington", + "street":"116 E. 57th Street", + "city":"New York", + "location" : { "latitude":40.761088, "longitude":-73.969984} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"10841", + "name":"55th & Lexington", + "street":"655 Lexington Avenue", + "city":"New York", + "location" : { "latitude":40.759446, "longitude":-73.969979} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7655", + "name":"53rd & Lexington", + "street":"630 Lexington Ave", + "city":"New York", + "location" : { "latitude":40.758743, "longitude":-73.97094} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7761", + "name":"52nd & Lexington", + "street":"599 Lexington", + "city":"New York", + "location" : { "latitude":40.757616, "longitude":-73.970857} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7802", + "name":"50th & Lexington", + "street":"560 Lexington Avenue", + "city":"New York", + "location" : { "latitude":40.756861, "longitude":-73.972635} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7370", + "name":"48th & 3rd", + "street":"757 Third Avenue", + "city":"New York", + "location" : { "latitude":40.754122, "longitude":-73.971714} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7670", + "name":"Worldwide Plaza II", + "street":"825 Eighth Avenue, W-9", + "city":"New York", + "location" : { "latitude":40.762228, "longitude":-73.986567} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"9242", + "name":"450 Lexington Ave.", + "street":"450 Lexington Avenue", + "city":"New York", + "location" : { "latitude":40.753176, "longitude":-73.974975} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7426", + "name":"575 Fifth Avenue", + "street":"575 Fifth Avenue", + "city":"New York", + "location" : { "latitude":40.756131, "longitude":-73.978922} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"14241", + "name":"NHL store @ 47th & 6th", + "street":"1185 Avenue of the Americas", + "city":"New York", + "location" : { "latitude":40.758048, "longitude":-73.982192} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7462", + "name":"545 Fifth Ave.", + "street":"545 Fifth Ave.", + "city":"New York", + "location" : { "latitude":40.755168, "longitude":-73.979409} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7297", + "name":"45th St. & Sixth Ave.", + "street":"1166 Avenue of the Americas", + "city":"New York", + "location" : { "latitude":40.756649, "longitude":-73.982141} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"11737", + "name":"Madison & 44th", + "street":"340 Madison Avenue", + "city":"New York", + "location" : { "latitude":40.753944, "longitude":-73.978759} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"9244", + "name":"335 Madison Ave.", + "street":"335 Madison Avenue", + "city":"New York", + "location" : { "latitude":40.753887, "longitude":-73.978719} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7506", + "name":"150 E. 42nd Street", + "street":"150 E. 42nd Street", + "city":"New York", + "location" : { "latitude":40.751238, "longitude":-73.975608} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7222", + "name":"330 Madison", + "street":"330 Madison Ave", + "city":"New York", + "location" : { "latitude":40.753335, "longitude":-73.979405} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7898", + "name":"42nd & Park", + "street":"125 Park Ave", + "city":"New York", + "location" : { "latitude":40.751779, "longitude":-73.977735} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"8993", + "name":"45th & Broadway", + "street":"1530 Broadway", + "city":"New York", + "location" : { "latitude":40.757662, "longitude":-73.985721} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"15440", + "name":"43rd & Sixth", + "street":"1101 - 1109 Avenue of the Americas", + "city":"New York", + "location" : { "latitude":40.755352, "longitude":-73.983972} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7801", + "name":"41st & Madison", + "street":"295 Madison Avenue", + "city":"New York", + "location" : { "latitude":40.751957, "longitude":-73.979722} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"11764", + "name":"Empire State Building", + "street":"350 Fifth Avenue", + "city":"New York", + "location" : { "latitude":40.74866, "longitude":-73.985614} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"8769", + "name":"West 43rd and Broadway", + "street":"1500 Broadway", + "city":"New York", + "location" : { "latitude":40.756643, "longitude":-73.985904} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7273", + "name":"42nd & 6th", + "street":"1100 Avenue of the Americas", + "city":"New York", + "location" : { "latitude":40.754883, "longitude":-73.984074} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"8812", + "name":"39th & Park", + "street":"90 Park Ave", + "city":"New York", + "location" : { "latitude":40.750628, "longitude":-73.979265} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7890", + "name":"42nd & Eighth", + "street":"251 West 42nd Street", + "city":"New York", + "location" : { "latitude":40.757171, "longitude":-73.98905} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7463", + "name":"41st and Broadway", + "street":"1460 Broadway", + "city":"New York", + "location" : { "latitude":40.755043, "longitude":-73.986415} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7511", + "name":"525 Seventh Avenue (New World)", + "street":"525 7th Avenue", + "city":"New York", + "location" : { "latitude":40.753647, "longitude":-73.988434} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7468", + "name":"39th and 8th", + "street":"600 Eighth Ave.", + "city":"New York", + "location" : { "latitude":40.755325, "longitude":-73.990906} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7536", + "name":"36th and Madison", + "street":"200 Madison Avenue", + "city":"New York", + "location" : { "latitude":40.748918, "longitude":-73.982682} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7238", + "name":"1372 Broadway", + "street":"1372 Broadway", + "city":"New York", + "location" : { "latitude":40.751985, "longitude":-73.986909} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"10784", + "name":"35th & 5th", + "street":"373 5th Avenue", + "city":"New York", + "location" : { "latitude":40.749101, "longitude":-73.983799} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"8130", + "name":"East 34th and Park", + "street":"3 Park Avenue", + "city":"New York", + "location" : { "latitude":40.747051, "longitude":-73.981236} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7403", + "name":"35th & 7th", + "street":"462 7th Avenue", + "city":"New York", + "location" : { "latitude":40.751842, "longitude":-73.990214} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"14092", + "name":"Macy's 6th Floor - Herald Square", + "street":"151 W. 34th Street", + "city":"New York", + "location" : { "latitude":40.751103, "longitude":-73.989518} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7446", + "name":"450 7th Avenue", + "street":"450 7th Avenue", + "city":"New York", + "location" : { "latitude":40.751357, "longitude":-73.990435} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7769", + "name":"Herald Square- Macy's", + "street":"151 W. 34th Street, Room 900", + "city":"New York", + "location" : { "latitude":40.751014, "longitude":-73.990248} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7470", + "name":"35th and 8th", + "street":"494 Eighth Ave.", + "city":"New York", + "location" : { "latitude":40.752633, "longitude":-73.992905} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"11650", + "name":"Hudson & 10th", + "street":"518 Hudson Street", + "city":"New York", + "location" : { "latitude":40.733677, "longitude":-74.006126} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7711", + "name":"15th & Ninth", + "street":"76 9th Ave", + "city":"New York", + "location" : { "latitude":40.741684, "longitude":-74.004629} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7255", + "name":"8th & 16th", + "street":"124 Eighth Avenue", + "city":"New York", + "location" : { "latitude":40.741152, "longitude":-74.001294} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7586", + "name":"19th & 8th", + "street":"177 Eighth Avenue", + "city":"New York", + "location" : { "latitude":40.742999, "longitude":-74.000343} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7622", + "name":"15th & Third", + "street":"145 Third Avenue", + "city":"New York", + "location" : { "latitude":40.733749, "longitude":-73.986598} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7285", + "name":"22nd St. & Sixth Ave.", + "street":"684 Avenue of the Americas", + "city":"New York", + "location" : { "latitude":40.741844, "longitude":-73.993237} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"14618", + "name":"23rd - 24th & 7th", + "street":"229 Seventh Avenue", + "city":"New York", + "location" : { "latitude":40.744315, "longitude":-73.99525} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"10396", + "name":"21st & 5th", + "street":"4 W. 21st Street", + "city":"New York", + "location" : { "latitude":40.740382, "longitude":-73.991165} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"14442", + "name":"19th & Park", + "street":"240 Park Avenue South", + "city":"New York", + "location" : { "latitude":40.73798, "longitude":-73.988303} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"13539", + "name":"23rd btwn 5th & 6th", + "street":"14 W. 23rd St", + "city":"New York", + "location" : { "latitude":40.741661, "longitude":-73.990313} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7587", + "name":"24th & 6th", + "street":"750 6th Avenue", + "city":"New York", + "location" : { "latitude":40.743574, "longitude":-73.992028} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"5072", + "name":"Fashion Inst of Technology", + "street":"227 W 27th St", + "city":"New York", + "location" : { "latitude":40.747097, "longitude":-73.994576} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7277", + "name":"23rd & Park", + "street":"304 Park Avenue South", + "city":"New York", + "location" : { "latitude":40.74016, "longitude":-73.986971} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"13538", + "name":"28th & Seventh", + "street":"315 Seventh Avenue", + "city":"New York", + "location" : { "latitude":40.746974, "longitude":-73.993323} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7826", + "name":"33rd & Tenth", + "street":"450 W. 33rd Street", + "city":"New York", + "location" : { "latitude":40.753066, "longitude":-73.999424} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7792", + "name":"27th & Sixth", + "street":"776 Avenue of the Americas", + "city":"New York", + "location" : { "latitude":40.745213, "longitude":-73.990874} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7420", + "name":"261 5th Avenue", + "street":"261 Fifth Avenue", + "city":"New York", + "location" : { "latitude":40.745069, "longitude":-73.986861} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"9722", + "name":"31st and Sixth Avenue", + "street":"875 Sixth Ave", + "city":"New York", + "location" : { "latitude":40.748026, "longitude":-73.989251} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7353", + "name":"1 Penn Plaza", + "street":"1 Penn Plaza", + "city":"New York", + "location" : { "latitude":40.752586, "longitude":-73.992834} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7851", + "name":"Penn Station LIRR", + "street":"1 Penn Plaza Concourse Level", + "city":"New York", + "location" : { "latitude":40.752587, "longitude":-73.992835} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"13791", + "name":"Penn Station LIRR #2", + "street":"1 Penn Plaza, Concourse level", + "city":"New York", + "location" : { "latitude":40.752587, "longitude":-73.992835} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7709", + "name":"76th & Columbus", + "street":"338 Columbus Avenue", + "city":"New York", + "location" : { "latitude":40.779982, "longitude":-73.977146} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"11765", + "name":"Sixth & 58th", + "street":"1411 Sixth Avenue", + "city":"New York", + "location" : { "latitude":40.764767, "longitude":-73.97709} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"10279", + "name":"W. 56th & 6th", + "street":"1380 Sixth Avenue", + "city":"New York", + "location" : { "latitude":40.763839, "longitude":-73.977174} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7344", + "name":"60th & Broadway-II", + "street":"1841 Broadway", + "city":"New York", + "location" : { "latitude":40.768869, "longitude":-73.982343} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7575", + "name":"43rd St & Third Ave", + "street":"685 Third Avenue", + "city":"New York", + "location" : { "latitude":40.751585, "longitude":-73.97359} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"13455", + "name":"42nd & Second", + "street":"220 East 42nd St", + "city":"New York", + "location" : { "latitude":40.749768, "longitude":-73.973188} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7698", + "name":"57th & Seventh", + "street":"142 W. 57th Street", + "city":"New York", + "location" : { "latitude":40.764875, "longitude":-73.97897} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7245", + "name":"57th btwn 8th & 9th", + "street":"322 West 57th Street", + "city":"New York", + "location" : { "latitude":40.767558, "longitude":-73.983086} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7696", + "name":"120 W. 56th", + "street":"120 W. 56th Street", + "city":"New York", + "location" : { "latitude":40.76402, "longitude":-73.978898} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"8615", + "name":"West 55th & 7th", + "street":"870 7th Avenue", + "city":"New York", + "location" : { "latitude":40.764304, "longitude":-73.980913} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"9240", + "name":"1345 Ave. of the Americas Acquisiti", + "street":"1345 6th Ave", + "city":"New York", + "location" : { "latitude":40.76201, "longitude":-73.978533} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"2784", + "name":"53rd & Sixth", + "street":"1330 6th Ave.", + "city":"New York", + "location" : { "latitude":40.761933, "longitude":-73.978633} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"8965", + "name":"51st between Park & Madison", + "street":"45 E. 51st Street", + "city":"New York", + "location" : { "latitude":40.758144, "longitude":-73.974267} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"8992", + "name":"54th & Broadway", + "street":"1710 Broadway", + "city":"New York", + "location" : { "latitude":40.764046, "longitude":-73.98223} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"9239", + "name":"1290 Ave. of the Americas", + "street":"1290 6th Ave", + "city":"New York", + "location" : { "latitude":40.760757, "longitude":-73.979621} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7673", + "name":"52nd & Seventh", + "street":"156 W 52nd St", + "city":"New York", + "location" : { "latitude":40.76183, "longitude":-73.981144} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7424", + "name":"48th & Park", + "street":"280 Park Avenue", + "city":"New York", + "location" : { "latitude":40.756423, "longitude":-73.975073} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"11736", + "name":"49th & Madison", + "street":"425 Madison Avenue", + "city":"New York", + "location" : { "latitude":40.756963, "longitude":-73.975901} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"2785", + "name":"47th & Eighth", + "street":"770 Eighth Ave", + "city":"New York", + "location" : { "latitude":40.760626, "longitude":-73.987171} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7443", + "name":"Rockefeller Center Concourse", + "street":"30 Rockefeller Plaza, Space A", + "city":"New York", + "location" : { "latitude":40.758759, "longitude":-73.978691} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7501", + "name":"52nd Street and 8th Ave", + "street":"871 8th Avenue", + "city":"New York", + "location" : { "latitude":40.763701, "longitude":-73.985292} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7444", + "name":"Rockefeller Center Subway", + "street":"30 Rockefeller Plaza", + "city":"New York", + "location" : { "latitude":40.758852, "longitude":-73.979169} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"15388", + "name":"ARAMARK @ JP Morgan Chase New York", + "street":"270 Park Ave", + "city":"New York", + "location" : { "latitude":40.75582, "longitude":-73.975683} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7282", + "name":"49th & 7th", + "street":"750 Seventh Avenue", + "city":"New York", + "location" : { "latitude":40.760755, "longitude":-73.983693} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7426", + "name":"575 Fifth Avenue (Relocation)", + "street":"575 Fifth Avenue", + "city":"New York", + "location" : { "latitude":40.756428, "longitude":-73.97853} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7577", + "name":"45th & Park Avenue", + "street":"230 Park Avenue", + "city":"New York", + "location" : { "latitude":40.754532, "longitude":-73.976097} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7663", + "name":"90th & First", + "street":"400 East 90th Street", + "city":"New York", + "location" : { "latitude":40.779119, "longitude":-73.947474} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"14218", + "name":"103rd & Broadway", + "street":"2690 Broadway", + "city":"New York", + "location" : { "latitude":40.798882, "longitude":-73.968372} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7699", + "name":"95th & Broadway", + "street":"2521 Broadway", + "city":"New York", + "location" : { "latitude":40.793864, "longitude":-73.972744} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7474", + "name":"93rd and Broadway", + "street":"2498 Broadway", + "city":"New York", + "location" : { "latitude":40.792522, "longitude":-73.973027} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7534", + "name":"B'way & 114 Street (New World)", + "street":"2929 Broadway", + "city":"New York", + "location" : { "latitude":40.807108, "longitude":-73.96491} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"14498", + "name":"Broadway btwn 87th & 88th", + "street":"2394 Broadway", + "city":"New York", + "location" : { "latitude":40.789286, "longitude":-73.975324} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7394", + "name":"81st & Columbus", + "street":"444 Columbus Avenue", + "city":"New York", + "location" : { "latitude":40.783633, "longitude":-73.974456} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7557", + "name":"50th & Second", + "street":"943 Second Avenue", + "city":"New York", + "location" : { "latitude":40.755042, "longitude":-73.968613} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7675", + "name":"14th & Sixth", + "street":"510 Sixth Avenue", + "city":"New York", + "location" : { "latitude":40.737022, "longitude":-73.996494} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7407", + "name":"92nd & 3rd", + "street":"1642 Third Avenue", + "city":"New York", + "location" : { "latitude":40.782627, "longitude":-73.951431} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"9439", + "name":"84th & Third Ave", + "street":"1488 Third Avenue #A", + "city":"New York", + "location" : { "latitude":40.777492, "longitude":-73.955133} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7465", + "name":"2 Columbus Ave.", + "street":"2 Columbus Avenue", + "city":"New York", + "location" : { "latitude":40.769313, "longitude":-73.984905} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"831", + "name":"32nd @ 2nd Ave.", + "street":"585 2nd Avenue", + "city":"New York", + "location" : { "latitude":40.743679, "longitude":-73.976866} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7414", + "name":"47th & 9th", + "street":"682 9th Avenue", + "city":"New York", + "location" : { "latitude":40.761614, "longitude":-73.990046} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"11277", + "name":"Lexington & 85th", + "street":"1261 Lexington Avenue", + "city":"New York", + "location" : { "latitude":40.778649, "longitude":-73.956036} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"3421", + "name":"West 23rd and 8th", + "street":"300 W 23rd St.", + "city":"New York", + "location" : { "latitude":40.745103, "longitude":-73.998743} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7558", + "name":"96th & Madison", + "street":"1378 Madison Avenue", + "city":"New York", + "location" : { "latitude":40.787139, "longitude":-73.954486} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7858", + "name":"17th & First (Stuyvesant Town)", + "street":"286 First Avenue, A", + "city":"New York", + "location" : { "latitude":40.732401, "longitude":-73.981499} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"8770", + "name":"80th & York", + "street":"1515 York Avenue", + "city":"New York", + "location" : { "latitude":40.772414, "longitude":-73.949904} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7261", + "name":"Greenwich Avenue", + "street":"93 Greenwich Avenue", + "city":"New York", + "location" : { "latitude":40.73744, "longitude":-74.001641} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"9467", + "name":"43rd & Ninth", + "street":"593 Ninth Ave", + "city":"New York", + "location" : { "latitude":40.758934, "longitude":-73.992514} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7612", + "name":"60th & First", + "street":"1102 1st Ave", + "city":"New York", + "location" : { "latitude":40.760348, "longitude":-73.961138} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7874", + "name":"2138 Broadway", + "street":"2140 Broadway", + "city":"New York", + "location" : { "latitude":40.781019, "longitude":-73.981072} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7354", + "name":"70th & Broadway", + "street":"2045 Broadway", + "city":"New York", + "location" : { "latitude":40.777773, "longitude":-73.982557} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"819", + "name":"Columbus @ 67th", + "street":"152 - 154 Columbus Avenue", + "city":"New York", + "location" : { "latitude":40.774211, "longitude":-73.981356} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"821", + "name":"Third @ 66th", + "street":"1128 Third Avenue", + "city":"New York", + "location" : { "latitude":40.765935, "longitude":-73.963591} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"823", + "name":"Lexington & 78th", + "street":"1117 Lexington Ave., #4", + "city":"New York", + "location" : { "latitude":40.774115, "longitude":-73.959318} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7672", + "name":"85th & First", + "street":"1631 1st Ave", + "city":"New York", + "location" : { "latitude":40.776103, "longitude":-73.949968} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"11423", + "name":"Macy's 35th Street Balcony", + "street":"151 W 34th Street", + "city":"New York", + "location" : { "latitude":40.750942, "longitude":-73.989757} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"8614", + "name":"58th & 8th", + "street":"4 Columbus Circle", + "city":"New York", + "location" : { "latitude":40.767539, "longitude":-73.983111} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"847", + "name":"6th & Waverly (Waverly Place)", + "street":"378 6th Avenue", + "city":"New York", + "location" : { "latitude":40.733037, "longitude":-73.99976} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7507", + "name":"33rd Street and 5th Avenue (Old Ban", + "street":"334 Fifth Ave.", + "city":"New York", + "location" : { "latitude":40.747763, "longitude":-73.985306} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"818", + "name":"Second @ 81st", + "street":"1559 2nd Avenue", + "city":"New York", + "location" : { "latitude":40.774639, "longitude":-73.95433} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7682", + "name":"76th & Second", + "street":"1449 Second Avenue", + "city":"New York", + "location" : { "latitude":40.771213, "longitude":-73.956828} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7341", + "name":"23rd & 3rd", + "street":"296-300 Third Avenue", + "city":"New York", + "location" : { "latitude":40.738792, "longitude":-73.983401} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7800", + "name":"Grand Central Station 2", + "street":"7800 Grand Central Station, Track 35", + "city":"New York", + "location" : { "latitude":40.752347, "longitude":-73.977456} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"7386", + "name":"111th & Broadway", + "street":"2853 Broadway", + "city":"New York", + "location" : { "latitude":40.804695, "longitude":-73.96667} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"1379", + "name":"Target East River Plaza T-2380", + "street":"517 E 117th St", + "city":"New York", + "location" : { "latitude":40.795688, "longitude":-73.932552} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"75491", + "name":"Limited Brands-NYC", + "street":"1740 Broadway", + "city":"New York", + "location" : { "latitude":40.765221, "longitude":-73.982023} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"75271", + "name":"Javits Convention Ctr Taxi North", + "street":"655 W 34th St", + "city":"New York", + "location" : { "latitude":40.756782, "longitude":-74.003423} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"9239", + "name":"1290 Sixth Ave (Ave of Americas)", + "street":"1290 Sixth Avenue", + "city":"New York", + "location" : { "latitude":40.760875, "longitude":-73.979729} + }, + { + "_class":"example.springdata.mongodb.Store", + "id":"75846", + "name":"Waldorf-Astoria", + "street":"301 Park Ave", + "city":"New York", + "location" : { "latitude":40.75656, "longitude":-73.97405} + } +] \ No newline at end of file diff --git a/mongodb/geo-json/src/test/java/example/springdata/mongodb/StoreRepositoryTests.java b/mongodb/geo-json/src/test/java/example/springdata/mongodb/StoreRepositoryTests.java new file mode 100644 index 00000000..4d100e64 --- /dev/null +++ b/mongodb/geo-json/src/test/java/example/springdata/mongodb/StoreRepositoryTests.java @@ -0,0 +1,134 @@ +/* + * Copyright 2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package example.springdata.mongodb; + +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.geo.Point; +import org.springframework.data.geo.Polygon; +import org.springframework.data.mongodb.core.MongoOperations; +import org.springframework.data.mongodb.core.convert.MongoConverter; +import org.springframework.data.mongodb.core.geo.GeoJson; +import org.springframework.data.mongodb.core.geo.GeoJsonPolygon; +import org.springframework.data.mongodb.core.query.BasicQuery; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.util.Version; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.mongodb.BasicDBObject; +import com.mongodb.DBObject; + +import example.springdata.mongodb.util.RequiresMongoDB; + +/** + * @author Christoph Strobl + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { App.class }) +public class StoreRepositoryTests { + + public static @ClassRule RequiresMongoDB requiresMongoDB_2_6 = RequiresMongoDB.atLeast(new Version(2, 6, 0)); + + @Autowired StoreRepository repo; + @Autowired MongoOperations mongoOps; + + /** + * Get all the Starbucks stores within the triange defined by + * + *
+	 * 
    + *
  1. 43rd & Ninth
  2. 60th & First
  3. Fresh Meadows
  4. + *
      + *
+ * + * Using {@code $geoWithin} and {@code $geometry} operators. + * + *
+	 * 
+	 * { 
+	 *   "location": {
+	 *     "$geoWithin": {
+	 *       "$geometry": {
+	 *         "type": "Polygon",
+	 *         "coordinates": [
+	 *           [
+	 *             [-73.992514,40.758934],
+	 *             [-73.961138,40.760348],
+	 *             [-73.991658,40.730006],
+	 *             [-73.992514,40.758934]
+	 *           ]
+	 *         ]
+	 *       }
+	 *     }
+	 *   }
+	 * }
+	 * 
+	 * 
+	 * 
+	 */
+	@Test
+	public void findWithinGeoJsonPolygon() {
+		repo.findByLocationWithin(
+				new GeoJsonPolygon(new Point(-73.992514, 40.758934), new Point(-73.961138, 40.760348), new Point(-73.991658,
+						40.730006), new Point(-73.992514, 40.758934))).forEach(System.out::println);
+	}
+
+	/**
+	 * The legacy format alternative to {@link #findWithinGeoJsonPolygon()}.
+	 * 
+	 * 
+	 * 
+	 * { 
+	 *   "location" : { 
+	 *     "$geoWithin" : {
+	 *        "$polygon" : [ [ -73.992514, 40.758934 ] , [ -73.961138, 40.760348 ] , [ -73.991658, 40.730006 ] ]
+	 *     }
+	 *   }
+	 * }
+	 * 
+	 * 
+	 * 
+	 */
+	@Test
+	public void findWithinLegacyPolygon() {
+		repo.findByLocationWithin(
+				new Polygon(new Point(-73.992514, 40.758934), new Point(-73.961138, 40.760348),
+						new Point(-73.991658, 40.730006))).forEach(System.out::println);
+	}
+
+	/**
+	 * The {@code $geoIntersects} keyword is not yet available via {@link Criteria} we need to fall back to manual
+	 * creation of the query using the registered {@link MongoConverter} for {@link GeoJson} conversion.
+	 */
+	@Test
+	public void findStoresThatIntersectGivenPolygon() {
+
+		DBObject geoJsonDbo = new BasicDBObject();
+
+		mongoOps.getConverter().write(
+				new GeoJsonPolygon(new Point(-73.992514, 40.758934), new Point(-73.961138, 40.760348), new Point(-73.991658,
+						40.730006), new Point(-73.992514, 40.758934)), geoJsonDbo);
+
+		BasicQuery bq = new BasicQuery(new BasicDBObject("location", new BasicDBObject("$geoIntersects", new BasicDBObject(
+				"$geometry", geoJsonDbo))));
+
+		mongoOps.find(bq, Store.class).forEach(System.out::println);
+	}
+
+}
diff --git a/mongodb/geo-json/src/test/resources/logback.xml b/mongodb/geo-json/src/test/resources/logback.xml
new file mode 100644
index 00000000..119ec50e
--- /dev/null
+++ b/mongodb/geo-json/src/test/resources/logback.xml
@@ -0,0 +1,17 @@
+
+
+
+	
+		
+			%d %5p %40.40c:%4L - %m%n
+		
+	
+	
+	
+	
+
+	
+		
+	
+
+
\ No newline at end of file
diff --git a/mongodb/pom.xml b/mongodb/pom.xml
index e0900d42..9ff92986 100644
--- a/mongodb/pom.xml
+++ b/mongodb/pom.xml
@@ -22,6 +22,7 @@
 		text-search
 		java8
 		util
+		geo-json