本文整理汇总了Java中com.spatial4j.core.shape.ShapeCollection类的典型用法代码示例。如果您正苦于以下问题:Java ShapeCollection类的具体用法?Java ShapeCollection怎么用?Java ShapeCollection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ShapeCollection类属于com.spatial4j.core.shape包,在下文中一共展示了ShapeCollection类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shape2Map
import com.spatial4j.core.shape.ShapeCollection; //导入依赖的package包/类
public static Map<String, Object> shape2Map(Shape shape) {
if (shape instanceof ShapeCollection) {
ShapeCollection<?> shapeCollection = (ShapeCollection<?>)shape;
List<Map<String, Object>> geometries = new ArrayList<>(shapeCollection.size());
for(Shape collShape : shapeCollection) {
geometries.add(shape2Map(collShape));
}
return ImmutableMap.of(
TYPE_FIELD, GEOMETRY_COLLECTION,
GEOMETRIES_FIELD, geometries
);
} else {
try {
return GEOJSON_CONVERTER.convert(JtsSpatialContext.GEO.getGeometryFrom(shape));
} catch (InvalidShapeException e) {
throw new IllegalArgumentException(
String.format(Locale.ENGLISH, "Cannot convert shape %s to Map", shape), e);
}
}
}
示例2: gridSnap
import com.spatial4j.core.shape.ShapeCollection; //导入依赖的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();
}
示例3: gridSnap
import com.spatial4j.core.shape.ShapeCollection; //导入依赖的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();
}
示例4: fromDoc
import com.spatial4j.core.shape.ShapeCollection; //导入依赖的package包/类
@Override
public ShapeCollection<Shape> fromDoc(ODocument doc) {
List<ODocument> geometries = doc.field("geometries");
List<Shape> shapes = new ArrayList<Shape>();
Geometry[] geoms = new Geometry[geometries.size()];
for (ODocument geometry : geometries) {
Shape shape = shapeFactory.fromDoc(geometry);
shapes.add(shape);
}
return new ShapeCollection(shapes, SPATIAL_CONTEXT);
}
示例5: asText
import com.spatial4j.core.shape.ShapeCollection; //导入依赖的package包/类
@Override
public String asText(ShapeCollection<Shape> shapes) {
Geometry[] geometries = new Geometry[shapes.size()];
int i = 0;
for (Shape shape : shapes) {
geometries[i] = SPATIAL_CONTEXT.getGeometryFrom(shape);
i++;
}
return GEOMETRY_FACTORY.createGeometryCollection(geometries).toText();
}
示例6: toDoc
import com.spatial4j.core.shape.ShapeCollection; //导入依赖的package包/类
@Override
public ODocument toDoc(ShapeCollection<Shape> shapes) {
ODocument doc = new ODocument(getName());
List<ODocument> geometries = new ArrayList<ODocument>(shapes.size());
for (Shape s : shapes) {
geometries.add(shapeFactory.toDoc(s));
}
doc.field("geometries", geometries);
return doc;
}
示例7: toDoc
import com.spatial4j.core.shape.ShapeCollection; //导入依赖的package包/类
@Override
public ODocument toDoc(Shape shape) {
// TODO REFACTOR
ODocument doc = null;
if (Point.class.isAssignableFrom(shape.getClass())) {
doc = factories.get(OPointShapeBuilder.NAME).toDoc(shape);
} else if (Rectangle.class.isAssignableFrom(shape.getClass())) {
doc = factories.get(ORectangleShapeBuilder.NAME).toDoc(shape);
} else if (JtsGeometry.class.isAssignableFrom(shape.getClass())) {
JtsGeometry geometry = (JtsGeometry) shape;
Geometry geom = geometry.getGeom();
doc = factories.get("O" + geom.getClass().getSimpleName()).toDoc(shape);
} else if (ShapeCollection.class.isAssignableFrom(shape.getClass())) {
ShapeCollection collection = (ShapeCollection) shape;
if (isMultiPolygon(collection)) {
doc = factories.get("OMultiPolygon").toDoc(createMultiPolygon(collection));
} else if (isMultiPoint(collection)) {
doc = factories.get("OMultiPoint").toDoc(createMultiPoint(collection));
} else if (isMultiLine(collection)) {
doc = factories.get("OMultiLineString").toDoc(createMultiLine(collection));
} else {
doc = factories.get("OGeometryCollection").toDoc(shape);
}
}
return doc;
}