public static OsmXmlLoader readOsmXml(File osmxml) { // Defines the interface for tasks consuming OSM data types. OsmXmlLoader sink = new OsmXmlLoader(); // compression (if any) CompressionMethod compression = CompressionMethod.None; if (osmxml.getName().endsWith(".gz")) { compression = CompressionMethod.GZip; } else if (osmxml.getName().endsWith(".bz2")) { compression = CompressionMethod.BZip2; } // read source file (into sink) XmlReader reader = new XmlReader(osmxml, false, compression); reader.setSink(sink); reader.run(); // just run, no threading return sink; }
/** * Parses a given <i>OpenStreetMap</i> file for amenity facilities. * @param file the {@code *.osm} file to parse for amenity facilities. * @throws FileNotFoundException */ public void parseAmenity(String file) throws FileNotFoundException{ File f = new File(file); if(!f.exists()){ throw new FileNotFoundException("Could not find " + file); } AmenitySink mes = new AmenitySink(this.ct, this.osmToMatsimTypeMap); XmlReader xr = new XmlReader(f, false, CompressionMethod.None); xr.setSink(mes); xr.run(); this.amenities = mes.getFacilities(); this.amenityAttributes = mes.getFacilityAttributes(); }
/** * Parses a given <i>OpenStreetMap</i> file for land use. * @param file the {@code *.osm} file to parse for land use * @throws FileNotFoundException */ public void parseLandUseAndBuildings(String file) throws FileNotFoundException{ File f = new File(file); if(!f.exists()){ throw new FileNotFoundException("Could not find " + file); } LandUseBuildingSink landUseBuildingSink = new LandUseBuildingSink(this.ct, this.osmLandUseToMatsimTypeMap, this.osmBuildingToMatsimTypeMap, this.buildingTypeFromVicinityRange, this.tagsToIgnoreBuildings); XmlReader xmlReader = new XmlReader(f, false, CompressionMethod.None); xmlReader.setSink(landUseBuildingSink); xmlReader.run(); this.landuse = landUseBuildingSink.getFacilities(); this.amenityAttributes = landUseBuildingSink.getFacilityAttributes(); }
/** * Parses a given <i>OpenStreetMap</i> file for land use. * @param osmFile the {@code *.osm} file to parse for land use * @throws FileNotFoundException */ public void parseFile(String osmFile) throws FileNotFoundException{ File file = new File(osmFile); if(!file.exists()){ throw new FileNotFoundException("Could not find OSM file " + osmFile); } CombinedOsmSink combinedOsmSink = new CombinedOsmSink(this.outputCRS, this.osmLandUseToMatsimTypeMap, this.osmBuildingToMatsimTypeMap, this.osmAmenityToMatsimTypeMap, this.osmLeisureToMatsimTypeMap, this.osmTourismToMatsimTypeMap, this.unmannedEntitiesList, this.buildingTypeFromVicinityRange); combinedOsmSink.setIdPrefix(idPrefix); XmlReader xmlReader = new XmlReader(file, false, CompressionMethod.None); xmlReader.setSink(combinedOsmSink); xmlReader.run(); this.facilities = combinedOsmSink.getFacilities(); this.facilityAttributes = combinedOsmSink.getFacilityAttributes(); }
/** * Parses a given <i>OpenStreetMap</i> file for data in it that can be converted into MATSim facilities. */ public void parseOsmFileAndAddFacilities(Map<String, String> osmToMatsimTypeMap, String osmKey) { OsmPoiSink sink = new OsmPoiSink(this.ct, osmToMatsimTypeMap, osmKey, useGeneralTypeIsSpecificTypeUnknown); XmlReader xmlReader = new XmlReader(inputFile, false, CompressionMethod.None); xmlReader.setSink(sink); xmlReader.run(); for (ActivityFacility af : sink.getFacilities().getFacilities().values()) { if (!this.facilities.getFacilities().containsKey(af.getId())) { this.facilities.addActivityFacility(af); } else { for (ActivityOption activityOption : af.getActivityOptions().values()) { ActivityFacility activityFacility = this.facilities.getFacilities().get(af.getId()); if (!activityFacility.getActivityOptions().containsKey(activityOption.getType())) { this.facilities.getFacilities().get(af.getId()).addActivityOption(activityOption); } } } } }