MATSIM
XY2LinksForFacilities.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * *
4  * *********************************************************************** *
5  * *
6  * copyright : (C) 2018 by the members listed in the COPYING, *
7  * LICENSE and WARRANTY file. *
8  * email : info at matsim dot org *
9  * *
10  * *********************************************************************** *
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * See also COPYING, LICENSE and WARRANTY file *
17  * *
18  * *********************************************************************** */
19 
20 package org.matsim.core.controler;
21 
22 import org.apache.logging.log4j.LogManager;
23 import org.apache.logging.log4j.Logger;
26 import org.matsim.core.gbl.Gbl;
31 
36 public class XY2LinksForFacilities {
37 
38  public static final Logger LOGGER = LogManager.getLogger(XY2LinksForFacilities.class);
39 
40  public static void run(Network network, ActivityFacilities facilities){
41 
42  int coordNullWarn = 0;
43  int linkNullWarn = 0;
44 
45  for (ActivityFacility activityFacility : facilities.getFacilities().values()) {
46 
47  if (activityFacility.getCoord()==null && activityFacility.getLinkId()== null) {
48  throw new RuntimeException("Neither coordinate nor linkId are available for facility id "+ activityFacility.getId()+". Aborting....");
49  } else if (activityFacility.getLinkId()==null){
50  if (linkNullWarn==0) {
51  LOGGER.warn("There is no link for at least a facility. Assigning links for such facilities from coords.");
52  LOGGER.warn(Gbl.ONLYONCE);
53  linkNullWarn++;
54  }
55  Link link = NetworkUtils.getNearestLink(network, activityFacility.getCoord());
56  if (link==null) {
57  LOGGER.warn("No nearest link is found for coord "+activityFacility.getCoord());
58  } else{
59  ((ActivityFacilityImpl)activityFacility).setLinkId(link.getId());
60  }
61 
62  } else if (activityFacility.getCoord()==null){
63  if (coordNullWarn==0) {
64  LOGGER.warn("There is no coord for the facility.");
65  LOGGER.warn(Gbl.ONLYONCE);
66  coordNullWarn++;
67  }
68  }
69  }
70  }
71 }
Map< Id< ActivityFacility >, ? extends ActivityFacility > getFacilities()
static final String ONLYONCE
Definition: Gbl.java:42
static Link getNearestLink(Network network, final Coord coord)