// Create Facilities inside the simulated area. private static void createInternalFacilities( Scenario scenario, Map<Integer, Emme2Zone> zonalAttributes, Map<Integer, SimpleFeature> zonalShapes) { // create indices for the zones Map<Integer, Integer> indices = new HashMap<Integer, Integer>(); int index = 0; for (Integer taz : zonalShapes.keySet()) { indices.put(taz, index); index++; } NetworkImpl network = (NetworkImpl) scenario.getNetwork(); ActivityFacilities activityFacilities = scenario.getActivityFacilities(); ObjectAttributes facilitiesAttributes = activityFacilities.getFacilityAttributes(); ActivityFacilitiesFactory factory = activityFacilities.getFactory(); for (Entry<Integer, SimpleFeature> entry : zonalShapes.entrySet()) { int taz = entry.getKey(); SimpleFeature feature = entry.getValue(); Geometry geometry = (Geometry) feature.getDefaultGeometry(); List<Coord> coordinates = getRandomCoordinatesInZone(facilitiesPerZone, geometry, random); int i = 0; for (Coord coord : coordinates) { Id<ActivityFacility> id = Id.create(taz + "_" + i, ActivityFacility.class); ActivityFacility facility = factory.createActivityFacility(id, coord); createAndAddActivityOptions(scenario, facility, zonalAttributes.get(taz)); activityFacilities.addActivityFacility(facility); Link link = network.getNearestLinkExactly(coord); ((ActivityFacilityImpl) facility).setLinkId(link.getId()); i++; // Also add a tta activity to all facilities. ActivityOption activityOption = factory.createActivityOption(ttaActivityType); activityOption.addOpeningTime(new OpeningTimeImpl(0 * 3600, 24 * 3600)); activityOption.setCapacity(capacity); facility.addActivityOption(activityOption); facilitiesAttributes.putAttribute(id.toString(), TAZObjectAttributesName, taz); facilitiesAttributes.putAttribute( id.toString(), indexObjectAttributesName, indices.get(taz)); } } }
private void processFacilities( ActivityFacilitiesFactory aff, Map<Long, ? extends EntityContainer> nodeMap) { for (Long n : nodeMap.keySet()) { Entity entity = nodeMap.get(n).getEntity(); Map<String, String> tags = new TagCollectionImpl(entity.getTags()).buildMap(); for (String s : this.keys) { String tourism = tags.get(s); String matsimType = null; if (tourism != null) { matsimType = getActivityType(tourism); } if (matsimType != null) { String name = tags.get("name"); if (name != null) { name.replace("ä", "ae"); name.replace("ö", "oe"); name.replace("ü", "ue"); } Coord coord = OsmCoordUtils.getCoord(entity, this.ct, this.nodeMap, this.wayMap, this.relationMap); Id<ActivityFacility> id = Id.create(entity.getId(), ActivityFacility.class); ActivityFacility af; if (!this.facilities.getFacilities().containsKey(id)) { af = aff.createActivityFacility(id, coord); // ((ActivityFacilityImpl)af).setDesc(name); this.facilities.addActivityFacility(af); } else { af = (ActivityFacilityImpl) this.facilities.getFacilities().get(id); } ActivityOption ao = aff.createActivityOption(matsimType); af.addActivityOption(ao); } } } }