本文整理汇总了Java中org.springframework.data.geo.Point类的典型用法代码示例。如果您正苦于以下问题:Java Point类的具体用法?Java Point怎么用?Java Point使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Point类属于org.springframework.data.geo包,在下文中一共展示了Point类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exposesGeoSpatialFunctionality
import org.springframework.data.geo.Point; //导入依赖的package包/类
/**
* Test case to show the usage of the geo-spatial APIs to lookup people within a given distance of a reference point.
*/
@Test
public void exposesGeoSpatialFunctionality() {
GeospatialIndex indexDefinition = new GeospatialIndex("address.location");
indexDefinition.getIndexOptions().put("min", -180);
indexDefinition.getIndexOptions().put("max", 180);
operations.indexOps(Customer.class).ensureIndex(indexDefinition);
Customer ollie = new Customer("Oliver", "Gierke");
ollie.setAddress(new Address(new Point(52.52548, 13.41477)));
ollie = repository.save(ollie);
Point referenceLocation = new Point(52.51790, 13.41239);
Distance oneKilometer = new Distance(1, Metrics.KILOMETERS);
GeoResults<Customer> result = repository.findByAddressLocationNear(referenceLocation, oneKilometer);
assertThat(result.getContent(), hasSize(1));
Distance distanceToFirstStore = result.getContent().get(0).getDistance();
assertThat(distanceToFirstStore.getMetric(), is(Metrics.KILOMETERS));
assertThat(distanceToFirstStore.getValue(), closeTo(0.862, 0.001));
}
示例2: test_GeoSpacialQuery
import org.springframework.data.geo.Point; //导入依赖的package包/类
@Test
public void test_GeoSpacialQuery() {
mongoTemplate.indexOps(Venue.class).ensureIndex(new GeospatialIndex("location"));
mongoTemplate.insert(new Venue("Venue 1", new Point(51.10682735591432, -114.11773681640625)));
mongoTemplate.insert(new Venue("Venue 2", new Point(51.09144802136697, -114.10400390625)));
mongoTemplate.insert(new Venue("Venue 3", new Point(51.08282186160978, -114.10400390625)));
mongoTemplate.insert(new Venue("Venue 4", new Point(51.12076493195686, -113.98040771484375)));
mongoTemplate.insert(new Venue("Venue 5", new Point(50.93939251390387, -113.98040771484375)));
mongoTemplate.insert(new Venue("Venue 6", new Point(150.93939251390387, 113.98040771484375)));
List<Venue> venueList = mongoTemplate.find(
query(where("location")
.near(new Point(51.00, -114.00))
.maxDistance(1.00)), Venue.class);
assertThat(venueList).size().isEqualTo(5);
assertThat(venueList.get(0).getLocation()).isNotNull();
assertThat(venueList.get(0).getName()).isNotNull();
}
示例3: testGeoLocation
import org.springframework.data.geo.Point; //导入依赖的package包/类
@Test
public void testGeoLocation() {
ExampleSolrBean searchableBeanInBuffalow = createExampleBeanWithId("1");
searchableBeanInBuffalow.setStore("45.17614,-93.87341");
ExampleSolrBean searchableBeanInNYC = createExampleBeanWithId("2");
searchableBeanInNYC.setStore("40.7143,-74.006");
solrTemplate.saveBeans(Arrays.asList(searchableBeanInBuffalow, searchableBeanInNYC));
solrTemplate.commit();
Page<ExampleSolrBean> result = solrTemplate.queryForPage(
new SimpleQuery(new Criteria("store").near(new Point(45.15, -93.85), new Distance(5))), ExampleSolrBean.class);
Assert.assertEquals(1, result.getContent().size());
}
示例4: testGeoLocationWithDistanceInMiles
import org.springframework.data.geo.Point; //导入依赖的package包/类
@Test
public void testGeoLocationWithDistanceInMiles() {
ExampleSolrBean searchableBeanInBuffalow = createExampleBeanWithId("1");
searchableBeanInBuffalow.setStore("45.17614,-93.87341");
ExampleSolrBean searchableBeanInNYC = createExampleBeanWithId("2");
searchableBeanInNYC.setStore("40.7143,-74.006");
solrTemplate.saveBeans(Arrays.asList(searchableBeanInBuffalow, searchableBeanInNYC));
solrTemplate.commit();
Page<ExampleSolrBean> result = solrTemplate.queryForPage(
new SimpleQuery(new Criteria("store").near(new Point(45.15, -93.85), new Distance(3.106856, Metrics.MILES))),
ExampleSolrBean.class);
Assert.assertEquals(1, result.getContent().size());
}
示例5: testFunctionQueryInFieldProjection
import org.springframework.data.geo.Point; //导入依赖的package包/类
@Test
public void testFunctionQueryInFieldProjection() {
ExampleSolrBean bean1 = new ExampleSolrBean("id-1", "one", null);
bean1.setStore("45.17614,-93.87341");
ExampleSolrBean bean2 = new ExampleSolrBean("id-2", "one two", null);
bean2.setStore("40.7143,-74.006");
solrTemplate.saveBeans(Arrays.asList(bean1, bean2));
solrTemplate.commit();
Query q = new SimpleQuery("*:*");
q.addProjectionOnField(new DistanceField("distance", "store", new Point(45.15, -93.85)));
Page<ExampleSolrBean> result = solrTemplate.queryForPage(q, ExampleSolrBean.class);
for (ExampleSolrBean bean : result) {
Assert.assertThat(bean.getDistance(), IsNull.notNullValue());
}
}
示例6: getUserDtoFromEntity
import org.springframework.data.geo.Point; //导入依赖的package包/类
/**
* Map user entity into data transfer object
*
* @param user User Entity
* @return UserDTO
*/
public UserDTO getUserDtoFromEntity(User user){
//convert geometry object to a point
Geometry g = null;
com.vividsolutions.jts.geom.Point point = null;
WKTReader reader = new WKTReader();
try {
g = reader.read(user.getLocation().toText());
point = (com.vividsolutions.jts.geom.Point) g;
}
catch (Exception e) {
//do nothing
}
//start mapping data into the dto
if (user == null)
return null;
UserDTO userDTO = map(user, UserDTO.class);
//add mapping for location if point object is not null
if (point != null) {
org.springframework.data.geo.Point gp = new Point(point.getX(), point.getY());
userDTO.setLongitude(Double.toString(point.getX()));
userDTO.setLatitude(Double.toString(point.getY()));
}
userDTO.setDisplayFlag((user.getDisplayFlag() != null && user.getDisplayFlag().booleanValue()) ? "Y" : "N");
return userDTO;
}
示例7: getUserEntityFromDto
import org.springframework.data.geo.Point; //导入依赖的package包/类
/**
* Map user data transfer object into user entity
*
* @param userDTO User Data Transfer object
* @return User
*/
public User getUserEntityFromDto(UserDTO userDTO){
User user = map(userDTO, User.class);
if (userDTO.getLatitude() != null && userDTO.getLongitude() != null){
GeometryFactory gf = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING));
Coordinate coordinate = new Coordinate(Double.parseDouble(userDTO.getLongitude()),
Double.parseDouble(userDTO.getLatitude()));
com.vividsolutions.jts.geom.Point point = gf.createPoint(coordinate);
user.setLocation(point);
}
user.setDisplayFlag(Boolean.valueOf(userDTO.getDisplayFlag()));
return user;
}
示例8: before
import org.springframework.data.geo.Point; //导入依赖的package包/类
@Before
public void before() {
geoOperations = operations.opsForGeo();
geoOperations.geoAdd("Sicily", new Point(13.361389, 38.115556), "Arigento");
geoOperations.geoAdd("Sicily", new Point(15.087269, 37.502669), "Catania");
geoOperations.geoAdd("Sicily", new Point(13.583333, 37.316667), "Palermo");
}
示例9: geoRadius
import org.springframework.data.geo.Point; //导入依赖的package包/类
/**
* Lookup points within a circle around coordinates.
*/
@Test
public void geoRadius() {
Circle circle = new Circle(new Point(13.583333, 37.316667), //
new Distance(100, DistanceUnit.KILOMETERS));
GeoResults<GeoLocation<String>> result = geoOperations.geoRadius("Sicily", circle);
assertThat(result).hasSize(2).extracting("content.name").contains("Arigento", "Palermo");
}
示例10: findByGeoLocationProperty
import org.springframework.data.geo.Point; //导入依赖的package包/类
/**
* Find entity by a {@link GeoIndexed} property on an embedded entity.
*/
@Test
public void findByGeoLocationProperty() {
Address winterfell = new Address();
winterfell.setCountry("the north");
winterfell.setCity("winterfell");
winterfell.setLocation(new Point(52.9541053, -1.2401016));
eddard.setAddress(winterfell);
Address casterlystein = new Address();
casterlystein.setCountry("Westerland");
casterlystein.setCity("Casterlystein");
casterlystein.setLocation(new Point(51.5287352, -0.3817819));
robb.setAddress(casterlystein);
flushTestUsers();
Circle innerCircle = new Circle(new Point(51.8911912, -0.4979756), new Distance(50, Metrics.KILOMETERS));
List<Person> eddardStark = repository.findByAddress_LocationWithin(innerCircle);
assertThat(eddardStark, hasItem(robb));
assertThat(eddardStark, hasSize(1));
Circle biggerCircle = new Circle(new Point(51.8911912, -0.4979756), new Distance(200, Metrics.KILOMETERS));
List<Person> eddardAndRobbStark = repository.findByAddress_LocationWithin(biggerCircle);
assertThat(eddardAndRobbStark, hasItems(robb, eddard));
assertThat(eddardAndRobbStark, hasSize(2));
}
示例11: index
import org.springframework.data.geo.Point; //导入依赖的package包/类
/**
* Looks up the stores in the given distance around the given location.
*
* @param model the {@link Model} to populate.
* @param location the optional location, if none is given, no search results will be returned.
* @param distance the distance to use, if none is given the {@link #DEFAULT_DISTANCE} is used.
* @param pageable the pagination information
* @return
*/
@RequestMapping(value = "/", method = RequestMethod.GET)
String index(Model model, @RequestParam Optional<Point> location, @RequestParam Optional<Distance> distance,
Pageable pageable) {
Point point = location.orElse(KNOWN_LOCATIONS.get("Timesquare NY"));
Page<Store> stores = repository.findByAddressLocationNear(point, distance.orElse(DEFAULT_DISTANCE), pageable);
model.addAttribute("stores", stores);
model.addAttribute("distances", DISTANCES);
model.addAttribute("selectedDistance", distance.orElse(DEFAULT_DISTANCE));
model.addAttribute("location", point);
model.addAttribute("locations", KNOWN_LOCATIONS);
model.addAttribute("api", entityLinks.linkToSearchResource(Store.class, "by-location", pageable).getHref());
return "index";
}
示例12: readStores
import org.springframework.data.geo.Point; //导入依赖的package包/类
/**
* Reads a file {@code starbucks.csv} from the class path and parses it into {@link Store} instances about to
* persisted.
*
* @return
* @throws Exception
*/
public static List<Store> readStores() throws Exception {
ClassPathResource resource = new ClassPathResource("starbucks.csv");
Scanner scanner = new Scanner(resource.getInputStream());
String line = scanner.nextLine();
scanner.close();
FlatFileItemReader<Store> itemReader = new FlatFileItemReader<Store>();
itemReader.setResource(resource);
// DelimitedLineTokenizer defaults to comma as its delimiter
DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
tokenizer.setNames(line.split(","));
tokenizer.setStrict(false);
DefaultLineMapper<Store> lineMapper = new DefaultLineMapper<Store>();
lineMapper.setFieldSetMapper(fields -> {
Point location = new Point(fields.readDouble("Longitude"), fields.readDouble("Latitude"));
Address address = new Address(fields.readString("Street Address"), fields.readString("City"),
fields.readString("Zip"), location);
return new Store(fields.readString("Name"), address);
});
lineMapper.setLineTokenizer(tokenizer);
itemReader.setLineMapper(lineMapper);
itemReader.setRecordSeparatorPolicy(new DefaultRecordSeparatorPolicy());
itemReader.setLinesToSkip(1);
itemReader.open(new ExecutionContext());
List<Store> stores = new ArrayList<>();
Store store = null;
do {
store = itemReader.read();
if (store != null) {
stores.add(store);
}
} while (store != null);
return stores;
}
示例13: findsStoresByLocation
import org.springframework.data.geo.Point; //导入依赖的package包/类
@Test
public void findsStoresByLocation() {
Point location = new Point(-73.995146, 40.740337);
Store store = new Store("Foo", new Address("street", "city", "zip", location));
store = repository.save(store);
Page<Store> stores = repository.findByAddressLocationNear(location, new Distance(1.0, Metrics.KILOMETERS),
new PageRequest(0, 10));
assertThat(stores.getContent(), hasSize(1));
assertThat(stores.getContent(), hasItem(store));
}
示例14: getProductsByLocation
import org.springframework.data.geo.Point; //导入依赖的package包/类
@Override
public List<Product> getProductsByLocation(String LatLng) throws GeoLocationException {
List<Product> found;
try {
Point point = GeoConverters.StringToPointConverter.INSTANCE.convert(LatLng);
found =
customProductRepository.findByLocationNear(new Point(point.getX(), point.getY()), new Distance(30));
} catch (Exception e) {
logger.debug("No location found with coordinates: {}", LatLng);
throw new GeoLocationException("Error in mapping latLng: " + LatLng);
}
return found;
}
示例15: testFindByLocationCriteria
import org.springframework.data.geo.Point; //导入依赖的package包/类
@Test
public void testFindByLocationCriteria() {
Point location = new Point(22.15, -90.85);
Criteria criteria = new Criteria("store").near(location, new Distance(5));
Page<Product> result =
solrOperations.queryForPage(new SimpleQuery(criteria), Product.class);
Assert.assertEquals(1, result.getTotalElements());
Assert.assertEquals(locatedInYonkers.getId(), result.getContent().get(0).getId());
}