Changeset 32320 in osm for applications/editors/josm/plugins/OSMRecPlugin/src/org
- Timestamp:
- 2016-06-19T01:55:37+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/FrequenceExtractor.java
r31106 r32320 1 1 package org.openstreetmap.josm.plugins.extractor; 2 2 3 import org.openstreetmap.josm.plugins.container.OSMNode;4 import org.openstreetmap.josm.plugins.container.OSMRelation;5 import org.openstreetmap.josm.plugins.container.OSMWay;6 3 import java.io.IOException; 7 4 import java.util.ArrayList; … … 9 6 import java.util.List; 10 7 import java.util.Map; 8 11 9 import javax.xml.parsers.ParserConfigurationException; 12 import javax.xml.parsers.SAXParser; 13 import javax.xml.parsers.SAXParserFactory; 10 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.plugins.container.OSMNode; 13 import org.openstreetmap.josm.plugins.container.OSMRelation; 14 import org.openstreetmap.josm.plugins.container.OSMWay; 15 import org.openstreetmap.josm.tools.Utils; 14 16 import org.xml.sax.Attributes; 15 17 import org.xml.sax.SAXException; … … 50 52 51 53 public void parseDocument() { 52 // parse 53 System.out.println("extracting frequencies..."); 54 SAXParserFactory factory = SAXParserFactory.newInstance(); 54 Main.info("extracting frequencies..."); 55 55 try { 56 SAXParser parser = factory.newSAXParser(); 57 parser.parse(osmXmlFileName, this); 58 } catch (ParserConfigurationException e) { 59 System.out.println("ParserConfig error " + e); 60 } catch (SAXException e) { 61 System.out.println("SAXException : xml not well formed " + e); 62 } catch (IOException e) { 63 System.out.println("IO error " + e); 64 } 65 //LOG.info("Frequencies from OSM/XML file parsed!"); 56 Utils.newSafeSAXParser().parse(osmXmlFileName, this); 57 } catch (ParserConfigurationException | IOException | SAXException e) { 58 Main.error(e); 59 } 66 60 } 67 61 -
applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/LanguageDetector.java
r31461 r32320 1 1 package org.openstreetmap.josm.plugins.extractor; 2 3 import java.io.File; 4 import java.io.IOException; 5 import java.io.InputStream; 6 import java.nio.file.Files; 7 import java.util.logging.Level; 8 import java.util.logging.Logger; 9 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.tools.Utils; 2 12 3 13 import com.cybozu.labs.langdetect.Detector; 4 14 import com.cybozu.labs.langdetect.DetectorFactory; 5 15 import com.cybozu.labs.langdetect.LangDetectException; 6 import java.io.File;7 import java.io.FileNotFoundException;8 import java.io.FileOutputStream;9 import java.io.IOException;10 import java.io.InputStream;11 import java.util.logging.Level;12 import java.util.logging.Logger;13 16 14 17 /** … … 26 29 27 30 public static LanguageDetector getInstance(String languageProfilesPath) { 28 //System.out.println("language profile path: \n" + languageProfilesPath + "/el");29 31 if (languageDetector == null) { 30 32 languageDetector = new LanguageDetector(); … … 52 54 53 55 if (!new File(languageProfilesPath).exists()) { 54 //new File(languageProfilesPath).mkdir(); 55 new File(languageProfilesPath).mkdirs(); 56 Utils.mkDirs(new File(languageProfilesPath)); 56 57 } 57 58 … … 67 68 68 69 try { 69 70 70 languageProfilesOutputFileEl.createNewFile(); 71 71 languageProfilesOutputFileEn.createNewFile(); … … 77 77 languageProfilesOutputFileZh.createNewFile(); 78 78 languageProfilesOutputFileHi.createNewFile(); 79 80 79 } catch (IOException ex) { 81 80 Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex); 82 } 83 84 FileOutputStream outputStreamEl = null; 85 FileOutputStream outputStreamEn = null; 86 FileOutputStream outputStreamDe = null; 87 FileOutputStream outputStreamFr = null; 88 FileOutputStream outputStreamEs = null; 89 FileOutputStream outputStreamRu = null; 90 FileOutputStream outputStreamTr = null; 91 FileOutputStream outputStreamZh = null; 92 FileOutputStream outputStreamHi = null; 93 94 try { 95 96 outputStreamEl = new FileOutputStream(languageProfilesOutputFileEl); 97 outputStreamEn = new FileOutputStream(languageProfilesOutputFileEn); 98 outputStreamDe = new FileOutputStream(languageProfilesOutputFileDe); 99 outputStreamFr = new FileOutputStream(languageProfilesOutputFileFr); 100 outputStreamEs = new FileOutputStream(languageProfilesOutputFileEs); 101 outputStreamRu = new FileOutputStream(languageProfilesOutputFileRu); 102 outputStreamTr = new FileOutputStream(languageProfilesOutputFileTr); 103 outputStreamZh = new FileOutputStream(languageProfilesOutputFileZh); 104 outputStreamHi = new FileOutputStream(languageProfilesOutputFileHi); 105 106 } catch (FileNotFoundException ex) { 107 Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex); 108 } 109 110 int read = 0; 111 byte[] bytes = new byte[1024]; 112 try { 113 114 while ((read = languageProfilesInputStreamEl.read(bytes)) != -1) { 115 outputStreamEl.write(bytes, 0, read); 116 } 117 118 read = 0; 119 bytes = new byte[1024]; 120 121 while ((read = languageProfilesInputStreamEn.read(bytes)) != -1) { 122 outputStreamEn.write(bytes, 0, read); 123 } 124 125 read = 0; 126 bytes = new byte[1024]; 127 128 while ((read = languageProfilesInputStreamDe.read(bytes)) != -1) { 129 outputStreamDe.write(bytes, 0, read); 130 } 131 132 read = 0; 133 bytes = new byte[1024]; 134 135 while ((read = languageProfilesInputStreamFr.read(bytes)) != -1) { 136 outputStreamFr.write(bytes, 0, read); 137 } 138 139 read = 0; 140 bytes = new byte[1024]; 141 142 while ((read = languageProfilesInputStreamEs.read(bytes)) != -1) { 143 outputStreamEs.write(bytes, 0, read); 144 } 145 146 read = 0; 147 bytes = new byte[1024]; 148 149 while ((read = languageProfilesInputStreamRu.read(bytes)) != -1) { 150 outputStreamRu.write(bytes, 0, read); 151 } 152 153 read = 0; 154 bytes = new byte[1024]; 155 156 while ((read = languageProfilesInputStreamTr.read(bytes)) != -1) { 157 outputStreamTr.write(bytes, 0, read); 158 } 159 160 read = 0; 161 bytes = new byte[1024]; 162 163 while ((read = languageProfilesInputStreamZh.read(bytes)) != -1) { 164 outputStreamZh.write(bytes, 0, read); 165 } 166 167 read = 0; 168 bytes = new byte[1024]; 169 170 while ((read = languageProfilesInputStreamHi.read(bytes)) != -1) { 171 outputStreamHi.write(bytes, 0, read); 172 } 173 174 } catch (IOException ex) { 175 Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex); 81 Main.error(ex); 176 82 } 177 83 178 84 try { 85 Files.copy(languageProfilesInputStreamEl, languageProfilesOutputFileEl.toPath()); 86 Files.copy(languageProfilesInputStreamEn, languageProfilesOutputFileEn.toPath()); 87 Files.copy(languageProfilesInputStreamDe, languageProfilesOutputFileDe.toPath()); 88 Files.copy(languageProfilesInputStreamFr, languageProfilesOutputFileFr.toPath()); 89 Files.copy(languageProfilesInputStreamEs, languageProfilesOutputFileEs.toPath()); 90 Files.copy(languageProfilesInputStreamRu, languageProfilesOutputFileRu.toPath()); 91 Files.copy(languageProfilesInputStreamTr, languageProfilesOutputFileTr.toPath()); 92 Files.copy(languageProfilesInputStreamZh, languageProfilesOutputFileZh.toPath()); 93 Files.copy(languageProfilesInputStreamHi, languageProfilesOutputFileHi.toPath()); 94 } catch (IOException ex) { 95 Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex); 96 Main.error(ex); 97 } 179 98 99 try { 180 100 DetectorFactory.loadProfile(languageProfilesPath); 181 182 101 } catch (LangDetectException ex) { 183 102 Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex); 103 Main.error(ex); 184 104 } 185 105 } … … 189 109 Detector detector = DetectorFactory.create(); 190 110 detector.append(text); 191 String lang = detector.detect(); 192 //System.out.println("language detected: " + lang); 193 return lang; 111 return detector.detect(); 194 112 } catch (LangDetectException ex) { 195 113 Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex); 114 Main.error(ex); 196 115 return "en"; //default lang to return if anything goes wrong at detection 197 116 } -
applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/personalization/HistoryParser.java
r31106 r32320 1 2 1 package org.openstreetmap.josm.plugins.osmrec.personalization; 3 2 4 import com.vividsolutions.jts.geom.Coordinate;5 import com.vividsolutions.jts.geom.Geometry;6 import com.vividsolutions.jts.geom.GeometryFactory;7 import com.vividsolutions.jts.geom.LineString;8 import com.vividsolutions.jts.geom.LinearRing;9 import com.vividsolutions.jts.geom.Point;10 import com.vividsolutions.jts.geom.Polygon;11 3 import java.io.IOException; 12 4 import java.io.InputStream; 13 import java.net.HttpURLConnection;14 import java.net.MalformedURLException;15 5 import java.net.URL; 16 6 import java.util.ArrayList; 7 import java.util.HashMap; 8 import java.util.HashSet; 17 9 import java.util.List; 10 import java.util.Map; 18 11 import java.util.logging.Level; 19 12 import java.util.logging.Logger; 20 import javax.xml.parsers.DocumentBuilder; 21 import javax.xml.parsers.DocumentBuilderFactory; 13 22 14 import javax.xml.parsers.ParserConfigurationException; 23 import org.w3c.dom.Document; 24 import org.w3c.dom.Node; 25 import org.w3c.dom.NodeList; 26 import org.xml.sax.SAXException; 27 import java.util.HashMap; 28 import java.util.HashSet; 29 import java.util.Map; 15 30 16 import org.geotools.geometry.jts.JTS; 31 17 import org.geotools.referencing.CRS; … … 37 23 import org.opengis.referencing.operation.MathTransform; 38 24 import org.opengis.referencing.operation.TransformException; 25 import org.openstreetmap.josm.Main; 26 import org.openstreetmap.josm.io.OsmApi; 39 27 import org.openstreetmap.josm.plugins.container.OSMNode; 40 28 import org.openstreetmap.josm.plugins.container.OSMWay; 41 29 import org.openstreetmap.josm.tools.HttpClient; 30 import org.openstreetmap.josm.tools.Utils; 31 import org.w3c.dom.Node; 32 import org.w3c.dom.NodeList; 33 import org.xml.sax.SAXException; 34 35 import com.vividsolutions.jts.geom.Coordinate; 36 import com.vividsolutions.jts.geom.Geometry; 37 import com.vividsolutions.jts.geom.GeometryFactory; 38 import com.vividsolutions.jts.geom.LineString; 39 import com.vividsolutions.jts.geom.LinearRing; 40 import com.vividsolutions.jts.geom.Point; 41 import com.vividsolutions.jts.geom.Polygon; 42 42 43 43 /** … … 46 46 * @author imis-nkarag 47 47 */ 48 49 48 public class HistoryParser { 50 private static final String OSM_API = "http://api.openstreetmap.org/api/0.6/"; 51 //private static final String GET_CHANGESET = "http://api.openstreetmap.org/api/0.6/changeset/28851695/download"; 49 private static final String OSM_API = OsmApi.getOsmApi().getBaseUrl(); 52 50 private static final CoordinateReferenceSystem sourceCRS = DefaultGeographicCRS.WGS84; 53 51 private static final CoordinateReferenceSystem targetCRS = DefaultGeocentricCRS.CARTESIAN; … … 62 60 private final String username; 63 61 62 /** 63 * Constructs a new {@code HistoryParser}. 64 * @param username user name 65 */ 64 66 public HistoryParser(String username) { 65 67 this.username = username; … … 81 83 try { 82 84 String osmUrl = OSM_API + "changesets?display_name=" + username + "&time=" + timeInterval; 83 84 System.out.println("requesting..\n" + osmUrl); 85 86 URL url = new URL(osmUrl); 87 HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 88 connection.setRequestMethod("GET"); 89 //connection.setRequestProperty("Accept", "application/xml"); 90 91 InputStream xml = connection.getInputStream(); 92 //System.out.println("xml" + xml.read()); 93 94 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 95 DocumentBuilder db = dbf.newDocumentBuilder(); 96 Document doc = db.parse(xml); 97 NodeList nodes = doc.getElementsByTagName("changeset"); 98 99 100 System.out.println("changeset size "+ nodes.getLength()); 101 //System.out.println("changeset "); 85 InputStream xml = HttpClient.create(new URL(osmUrl)).connect().getContent(); 86 NodeList nodes = Utils.parseSafeDOM(xml).getElementsByTagName("changeset"); 87 88 Main.debug("changeset size "+ nodes.getLength()); 102 89 for (int i = 0; i < nodes.getLength(); i++) { 103 //Element element = (Element) nodes.item(i); 104 System.out.println("attributes of " + i + "th changeset"); 105 //for(int j = 0; j < nodes.item(i).getAttributes().getLength(); j++){ 106 //System.out.println("- "+ nodes.item(i).getAttributes().item(j)); 107 108 //} 90 Main.debug("attributes of " + i + "th changeset"); 109 91 String id = nodes.item(i).getAttributes().item(3).toString(); 110 System.out.println("id:" + nodes.item(i).getAttributes().item(3));92 Main.debug("id:" + nodes.item(i).getAttributes().item(3)); 111 93 id = stripQuotes(id); 112 94 changesetIDsList.add(id); 113 95 } 114 96 115 97 for(String id : changesetIDsList){ 116 98 getChangesetByID(id); 117 99 } 118 } catch (MalformedURLException ex) { 119 Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex); 120 } catch (IOException ex) { 121 Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex); 122 } catch (ParserConfigurationException | SAXException ex) { 100 } catch (IOException | ParserConfigurationException | SAXException ex) { 123 101 Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex); 124 102 } … … 128 106 try { 129 107 String changesetByIDURL = OSM_API+ "changeset/" + id + "/download"; 130 131 System.out.println("requesting..\n" + changesetByIDURL); 132 133 URL url = new URL(changesetByIDURL); 134 HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 135 connection.setRequestMethod("GET"); 136 //connection.setRequestProperty("Accept", "application/xml"); 137 138 InputStream xml = connection.getInputStream(); 139 140 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 141 DocumentBuilder db = dbf.newDocumentBuilder(); 142 Document doc = db.parse(xml); 143 //NodeList nodes = doc.getElementsByTagName("create"); 144 //NodeList nodes2 = doc.getChildNodes(); 145 Node osmChange = doc.getFirstChild(); 108 InputStream xml = HttpClient.create(new URL(changesetByIDURL)).connect().getContent(); 109 Node osmChange = Utils.parseSafeDOM(xml).getFirstChild(); 146 110 147 111 //get all nodes first, in order to be able to call all nodes references and create the geometries … … 155 119 156 120 if(osmObject.getNodeName().equals("node")){ 157 //System.out.println("node");158 121 //node data 159 122 nodeTmp = new OSMNode(); 160 //System.out.println("id of node: " + wayChild.getAttributes().getNamedItem("id").getNodeValue());161 123 nodeTmp.setID(osmObject.getAttributes().getNamedItem("id").getNodeValue()); 162 124 … … 178 140 nodeList.add(nodeTmp); 179 141 nodesWithIDs.put(nodeTmp.getID(), nodeTmp); 180 181 142 } 182 143 } … … 186 147 String changeType = osmChange.getChildNodes().item(i).getNodeName(); 187 148 if(!(changeType.equals("#text") || changeType.equals("delete"))){ 188 //if(!(changeType.equals("#text"))){189 149 NodeList changeChilds = osmChange.getChildNodes().item(i).getChildNodes(); 190 150 … … 196 156 wayTmp.setID(osmObject.getAttributes().getNamedItem("id").getNodeValue()); 197 157 //osmObject.getChildNodes() <-extract tags, then set tags to osm object 198 System.out.println("\n\nWAY: " + wayTmp.getID()); 199 //System.out.println("i " + i + " j " + j + " wayTmp refers: " + wayTmp.getNodeReferences()); 158 Main.debug("\n\nWAY: " + wayTmp.getID()); 200 159 for(int l=0; l<osmObject.getChildNodes().getLength(); l++){ 201 160 String wayChild = osmObject.getChildNodes().item(l).getNodeName(); … … 208 167 } 209 168 else if(wayChild.equals("nd")){ 210 //System.out.println("nd ref: " + osmObject.getChildNodes().item(j).getAttributes().getNamedItem("ref").getNodeValue());211 169 wayTmp.addNodeReference(osmObject.getChildNodes().item(l).getAttributes().getNamedItem("ref").getNodeValue()); 212 213 170 } 214 171 } … … 216 173 //construct the Way geometry from each node of the node references 217 174 List<String> references = wayTmp.getNodeReferences(); 218 //System.out.println("references exist? size: " + references.size());219 175 220 176 for (String entry: references) { 221 177 if(nodesWithIDs.containsKey(entry)){ 222 //System.out.println("nodes with ids, entry " + entry);223 //System.out.println("nodes with ids: " + nodesWithIDs);224 178 Geometry geometry = nodesWithIDs.get(entry).getGeometry(); //get the geometry of the node with ID=entry 225 179 wayTmp.addNodeGeometry(geometry); //add the node geometry in this way 226 //}227 180 } 228 181 else{ 229 System.out.println("nodes with ids, no entry " + entry);182 Main.debug("nodes with ids, no entry " + entry); 230 183 getNodeFromAPI(entry); 231 184 } … … 233 186 234 187 Geometry geom = geometryFactory.buildGeometry(wayTmp.getNodeGeometries()); 235 //System.out.println("geom: " + geom);236 188 if((wayTmp.getNodeGeometries().size()>3) && 237 189 wayTmp.getNodeGeometries().get(0).equals(wayTmp.getNodeGeometries() … … 256 208 //it is an open geometry with more than one nodes, make it linestring 257 209 258 LineString lineString = 210 LineString lineString = geometryFactory.createLineString(geom.getCoordinates()); 259 211 wayTmp.setGeometry(lineString); 260 212 } … … 268 220 } 269 221 } 270 271 } catch (MalformedURLException ex) { 272 Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex); 273 } catch (IOException ex) { 274 Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex); 275 } catch (ParserConfigurationException | SAXException ex) { 222 } catch (IOException | ParserConfigurationException | SAXException ex) { 276 223 Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex); 277 224 } … … 279 226 280 227 private String stripQuotes(String id) { 281 id = id.substring(4, id.length()-1); 282 //System.out.println("id: " + id); 283 return id; 228 return id.substring(4, id.length()-1); 284 229 } 285 230 … … 287 232 try { 288 233 String osmUrl = OSM_API + "node/" + nodeID; 289 290 System.out.println("requesting..\n" + osmUrl); 291 292 URL url = new URL(osmUrl); 293 HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 294 connection.setRequestMethod("GET"); 295 //connection.setRequestProperty("Accept", "application/xml"); 296 297 InputStream xml = connection.getInputStream(); 298 //System.out.println("xml" + xml.read()); 299 300 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 301 DocumentBuilder db = dbf.newDocumentBuilder(); 302 Document doc = db.parse(xml); 303 NodeList nodes = doc.getElementsByTagName("node"); 234 InputStream xml = HttpClient.create(new URL(osmUrl)).connect().getContent(); 235 NodeList nodes = Utils.parseSafeDOM(xml).getElementsByTagName("node"); 304 236 String lat = nodes.item(0).getAttributes().getNamedItem("lat").getNodeValue(); 305 237 String lon = nodes.item(0).getAttributes().getNamedItem("lon").getNodeValue(); 306 //System.out.println("lat from api " + lat);307 238 308 239 nodeTmp = new OSMNode(); … … 327 258 nodesWithIDs.put(nodeTmp.getID(), nodeTmp); 328 259 329 } catch (MalformedURLException ex) { 330 Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex); 331 } catch (IOException ex) { 332 Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex); 333 } catch (ParserConfigurationException | SAXException ex) { 260 } catch (IOException | ParserConfigurationException | SAXException ex) { 334 261 Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex); 335 262 } -
applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/parsers/OSMParser.java
r31441 r32320 1 1 package org.openstreetmap.josm.plugins.parsers; 2 2 3 import com.vividsolutions.jts.geom.Coordinate;4 import com.vividsolutions.jts.geom.Geometry;5 import com.vividsolutions.jts.geom.GeometryFactory;6 import com.vividsolutions.jts.geom.LineString;7 import com.vividsolutions.jts.geom.LinearRing;8 import com.vividsolutions.jts.geom.Point;9 import com.vividsolutions.jts.geom.Polygon;10 import org.openstreetmap.josm.plugins.container.OSMNode;11 import org.openstreetmap.josm.plugins.container.OSMRelation;12 import org.openstreetmap.josm.plugins.container.OSMWay;13 3 import java.io.IOException; 14 4 import java.util.ArrayList; … … 18 8 import java.util.logging.Level; 19 9 import java.util.logging.Logger; 10 20 11 import javax.xml.parsers.ParserConfigurationException; 21 import javax.xml.parsers.SAXParser; 22 import javax.xml.parsers.SAXParserFactory; 12 23 13 import org.geotools.geometry.jts.JTS; 24 14 import org.geotools.referencing.CRS; … … 30 20 import org.opengis.referencing.operation.MathTransform; 31 21 import org.opengis.referencing.operation.TransformException; 22 import org.openstreetmap.josm.Main; 23 import org.openstreetmap.josm.plugins.container.OSMNode; 24 import org.openstreetmap.josm.plugins.container.OSMRelation; 25 import org.openstreetmap.josm.plugins.container.OSMWay; 26 import org.openstreetmap.josm.tools.Utils; 32 27 import org.xml.sax.Attributes; 33 28 import org.xml.sax.SAXException; 34 29 import org.xml.sax.helpers.DefaultHandler; 30 31 import com.vividsolutions.jts.geom.Coordinate; 32 import com.vividsolutions.jts.geom.Geometry; 33 import com.vividsolutions.jts.geom.GeometryFactory; 34 import com.vividsolutions.jts.geom.LineString; 35 import com.vividsolutions.jts.geom.LinearRing; 36 import com.vividsolutions.jts.geom.Point; 37 import com.vividsolutions.jts.geom.Polygon; 35 38 36 39 /** … … 39 42 * @author imis-nkarag 40 43 */ 41 42 44 public class OSMParser extends DefaultHandler { 43 45 … … 62 64 63 65 public OSMParser(String osmXmlFileName) { 64 //System.out.println("creating osmParser..");65 66 this.osmXmlFileName = osmXmlFileName; 66 67 nodeList = new ArrayList<>(); … … 73 74 Logger.getLogger(OSMParser.class.getName()).log(Level.SEVERE, null, ex); 74 75 } 75 //System.out.println("osmParser created!");76 76 } 77 77 78 78 public void parseDocument() { 79 // parse80 System.out.println("parsing OSM file...");81 SAXParserFactory factory = SAXParserFactory.newInstance();82 79 try { 83 SAXParser parser = factory.newSAXParser(); 84 parser.parse(osmXmlFileName, this); 85 } catch (ParserConfigurationException e) { 86 System.out.println("ParserConfig error " + e); 87 } catch (SAXException e) { 88 System.out.println("SAXException : xml not well formed " + e); 89 } catch (IOException e) { 90 System.out.println("IO error " + e); 91 } 92 //LOG.info("Instances from OSM/XML file parsed!"); 80 Utils.newSafeSAXParser().parse(osmXmlFileName, this); 81 } catch (ParserConfigurationException | SAXException | IOException e) { 82 Main.error(e); 83 } 93 84 } 94 85 … … 130 121 wayTmp.setUser("undefined"); 131 122 } 132 //System.out.println("way user: " + attributes.getValue("user"));133 123 134 124 inWay = true; … … 211 201 wayTmp.setGeometry(point); 212 202 } 213 wayList.add(wayTmp);203 wayList.add(wayTmp); 214 204 } 215 205
Note:
See TracChangeset
for help on using the changeset viewer.