/** * Creates a new instance. * * @param file * The file to write. */ public CopyFileWriter(File file) { this.file = file; midRecord = false; dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ"); postgisBinaryWriter = new BinaryWriter(); }
public synchronized String writeHexed(Geometry geom) { return writeHexed(geom, ValueSetter.NDR.NUMBER); }
public synchronized byte[] writeBinary(Geometry geom) { return writeBinary(geom, ValueSetter.NDR.NUMBER); }
result += estimatePoint((Point) geom); break; case Geometry.LINESTRING : result += estimateLineString((LineString) geom); break; case Geometry.POLYGON : result += estimatePolygon((Polygon) geom); break; case Geometry.MULTIPOINT : result += estimateMultiPoint((MultiPoint) geom); break; case Geometry.MULTILINESTRING : result += estimateMultiLineString((MultiLineString) geom); break; case Geometry.MULTIPOLYGON : result += estimateMultiPolygon((MultiPolygon) geom); break; case Geometry.GEOMETRYCOLLECTION : result += estimateCollection((GeometryCollection) geom); break; default :
public Geometry read( String wkt ) throws ParseException { try { org.postgis.Geometry g = org.postgis.PGgeometry.geomFromString( wkt ); byte[] bs = new BinaryWriter().writeBinary( g ); return WKBReader.read( bs, crs ); } catch ( SQLException e ) { e.printStackTrace(); // wrap the exception nicely as to not break 172643521 API calls throw new ParseException( e ); } }
/** * Write a hex encoded geometry * * Is synchronized to protect offset counter. (Unfortunately, Java does not * have neither call by reference nor multiple return values.) This is a * TODO item. * * The geometry you put in must be consistent, geom.checkConsistency() must * return true. If not, the result may be invalid WKB. * * @see Geometry#checkConsistency() the consistency checker * * @param geom the geometry to be written * @param REP endianness to write the bytes with * @return String containing the hex encoded geometry */ public synchronized String writeHexed(Geometry geom, byte REP) { int length = estimateBytes(geom); ByteSetter.StringByteSetter bytes = new ByteSetter.StringByteSetter(length); writeGeometry(geom, valueSetterForEndian(bytes, REP)); return bytes.result(); }
private int estimateCollection(GeometryCollection geom) { // 4-byte count + subgeometries return 4 + estimateGeometryArray(geom.getGeometries()); } }
/** Write an Array of "full" Geometries */ private int estimateGeometryArray(Geometry[] container) { int result = 0; for (int i = 0; i < container.length; i++) { result += estimateBytes(container[i]); } return result; }
private int estimatePolygon(Polygon geom) { // int length int result = 4; for (int i = 0; i < geom.numRings(); i++) { result += estimateLinearRing(geom.getRing(i)); } return result; }
result += estimatePoint((Point) geom); break; case Geometry.LINESTRING : result += estimateLineString((LineString) geom); break; case Geometry.POLYGON : result += estimatePolygon((Polygon) geom); break; case Geometry.MULTIPOINT : result += estimateMultiPoint((MultiPoint) geom); break; case Geometry.MULTILINESTRING : result += estimateMultiLineString((MultiLineString) geom); break; case Geometry.MULTIPOLYGON : result += estimateMultiPolygon((MultiPolygon) geom); break; case Geometry.GEOMETRYCOLLECTION : result += estimateCollection((GeometryCollection) geom); break; default :
/** * Write a binary encoded geometry. * * Is synchronized to protect offset counter. (Unfortunately, Java does not * have neither call by reference nor multiple return values.) This is a * TODO item. * * The geometry you put in must be consistent, geom.checkConsistency() must * return true. If not, the result may be invalid WKB. * * @see Geometry#checkConsistency() * * @param geom the geometry to be written * @param REP endianness to write the bytes with * @return byte array containing the encoded geometry */ public synchronized byte[] writeBinary(Geometry geom, byte REP) { int length = estimateBytes(geom); ByteSetter.BinaryByteSetter bytes = new ByteSetter.BinaryByteSetter(length); writeGeometry(geom, valueSetterForEndian(bytes, REP)); return bytes.result(); }
private int estimateMultiPolygon(MultiPolygon geom) { // 4-byte count + subgeometries return 4 + estimateGeometryArray(geom.getPolygons()); }
/** Write an Array of "full" Geometries */ private int estimateGeometryArray(Geometry[] container) { int result = 0; for (int i = 0; i < container.length; i++) { result += estimateBytes(container[i]); } return result; }
private int estimatePolygon(Polygon geom) { // int length int result = 4; for (int i = 0; i < geom.numRings(); i++) { result += estimateLinearRing(geom.getRing(i)); } return result; }
public synchronized String writeHexed(Geometry geom) { return writeHexed(geom, ValueSetter.NDR.NUMBER); }
/** * Write a binary encoded geometry. * * Is synchronized to protect offset counter. (Unfortunately, Java does not * have neither call by reference nor multiple return values.) This is a * TODO item. * * The geometry you put in must be consistent, geom.checkConsistency() must * return true. If not, the result may be invalid WKB. * * @see Geometry#checkConsistency() * * @param geom the geometry to be written * @param REP endianness to write the bytes with * @return byte array containing the encoded geometry */ public synchronized byte[] writeBinary(Geometry geom, byte REP) { int length = estimateBytes(geom); ByteSetter.BinaryByteSetter bytes = new ByteSetter.BinaryByteSetter(length); writeGeometry(geom, valueSetterForEndian(bytes, REP)); return bytes.result(); }
/** * Creates a new instance. * * @param file * The file to write. */ public CopyFileWriter(File file) { this.file = file; midRecord = false; dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ"); postgisBinaryWriter = new BinaryWriter(); }
public synchronized byte[] writeBinary(Geometry geom) { return writeBinary(geom, ValueSetter.NDR.NUMBER); }
private int estimateCollection(GeometryCollection geom) { // 4-byte count + subgeometries return 4 + estimateGeometryArray(geom.getGeometries()); } }
private int estimateMultiPoint(MultiPoint geom) { // int size int result = 4; if (geom.numPoints() > 0) { // We can shortcut here, as all subgeoms have the same fixed size result += geom.numPoints() * estimateBytes(geom.getFirstPoint()); } return result; }