我正在努力实现简单的目标。使用https://github.com/Esri/geometry-api-java库我想从shapefile中读取多个几何图形,但到目前为止似乎API没有提供这样做的能力,现在我设法从档案(第一个)。
以下是我尝试过的代码示例:
property in = FileInputStream
Geometry geometry = GeometryEngine.geometryFromEsriShape(IOUtils.toByteArray(in), Geometry.Type.Unknown);
System.out.println(geometry);
OperatorImportFromESRIShape importerShape = (OperatorImportFromESRIShape) OperatorFactoryLocal.getInstance().getOperator(Operator.Type.ImportFromESRIShape);
ByteBuffer byteBuffer = ByteBuffer.wrap(IOUtils.toByteArray(in));
Geometry geometry = importerShape.execute(0, Geometry.Type.Unknown, byteBuffer);
在这两种情况下,API都只返回单个Geometry。 问题是如何逐个从输入流中读取多个几何。
感谢您的帮助。
答案 0 :(得分:0)
将java包移动到:
package com.esri.core.geometry;
您可以访问一个包受保护的方法,该方法返回GeometryCursor:
buffer = ByteBuffer.wrap(Files.readAllBytes(Paths.get("Path_to_Shapefile")));
buffer.order(ByteOrder.LITTLE_ENDIAN);
OperatorImportFromESRIShape op = (OperatorImportFromESRIShape) OperatorFactoryLocal.getInstance().getOperator(
Type.ImportFromESRIShape);
SimpleByteBufferCursor byteBufferCursor = new SimpleByteBufferCursor(buffer);
GeometryCursor geometryCursor = op.execute(ShapeImportFlags.ShapeImportNonTrusted, Geometry.Type.Unknown,
byteBufferCursor);
Geometry cursor;
while ((cursor = geometryCursor.next()) != null) {
System.out.println(cursor);
}