public static void createGeom(List<Node> nodes) { StringBuilder wkt = new StringBuilder(); for (Node node : nodes) wkt.append(node.lng + " " + node.lat + ", "); wkt.delete(wkt.length() - 2, wkt.length()); wkt.insert(0, "POLYGON(("); wkt.append("))"); WKTReader wktreader = new WKTReader(); Geometry geom = null; try { geom = wktreader.read(wkt.toString()); } catch (Exception ex) { ex.printStackTrace(); } Polygon pol = (Polygon) geom; if (!pol.isValid()) { Geometry repaired = pol.buffer(0.0D); log.info("Invalid polygon detected. Is fixed? " + repaired.isValid()); wkt = new StringBuilder(repaired.toText()); } try { System.out.println(pol.contains(wktreader.read("POINT(82 25)"))); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Override public void parseValue(XmlObject value, MapEposEvent result) { Geometry geom; try { geom = GMLGeometryFactory.parseGeometry(value); } catch (ParseException e) { logger.warn(e.getMessage(), e); return; } if (geom != null) { result.put(MapEposEvent.GEOMETRY_KEY, geom); } }
/* * (non-Javadoc) * * @see org.geotools.gce.imagemosaic.jdbc.JDBCAccessBase#getEnvelopeFromResultSet(java.sql.ResultSet) */ @Override protected Envelope getEnvelopeFromResultSet(ResultSet r) throws SQLException { byte[] bytes = r.getBytes(2); WKBReader reader = new WKBReader(); Geometry bbox = null; try { bbox = reader.read(bytes); } catch (ParseException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); throw new SQLException(e.getMessage()); } return bbox.getEnvelopeInternal(); }
@Override public void modelChanged(Object element, String event) { if (element instanceof IDataContent) { try { IDataContent datacontent = (IDataContent) element; if (event == com.metaaps.eoclipse.common.Model.ADDED) { addDataLayer(datacontent); } else if (event == com.metaaps.eoclipse.common.Model.REMOVED) { removeDataLayer(datacontent); } } catch (ParseException e) { Util.errorMessage("Could not remove data layer."); e.printStackTrace(); } } }
private void renderLayers() { if ((m_datasets != null) && (canvas != null)) { // scan datasets for all data for (Object obj : m_datasets.getChildren()) { if (obj instanceof IDataContent) { IDataContent datacontent = (IDataContent) obj; try { addDataLayer(datacontent); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }
private double calculateArea(StringBuilder builder) { WKTReader reader = new WKTReader(geometryFactory); builder.append(this.firstLat).append(" ").append(this.firstLong); builder.append("))"); try { System.out.println("generate polygon"); Polygon polygon = (Polygon) reader.read("POLYGON ((" + builder.toString()); double polygonArea = polygon.getArea(); System.out.println("Area: " + polygonArea); return polygonArea; } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return 0; }
public Map<String, Geometry> readShapeFile(String filename, String attrString) { Map<String, Geometry> shapeMap = new HashMap<String, Geometry>(); for (SimpleFeature ft : ShapeFileReader.getAllFeatures(filename)) { GeometryFactory geometryFactory = new GeometryFactory(); WKTReader wktReader = new WKTReader(geometryFactory); Geometry geometry; try { geometry = wktReader.read((ft.getAttribute("the_geom")).toString()); shapeMap.put(ft.getAttribute(attrString).toString(), geometry); } catch (ParseException e) { e.printStackTrace(); } } return shapeMap; }
public Map<String, Geometry> readShapeFile(String filename, String attrString) { // attrString: Für Brandenburg: Nr // für OSM: osm_id Map<String, Geometry> shapeMap = new HashMap<String, Geometry>(); for (SimpleFeature ft : ShapeFileReader.getAllFeatures(filename)) { GeometryFactory geometryFactory = new GeometryFactory(); WKTReader wktReader = new WKTReader(geometryFactory); Geometry geometry; try { geometry = wktReader.read((ft.getAttribute("the_geom")).toString()); shapeMap.put(ft.getAttribute(attrString).toString(), geometry); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return shapeMap; }