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; }
/** * {@inheritDoc} */ @Override protected TaskManager createTaskManagerImpl(TaskConfiguration taskConfig) { String fileName; File file; boolean enableDateParsing; CompressionMethod compressionMethod; XmlReader task; // Get the task arguments. fileName = getStringArgument( taskConfig, ARG_FILE_NAME, getDefaultStringArgument(taskConfig, DEFAULT_FILE_NAME) ); enableDateParsing = getBooleanArgument(taskConfig, ARG_ENABLE_DATE_PARSING, DEFAULT_ENABLE_DATE_PARSING); compressionMethod = getCompressionMethodArgument(taskConfig, fileName); // Create a file object from the file name provided. file = new File(fileName); // Build the task object. task = new XmlReader(file, enableDateParsing, compressionMethod); return new RunnableSourceManager(taskConfig.getId(), task, taskConfig.getPipeArgs()); } }
/** * {@inheritDoc} */ @Override protected TaskManager createTaskManagerImpl(TaskConfiguration taskConfig) { String fileName; File file; boolean enableDateParsing; CompressionMethod compressionMethod; XmlReader task; // Get the task arguments. fileName = getStringArgument( taskConfig, ARG_FILE_NAME, getDefaultStringArgument(taskConfig, DEFAULT_FILE_NAME) ); enableDateParsing = getBooleanArgument(taskConfig, ARG_ENABLE_DATE_PARSING, DEFAULT_ENABLE_DATE_PARSING); compressionMethod = getCompressionMethodArgument(taskConfig, fileName); // Create a file object from the file name provided. file = new File(fileName); // Build the task object. task = new XmlReader(file, enableDateParsing, compressionMethod); return new RunnableSourceManager(taskConfig.getId(), task, taskConfig.getPipeArgs()); } }
/** * 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(); }
final List<Throwable> exceptions = Collections.synchronizedList(new ArrayList<Throwable>()); XmlReader reader = new XmlReader(sourceFile, false, CompressionMethod.None);
/** * 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(); }
RunnableSource left = new XmlReader(dataUtils.createDataFile( "v0_6/derive_change/simple.osm"), true, CompressionMethod.None); RunnableSource right = new EmptyReader();
/** * 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); } } } } }