org.matsim.core.utils.geometry.CoordinateTransformation Java Examples
The following examples show how to use
org.matsim.core.utils.geometry.CoordinateTransformation.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OsmMultimodalNetworkConverter.java From pt2matsim with GNU General Public License v2.0 | 6 votes |
/** * Converts the OSM data according to the parameters defined in config. */ public void convert(OsmConverterConfigGroup config) { this.config = config; this.geometryExporter = new LinkGeometryExporter(); CoordinateTransformation transformation = (config.getOutputCoordinateSystem() == null ? new IdentityTransformation() : TransformationFactory.getCoordinateTransformation(TransformationFactory.WGS84, config.getOutputCoordinateSystem())); initPT(); readWayParams(); convertToNetwork(transformation); cleanNetwork(); if(config.getKeepTagsAsAttributes()) addAttributes(); if (this.config.getOutputDetailedLinkGeometryFile() != null) { try { geometryExporter.onlyKeepGeometryForTheseLinks(network.getLinks().keySet()); geometryExporter.writeToFile(Paths.get(this.config.getOutputDetailedLinkGeometryFile())); } catch (IOException e) { log.warn("Error while writing network geometry", e); e.printStackTrace(); } } }
Example #2
Source File: GtfsFeedImpl.java From pt2matsim with GNU General Public License v2.0 | 6 votes |
@Override public double[] transform(String targetCoordinateSystem) { double minE = Double.MAX_VALUE, minN = Double.MAX_VALUE, maxE = Double.MIN_VALUE, maxN = Double.MIN_VALUE; CoordinateTransformation transformation = TransformationFactory.getCoordinateTransformation(coordSys, targetCoordinateSystem); for(Stop stop : stops.values()) { ((StopImpl) stop).setCoord(transformation.transform(stop.getCoord())); if(stop.getCoord().getX() > maxE) maxE = stop.getCoord().getX(); if(stop.getCoord().getY() > maxN) maxN = stop.getCoord().getY(); if(stop.getCoord().getX() < minE) minE = stop.getCoord().getX(); if(stop.getCoord().getY() < minN) minN = stop.getCoord().getY(); } for(RouteShape routeShape : this.shapes.values()) { ((GtfsShape) routeShape).transformCoords(transformation); } this.coordSys = targetCoordinateSystem; return new double[]{minE, minN, maxE, maxN}; }
Example #3
Source File: HafasConverter.java From pt2matsim with GNU General Public License v2.0 | 6 votes |
public static void run(String hafasFolder, TransitSchedule schedule, CoordinateTransformation transformation, Vehicles vehicles, String chosenDateString) throws IOException { if(!hafasFolder.endsWith("/")) hafasFolder += "/"; // 3a. Get start_fahrplan date LocalDate fahrplanStartDate = ECKDATENReader.getFahrPlanStart(hafasFolder); LocalDate fahrplanEndDate = ECKDATENReader.getFahrPlanEnd(hafasFolder); try { LocalDate chosenDate = ECKDATENReader.getDate(chosenDateString); if (chosenDate.isBefore(fahrplanStartDate) || chosenDate.isAfter(fahrplanEndDate)) { throw new IllegalArgumentException( String.format("Chosen date %s is outside fahrplan period: (%s, %s)", chosenDate, fahrplanStartDate, fahrplanEndDate) ); } int dayNr = (int) ChronoUnit.DAYS.between(fahrplanStartDate, chosenDate); run(hafasFolder, schedule, transformation, vehicles, dayNr); } catch (DateTimeParseException ex) { throw new IllegalArgumentException( "Format of chosen date (should be dd.MM.yyyy) is invalid: " + chosenDateString ); } }
Example #4
Source File: HafasConverterTest.java From pt2matsim with GNU General Public License v2.0 | 5 votes |
@Before public void convert() throws IOException { this.schedule = ScheduleTools.createSchedule(); this.vehicles = VehicleUtils.createVehiclesContainer(); String hafasFolder = "test/BrienzRothornBahn-HAFAS/"; String cs = "EPSG:2056"; CoordinateTransformation ct = TransformationFactory.getCoordinateTransformation("WGS84", cs); HafasConverter.run(hafasFolder, schedule, ct, vehicles); }
Example #5
Source File: Hafas2TransitSchedule.java From pt2matsim with GNU General Public License v2.0 | 5 votes |
/** * Converts all files in <tt>hafasFolder</tt> and writes the output schedule and vehicles to the respective * files. Stop Facility coordinates are transformed from WGS84 to <tt>outputCoordinateSystem</tt>. */ public static void run(String hafasFolder, String outputCoordinateSystem, String outputScheduleFile, String outputVehicleFile, String chosenDateString) throws IOException { TransitSchedule schedule = ScheduleTools.createSchedule(); Vehicles vehicles = VehicleUtils.createVehiclesContainer(); CoordinateTransformation transformation = !outputCoordinateSystem.equals("null") ? TransformationFactory.getCoordinateTransformation("WGS84", outputCoordinateSystem) : new IdentityTransformation(); HafasConverter.run(hafasFolder, schedule, transformation, vehicles, chosenDateString); ScheduleTools.writeTransitSchedule(schedule, outputScheduleFile); ScheduleTools.writeVehicles(vehicles, outputVehicleFile); }
Example #6
Source File: Osm2TransitSchedule.java From pt2matsim with GNU General Public License v2.0 | 5 votes |
public static void run(String osmFile, String outputScheduleFile, String outputCoordinateSystem) { TransitSchedule schedule = ScheduleTools.createSchedule(); CoordinateTransformation ct = outputCoordinateSystem != null ? TransformationFactory.getCoordinateTransformation("WGS84", outputCoordinateSystem) : new IdentityTransformation(); // load osm file OsmData osmData = new OsmDataImpl(); new OsmFileReader(osmData).readFile(osmFile); // convert osm data new OsmTransitScheduleConverter(osmData).convert(schedule, ct); // write file ScheduleTools.writeTransitSchedule(schedule, outputScheduleFile); }
Example #7
Source File: ShapeTools.java From pt2matsim with GNU General Public License v2.0 | 5 votes |
public static List<Coord> transformCoords(CoordinateTransformation ct, List<Coord> coords) { List<Coord> transformed = new ArrayList<>(); for(Coord coord : coords) { transformed.add(ct.transform(coord)); } return transformed; }
Example #8
Source File: GtfsTools.java From pt2matsim with GNU General Public License v2.0 | 5 votes |
public static void writeShapesToGeojson(GtfsFeed feed, String file) { CoordinateTransformation ct = TransformationFactory.getCoordinateTransformation(feed.getCurrentCoordSystem(), TransformationFactory.WGS84); FeatureCollection features = new FeatureCollection(); for(RouteShape routeShape : feed.getShapes().values()) { List<Coord> coords = ShapeTools.transformCoords(ct, routeShape.getCoords()); Feature lineFeature = GeojsonTools.createLineFeature(coords); lineFeature.setProperty("id", routeShape.getId().toString()); features.add(lineFeature); } GeojsonTools.writeFeatureCollectionToFile(features, file); }
Example #9
Source File: MatsimAmodeusDatabase.java From amodeus with GNU General Public License v2.0 | 5 votes |
public static MatsimAmodeusDatabase initialize(Network network, ReferenceFrame referenceFrame) { CoordinateTransformation coords_toWGS84 = referenceFrame.coords_toWGS84(); List<OsmLink> osmLinks = network.getLinks().values().stream().sorted(Comparator.comparing(link -> link.getId().toString())).map(link -> // new OsmLink(link, // coords_toWGS84.transform(link.getFromNode().getCoord()), // coords_toWGS84.transform(link.getToNode().getCoord()) // )).collect(Collectors.toList()); return new MatsimAmodeusDatabase(referenceFrame, osmLinks); }
Example #10
Source File: StopReader.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
public static void run(TransitSchedule schedule, CoordinateTransformation transformation, String pathToBFKOORD_GEOFile) throws IOException { new StopReader(schedule, transformation, pathToBFKOORD_GEOFile).createStops(); }
Example #11
Source File: HafasConverter.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
public static void run(String hafasFolder, TransitSchedule schedule, CoordinateTransformation transformation, Vehicles vehicles) throws IOException { run(hafasFolder, schedule, transformation, vehicles, -1); }
Example #12
Source File: StopReader.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
public StopReader(TransitSchedule schedule, CoordinateTransformation transformation, String pathToBFKOORD_GEOFile) { this.schedule = schedule; this.transformation = transformation; this.scheduleBuilder = this.schedule.getFactory(); this.pathToBFKOORD_GEOFile = pathToBFKOORD_GEOFile; }
Example #13
Source File: HafasConverter.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
public static void run(String hafasFolder, TransitSchedule schedule, CoordinateTransformation transformation, Vehicles vehicles, int dayNr) throws IOException { if(!hafasFolder.endsWith("/")) hafasFolder += "/"; log.info("Creating the schedule based on HAFAS..."); // 1. Read and create stop facilities log.info(" Read transit stops..."); StopReader.run(schedule, transformation, hafasFolder + "BFKOORD_GEO"); log.info(" Read transit stops... done."); // 1.a Read minimal transfer times log.info(" Read minimal transfer times..."); MinimalTransferTimesReader.run(schedule, hafasFolder, "UMSTEIGB","METABHF"); log.info(" Read minimal transfer times... done."); // 2. Read all operators from BETRIEB_DE log.info(" Read operators..."); Map<String, String> operators = OperatorReader.readOperators(hafasFolder + "BETRIEB_DE"); log.info(" Read operators... done."); // 3. Read all ids for work-day-routes from HAFAS-BITFELD log.info(" Read bitfeld numbers..."); Set<Integer> bitfeldNummern; if (dayNr < 0) { bitfeldNummern = BitfeldAnalyzer.findBitfeldnumbersOfBusiestDay(hafasFolder + "FPLAN", hafasFolder + "BITFELD"); log.info(" nb of bitfields at busiest day: " + bitfeldNummern.size()); } else { // TODO: check if dayNr is within the timetable period defined in ECKDATEN bitfeldNummern = BitfeldAnalyzer.getBitfieldsAtValidDay(dayNr, hafasFolder); log.info(" nb of bitfields valid at day " + dayNr + ": " + bitfeldNummern.size()); } log.info(" Read bitfeld numbers... done."); // 4. Create all lines from HAFAS-Schedule log.info(" Read transit lines..."); List<FPLANRoute> routes = FPLANReader.parseFPLAN(bitfeldNummern, operators, hafasFolder + "FPLAN"); log.info(" Read transit lines... done."); // TODO another important HAFAS-file is DURCHBI. This feature is not supported by MATSim yet (but in Switzerland, for example, locally very important. log.info(" Creating transit routes..."); createTransitRoutesFromFPLAN(routes, schedule, vehicles); log.info(" Creating transit routes... done."); // 5. Clean schedule ScheduleCleaner.removeNotUsedStopFacilities(schedule); ScheduleCleaner.removeNotUsedMinimalTransferTimes(schedule); ScheduleCleaner.combineIdenticalTransitRoutes(schedule); ScheduleCleaner.cleanDepartures(schedule); ScheduleCleaner.cleanVehicles(schedule, vehicles); log.info("Creating the schedule based on HAFAS... done."); }
Example #14
Source File: AmodeusDrtModule.java From amodeus with GNU General Public License v2.0 | 4 votes |
@Override public CoordinateTransformation coords_toWGS84() { return coords_toWGS84; }
Example #15
Source File: AmodeusDrtModule.java From amodeus with GNU General Public License v2.0 | 4 votes |
@Override public CoordinateTransformation coords_fromWGS84() { return coords_fromWGS84; }
Example #16
Source File: AmodeusModule.java From amodeus with GNU General Public License v2.0 | 4 votes |
@Override public CoordinateTransformation coords_toWGS84() { return coords_toWGS84; }
Example #17
Source File: GtfsShape.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
public void transformCoords(CoordinateTransformation transformation) { for(Map.Entry<Integer, Coord> entry : this.coordSorted.entrySet()) { Coord transformedCoord = transformation.transform(entry.getValue()); this.coordSorted.put(entry.getKey(), transformedCoord); } }
Example #18
Source File: AmodeusModule.java From amodeus with GNU General Public License v2.0 | 4 votes |
@Override public CoordinateTransformation coords_fromWGS84() { return coords_fromWGS84; }
Example #19
Source File: ReferenceFrame.java From amodeus with GNU General Public License v2.0 | 4 votes |
/** @return transformation from simulation coordinates to WGS84 */ CoordinateTransformation coords_toWGS84();
Example #20
Source File: ReferenceFrame.java From amodeus with GNU General Public License v2.0 | 4 votes |
/** @return transformation from WGS84 to simulation coordinates */ CoordinateTransformation coords_fromWGS84();