本文整理汇总了Java中com.spatial4j.core.shape.Point类的典型用法代码示例。如果您正苦于以下问题:Java Point类的具体用法?Java Point怎么用?Java Point使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Point类属于com.spatial4j.core.shape包,在下文中一共展示了Point类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBoundingStateForCoordinate
import com.spatial4j.core.shape.Point; //导入依赖的package包/类
public String getBoundingStateForCoordinate(Double lat, Double lng) {
Point onePoint = ctx.makePoint(lat, lng);
for (String oneShapeKey : geometries.keySet()) {
Shape oneShape = geometries.get(oneShapeKey);
SpatialRelation relation = oneShape.relate(onePoint);
if (relation == SpatialRelation.CONTAINS || relation == SpatialRelation.INTERSECTS
|| relation == SpatialRelation.WITHIN) {
return oneShapeKey;
} else {
System.out.println("NOT IN:" + relation.toString());
}
}
return null;
}
示例2: isPointInPolygon
import com.spatial4j.core.shape.Point; //导入依赖的package包/类
public Boolean isPointInPolygon(Double lat, Double lng) {
Point onePoint = ctx.makePoint(lat, lng);
for (Shape oneShape : geometries.values()) {
SpatialRelation relation = oneShape.relate(onePoint);
if (relation == SpatialRelation.CONTAINS || relation == SpatialRelation.INTERSECTS
|| relation == SpatialRelation.WITHIN) {
return true;
} else {
System.out.println("NOT IN:" + relation.toString());
}
}
return false;
}
示例3: createField
import com.spatial4j.core.shape.Point; //导入依赖的package包/类
/**
* Normally called by Solr's {@link org.apache.solr.update.DocumentBuilder}.
* It will also be called by {@link org.apache.solr.update.processor.MultiValUpdateRequestProcessorFactory}
* given a SolrInputField which has access to multiple values. This is
* arranged to circumvent DocumentBuilder's limitation.
*/
@Override
public IndexableField createField(SchemaField field, Object value, float boost) {
if (field.stored())
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "This field" +
"cannot be configured as stored: " + field);
List<Point> points;
if (value instanceof SolrInputField) {
SolrInputField inputField = ((SolrInputField) value);
points = new ArrayList<Point>(inputField.getValueCount());
for (Object iVal : inputField.getValues()) {
points.add(pointFromValue(iVal));
}
} else if (value instanceof IndexableField) {//result of MultiValUpdateRequestProcessorFactory
return (IndexableField) value;
} else {
points = Collections.singletonList(pointFromValue(value));
}
BytesRef bytes = MultiPointEncoding.pointsToBytes(points);
return new BinaryDocValuesField(field.getName(), bytes);
}
示例4: testEncoding
import com.spatial4j.core.shape.Point; //导入依赖的package包/类
@Test
public void testEncoding() {
Point[] points = new Point[random().nextInt(4)];
for (int i = 0; i < points.length; i++) {
points[i] = ctx.makePoint(randomFloatIn(-180, 180), randomFloatIn(-90, 90));
}
BytesRef bytes = MultiPointEncoding.pointsToBytes(Arrays.asList(points));
float[] output = MultiPointEncoding.bytesToFloats(bytes);
Arrays.sort(points, MultiPointEncoding.POINT_COMPARATOR);
float[] inputs = new float[points.length * 2];
for (int i = 0; i < points.length; i++) {
inputs[i*2] = (float) points[i].getX();
inputs[i*2 + 1] = (float) points[i].getY();
}
assertArrayEquals(inputs, output, 0.0f);
}
示例5: searchIntersect
import com.spatial4j.core.shape.Point; //导入依赖的package包/类
public Object searchIntersect(OCompositeKey key, double distance, OCommandContext context) throws IOException {
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();
SpatialOperation operation = SpatialOperation.Intersects;
Point p = ctx.makePoint(lng, lat);
SpatialArgs args = new SpatialArgs(operation, ctx.makeCircle(lng, lat,
DistanceUtils.dist2Degrees(distance, DistanceUtils.EARTH_MEAN_RADIUS_KM)));
Filter filter = strategy.makeFilter(args);
IndexSearcher searcher = searcher();
ValueSource valueSource = strategy.makeDistanceValueSource(p);
Sort distSort = new Sort(valueSource.getSortField(false)).rewrite(searcher);
return new LuceneResultSet(this,
new SpatialQueryContext(context, searcher, new MatchAllDocsQuery(), filter, distSort).setSpatialArgs(args));
}
示例6: makeShape
import com.spatial4j.core.shape.Point; //导入依赖的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);
}
示例7: build
import com.spatial4j.core.shape.Point; //导入依赖的package包/类
@Override
public SpatialQueryContext build(Map<String, Object> query) throws Exception {
Shape shape = parseShape(query);
double distance = 0;
Number n = (Number) query.get(MAX_DISTANCE);
if (n != null) {
distance = n.doubleValue();
}
Point p = (Point) shape;
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, factory.context().makeCircle(p.getX(), p.getY(),
DistanceUtils.dist2Degrees(distance, DistanceUtils.EARTH_MEAN_RADIUS_KM)));
Filter filter = manager.strategy().makeFilter(args);
ValueSource valueSource = manager.strategy().makeDistanceValueSource(p);
IndexSearcher searcher = manager.searcher();
Sort distSort = new Sort(valueSource.getSortField(false)).rewrite(searcher);
return new SpatialQueryContext(null, searcher, new MatchAllDocsQuery(), filter, distSort).setSpatialArgs(args);
}
示例8: testPointIO
import com.spatial4j.core.shape.Point; //导入依赖的package包/类
@Test
public void testPointIO() throws ParseException {
ODocument doc = new ODocument("OPoint");
doc.field("coordinates", new ArrayList<Double>() {
{
add(-100d);
add(45d);
}
});
OPointShapeBuilder builder = new OPointShapeBuilder();
String p1 = builder.asText(doc);
Assert.assertNotNull(p1);
Point point = context.makePoint(-100d, 45d);
String p2 = context.getGeometryFrom(point).toText();
Assert.assertEquals(p2, p1);
ODocument parsed = builder.toDoc(p2);
Assert.assertEquals(doc.field("coordinates"), parsed.field("coordinates"));
}
示例9: boundingBoxTestNew
import com.spatial4j.core.shape.Point; //导入依赖的package包/类
@Test
public void boundingBoxTestNew() {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:test");
db.create();
try {
// Shape parse = JtsSpatialContext.GEO
// .getWktShapeParser()
// .parse(
// "POLYGON((-83.757293 42.281164, -83.749274 42.281164, -83.749274 42.275227, -83.757293 42.275227, -83.757293 42.281164))");
Shape parse = JtsSpatialContext.GEO
.makeRectangle(-83.7662120858887,-83.71986351411135, 42.26531323615103, 42.29239784478525);
Point point = JtsSpatialContext.GEO.makePoint(-83.7605452, 42.2814837);
point.relate(parse);
} catch (Exception e) {
e.printStackTrace();
} finally {
db.drop();
}
}
示例10: getCells
import com.spatial4j.core.shape.Point; //导入依赖的package包/类
/**
* A Point-optimized implementation of
* {@link #getCells(com.spatial4j.core.shape.Shape, int, boolean, boolean)}. That
* method in facts calls this for points.
* <p/>
* This implementation depends on {@link #getCell(String)} being fast, as its
* called repeatedly when incPlarents is true.
*/
public List<Cell> getCells(Point p, int detailLevel, boolean inclParents) {
Cell cell = getCell(p, detailLevel);
if (!inclParents) {
return Collections.singletonList(cell);
}
String endToken = cell.getTokenString();
assert endToken.length() == detailLevel;
List<Cell> cells = new ArrayList<>(detailLevel);
for (int i = 1; i < detailLevel; i++) {
cells.add(getCell(endToken.substring(0, i)));//TODO refactor: add a cell.getParent()
}
cells.add(cell);
return cells;
}
示例11: calcDistanceFromErrPct
import com.spatial4j.core.shape.Point; //导入依赖的package包/类
/**
* Computes the distance given a shape and the {@code distErrPct}. The
* algorithm is the fraction of the distance from the center of the query
* shape to its closest bounding box corner.
*
* @param shape Mandatory.
* @param distErrPct 0 to 0.5
* @param ctx Mandatory
* @return A distance (in degrees).
*/
public static double calcDistanceFromErrPct(Shape shape, double distErrPct, SpatialContext ctx) {
if (distErrPct < 0 || distErrPct > 0.5) {
throw new IllegalArgumentException("distErrPct " + distErrPct + " must be between [0 to 0.5]");
}
if (distErrPct == 0 || shape instanceof Point) {
return 0;
}
Rectangle bbox = shape.getBoundingBox();
//Compute the distance from the center to a corner. Because the distance
// to a bottom corner vs a top corner can vary in a geospatial scenario,
// take the closest one (greater precision).
Point ctr = bbox.getCenter();
double y = (ctr.getY() >= 0 ? bbox.getMaxY() : bbox.getMinY());
double diagonalDist = ctx.getDistCalc().distance(ctr, bbox.getMaxX(), y);
return diagonalDist * distErrPct;
}
示例12: testRecipScore
import com.spatial4j.core.shape.Point; //导入依赖的package包/类
@Test
public void testRecipScore() throws IOException {
Point p100 = ctx.makePoint(2, 1);
adoc("100", p100);
Point p101 = ctx.makePoint(-1, 4);
adoc("101", p101);
adoc("103", (Shape)null);//test score for nothing
adoc("999", ctx.makePoint(2, 1));//test deleted
commit();
deleteDoc("999");
commit();
double dist = ctx.getDistCalc().distance(p100, p101);
Shape queryShape = ctx.makeCircle(2.01, 0.99, dist);
checkValueSource(strategy.makeRecipDistanceValueSource(queryShape),
new float[]{1.00f, 0.10f, 0f}, 0.09f);
}
示例13: gridSnap
import com.spatial4j.core.shape.Point; //导入依赖的package包/类
protected Shape gridSnap(Shape snapMe) {
if (snapMe == null)
return null;
if (snapMe instanceof ShapePair) {
ShapePair me = (ShapePair) snapMe;
return new ShapePair(gridSnap(me.shape1), gridSnap(me.shape2), me.biasContainsThenWithin);
}
if (snapMe instanceof Point) {
snapMe = snapMe.getBoundingBox();
}
//The next 4 lines mimic PrefixTreeStrategy.createIndexableFields()
double distErrPct = ((PrefixTreeStrategy) strategy).getDistErrPct();
double distErr = SpatialArgs.calcDistanceFromErrPct(snapMe, distErrPct, ctx);
int detailLevel = grid.getLevelForDistance(distErr);
List<Cell> cells = grid.getCells(snapMe, detailLevel, false, true);
//calc bounding box of cells.
List<Shape> cellShapes = new ArrayList<>(cells.size());
for (Cell cell : cells) {
cellShapes.add(cell.getShape());
}
return new ShapeCollection<>(cellShapes, ctx).getBoundingBox();
}
示例14: gridSnap
import com.spatial4j.core.shape.Point; //导入依赖的package包/类
protected Shape gridSnap(Shape snapMe) {
if (snapMe == null)
return null;
if (snapMe instanceof ShapePair) {
ShapePair me = (ShapePair) snapMe;
return new ShapePair(gridSnap(me.shape1), gridSnap(me.shape2), me.biasContainsThenWithin);
}
if (snapMe instanceof Point) {
snapMe = snapMe.getBoundingBox();
}
//The next 4 lines mimic PrefixTreeStrategy.createIndexableFields()
double distErrPct = ((PrefixTreeStrategy) strategy).getDistErrPct();
double distErr = SpatialArgs.calcDistanceFromErrPct(snapMe, distErrPct, ctx);
int detailLevel = grid.getLevelForDistance(distErr);
Iterator<Cell> cells = grid.getCells(snapMe, detailLevel, false, false).iterator();
//calc bounding box of cells.
List<Shape> cellShapes = new ArrayList<>(1024);
while (cells.hasNext()) {
Cell cell = cells.next();
if (!cell.isLeaf())
continue;
cellShapes.add(cell.getShape());
}
return new ShapeCollection<>(cellShapes, ctx).getBoundingBox();
}
示例15: newSampleDocument
import com.spatial4j.core.shape.Point; //导入依赖的package包/类
private Document newSampleDocument(int id, Shape... shapes) {
Document doc = new Document();
doc.add(new IntField("id", id, Field.Store.YES));
//Potentially more than one shape in this field is supported by some
// strategies; see the javadocs of the SpatialStrategy impl to see.
for (Shape shape : shapes) {
for (IndexableField f : strategy.createIndexableFields(shape)) {
doc.add(f);
}
//store it too; the format is up to you
// (assume point in this example)
Point pt = (Point) shape;
doc.add(new StoredField(strategy.getFieldName(), pt.getX()+" "+pt.getY()));
}
return doc;
}