本文整理汇总了Java中com.vividsolutions.jts.io.WKBReader.read方法的典型用法代码示例。如果您正苦于以下问题:Java WKBReader.read方法的具体用法?Java WKBReader.read怎么用?Java WKBReader.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vividsolutions.jts.io.WKBReader
的用法示例。
在下文中一共展示了WKBReader.read方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doEvaluate
import com.vividsolutions.jts.io.WKBReader; //导入方法依赖的package包/类
@Override
protected void doEvaluate(TExecutionContext context, LazyList<? extends ValueSource> inputs, ValueTarget output) {
byte[] data = new byte[0];
if (inputs.get(0).hasAnyValue()) {
Object o = inputs.get(0).getObject();
if (o instanceof BlobRef) {
BlobRef blob;
blob = (BlobRef) o;
String mode = context.getQueryContext().getStore().getConfig().getProperty(AkBlob.RETURN_UNWRAPPED);
if (mode.equalsIgnoreCase(AkBlob.UNWRAPPED)){
data = blob.getBytes();
}
else {
if (blob.isShortLob()) {
data = blob.getBytes();
} else {
LobService ls = context.getQueryContext().getServiceManager().getServiceByClass(LobService.class);
data = ls.readBlob(context.getQueryContext().getSession(), blob.getId());
}
}
} else if (o instanceof byte[]) {
data = (byte[])o;
}
}
WKBReader reader = (WKBReader)context.preptimeObjectAt(READER_CONTEXT_POS);
try {
Geometry geometry = reader.read(data);
output.putObject(geometry);
} catch(ParseException e) {
throw new InvalidSpatialObjectException(e.getMessage());
}
}
示例2: Binary2Geometry
import com.vividsolutions.jts.io.WKBReader; //导入方法依赖的package包/类
public static Geometry Binary2Geometry(final byte[] geometryAsBytes) throws ParseException {
final byte[] wkb = new byte[geometryAsBytes.length - 4];
System.arraycopy(geometryAsBytes, 4, wkb, 0, wkb.length);
final WKBReader wkbReader = new WKBReader();
final Geometry geom = wkbReader.read(wkb);
return geom;
}
示例3: fromWkb
import com.vividsolutions.jts.io.WKBReader; //导入方法依赖的package包/类
public static Geometry fromWkb(ValueMetaInterface metaA, Object dataA) throws KettleValueException{
Geometry geom = null;
WKBReader wkbReader = new WKBReader();
if (dataA==null || !metaA.isString())
return null;
try {
geom = wkbReader.read(WKBReader.hexToBytes(metaA.getString(dataA)));
return geom;
} catch (ParseException e) {
return null;
}
}
示例4: onGeometryLoadingFinished
import com.vividsolutions.jts.io.WKBReader; //导入方法依赖的package包/类
protected void onGeometryLoadingFinished(Cursor cursor) {
try {
if (cursor == null || cursor.getCount() == 0)
return;
Log.v(TAG, "Geometries loaded: " + cursor.getCount());
final int colId = cursor.getColumnIndexOrThrow(mIdColumn);
final int colGeom = cursor.getColumnIndexOrThrow(mGeomColumn);
final int colName = cursor.getColumnIndex(mNameColumn);
final WKBReader geomReader = new WKBReader();
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
final long id = cursor.getLong(colId);
final String name = (colName != -1) ? cursor.getString(colName) : null;
final String key = createGeomKey(mLoaderId, id);
if (mGeomKeys.contains(key))
continue;
Geometry geom;
//Geometry geom = mGeomCache.getGeometry(key);
//if (geom == null)
//{
try {
final byte[] geomBlob = cursor.getBlob(colGeom);
if (geomBlob == null) {
Log.e(TAG, "Malformed or null geometry with id=" + id + ", name=" + name + " in table " + mTable);
continue;
}
geom = geomReader.read(geomBlob);
//mGeomCache.putGeometry(key, geom);
addGeometry(geom, name);
} catch (Exception ex) {
Log.e(TAG, "Failed to parse geometry blob with id=" + id + ", name=" + name + " in table " + mTable);
ex.printStackTrace();
} finally {
// Add the key even if geometry is broken just to prevent perpetual attempts to load it
mGeomKeys.add(key);
cursor.moveToNext();
}
//}
}
} catch (SQLiteException sqlEx) {
Log.e(TAG, sqlEx.getMessage());
} finally {
Utils.closeSilently(cursor);
final GeomLoader loader = getLoader();
loader.gotoPhase(0, null);
}
}
示例5: read
import com.vividsolutions.jts.io.WKBReader; //导入方法依赖的package包/类
public static Geometry read(final byte[] b) throws IOException, ParseException {
final WKBReader wkb = new WKBReader();
final Geometry geom = wkb.read(b);
return geom;
}
示例6: InputStream2Geometry
import com.vividsolutions.jts.io.WKBReader; //导入方法依赖的package包/类
public static Geometry InputStream2Geometry(final InputStream inputStream) throws Exception {
Geometry dbGeometry = null;
if (inputStream != null) {
// convert the stream to a byte[] array
// so it can be passed to the WKBReader
final byte[] buffer = new byte[255];
int bytesRead = 0;
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((bytesRead = inputStream.read(buffer)) != -1) {
baos.write(buffer, 0, bytesRead);
}
final byte[] geometryAsBytes = baos.toByteArray();
if (geometryAsBytes.length < 5) { throw new Exception(
"Invalid geometry inputStream - less than five bytes"); }
// first four bytes of the geometry are the SRID,
// followed by the actual WKB. Determine the SRID
// here
final byte[] sridBytes = new byte[4];
System.arraycopy(geometryAsBytes, 0, sridBytes, 0, 4);
final boolean bigEndian = geometryAsBytes[4] == 0x00;
int srid = 0;
if (bigEndian) {
for (int i = 0; i < sridBytes.length; i++) {
srid = (srid << 8) + (sridBytes[i] & 0xff);
}
} else {
for (int i = 0; i < sridBytes.length; i++) {
srid += (sridBytes[i] & 0xff) << 8 * i;
}
}
// use the JTS WKBReader for WKB parsing
final WKBReader wkbReader = new WKBReader();
// copy the byte array, removing the first four
// SRID bytes
final byte[] wkb = new byte[geometryAsBytes.length - 4];
System.arraycopy(geometryAsBytes, 4, wkb, 0, wkb.length);
dbGeometry = wkbReader.read(wkb);
dbGeometry.setSRID(srid);
}
return dbGeometry;
}
示例7: build
import com.vividsolutions.jts.io.WKBReader; //导入方法依赖的package包/类
public QuadBlock build(Iterable<PendingWrite> writes, TileFactoryInfo info, final int zoom){
// calculate all centroids
WKBReader reader = new WKBReader();
for(PendingWrite pw:writes){
try {
Geometry g = reader.read(pw.geomBytes);
pw.centroid= g.getCentroid();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
// get bounds
Rectangle2D.Double mapBounds=null;
if(zoom<0){
// WGS84
mapBounds = new Rectangle2D.Double(-180, -90, 360, 180);
}else{
// Map tile
Dimension dim = GeoUtil.getMapSize(zoom, info);
double h = (double)dim.height * info.getTileSize(zoom);
double w = (double)dim.width * info.getTileSize(zoom);
Point2D centre = info.getMapCenterInPixelsAtZoom(zoom);
mapBounds = new Rectangle2D.Double(centre.getX() - w/2, centre.getY() - h/2, w, h);
}
QuadBlock root = new QuadBlock(mapBounds);
SplitRule splitRule = new SplitRule() {
@Override
public boolean isSplit(QuadBlock block, PendingWrite newPending) {
if(zoom>=0){
// don't split beyond the minimum on-screen size as we will typically want to load this all at once
if(block.bounds.getWidth() / 2 < MIN_SIZE_PIXELS || block.bounds.getHeight() < MIN_SIZE_PIXELS){
return false;
}
}
// never split an empty leaf
if(block.getNbLeaves()==0){
return false;
}
// don't split if block will still be under the minimum size in uncompressed bytes
long newNbBytes = block.leafBytesCount + newPending.geomBytes.length;
if(newNbBytes < MIN_SIZE_BYTES){
return false;
}
// split if new size is over max limit
if(newNbBytes > MAX_SIZE_BYTES){
return true;
}
return false;
}
};
// add all
for(PendingWrite write:writes){
root.addWrite(write, splitRule);
}
// System.out.println("Built zoom " + zoom + " quadtree: " + root.getSummary());
return root;
}
示例8: testInterning
import com.vividsolutions.jts.io.WKBReader; //导入方法依赖的package包/类
/**
* Verifies equality for interning is still working as expected
* (topologically), as the the largeQuery() test has a dependency on this;
*
* @throws ParseException
*/
@Test
public void testInterning()
throws ParseException {
final Geometry g = GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] {
new Coordinate(
0,
0),
new Coordinate(
1,
0),
new Coordinate(
1,
1),
new Coordinate(
0,
1),
new Coordinate(
0,
0)
});
final Geometry gNewInstance = GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] {
new Coordinate(
0,
0),
new Coordinate(
1,
0),
new Coordinate(
1,
1),
new Coordinate(
0,
1),
new Coordinate(
0,
0)
});
final WKBWriter wkbWriter = new WKBWriter();
final byte[] b = wkbWriter.write(g);
final byte[] b2 = new byte[b.length];
System.arraycopy(
b,
0,
b2,
0,
b.length);
final WKBReader wkbReader = new WKBReader();
final Geometry gSerialized = wkbReader.read(b);
final Geometry gSerializedArrayCopy = wkbReader.read(b2);
Assert.assertEquals(
g,
gNewInstance);
Assert.assertEquals(
g,
gSerializedArrayCopy);
Assert.assertEquals(
gSerialized,
gSerializedArrayCopy);
Assert.assertEquals(
gSerialized,
gSerializedArrayCopy);
}
示例9: fromWKB
import com.vividsolutions.jts.io.WKBReader; //导入方法依赖的package包/类
public static Geometry fromWKB(String wkbHex) throws ParseException {
byte[] wkb = WKBReader.hexToBytes(wkbHex);
WKBReader rdr = new WKBReader();
Geometry g = rdr.read(wkb);
return g;
}