/**
* Spatial selection of CarStation entity using circle around target point
* NOTE: the \\ notation is required for escaping the query
*
* @param targetX X coordinate of the target location (longitude)
* @param targetY Y coordinate of the target location (latitude)
* @param radius Radius around target in meters
* @return List of CarStation entities in range
*/
@Override
public List<CarStation> findCarStationsInRadius(Double targetX, Double targetY, Double radius) {
String sql = "WITH index_sel AS (" +
"SELECT s.*, st_distance(st_geomfromtext('POINT(' || ? || ' ' || ? || ')', 4326)" +
"\\:\\:GEOGRAPHY, s.geopos\\:\\:GEOGRAPHY) AS distance " +
"FROM carstation s " +
"ORDER BY st_geomfromtext('POINT(' || ? || ' ' || ? || ')', 4326) <-> s.geopos) " +
"SELECT " + getStationFieldsConcat() +
"FROM index_sel " +
"WHERE distance < ? ORDER BY distance;";
Query query = entityManager.createNativeQuery(sql, CarStation.class);
query.setParameter(1, targetX);
query.setParameter(2, targetY);
query.setParameter(3, targetX);
query.setParameter(4, targetY);
query.setParameter(5, radius);
try {
return query.getResultList();
} catch (PersistenceException e) {
// Unable to find closest Sharing Station in Database
return Lists.newArrayList();
}
}
StationRepositoryImpl.java 文件源码
java
阅读 34
收藏 0
点赞 0
评论 0
项目:xsharing-services-router
作者:
评论列表
文章目录