Java Code Examples for com.vividsolutions.jts.io.WKBWriter#toHex()

The following examples show how to use com.vividsolutions.jts.io.WKBWriter#toHex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeometrySerializer.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void serialize(SerializationStreamWriter streamWriter,
		Geometry instance) throws SerializationException {
	WKBWriter writer = sWriter;
	
	byte[] wkb = writer.write(instance);
	String hex = WKBWriter.toHex(wkb);
	streamWriter.writeString(hex);
}
 
Example 2
Source File: SimpleDemo.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void demonstrateWkb() {
	GeometryFactory gf = new GeometryFactory();

	WKBReader wkbReader = new WKBReader(gf);
	WKBWriter wkbWriter = new WKBWriter();

	// geometry collection from above
	String hexEncodedWkb = "00000000070000000600000000014132D53A3BC2DADC414"
			+ "10BBD1DFB613500000000040000000200000000014132D53A3BC2DADC414"
			+ "10BBD1DFB61350000000001415026FE8EF0B6B74153F78BCEFDB09A00000"
			+ "00002000000024132D53A3BC2DADC41410BBD1DFB6135415026FE8EF0B6B"
			+ "74153F78BCEFDB09A0000000005000000020000000002000000024132D53"
			+ "A3BC2DADC41410BBD1DFB6135415026FE8EF0B6B74153F78BCEFDB09A000"
			+ "0000002000000024132D53A3BC2DADC41410BBD1DFB6135415026FE8EF0B"
			+ "6B74153F78BCEFDB09A000000000300000001000000044132D53A3BC2DAD"
			+ "C41410BBD1DFB6135415026FE8EF0B6B74153F78BCEFDB09A4157C81E8EF"
			+ "0B6B7415F693E8EFDB09A4132D53A3BC2DADC41410BBD1DFB61350000000"
			+ "00600000002000000000300000001000000044132D53A3BC2DADC41410BB"
			+ "D1DFB6135415026FE8EF0B6B74153F78BCEFDB09A4157C81E8EF0B6B7415"
			+ "F693E8EFDB09A4132D53A3BC2DADC41410BBD1DFB6135000000000300000"
			+ "001000000044132D53A3BC2DADC41410BBD1DFB6135415026FE8EF0B6B74"
			+ "153F78BCEFDB09A4157C81E8EF0B6B7415F693E8EFDB09A4132D53A3BC2D"
			+ "ADC41410BBD1DFB6135";

	try {
		Geometry g = wkbReader.read(WKBReader.hexToBytes(hexEncodedWkb));

		sLogger.info("Geom from WKB: " + g);

		byte[] freshWkb = wkbWriter.write(g);
		String freshWkbHex = WKBWriter.toHex(freshWkb);

		sLogger.warning("Hexes are equal?   "
				+ hexEncodedWkb.equals(freshWkbHex));
	} catch (ParseException e) {
		sLogger.log(Level.WARNING, "Unable to parse hex wkb", e);
	}
}
 
Example 3
Source File: XMLTestWriter.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
private String getWKTorWKB(Geometry g, boolean useWKT)
{
  if (useWKT)
    return wktWriter.writeFormatted(g);
  return WKBWriter.toHex(wkbWriter.write(g));
}
 
Example 4
Source File: WriterFunctions.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static String writeWKB(Geometry g)
{
  if (g == null) return "";
  return WKBWriter.toHex((new WKBWriter().write(g)));
}