本文整理汇总了Java中com.spatial4j.core.distance.DistanceUtils.dist2Degrees方法的典型用法代码示例。如果您正苦于以下问题:Java DistanceUtils.dist2Degrees方法的具体用法?Java DistanceUtils.dist2Degrees怎么用?Java DistanceUtils.dist2Degrees使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.spatial4j.core.distance.DistanceUtils
的用法示例。
在下文中一共展示了DistanceUtils.dist2Degrees方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: searchNearby
import com.spatial4j.core.distance.DistanceUtils; //导入方法依赖的package包/类
/**
* Returns a list of location near a certain coordinate.
* @param latitude, @param longitude - Center of search area
* @param distanceInMiles - Search Radius in miles
* @param indexerPath - Path to Lucene index
* @param count - Upper bound to number of results
* @return - List of locations sorted by population
* @throws IOException
*/
public List<Location> searchNearby(Double latitude, Double longitude, Double distanceInMiles, String indexerPath, int count) throws IOException {
double distanceInDeg = DistanceUtils.dist2Degrees(distanceInMiles,DistanceUtils.EARTH_EQUATORIAL_RADIUS_MI);
SpatialArgs spatialArgs = new SpatialArgs(SpatialOperation.IsWithin,
ctx.makeCircle(longitude,latitude, distanceInDeg));
String key = latitude+"-"+longitude;
Filter filter = strategy.makeFilter(spatialArgs);
IndexSearcher searcher = new IndexSearcher(createIndexReader(indexerPath));
Sort sort = new Sort(populationSort);
TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), filter, count, sort);
ScoreDoc[] scoreDocs = topDocs.scoreDocs;
HashMap<String, List<Location>> allCandidates = new HashMap<String, List<Location>>();
getMatchingCandidates(searcher, allCandidates, key, scoreDocs);
List<Location> results = allCandidates.get(key);
return results;
}
示例2: initMaxLevels
import com.spatial4j.core.distance.DistanceUtils; //导入方法依赖的package包/类
protected void initMaxLevels() {
String mlStr = args.get(MAX_LEVELS);
if (mlStr != null) {
maxLevels = Integer.valueOf(mlStr);
return;
}
double degrees;
String maxDetailDistStr = args.get(MAX_DIST_ERR);
if (maxDetailDistStr == null) {
if (!ctx.isGeo()) {
return;//let default to max
}
degrees = DistanceUtils.dist2Degrees(DEFAULT_GEO_MAX_DETAIL_KM, DistanceUtils.EARTH_MEAN_RADIUS_KM);
} else {
degrees = Double.parseDouble(maxDetailDistStr);
}
maxLevels = getLevelForDistance(degrees);
}
示例3: createSpatialQuery
import com.spatial4j.core.distance.DistanceUtils; //导入方法依赖的package包/类
/**
* Implemented for compatibility with Solr 3 spatial geofilt & bbox query parsers:
* {@link SpatialQueryable}.
*/
@Override
public Query createSpatialQuery(QParser parser, SpatialOptions options) {
//--WARNING: the code from here to the next marker is identical to LatLonType's impl.
double[] point = null;
try {
point = ParseUtils.parseLatitudeLongitude(options.pointStr);
} catch (InvalidShapeException e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
// lat & lon in degrees
double latCenter = point[0];
double lonCenter = point[1];
double distDeg = DistanceUtils.dist2Degrees(options.distance, options.radius);
//--END-WARNING
Shape shape = ctx.makeCircle(lonCenter, latCenter, distDeg);
if (options.bbox)
shape = shape.getBoundingBox();
SpatialArgs spatialArgs = new SpatialArgs(SpatialOperation.Intersects, shape);
return getQueryFromSpatialArgs(parser, options.field, spatialArgs);
}
示例4: geoSearch
import com.spatial4j.core.distance.DistanceUtils; //导入方法依赖的package包/类
/**
* Returns a geoquery.
*/
public Filter geoSearch(String value) {
GeopositionComparator comp = (GeopositionComparator) prop.getComparator();
double dist = comp.getMaxDistance();
double degrees = DistanceUtils.dist2Degrees(dist, DistanceUtils.EARTH_MEAN_RADIUS_KM * 1000.0);
Shape circle = spatialctx.makeCircle(parsePoint(value), degrees);
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle);
return strategy.makeFilter(args);
}
示例5: testOneMeterPrecision
import com.spatial4j.core.distance.DistanceUtils; //导入方法依赖的package包/类
@Test
public void testOneMeterPrecision() {
init(GeohashPrefixTree.getMaxLevelsPossible());
GeohashPrefixTree grid = (GeohashPrefixTree) ((RecursivePrefixTreeStrategy) strategy).getGrid();
//DWS: I know this to be true. 11 is needed for one meter
double degrees = DistanceUtils.dist2Degrees(0.001, DistanceUtils.EARTH_MEAN_RADIUS_KM);
assertEquals(11, grid.getLevelForDistance(degrees));
}
示例6: testPrecision
import com.spatial4j.core.distance.DistanceUtils; //导入方法依赖的package包/类
@Test
public void testPrecision() throws IOException{
init(GeohashPrefixTree.getMaxLevelsPossible());
Point iPt = ctx.makePoint(2.8028712999999925, 48.3708044);//lon, lat
addDocument(newDoc("iPt", iPt));
commit();
Point qPt = ctx.makePoint(2.4632387000000335, 48.6003516);
final double KM2DEG = DistanceUtils.dist2Degrees(1, DistanceUtils.EARTH_MEAN_RADIUS_KM);
final double DEG2KM = 1 / KM2DEG;
final double DIST = 35.75;//35.7499...
assertEquals(DIST, ctx.getDistCalc().distance(iPt, qPt) * DEG2KM, 0.001);
//distErrPct will affect the query shape precision. The indexed precision
// was set to nearly zilch via init(GeohashPrefixTree.getMaxLevelsPossible());
final double distErrPct = 0.025; //the suggested default, by the way
final double distMult = 1+distErrPct;
assertTrue(35.74*distMult >= DIST);
checkHits(q(qPt, 35.74 * KM2DEG, distErrPct), 1, null);
assertTrue(30*distMult < DIST);
checkHits(q(qPt, 30 * KM2DEG, distErrPct), 0, null);
assertTrue(33*distMult < DIST);
checkHits(q(qPt, 33 * KM2DEG, distErrPct), 0, null);
assertTrue(34*distMult < DIST);
checkHits(q(qPt, 34 * KM2DEG, distErrPct), 0, null);
}
示例7: createSpatialQuery
import com.spatial4j.core.distance.DistanceUtils; //导入方法依赖的package包/类
/**
* Implemented for compatibility with geofilt & bbox query parsers:
* {@link SpatialQueryable}.
*/
@Override
public Query createSpatialQuery(QParser parser, SpatialOptions options) {
Point pt = SpatialUtils.parsePointSolrException(options.pointStr, ctx);
double distDeg = DistanceUtils.dist2Degrees(options.distance, options.radius);
Shape shape = ctx.makeCircle(pt, distDeg);
if (options.bbox)
shape = shape.getBoundingBox();
SpatialArgs spatialArgs = new SpatialArgs(SpatialOperation.Intersects, shape);
return getQueryFromSpatialArgs(parser, options.field, spatialArgs);
}
示例8: toSpatial4j
import com.spatial4j.core.distance.DistanceUtils; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Shape toSpatial4j(SpatialContext spatialContext) {
double kms = distance.getValue(GeoDistanceUnit.KILOMETRES);
double d = DistanceUtils.dist2Degrees(kms, DistanceUtils.EARTH_MEAN_RADIUS_KM);
return spatialContext.makeCircle(longitude, latitude, d);
}
示例9: checkHits
import com.spatial4j.core.distance.DistanceUtils; //导入方法依赖的package包/类
private void checkHits(String fieldName, boolean exact, String ptStr, double distKM, int count, int ... docIds) throws ParseException {
if (exact && fieldName.equalsIgnoreCase("bbox")) {
return; // bbox field only supports rectangular query
}
String [] tests = new String[docIds != null && docIds.length > 0 ? docIds.length + 1 : 1];
//test for presence of required ids first
int i = 0;
if (docIds != null && docIds.length > 0) {
for (int docId : docIds) {
tests[i++] = "//result/doc/*[@name='id'][.='" + docId + "']";
}
}
//check total length last; maybe response includes ids it shouldn't. Nicer to check this last instead of first so
// that there may be a more specific detailed id to investigate.
tests[i++] = "*[count(//doc)=" + count + "]";
//Test using the Lucene spatial syntax
{
//never actually need the score but lets test
String score = new String[]{null, "none","distance","recipDistance"}[random().nextInt(4)];
double distDEG = DistanceUtils.dist2Degrees(distKM, DistanceUtils.EARTH_MEAN_RADIUS_KM);
Point point = SpatialUtils.parsePoint(ptStr, SpatialContext.GEO);
String circleStr = "BUFFER(POINT(" + point.getX()+" "+point.getY()+")," + distDEG + ")";
String shapeStr;
if (exact) {
shapeStr = circleStr;
} else {//bbox
//the GEO is an assumption
SpatialContext ctx = SpatialContext.GEO;
Rectangle bbox = ctx.readShapeFromWkt(circleStr).getBoundingBox();
shapeStr = "ENVELOPE(" + bbox.getMinX() + ", " + bbox.getMaxX() +
", " + bbox.getMaxY() + ", " + bbox.getMinY() + ")";
}
//FYI default distErrPct=0.025 works with the tests in this file
assertQ(req(
"fl", "id", "q","*:*", "rows", "1000",
"fq", "{!field f=" + fieldName + (score==null?"":" score="+score)
+ "}Intersects(" + shapeStr + ")"),
tests);
}
//Test using geofilt
{
assertQ(req(
"fl", "id", "q", "*:*", "rows", "1000",
"fq", "{!" + (exact ? "geofilt" : "bbox") + " sfield=" + fieldName + " pt='" + ptStr + "' d=" + distKM + "}"),
tests);
}
}
示例10: checkHits
import com.spatial4j.core.distance.DistanceUtils; //导入方法依赖的package包/类
private void checkHits(String fieldName, boolean exact, String ptStr, double distKM, int count, int ... docIds) {
String [] tests = new String[docIds != null && docIds.length > 0 ? docIds.length + 1 : 1];
//test for presence of required ids first
int i = 0;
if (docIds != null && docIds.length > 0) {
for (int docId : docIds) {
tests[i++] = "//result/doc/*[@name='id'][.='" + docId + "']";
}
}
//check total length last; maybe response includes ids it shouldn't. Nicer to check this last instead of first so
// that there may be a more specific detailed id to investigate.
tests[i++] = "*[count(//doc)=" + count + "]";
//Test using the Solr 4 syntax
{
//never actually need the score but lets test
String score = new String[]{null, "none","distance","recipDistance"}[random().nextInt(4)];
double distDEG = DistanceUtils.dist2Degrees(distKM, DistanceUtils.EARTH_MEAN_RADIUS_KM);
String circleStr = "Circle(" + ptStr.replaceAll(" ", "") + " d=" + distDEG + ")";
String shapeStr;
if (exact) {
shapeStr = circleStr;
} else {//bbox
//the GEO is an assumption
SpatialContext ctx = SpatialContext.GEO;
shapeStr = ctx.toString( ctx.readShape(circleStr).getBoundingBox() );
}
//FYI default distErrPct=0.025 works with the tests in this file
assertQ(req(
"fl", "id", "q","*:*", "rows", "1000",
"fq", "{!field f=" + fieldName + (score==null?"":" score="+score)
+ "}Intersects(" + shapeStr + ")"),
tests);
}
//Test using the Solr 3 syntax
{
assertQ(req(
"fl", "id", "q", "*:*", "rows", "1000",
"fq", "{!" + (exact ? "geofilt" : "bbox") + " sfield=" + fieldName + " pt='" + ptStr + "' d=" + distKM + "}"),
tests);
}
}