本文整理汇总了Java中com.spatial4j.core.io.GeohashUtils类的典型用法代码示例。如果您正苦于以下问题:Java GeohashUtils类的具体用法?Java GeohashUtils怎么用?Java GeohashUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GeohashUtils类属于com.spatial4j.core.io包,在下文中一共展示了GeohashUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapByGeoHash
import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
/**
* Group the points with similar Geohash at specified level
*
* @param points
* @param level Geohash level
* @return
*/
private Map<String, MutableDouble> mapByGeoHash(List<GeoPoint> points, int level) {
if (level < 1 || points == null)
throw new IllegalArgumentException();
Map<String, MutableDouble> hashPoints = new HashMap<String, MutableDouble>();
for (GeoPoint point : points) {
try {
// Calculate geo hash
String hash = GeohashUtils.encodeLatLon(point.getLatitude(), point.getLongitude());
// Cut to geo hash level
hash = hash.substring(0, level);
// Group values
MutableDouble val = hashPoints.get(hash);
if (val == null) {
hashPoints.put(hash, new MutableDouble(point.getValue()));
} else {
val.add(point.getValue());
}
} catch (Exception e) {
log.error(e);
}
}
return hashPoints;
}
示例2: getLevelForDistance
import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
@Override
public int getLevelForDistance(double dist) {
if (dist == 0)
return maxLevels;//short circuit
final int level = GeohashUtils.lookupHashLenForWidthHeight(dist, dist);
return Math.max(Math.min(level, maxLevels), 1);
}
示例3: getSubCells
import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
@Override
public Collection<Cell> getSubCells() {
String[] hashes = GeohashUtils.getSubGeohashes(getGeohash());//sorted
List<Cell> cells = new ArrayList<>(hashes.length);
for (String hash : hashes) {
cells.add(new GhCell(hash));
}
return cells;
}
示例4: getShape
import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
@Override
public Shape getShape() {
if (shape == null) {
shape = GeohashUtils.decodeBoundary(getGeohash(), ctx);
}
return shape;
}
示例5: distance
import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
protected double distance(int doc, FunctionValues gh1DV, FunctionValues gh2DV) {
double result = 0;
String h1 = gh1DV.strVal(doc);
String h2 = gh2DV.strVal(doc);
if (h1 != null && h2 != null && h1.equals(h2) == false){
//TODO: If one of the hashes is a literal value source, seems like we could cache it
//and avoid decoding every time
Point p1 = GeohashUtils.decode(h1,ctx);
Point p2 = GeohashUtils.decode(h2,ctx);
result = ctx.getDistCalc().distance(p1, p2) * degreesToDist;
} else if (h1 == null || h2 == null){
result = Double.MAX_VALUE;
}
return result;
}
示例6: testHaversine
import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
@Test
public void testHaversine() throws Exception {
clearIndex();
assertU(adoc("id", "1", "x_td", "0", "y_td", "0", "gh_s1", GeohashUtils.encodeLatLon(32.7693246, -79.9289094)));
assertU(adoc("id", "2", "x_td", "0", "y_td", String.valueOf(Math.PI / 2), "gh_s1", GeohashUtils.encodeLatLon(32.7693246, -78.9289094)));
assertU(adoc("id", "3", "x_td", String.valueOf(Math.PI / 2), "y_td", String.valueOf(Math.PI / 2), "gh_s1", GeohashUtils.encodeLatLon(32.7693246, -80.9289094)));
assertU(adoc("id", "4", "x_td", String.valueOf(Math.PI / 4), "y_td", String.valueOf(Math.PI / 4), "gh_s1", GeohashUtils.encodeLatLon(32.7693246, -81.9289094)));
assertU(adoc("id", "5", "x_td", "45.0", "y_td", "45.0",
"gh_s1", GeohashUtils.encodeLatLon(32.7693246, -81.9289094)));
assertU(adoc("id", "6", "point_hash", "32.5, -79.0", "point", "32.5, -79.0"));
assertU(adoc("id", "7", "point_hash", "32.6, -78.0", "point", "32.6, -78.0"));
assertU(commit());
//Get the haversine distance between the point 0,0 and the docs above assuming a radius of 1
assertQ(req("fl", "*,score", "q", "{!func}hsin(1, false, x_td, y_td, 0, 0)", "fq", "id:1"), "//float[@name='score']='0.0'");
assertQ(req("fl", "*,score", "q", "{!func}hsin(1, false, x_td, y_td, 0, 0)", "fq", "id:2"), "//float[@name='score']='" + (float) (Math.PI / 2) + "'");
assertQ(req("fl", "*,score", "q", "{!func}hsin(1, false, x_td, y_td, 0, 0)", "fq", "id:3"), "//float[@name='score']='" + (float) (Math.PI / 2) + "'");
assertQ(req("fl", "*,score", "q", "{!func}hsin(1, false, x_td, y_td, 0, 0)", "fq", "id:4"), "//float[@name='score']='1.0471976'");
assertQ(req("fl", "*,score", "q", "{!func}hsin(1, true, x_td, y_td, 0, 0)", "fq", "id:5"), "//float[@name='score']='1.0471976'");
//SOLR-2114
assertQ(req("fl", "*,score", "q", "{!func}hsin(6371.009, true, point, vector(0, 0))", "fq", "id:6"), "//float[@name='score']='8977.814'");
//Geo Hash Haversine
//Can verify here: http://www.movable-type.co.uk/scripts/latlong.html, but they use a slightly different radius for the earth, so just be close
//note: using assertJQ because it supports numeric deltas, and by default too
assertJQ(req("fl", "*,score", "q", "{!func}ghhsin(" + DistanceUtils.EARTH_MEAN_RADIUS_KM + ", gh_s1, \"" + GeohashUtils.encodeLatLon(32, -79) + "\",)", "fq", "id:1"),
"/response/docs/[0]/score==122.171875");
assertQ(req("fl", "id,point_hash,score", "q", "{!func}recip(ghhsin(" + DistanceUtils.EARTH_MEAN_RADIUS_KM + ", point_hash, \"" + GeohashUtils.encodeLatLon(32, -79) + "\"), 1, 1, 0)"),
"//*[@numFound='7']",
"//result/doc[1]/str[@name='id'][.='6']",
"//result/doc[2]/str[@name='id'][.='7']"//all the rest don't matter
);
assertJQ(req("fl", "*,score", "q", "{!func}ghhsin(" + DistanceUtils.EARTH_MEAN_RADIUS_KM + ", gh_s1, geohash(32, -79))", "fq", "id:1"),
"/response/docs/[0]/score==122.171875");
}
示例7: getSubCells
import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
@Override
public Collection<Node> getSubCells() {
String[] hashes = GeohashUtils.getSubGeohashes(getGeohash());//sorted
List<Node> cells = new ArrayList<Node>(hashes.length);
for (String hash : hashes) {
cells.add(new GhCell(hash));
}
return cells;
}
示例8: createSpatialQuery
import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
@Override
public Query createSpatialQuery(QParser parser, SpatialOptions options) {
double [] point = new double[0];
try {
point = ParseUtils.parsePointDouble(null, options.pointStr, 2);
} catch (InvalidShapeException e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
String geohash = GeohashUtils.encodeLatLon(point[0], point[1]);
//TODO: optimize this
return new SolrConstantScoreQuery(new ValueSourceRangeFilter(new GeohashHaversineFunction(getValueSource(options.field, parser),
new LiteralValueSource(geohash), options.radius), "0", String.valueOf(options.distance), true, true));
}
示例9: toInternal
import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
@Override
public String toInternal(String val) {
// validate that the string is of the form
// latitude, longitude
double[] latLon = new double[0];
try {
latLon = ParseUtils.parseLatitudeLongitude(null, val);
} catch (InvalidShapeException e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
return GeohashUtils.encodeLatLon(latLon[0], latLon[1]);
}
示例10: getSubCells
import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
@Override
public Collection<Cell> getSubCells() {
String[] hashes = GeohashUtils.getSubGeohashes(getGeohash());//sorted
List<Cell> cells = new ArrayList<Cell>(hashes.length);
for (String hash : hashes) {
cells.add(new GhCell(hash));
}
return cells;
}
示例11: getMaxLevelsPossible
import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
/** Any more than this and there's no point (double lat & lon are the same). */
public static int getMaxLevelsPossible() {
return GeohashUtils.MAX_PRECISION;
}
示例12: getCell
import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
@Override
public Cell getCell(Point p, int level) {
return new GhCell(GeohashUtils.encodeLatLon(p.getY(), p.getX(), level));//args are lat,lon (y,x)
}
示例13: getCenter
import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
@Override
public Point getCenter() {
return GeohashUtils.decode(getGeohash(), ctx);
}
示例14: toExternal
import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
@Override
public String toExternal(IndexableField f) {
Point p = GeohashUtils.decode(f.stringValue(), SpatialContext.GEO);
return p.getY() + "," + p.getX();
}
示例15: toInternal
import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
@Override
public String toInternal(String val) {
Point point = SpatialUtils.parsePointSolrException(val, SpatialContext.GEO);
return GeohashUtils.encodeLatLon(point.getY(), point.getX());
}