📄 junctioncontext.java
字号:
/*〤opyright 2008 Nick MallesonThis file is part of RepastCity.RepastCity is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.RepastCity is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.You should have received a copy of the GNU General Public License along with RepastCity. If not, see <http://www.gnu.org/licenses/>. */package repastcity.citycontext;import java.lang.Iterable;import repast.simphony.context.DefaultContext;import repast.simphony.context.space.gis.GeographyFactoryFinder;import repast.simphony.context.space.graph.NetworkFactory;import repast.simphony.context.space.graph.NetworkFactoryFinder;import repast.simphony.space.gis.GeographyParameters;import java.util.HashMap;import com.vividsolutions.jts.geom.Coordinate;/** * Context which holds juntction objects and also the RoadNetwork. * * @author Nick Malleson * */public class JunctionContext extends DefaultContext<Junction> { public JunctionContext() { super("JunctionContext"); System.out.println("JunctionContext building junction context and projections"); /* Create a Network projection for the road network */ NetworkFactory netFac = NetworkFactoryFinder.createNetworkFactory(new HashMap<String, Object>()); netFac.createNetwork("RoadNetwork", this, false); /* Create a Geography to store junctions in spatially */ GeographyParameters<Junction> geoParams = new GeographyParameters<Junction>(); GeographyFactoryFinder.createGeographyFactory(null).createGeography( "JunctionGeography", this, geoParams); } /* Runs through all the junctions in the context. If it finds one with coordinates which are the same as the * Junction passed to this functions it returns true. */ public boolean existsInContext(Junction j) { Iterable<Junction> it = this.getObjects(Junction.class); for (Junction junc:it) { if (junc.equals(j) ) return true; } return false; } public Junction getJunctionWithCoordinates(Coordinate c) { Iterable<Junction> it = this.getObjects(Junction.class); for (Junction junc:it) { if (junc.getCoordinate().equals(c)) return junc; } System.err.print("JunctionContext: getJunctionWithCoordinates: error, junction not found. "); System.err.println("Coordinates: "+c.toString()); return null; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -