use of de.topobyte.osm4j.geometry.GeometryBuilder in project osm4j-geometry by topobyte.
the class TestBuildPolygon method main.
public static void main(String[] args) throws MalformedURLException, IOException, ParserConfigurationException, SAXException, EntityNotFoundException {
String query = "http://overpass-api.de/api/interpreter?data=(rel(8638);>;);out;";
// Open a stream
InputStream input = new URL(query).openStream();
OsmIterator iterator = new OsmXmlIterator(input, false);
InMemoryMapDataSet data = MapDataSetLoader.read(iterator, false, false, true);
TLongObjectMap<OsmRelation> relations = data.getRelations();
if (relations.isEmpty()) {
System.out.println("No relation found");
return;
}
TLongObjectIterator<OsmRelation> ri = relations.iterator();
ri.advance();
OsmRelation relation = ri.value();
File outputDir = new File("/tmp");
String filename = String.format("relation-%d.wkt", relation.getId());
File file = new File(outputDir, filename);
GeometryBuilder geometryBuilder = new GeometryBuilder();
geometryBuilder.setMissingEntitiesStrategy(MissingEntitiesStrategy.BUILD_PARTIAL);
geometryBuilder.setMissingWayNodeStrategy(MissingWayNodeStrategy.OMIT_VERTEX_FROM_POLYLINE);
Geometry polygon = geometryBuilder.build(relation, data);
WKTWriter writer = new WKTWriter();
FileWriter fileWriter = new FileWriter(file);
writer.write(polygon, fileWriter);
fileWriter.close();
System.out.println("Successfully created WKT representation");
}
Aggregations