package pl.wat.ms4ds.terrain.konwersja; import pl.wat.ms4ds.terrain.Coord; import pl.wat.ms4ds.terrain.Teren; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.FileInputStream; import java.util.ArrayList; import java.util.HashMap; import javax.xml.stream.*; /** * */ public class OpenStreetMapReader { private static final Logger LOGGER = LoggerFactory.getLogger(OpenStreetMapReader.class); private static final String DATA_DIR = "c:/Workspace/openstreetmap-data-20160925/"; static final Object synch = new Object(); public static void main(String[] args) throws Exception { System.out.println("OpenStreetMapReader - Working Directory = " + System.getProperty("user.dir")); String osm_fn = DATA_DIR + args[0] + "-latest.osm"; HashMap relationsMap = new HashMap<>(8000); HashMap relationWaysMap = new HashMap<>(50000); HashMap nodesMap = new HashMap<>(5000000); HashMap buildingNodesMap = new HashMap<>(500000); HashMap waysMap = new HashMap<>(800000); String[] goals = {"lasy", "wody", "bagna", "zabudowa", "drogi", "rzeki", "rowy"}; ArrayList toDo = new ArrayList<>(); for (int i = 1; i < args.length; i++) { for (int j = 0; j < goals.length; j++) { if (goals[j].equals(args[i])) { toDo.add(goals[j]); break; } } } MapBounds mapBounds = new MapBounds(); // readMapBounds(mapBounds, osm_fn); for (int i = 0; i < toDo.size(); i++) { relationsMap.clear(); relationWaysMap.clear(); nodesMap.clear(); buildingNodesMap.clear(); waysMap.clear(); readRelations(relationsMap, relationWaysMap, osm_fn, toDo.get(i)); readWays(nodesMap, relationWaysMap, waysMap, osm_fn, toDo.get(i)); readNodes(nodesMap, buildingNodesMap, mapBounds, osm_fn, toDo.get(i)); if (nodesMap.size() > 0) { String nodes_poland_fn = DATA_DIR + "poland-latest_nodes.osm"; readNodes(nodesMap, null, mapBounds, nodes_poland_fn, toDo.get(i)); } for (Relation rel : relationsMap.values()) { rel.outerWays = rel.generatePolygons(rel.outerWays); rel.innerWays = rel.generatePolygons(rel.innerWays); } LOGGER.debug("Poczatek przetwarzania danych dla regionu " + osm_fn + " - cel: " + toDo.get(i)); generujDaneTerenowe(toDo.get(i), relationsMap, waysMap, buildingNodesMap); LOGGER.debug("Koniec przetwarzania danych dla regionu " + osm_fn + " - cel: " + toDo.get(i)); // Teren.setBinarnyFormatPliku(false); // Teren.zapisBuforaMapyDoPliku(); // Teren.reset(); // Teren.setBinarnyFormatPliku(true); } LOGGER.debug("Poczatek zapisu danych dla regionu " + osm_fn); Teren.saveToFiles(null); LOGGER.debug("Koniec zapisu danych dla regionu " + osm_fn); } // XMLOutputFactory outFactory = XMLOutputFactory.newInstance(); // // try { // XMLStreamWriter writer = outFactory.createXMLStreamWriter(new FileWriter("au2data\\output2.xml")); // // writer.writeStartDocument(); // writer.writeStartElement("document"); // writer.writeStartElement("data"); // writer.writeAttribute("name", "value"); // writer.writeEndElement(); // writer.writeEndElement(); // writer.writeEndDocument(); // // writer.flush(); // writer.close(); // // } catch (XMLStreamException e) { // e.printStackTrace(); // } catch (IOException e) { // e.printStackTrace(); // } private static void readMapBounds(MapBounds mapBounds, String fn) throws Exception { XMLInputFactory factory = XMLInputFactory.newInstance(); // FileInputStream is = new FileInputStream(fn); FileInputStream is = new FileInputStream(fn); // XMLStreamReader reader = factory.createXMLStreamReader(ClassLoader.getSystemResourceAsStream(fn)); XMLStreamReader reader = factory.createXMLStreamReader(is); String val; while (reader.hasNext()) { int eventType = reader.next(); switch (eventType) { case XMLStreamConstants.START_ELEMENT: if ("bounds".equals(reader.getLocalName())) { for (int i = 0; i < reader.getAttributeCount(); i++) { val = reader.getAttributeLocalName(i); switch (val) { case "minlat": val = reader.getAttributeValue(i); mapBounds.minLat = Double.parseDouble(val); break; case "minlon": val = reader.getAttributeValue(i); mapBounds.minLon = Double.parseDouble(val); break; case "maxlat": val = reader.getAttributeValue(i); mapBounds.maxLat = Double.parseDouble(val); break; case "maxlon": val = reader.getAttributeValue(i); mapBounds.maxLon = Double.parseDouble(val); break; default: } } reader.close(); return; } break; default: break; } } reader.close(); } private static void readNodes(HashMap nodesMap, HashMap buildingNodesMap, MapBounds mapBounds, String fn, String genGoal) throws Exception { Node currNode = null; XMLInputFactory factory = XMLInputFactory.newInstance(); FileInputStream is = new FileInputStream(fn); // XMLStreamReader reader = factory.createXMLStreamReader(ClassLoader.getSystemResourceAsStream(fn)); XMLStreamReader reader = factory.createXMLStreamReader(is); String val; int count = 1; LOGGER.debug("Poczatek odczytu wezlow z pliku: " + fn); while (reader.hasNext()) { int eventType = reader.next(); switch (eventType) { case XMLStreamConstants.START_ELEMENT: if ("node".equals(reader.getLocalName())) { val = reader.getAttributeValue(0); // if ("3206180317".equals(val)) { // logger.debug("!!!!!!!!!!! niepoprawny wezel id= " + val); // } if (count % 100000 == 0) { LOGGER.debug("+-+-+-+-+-+-+-+- liczba odczytanych wezlow= " + count / 1000 + " [tys.], ostatni wezel id= " + val); } currNode = nodesMap.remove(val); if (!"zabudowa".equals(genGoal)) { if (currNode != null) { int c = 0; for (int i = 1; i < reader.getAttributeCount() && c < 2; i++) { val = reader.getAttributeLocalName(i); switch (val) { case "lat": val = reader.getAttributeValue(i); currNode.lat = Double.parseDouble(val); c++; break; case "lon": val = reader.getAttributeValue(i); currNode.lon = Double.parseDouble(val); c++; break; default: } } } } else if (buildingNodesMap != null) { if (currNode == null) { currNode = buildingNodesMap.get(val); if (currNode == null) { currNode = new Node(val); } } int c = 0; for (int i = 1; i < reader.getAttributeCount() && c < 2; i++) { val = reader.getAttributeLocalName(i); switch (val) { case "lat": val = reader.getAttributeValue(i); currNode.lat = Double.parseDouble(val); c++; break; case "lon": val = reader.getAttributeValue(i); currNode.lon = Double.parseDouble(val); c++; break; default: } } } } else if ("tag".equals(reader.getLocalName())) { if (currNode != null) { String k = reader.getAttributeValue(0); String v = reader.getAttributeValue(1); switch (k) { case "building": currNode.building = EOSMBuilding.getValue(v); break; case "amenity": currNode.amenity = EOSMAmenity.getValue(v); break; case "addr:housenumber": currNode.buildingsCount++; break; default: break; } } } else if ("way".equals(reader.getLocalName())) { reader.close(); return; } break; case XMLStreamConstants.CHARACTERS: // tagContent = reader.getText().trim(); break; case XMLStreamConstants.END_ELEMENT: switch (reader.getLocalName()) { case "node": if (currNode != null) { currNode.idX = Coord.zamienDlugoscGeoNaIdKwadratuX(currNode.lon); currNode.idY = Coord.zamienSzerokoscGeoNaIdKwadratuY(currNode.lat); if ("zabudowa".equals(genGoal) && currNode.buildingsCount > 0) { buildingNodesMap.put(currNode.id, currNode); } count++; currNode = null; } break; default: break; } break; default: break; } } reader.close(); } private static void readWays(HashMap nodesMap, HashMap relationWaysMap, HashMap goalWaysMap, String fn, String genGoal) throws Exception { Way currWay = null; String tagContent = null; XMLInputFactory factory = XMLInputFactory.newInstance(); // FileInputStream is = new FileInputStream(fn); FileInputStream is = new FileInputStream(fn); // XMLStreamReader reader = factory.createXMLStreamReader(ClassLoader.getSystemResourceAsStream(fn)); XMLStreamReader reader = factory.createXMLStreamReader(is); String val; int count = 0; LOGGER.debug("Poczatek odczytu lamanych z pliku: " + fn + " - cel: " + genGoal); while (reader.hasNext()) { int eventType = reader.next(); switch (eventType) { case XMLStreamConstants.START_ELEMENT: if ("way".equals(reader.getLocalName())) { val = reader.getAttributeValue(0); currWay = relationWaysMap.get(val); if (currWay == null) { currWay = new Way(val); } // if ("314575560".equals(val)) { // logger.debug("!!!!!"); // } count++; if (count % 10000 == 0) { LOGGER.debug("=================== liczba odczytanych lamanych= " + count / 1000 + " [tys.], ostatnia lamana id= " + val); LOGGER.debug("=>liczba lamanych celu=" + goalWaysMap.size() + ", liczba lamanych relacji=" + relationWaysMap.size() + ", liczba wezlow=" + nodesMap.size()); } } else if ("nd".equals(reader.getLocalName())) { if (currWay != null) { // odczyt id wezla wchodzacego w sklad lamanej val = reader.getAttributeValue(0); Node node = nodesMap.get(val); if (node == null) { for (int i = 0; i < currWay.nodes.size(); i++) { if (val.equals(currWay.nodes.get(i).id)) { node = currWay.nodes.get(i); break; } } if (node == null) { node = new Node(val); } } currWay.nodes.add(node); } } else if ("tag".equals(reader.getLocalName())) { if (currWay != null) { String k = reader.getAttributeValue(0); String v = reader.getAttributeValue(1); switch (k) { case "highway": currWay.highway = EOSMHighway.getValue(v); break; case "waterway": currWay.waterway = EOSMWaterway.getValue(v); break; case "natural": currWay.natural = EOSMNatural.getValue(v); break; case "water": currWay.water = EOSMWater.getValue(v); break; case "landuse": currWay.landuse = EOSMLanduse.getValue(v); break; case "landcover": currWay.landcover = EOSMLandcover.getValue(v); break; case "bridge": currWay.bridge = EOSMBridge.getValue(v); break; case "building": currWay.building = EOSMBuilding.getValue(v); break; case "amenity": currWay.amenity = EOSMAmenity.getValue(v); break; default: break; } } } break; case XMLStreamConstants.CHARACTERS: // tagContent = reader.getText().trim(); break; case XMLStreamConstants.END_ELEMENT: if (currWay != null) { switch (reader.getLocalName()) { case "way": if ("lasy".equals(genGoal)) { // LASY if (relationWaysMap.containsKey(currWay.id)) { for (Node node : currWay.nodes) { nodesMap.put(node.id, node); } } else if ((currWay.landuse != null) && currWay.landuse == EOSMLanduse.FOREST) { goalWaysMap.put(currWay.id, currWay); for (Node node : currWay.nodes) { nodesMap.put(node.id, node); } } else if ((currWay.landcover != null) && currWay.landcover == EOSMLandcover.TREES) { goalWaysMap.put(currWay.id, currWay); for (Node node : currWay.nodes) { nodesMap.put(node.id, node); } } else if ((currWay.natural != null) && currWay.natural == EOSMNatural.WOOD) { goalWaysMap.put(currWay.id, currWay); for (Node node : currWay.nodes) { nodesMap.put(node.id, node); } } } else if ("wody".equals(genGoal)) { // SZEROKIE RZEKI, JEZIORA I ZBIORNIKI WODNE if (relationWaysMap.containsKey(currWay.id)) { for (Node node : currWay.nodes) { nodesMap.put(node.id, node); } } else if (currWay.natural != null && currWay.natural == EOSMNatural.WATER) { goalWaysMap.put(currWay.id, currWay); for (Node node : currWay.nodes) { nodesMap.put(node.id, node); } } else if (currWay.waterway != null && currWay.waterway == EOSMWaterway.RIVERBANK) { goalWaysMap.put(currWay.id, currWay); for (Node node : currWay.nodes) { nodesMap.put(node.id, node); } } } else if ("drogi".equals(genGoal)) { // DROGI if (currWay.highway != null) { switch (currWay.highway) { case MOTORWAY: case TRUNCK: case PRIMARY: case SECONDARY: case TERTIARY: case UNCLASSIFIED: case RESIDENTIAL: case PEDESTRIAN: case TRACK: case MOTORWAY_LINK: case TRUNCK_LINK: case PRIMARY_LINK: case SECONDARY_LINK: case TERTIARY_LINK: case SERVICE: case LIVING_STREET: goalWaysMap.put(currWay.id, currWay); for (Node node : currWay.nodes) { nodesMap.put(node.id, node); } break; default: // case "footway": // case "bridleway": // case "steps": // case "cycleway": // case "PATH": // case "proposed": break; } } } else if ("rzeki".equals(genGoal)) { // RZEKI (LINIOWE, NIESZEROKIE) if (currWay.waterway != null) { switch (currWay.waterway) { case RIVER: case CANAL: goalWaysMap.put(currWay.id, currWay); for (Node node : currWay.nodes) { nodesMap.put(node.id, node); } break; default: } } } else if ("rowy".equals(genGoal)) { // ROWY if (currWay.waterway != null) { switch (currWay.waterway) { case STREAM: case DRAIN: case DITCH: goalWaysMap.put(currWay.id, currWay); for (Node node : currWay.nodes) { nodesMap.put(node.id, node); } break; default: } } } else if ("bagna".equals(genGoal)) { // BAGNA if (currWay.natural != null) { switch (currWay.natural) { case WETLAND: goalWaysMap.put(currWay.id, currWay); for (Node node : currWay.nodes) { nodesMap.put(node.id, node); } break; default: } } } else if ("zabudowa".equals(genGoal)) { // ZABUDOWA if (currWay.landuse != null) { switch (currWay.landuse) { case RESIDENTIAL: case COMMERCIAL: goalWaysMap.put(currWay.id, currWay); for (Node node : currWay.nodes) { nodesMap.put(node.id, node); } break; default: } } else if (currWay.building != null) { goalWaysMap.put(currWay.id, currWay); for (Node node : currWay.nodes) { nodesMap.put(node.id, node); } } else if (currWay.amenity != null) { switch (currWay.amenity) { case HOSPITAL: case CLINIC: case POST_OFFICE: case POLICE: case FIRE_STATION: case MARKETPLACE: goalWaysMap.put(currWay.id, currWay); for (Node node : currWay.nodes) { nodesMap.put(node.id, node); } break; default: } } } currWay = null; break; default: break; } } break; default: } } reader.close(); } private static void readRelations(HashMap relationsMap, HashMap relationWaysMap, String fn, String genGoal) throws Exception { Relation currRelation = null; String tagContent = null; if (!("lasy".equals(genGoal)) && !("wody".equals(genGoal))) { return; } // fn += "-latest_relations.osm"; XMLInputFactory factory = XMLInputFactory.newInstance(); // XMLStreamReader reader = factory.createXMLStreamReader(ClassLoader.getSystemResourceAsStream(fn)); // BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(fn)); // XMLStreamReader reader = factory.createXMLStreamReader(inputStream); FileInputStream is = new FileInputStream(fn); // XMLStreamReader reader = factory.createXMLStreamReader(ClassLoader.getSystemResourceAsStream(fn)); XMLStreamReader reader = factory.createXMLStreamReader(is); String val; int count = 0; LOGGER.debug("Poczatek odczytu relacji z pliku: " + fn + " - cel: " + genGoal); while (reader.hasNext()) { int eventType = reader.next(); switch (eventType) { case XMLStreamConstants.START_ELEMENT: if ("relation".equals(reader.getLocalName())) { val = reader.getAttributeValue(0); currRelation = new Relation(val); count++; if (count % 1000 == 0) { LOGGER.debug("+-+-+-+-+-+-+-+- liczba odczytanych relacji= " + count / 1000 + " [tys.], ostatnia relacja id= " + val); } } else if ("member".equals(reader.getLocalName())) { if (currRelation != null) { String v = reader.getAttributeValue(0); if ("way".equals(v)) { // identyfikator łamanej String v1 = reader.getAttributeValue(1); // rola łamanej w relacji String v2 = reader.getAttributeValue(2); if ("outer".equals(v2)) { Way way = new Way(v1); if (way != null) { currRelation.outerWays.add(way); } } else if ("inner".equals(v2)) { Way way = new Way(v1); if (way != null) { currRelation.innerWays.add(way); } } } } } else if ("tag".equals(reader.getLocalName())) { if (currRelation != null) { String k = reader.getAttributeValue(0); String v = reader.getAttributeValue(1); switch (k) { case "waterway": currRelation.waterway = EOSMWaterway.getValue(v); break; case "natural": currRelation.natural = EOSMNatural.getValue(v); break; case "landuse": currRelation.landuse = EOSMLanduse.getValue(v); break; case "landcover": currRelation.landcover = EOSMLandcover.getValue(v); break; case "type": if (!"multipolygon".equals(v)) { currRelation = null; } break; default: break; } } } break; case XMLStreamConstants.CHARACTERS: // tagContent = reader.getText().trim(); break; case XMLStreamConstants.END_ELEMENT: switch (reader.getLocalName()) { case "relation": if (currRelation != null) { if (currRelation.outerWays.size() > 0) { if ("lasy".equals(genGoal)) { if (((currRelation.landuse != null) && currRelation.landuse == EOSMLanduse.FOREST) || ((currRelation.natural != null) && currRelation.natural == EOSMNatural.WOOD)) { relationsMap.put(currRelation.id, currRelation); for (Way way : currRelation.outerWays) { // kopiuje tagi dla lamanych zewnetrznych way.copyTags(currRelation); relationWaysMap.put(way.id, way); } for (Way way : currRelation.innerWays) { relationWaysMap.put(way.id, way); // nie kopiuje tagow dla lamanych wewnetrznych, gdyz one maja wlasne tagi } } } else if ("wody".equals(genGoal)) { if (((currRelation.natural != null) && currRelation.natural == EOSMNatural.WATER) || ((currRelation.waterway != null) && currRelation.waterway == EOSMWaterway.RIVERBANK)) { relationsMap.put(currRelation.id, currRelation); for (Way way : currRelation.outerWays) { // kopiuje tagi dla lamanych zewnetrznych way.copyTags(currRelation); relationWaysMap.put(way.id, way); } for (Way way : currRelation.innerWays) { relationWaysMap.put(way.id, way); // nie kopiuje tagow dla lamanych wewnetrznych, gdyz one maja wlasne tagi } } } } } currRelation = null; break; default: break; } break; default: break; } } reader.close(); } static void generujDaneTerenowe(String genGoal, HashMap relationsMap, HashMap waysMap, HashMap buildingNodesMap) { int count = 0; int m1 = relationsMap.size() / 100; m1 = (m1 == 0) ? 1 : m1; int m2 = waysMap.size() / 100; m2 = (m2 == 0) ? 1 : m2; ArrayList wayList = new ArrayList<>(waysMap.values()); // określenie formatu odczytu danych terenowych przed uaktualnieniem if ("lasy".equals(genGoal)) { for (Relation rel : relationsMap.values()) { count++; rel.removeLastNodes(); rel.removeSimilarNodes(); rel.removeCollinearNodes(true); rel.writeAreaFeatureIntoSquares(EAreaFeature.FOREST); if (count % m1 == 0) { LOGGER.debug(">><<>><<>><<: rel count= " + count + ", " + genGoal); } } count = 0; for (Way way : wayList) { count++; // usunięcie powtórzenia węzła z łamanej definiującej obszar if (way.nodes.size() > 1) { way.nodes.remove(way.nodes.size() - 1); } way.removeSimilarNodes(); way.removeCollinearNodes(true); way.writeAreaFeatureIntoSquares(EAreaFeature.FOREST, false); if (count % m2 == 0) { LOGGER.debug("<><><><><><>: way count= " + count + ", " + genGoal); } } } else if ("wody".equals(genGoal)) { for (Relation rel : relationsMap.values()) { count++; rel.removeLastNodes(); rel.removeSimilarNodes(); rel.removeCollinearNodes(true); rel.writeAreaFeatureIntoSquares(EAreaFeature.WATER); if (count % m1 == 0) { LOGGER.debug(">><<>><<>><<: rel count= " + count + ", " + genGoal); } } count = 0; for (Way way : wayList) { count++; // usunięcie powtórzenia węzła z łamanej definiującej obszar if (way.nodes.size() > 1) { way.nodes.remove(way.nodes.size() - 1); } way.removeSimilarNodes(); way.removeCollinearNodes(true); way.writeAreaFeatureIntoSquares(EAreaFeature.WATER, false); if (count % m2 == 0) { LOGGER.debug("<><><><><><>: way count= " + count + ", " + genGoal); } } } else if ("bagna".equals(genGoal)) { for (Way way : wayList) { count++; // usunięcie powtórzenia węzła z łamanej definiującej obszar if (way.nodes.size() > 1) { way.nodes.remove(way.nodes.size() - 1); } way.removeSimilarNodes(); way.removeCollinearNodes(true); way.writeAreaFeatureIntoSquares(EAreaFeature.SWAMP, false); if (count % m2 == 0) { LOGGER.debug("<><><><><><>: way count= " + count + ", " + genGoal); } } } else if ("zabudowa".equals(genGoal)) { // wygenerowanie danych o stopniu zabudowy na podstawie danych adresowych // HashMap newNodesMap = new HashMap<>(); // for (Node node : buildingNodesMap.values()) { // Node node1 = newNodesMap.get(node); // if (node1 != null) { // node1.buildingsCount += node.buildingsCount; // } else { // newNodesMap.put(node, node); // } // } // buildingNodesMap.clear(); for (Node node : buildingNodesMap.values()) { node.writeAreaFeatureIntoSquare(EAreaFeature.BUILDINGS); } for (Way way : wayList) { count++; // usunięcie powtórzenia węzła z łamanej definiującej obszar if (way.nodes.size() > 1) { way.nodes.remove(way.nodes.size() - 1); } // for (int i = 0; i < way.nodes.size(); i++) { // Node node = way.nodes.get(i); // if (node.idX <= 0 || node.idY <= 0) { // logger.debug("!!!! niepoprawny wezel id= " + node.id + ", lamana id= " + way.id); // } // } way.removeSimilarNodes(); way.removeCollinearNodes(true); way.writeAreaFeatureIntoSquares(EAreaFeature.BUILDINGS, false); if (count % m2 == 0) { LOGGER.debug("<><><><><><>: way count= " + count + ", " + genGoal); } } } else if ("drogi".equals(genGoal)) { for (Way way : wayList) { count++; // if ("249908111".equals(way.id) || "238353558".equals(way.id)) { // logger.debug("!!!!!"); // } way.removeSimilarNodes(); way.removeCollinearNodes(false); way.removeSteps(); if (way.nodes.size() > 1) { way.writeLinearFeatureIntoSquares(ELinearFeature.ROAD); } // if (count % 10000 == 0) { // logger.debug("-*-*-*-*-"); // logger.debug("maxMemory=" + java.lang.Runtime.getRuntime().maxMemory() // + ", totalMemory=" + java.lang.Runtime.getRuntime().totalMemory() // + ", freeMemory=" + java.lang.Runtime.getRuntime().freeMemory()); // } // count++; if (count % m2 == 0) { LOGGER.debug("<><><><><><>: way count= " + count + ", " + genGoal); } } } else if ("rzeki".equals(genGoal)) { for (Way way : wayList) { count++; way.removeSimilarNodes(); way.removeCollinearNodes(false); way.removeSteps(); if (way.nodes.size() > 1) { way.writeLinearFeatureIntoSquares(ELinearFeature.WATER_WAY); } if (count % m2 == 0) { LOGGER.debug("<><><><><><>: way count= " + count + ", " + genGoal); } } } else if ("rowy".equals(genGoal)) { for (Way way : wayList) { count++; way.removeSimilarNodes(); way.removeCollinearNodes(false); way.removeSteps(); if (way.nodes.size() > 1) { way.writeLinearFeatureIntoSquares(ELinearFeature.DITCH); } if (count % m2 == 0) { LOGGER.debug("<><><><><><>: way count= " + count + ", " + genGoal); } } } } static void generujDaneTerenowe2(String genGoal, HashMap relationsMap, HashMap waysMap, HashMap buildingNodesMap) { int count = 0; int m1 = relationsMap.size() / 100; m1 = (m1 == 0) ? 1 : m1; ArrayList wayList = new ArrayList<>(waysMap.values()); // określenie formatu odczytu danych terenowych przed uaktualnieniem if ("lasy".equals(genGoal)) { for (Relation rel : relationsMap.values()) { count++; rel.removeLastNodes(); rel.removeSimilarNodes(); rel.removeCollinearNodes(true); rel.writeAreaFeatureIntoSquares(EAreaFeature.FOREST); if (count % m1 == 0) { synchronized (synch) { LOGGER.debug(Thread.currentThread().getName() + " >><<>><<>><<: rel count= " + count + ", " + genGoal); } } } count = 0; for (Way way : wayList) { count++; // usunięcie powtórzenia węzła z łamanej definiującej obszar if (way.nodes.size() > 1) { way.nodes.remove(way.nodes.size() - 1); } way.removeSimilarNodes(); way.removeCollinearNodes(true); way.writeAreaFeatureIntoSquares(EAreaFeature.FOREST, false); synchronized (synch) { LOGGER.debug(Thread.currentThread().getName() + " <><><><><><>: way count= " + count + ", " + genGoal); } } } else if ("wody".equals(genGoal)) { for (Relation rel : relationsMap.values()) { count++; rel.removeLastNodes(); rel.removeSimilarNodes(); rel.removeCollinearNodes(true); rel.writeAreaFeatureIntoSquares(EAreaFeature.WATER); synchronized (synch) { LOGGER.debug(Thread.currentThread().getName() + " >><<>><<>><<: rel count= " + count + ", " + genGoal); } } count = 0; for (Way way : wayList) { count++; // usunięcie powtórzenia węzła z łamanej definiującej obszar if (way.nodes.size() > 1) { way.nodes.remove(way.nodes.size() - 1); } way.removeSimilarNodes(); way.removeCollinearNodes(true); way.writeAreaFeatureIntoSquares(EAreaFeature.WATER, false); synchronized (synch) { LOGGER.debug(Thread.currentThread().getName() + " <><><><><><>: way count= " + count + ", " + genGoal); } } } else if ("bagna".equals(genGoal)) { for (Way way : wayList) { count++; // usunięcie powtórzenia węzła z łamanej definiującej obszar if (way.nodes.size() > 1) { way.nodes.remove(way.nodes.size() - 1); } way.removeSimilarNodes(); way.removeCollinearNodes(true); way.writeAreaFeatureIntoSquares(EAreaFeature.SWAMP, false); synchronized (synch) { LOGGER.debug(Thread.currentThread().getName() + " <><><><><><>: way count= " + count + ", " + genGoal); } } } else if ("zabudowa".equals(genGoal)) { // wygenerowanie danych o stopniu zabudowy na podstawie danych adresowych // HashMap newNodesMap = new HashMap<>(); // for (Node node : buildingNodesMap.values()) { // Node node1 = newNodesMap.get(node); // if (node1 != null) { // node1.buildingsCount += node.buildingsCount; // } else { // newNodesMap.put(node, node); // } // } // buildingNodesMap.clear(); for (Node node : buildingNodesMap.values()) { node.writeAreaFeatureIntoSquare(EAreaFeature.BUILDINGS); } for (Way way : wayList) { count++; // usunięcie powtórzenia węzła z łamanej definiującej obszar if (way.nodes.size() > 1) { way.nodes.remove(way.nodes.size() - 1); } // for (int i = 0; i < way.nodes.size(); i++) { // Node node = way.nodes.get(i); // if (node.idX <= 0 || node.idY <= 0) { // logger.debug("!!!! niepoprawny wezel id= " + node.id + ", lamana id= " + way.id); // } // } way.removeSimilarNodes(); way.removeCollinearNodes(true); way.writeAreaFeatureIntoSquares(EAreaFeature.BUILDINGS, false); synchronized (synch) { LOGGER.debug(Thread.currentThread().getName() + " <><><><><><>: way count= " + count + ", " + genGoal); } } } else if ("drogi".equals(genGoal)) { for (Way way : wayList) { count++; // if ("249908111".equals(way.id) || "238353558".equals(way.id)) { // logger.debug("!!!!!"); // } way.removeSimilarNodes(); way.removeCollinearNodes(false); way.removeSteps(); if (way.nodes.size() > 1) { way.writeLinearFeatureIntoSquares(ELinearFeature.ROAD); } // if (count % 10000 == 0) { // logger.debug("-*-*-*-*-"); // logger.debug("maxMemory=" + java.lang.Runtime.getRuntime().maxMemory() // + ", totalMemory=" + java.lang.Runtime.getRuntime().totalMemory() // + ", freeMemory=" + java.lang.Runtime.getRuntime().freeMemory()); // } // count++; synchronized (synch) { LOGGER.debug(Thread.currentThread().getName() + " <><><><><><>: way count= " + count + ", " + genGoal); } } } else if ("rzeki".equals(genGoal)) { for (Way way : wayList) { count++; way.removeSimilarNodes(); way.removeCollinearNodes(false); way.removeSteps(); if (way.nodes.size() > 1) { way.writeLinearFeatureIntoSquares(ELinearFeature.WATER_WAY); } synchronized (synch) { LOGGER.debug(Thread.currentThread().getName() + " <><><><><><>: way count= " + count + ", " + genGoal); } } } else if ("rowy".equals(genGoal)) { for (Way way : wayList) { count++; way.removeSimilarNodes(); way.removeCollinearNodes(false); way.removeSteps(); if (way.nodes.size() > 1) { way.writeLinearFeatureIntoSquares(ELinearFeature.DITCH); } synchronized (synch) { LOGGER.debug(Thread.currentThread().getName() + " <><><><><><>: way count= " + count + ", " + genGoal); } } } } }