本文整理汇总了Java中com.spatial4j.core.context.SpatialContext.makePoint方法的典型用法代码示例。如果您正苦于以下问题:Java SpatialContext.makePoint方法的具体用法?Java SpatialContext.makePoint怎么用?Java SpatialContext.makePoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.spatial4j.core.context.SpatialContext
的用法示例。
在下文中一共展示了SpatialContext.makePoint方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeShape
import com.spatial4j.core.context.SpatialContext; //导入方法依赖的package包/类
@Override
public Rectangle makeShape(OCompositeKey key, SpatialContext ctx) {
Point[] points = new Point[2];
int i = 0;
for (Object o : key.getKeys()) {
List<Number> numbers = (List<Number>) o;
double lat = ((Double) OType.convert(numbers.get(0), Double.class)).doubleValue();
double lng = ((Double) OType.convert(numbers.get(1), Double.class)).doubleValue();
points[i] = ctx.makePoint(lng, lat);
i++;
}
Point lowerLeft = points[0];
Point topRight = points[1];
if (lowerLeft.getX() > topRight.getX()) {
double x = lowerLeft.getX();
lowerLeft = ctx.makePoint(topRight.getX(), lowerLeft.getY());
topRight = ctx.makePoint(x, topRight.getY());
}
return ctx.makeRectangle(lowerLeft, topRight);
}
示例2: getDistance
import com.spatial4j.core.context.SpatialContext; //导入方法依赖的package包/类
/**
* Returns distance (in meters) between 2 points.
*
* @param point1 Must not be null
* @param point2 Must not be null
* @return distance in meters
*/
public static double getDistance(Point point1, Point point2) {
Assert.notNull(point1, "point1 must not be null");
Assert.notNull(point2, "point2 must not be null");
final SpatialContext ctx = SpatialContext.GEO;
com.spatial4j.core.shape.Point p1 = ctx.makePoint(point1.getLongitude(), point1.getLatitude());
com.spatial4j.core.shape.Point p2 = ctx.makePoint(point2.getLongitude(), point2.getLatitude());
return DistanceUtils.degrees2Dist(ctx.getDistCalc().distance(p1, p2), DistanceUtils.EARTH_MEAN_RADIUS_KM) * 1000;
}
示例3: parse
import com.spatial4j.core.context.SpatialContext; //导入方法依赖的package包/类
@Override
public ValueSource parse(FunctionQParser fp) throws SyntaxError {
String fieldName = fp.parseId();
SchemaField field = fp.getReq().getSchema().getField(fieldName);
FieldType type = field.getType();
if (!(type instanceof MultiPointDocValuesField))
throw new SyntaxError("This function only supports fields of type "+
MultiPointDocValuesField.class.getName()+", not "+type.getClass().getName());
MultiPointDocValuesField mpdvFieldType = (MultiPointDocValuesField) type;
double[] parsedLatLong = null;
try {
parsedLatLong = ParseUtils.parseLatitudeLongitude(fp.parseArg());
} catch (InvalidShapeException e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
double y = parsedLatLong[0];
double x = parsedLatLong[1];
SpatialContext ctx = mpdvFieldType.getCtx();
Point point = ctx.makePoint(x, y);
String score = fp.getLocalParams().get("score", "distance");
ValueSource valueSource = new MultiPointDistanceValueSource(fieldName, point, ctx);
if ("distance".equals(score)) {
return valueSource;
}
else if ("recipDistance".equals(score)) {
int shift = fp.getLocalParams().getInt("shift", 100);
int maxScore = fp.getLocalParams().getInt("maxScore", 10);
return new ReciprocalFloatFunction(valueSource, maxScore, shift, shift);
}
else {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "'score' local-param must be one of 'distance', or 'recipDistance'");
}
}
示例4: makeShape
import com.spatial4j.core.context.SpatialContext; //导入方法依赖的package包/类
@Override
public Point makeShape(OCompositeKey key, SpatialContext ctx) {
double lat = ((Double) OType.convert(((OCompositeKey) key).getKeys().get(0), Double.class)).doubleValue();
double lng = ((Double) OType.convert(((OCompositeKey) key).getKeys().get(1), Double.class)).doubleValue();
return ctx.makePoint(lng, lat);
}
示例5: testNGramPrefixGridLosAngeles
import com.spatial4j.core.context.SpatialContext; //导入方法依赖的package包/类
@Test
public void testNGramPrefixGridLosAngeles() throws IOException {
SpatialContext ctx = SpatialContext.GEO;
TermQueryPrefixTreeStrategy prefixGridStrategy = new TermQueryPrefixTreeStrategy(new QuadPrefixTree(ctx), "geo");
Shape point = ctx.makePoint(-118.243680, 34.052230);
Document losAngeles = new Document();
losAngeles.add(new StringField("name", "Los Angeles", Field.Store.YES));
for (IndexableField field : prefixGridStrategy.createIndexableFields(point)) {
losAngeles.add(field);
}
losAngeles.add(new StoredField(prefixGridStrategy.getFieldName(), point.toString()));//just for diagnostics
addDocumentsAndCommit(Arrays.asList(losAngeles));
// This won't work with simple spatial context...
SpatialArgsParser spatialArgsParser = new SpatialArgsParser();
// TODO... use a non polygon query
// SpatialArgs spatialArgs = spatialArgsParser.parse(
// "Intersects(POLYGON((-127.00390625 39.8125,-112.765625 39.98828125,-111.53515625 31.375,-125.94921875 30.14453125,-127.00390625 39.8125)))",
// new SimpleSpatialContext());
// Query query = prefixGridStrategy.makeQuery(spatialArgs, fieldInfo);
// SearchResults searchResults = executeQuery(query, 1);
// assertEquals(1, searchResults.numFound);
}
示例6: makeShape
import com.spatial4j.core.context.SpatialContext; //导入方法依赖的package包/类
@Override
public Shape makeShape(OCompositeKey key, SpatialContext ctx) {
double lat = ((Double) OType.convert(((OCompositeKey) key).getKeys().get(0), Double.class)).doubleValue();
double lng = ((Double) OType.convert(((OCompositeKey) key).getKeys().get(1), Double.class)).doubleValue();
return ctx.makePoint(lng, lat);
}
示例7: makeShape
import com.spatial4j.core.context.SpatialContext; //导入方法依赖的package包/类
@Override
public Shape makeShape(OCompositeKey key, SpatialContext ctx) {
Point[] points = new Point[2];
int i = 0;
for (Object o : key.getKeys()) {
List<Number> numbers = (List<Number>) o;
double lat = ((Double) OType.convert(numbers.get(0), Double.class)).doubleValue();
double lng = ((Double) OType.convert(numbers.get(1), Double.class)).doubleValue();
points[i] = ctx.makePoint(lng, lat);
i++;
}
return ctx.makeRectangle(points[0], points[1]);
}
示例8: testNGramPrefixGridLosAngeles
import com.spatial4j.core.context.SpatialContext; //导入方法依赖的package包/类
@Test
public void testNGramPrefixGridLosAngeles() throws IOException {
SpatialContext ctx = SpatialContext.GEO;
TermQueryPrefixTreeStrategy prefixGridStrategy = new TermQueryPrefixTreeStrategy(new QuadPrefixTree(ctx), "geo");
Shape point = ctx.makePoint(-118.243680, 34.052230);
Document losAngeles = new Document();
losAngeles.add(new StringField("name", "Los Angeles", Field.Store.YES));
for (IndexableField field : prefixGridStrategy.createIndexableFields(point)) {
losAngeles.add(field);
}
losAngeles.add(new StoredField(prefixGridStrategy.getFieldName(), ctx.toString(point)));
addDocumentsAndCommit(Arrays.asList(losAngeles));
// This won't work with simple spatial context...
SpatialArgsParser spatialArgsParser = new SpatialArgsParser();
// TODO... use a non polygon query
// SpatialArgs spatialArgs = spatialArgsParser.parse(
// "Intersects(POLYGON((-127.00390625 39.8125,-112.765625 39.98828125,-111.53515625 31.375,-125.94921875 30.14453125,-127.00390625 39.8125)))",
// new SimpleSpatialContext());
// Query query = prefixGridStrategy.makeQuery(spatialArgs, fieldInfo);
// SearchResults searchResults = executeQuery(query, 1);
// assertEquals(1, searchResults.numFound);
}
示例9: toSpatial4j
import com.spatial4j.core.context.SpatialContext; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public com.spatial4j.core.shape.Shape toSpatial4j(SpatialContext spatialContext) {
return spatialContext.makePoint(longitude, latitude);
}