private List read(BufferedReader bufferedReader) throws IOException, ParseException { List geoms = new ArrayList(); while (! isAtEndOfFile(bufferedReader) && ! isAtLimit(geoms)) { String line = bufferedReader.readLine().trim(); if (line.length() == 0) continue; Geometry g = wkbReader.read(WKBReader.hexToBytes(line)); if (count >= offset) geoms.add(g); count++; } return geoms; }
private List read(BufferedReader bufferedReader) throws IOException, ParseException { List geoms = new ArrayList(); while (! isAtEndOfFile(bufferedReader) && ! isAtLimit(geoms)) { String line = bufferedReader.readLine().trim(); if (line.length() == 0) continue; Geometry g = wkbReader.read(WKBReader.hexToBytes(line)); if (count >= offset) geoms.add(g); count++; } return geoms; }
public Geometry readWkb(String line) throws ParseException { final String[] columns = line.split(splitter.getDelimiter()); final byte[] aux = WKBReader.hexToBytes(columns[this.startOffset]); // For some unknown reasons, the wkb reader cannot be used in transient variable like the wkt reader. WKBReader wkbReader = new WKBReader(); final Geometry geometry = wkbReader.read(aux); handleNonSpatialDataToGeometry(geometry, Arrays.asList(columns)); return geometry; }
public Geometry parseText(String str) throws ParseException { Geometry geom = null; try { // Parse string as well known text (WKT) geom = wktReader.read(str); } catch (ParseException e) { try { // Error parsing from WKT, try hex string instead byte[] binary = WKBReader.hexToBytes(str); geom = wkbReader.read(binary); } catch (RuntimeException e1) { // Cannot parse text. Just return null } } return geom; }
public void parse(String s) { /* * first see if we start with a token that matches "EPSG:[0-9]*". If so, * set the CRS from it; otherwise it is null (not the plugin default). */ if (s.startsWith("EPSG:") || s.startsWith("urn:")) { int n = s.indexOf(' '); this.crsId = s.substring(0, n); s = s.substring(n + 1); } try { if (s.contains("(")) { value = new WKTReader().read(s); } else { value = new WKBReader().read(WKBReader.hexToBytes(s)); } } catch (ParseException e) { throw new KlabRuntimeException(e); } }
import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.PrecisionModel; import com.vividsolutions.jts.io.WKBReader; import java.util.Arrays; import java.util.List; public class Foo { public static void main(String... args) throws Exception { final List<String> points = Arrays.asList( "0101000020E6100000AECB9307F9D812400F2ADCE003704940", "0101000020E6100000E40AAE6CD6DA1240941F95531C704940", "0101000020E6100000C0D7C68E7CD81240F550364044704940" ); final GeometryFactory gm = new GeometryFactory(new PrecisionModel(), 4326); final WKBReader wkbr = new WKBReader(gm); for (String point: points) { byte[] wkbBytes = wkbr.hexToBytes(point); final Geometry geom = wkbr.read(wkbBytes); System.out.printf("%s -> %s\n", point, geom.toText()); // you can access longitude and latitude via double longitude = geom.getCoordinate().x; double latitude = geom.getCoordinate().y; // then do what you need to do with it } } }
public void parse(String s) { /* * first see if we start with a token that matches "EPSG:[0-9]*". If so, set the * CRS from it; otherwise it is null (not the plugin default). */ try { if (s.startsWith("EPSG:") || s.startsWith("urn:")) { int n = s.indexOf(' '); String escode = s.substring(0, n); s = s.substring(n + 1); crs = Geospace.getCRSFromID(escode); } else { crs = Geospace.get().getDefaultCRS(); } if (s.contains("(")) { value = new WKTReader().read(s); } else { value = new WKBReader().read(WKBReader.hexToBytes(s)); } } catch (Exception e) { throw new KlabRuntimeException(e); } }
public Geometry readWkb(String line) throws ParseException { final String[] columns = line.split(splitter.getDelimiter()); final byte[] aux = WKBReader.hexToBytes(columns[this.startOffset]); // For some unknown reasons, the wkb reader cannot be used in transient variable like the wkt reader. WKBReader wkbReader = new WKBReader(); final Geometry geometry = wkbReader.read(aux); if (carryInputData) { boolean firstColumnFlag = true; otherAttributes = ""; for (int i=0; i<columns.length;i++) { if (i!=this.startOffset ) { if (firstColumnFlag) { otherAttributes +=columns[i]; firstColumnFlag = false; } else { otherAttributes += "\t"+columns[i]; } } } geometry.setUserData(otherAttributes); } return geometry; }
byte[] binary = WKBReader.hexToBytes(hex); try { return wkb_reader.read(binary);
case WKB: return string -> Optional.of(Collections.singletonList( new WkbPolygonConverter().backwardConvert(WKBReader.hexToBytes(string)))); case UNSUPPORTED: default:
return string -> Optional .of(Collections.singletonList(new WkbMultiPolygonConverter() .backwardConvert(WKBReader.hexToBytes(string)))); case WKT: return string -> Optional.of(Collections
final byte[] wkb = WKBReader.hexToBytes(string); final PolyLine convertedPolyLine = converter.backwardConvert(wkb); Assert.assertEquals(convertedPolyLine, polyLines.get(stringIndex));