@Override public void readFields(DataInput in) throws IOException { try { byte[] wkb = new byte[in.readInt()]; in.readFully(wkb); geom = wkbReader.read(wkb); } catch (ParseException e) { e.printStackTrace(); throw new IOException(e); } }
public static Geometry createJtsGeometryFromWKT(final String wktString) { Geometry geometry = null; try { geometry = reader.read(wktString); } catch (final ParseException e) { e.printStackTrace(); } return geometry; };
public Geometry getShape(String wtk) throws FactoryException, TransformException { GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), Subject.SRID); WKTReader reader = new WKTReader(geometryFactory); MathTransform crsTransform = GeotoolsDataStoreUtils.makeCrsTransform("EPSG:27700"); try { LineString line = (LineString) reader.read(wtk); Geometry transformedGeom = JTS.transform(line, crsTransform); return transformedGeom; } catch (ParseException e) { e.printStackTrace(); log.error("Not a valid geometry"); return null; } }
@Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { if (placemark != null) { final AttributeDescriptor attributeDescriptor = placemark.getFeature().getFeatureType().getAttributeDescriptors().get(rowIndex); final Class<?> binding = attributeDescriptor.getType().getBinding(); if (String.class.isAssignableFrom(binding)) { placemark.setAttributeValue(attributeDescriptor.getLocalName(), aValue); } else if (Geometry.class.isAssignableFrom(binding)) { WKTReader reader = new WKTReader(); try { final Geometry geometry = reader.read((String) aValue); placemark.setAttributeValue(attributeDescriptor.getLocalName(), geometry); } catch (ParseException e) { // No way to handle this any further :( e.printStackTrace(); } } } }