• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java GeohashUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.spatial4j.core.io.GeohashUtils的典型用法代码示例。如果您正苦于以下问题:Java GeohashUtils类的具体用法?Java GeohashUtils怎么用?Java GeohashUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



GeohashUtils类属于com.spatial4j.core.io包,在下文中一共展示了GeohashUtils类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
 
开发者ID:Samsv77,项目名称:efficient-geo-clustering,代码行数:36,代码来源:GeoClusterManager.java


示例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);
}
 
开发者ID:europeana,项目名称:search,代码行数:8,代码来源:GeohashPrefixTree.java


示例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;
}
 
开发者ID:europeana,项目名称:search,代码行数:10,代码来源:GeohashPrefixTree.java


示例4: getShape

import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
@Override
public Shape getShape() {
  if (shape == null) {
    shape = GeohashUtils.decodeBoundary(getGeohash(), ctx);
  }
  return shape;
}
 
开发者ID:europeana,项目名称:search,代码行数:8,代码来源:GeohashPrefixTree.java


示例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;
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:GeohashHaversineFunction.java


示例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");

}
 
开发者ID:europeana,项目名称:search,代码行数:39,代码来源:DistanceFunctionTest.java


示例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;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:10,代码来源:GeohashPrefixTree.java


示例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));
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:14,代码来源:GeoHashField.java


示例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]);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:13,代码来源:GeoHashField.java


示例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;
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:10,代码来源:GeohashPrefixTree.java


示例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;
}
 
开发者ID:europeana,项目名称:search,代码行数:5,代码来源:GeohashPrefixTree.java


示例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)
}
 
开发者ID:europeana,项目名称:search,代码行数:5,代码来源:GeohashPrefixTree.java


示例13: getCenter

import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
@Override
public Point getCenter() {
  return GeohashUtils.decode(getGeohash(), ctx);
}
 
开发者ID:europeana,项目名称:search,代码行数:5,代码来源:GeohashPrefixTree.java


示例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();
}
 
开发者ID:europeana,项目名称:search,代码行数:6,代码来源:GeoHashField.java


示例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());
}
 
开发者ID:europeana,项目名称:search,代码行数:6,代码来源:GeoHashField.java


示例16: getNode

import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
@Override
public Node getNode(Point p, int level) {
  return new GhCell(GeohashUtils.encodeLatLon(p.getY(), p.getX(), level));//args are lat,lon (y,x)
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:5,代码来源:GeohashPrefixTree.java


示例17: alignGeohash

import com.spatial4j.core.io.GeohashUtils; //导入依赖的package包/类
/** NGeohash round-trip for given precision. */
private Point alignGeohash(Point p) {
  return GeohashUtils.decode(GeohashUtils.encodeLatLon(p.getY(), p.getX(), maxLength), ctx);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:5,代码来源:TestRecursivePrefixTreeStrategy.java



注:本文中的com.spatial4j.core.io.GeohashUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TabItemConfig类代码示例发布时间:2022-05-22
下一篇:
Java MUCRoom类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap