21 package org.matsim.core.network.io;
23 import java.io.IOException;
25 import org.apache.logging.log4j.LogManager;
26 import org.apache.logging.log4j.Logger;
27 import org.geotools.api.data.SimpleFeatureSource;
28 import org.geotools.api.feature.simple.SimpleFeature;
29 import org.geotools.api.geometry.BoundingBox;
30 import org.geotools.data.simple.SimpleFeatureIterator;
175 public void read() throws IOException {
176 log.info(
"reading nodes from Junction Shape file '" + this.jcShpFileName +
"'...");
179 log.info(
"reading links from Network Shape file '" + this.nwShpFileName +
"'...");
222 int nCnt = network.
getNodes().size();
224 SimpleFeatureIterator fIt = fs.getFeatures().features();
225 while (fIt.hasNext()) {
226 SimpleFeature f = fIt.next();
229 BoundingBox bb = f.getBounds();
230 Coord c =
new Coord((bb.getMinX() + bb.getMaxX()) / 2.0, (bb.getMinY() + bb.getMaxY()) / 2.0);
232 Object
id = f.getAttribute(NODE_ID_NAME);
233 int feattyp = Integer.parseInt(f.getAttribute(NODE_FEATTYP_NAME).toString());
234 if ((feattyp != 4120) && (feattyp != 4220)) {
235 throw new IllegalArgumentException(NODE_ID_NAME +
"=" +
id +
": " + NODE_FEATTYP_NAME +
"=" + feattyp +
" not allowed.");
237 int jncttyp = Integer.parseInt(f.getAttribute(NODE_JNCTTYP_NAME).toString());
238 if ((jncttyp < 0) || (jncttyp == 1) || (jncttyp > 6)) {
239 throw new IllegalArgumentException(NODE_ID_NAME +
"=" +
id +
": " + NODE_JNCTTYP_NAME +
"=" + jncttyp +
" not allowed.");
242 throw new IllegalArgumentException(
"In " + jcShpFileName +
": There is at least one feature that does not have an ID set.");
244 String type = feattyp +
"-" + jncttyp;
246 final String type1 = type;
252 nCnt = network.
getNodes().size() - nCnt;
253 log.info(
" " + nCnt +
" nodes added to the network.");
345 int lCnt = network.
getLinks().size();
348 SimpleFeatureIterator fIt = fs.getFeatures().features();
349 while (fIt.hasNext()) {
350 SimpleFeature f = fIt.next();
351 boolean ignore =
false;
353 Object
id = f.getAttribute(LINK_ID_NAME);
354 int featTyp = Integer.parseInt(f.getAttribute(LINK_FEATTYP_NAME).toString());
355 if ((featTyp != 4110) && (featTyp != 4130) && (featTyp != 4165)) {
356 throw new IllegalArgumentException(LINK_ID_NAME +
"=" +
id +
": " + LINK_FEATTYP_NAME +
"=" + featTyp +
" not allowed.");
358 int ferryType = Integer.parseInt(f.getAttribute(LINK_FERRYTYP_NAME).toString());
359 if ((ferryType < 0) || (ferryType > 2)) {
360 throw new IllegalArgumentException(LINK_ID_NAME +
"=" +
id +
": " + LINK_FERRYTYP_NAME +
"=" + ferryType +
" not allowed.");
364 double length = Double.parseDouble(f.getAttribute(LINK_LENGTH_NAME).toString());
365 int linksType = Integer.parseInt(f.getAttribute(LINK_FRCTYP_NAME).toString());
366 if ((linksType < -1) || (linksType > 8)) {
367 throw new IllegalArgumentException(LINK_ID_NAME +
"=" +
id +
": " + LINK_FRCTYP_NAME +
"=" + linksType +
" not allowed.");
369 String oneway = f.getAttribute(LINK_ONEWAY_NAME).toString();
370 if (!oneway.equals(
" ") && !oneway.equals(
"FT") && !oneway.equals(
"TF") && !oneway.equals(
"N")) {
371 throw new IllegalArgumentException(LINK_ID_NAME +
"=" +
id +
": " + LINK_ONEWAY_NAME +
"=" + oneway +
" not allowed.");
373 double speed = Double.parseDouble(f.getAttribute(LINK_SPEED_NAME).toString());
374 double lanes = Double.parseDouble(f.getAttribute(LINK_LANES_NAME).toString());
378 if ((fNode == null) || (tNode == null)) {
379 log.warn(
" linkId=" +
id.toString()
380 +
": at least one of the two junctions do not exist. Ignoring and proceeding anyway...");
385 if ((featTyp != 4110) && (featTyp != 4130)) {
386 log.trace(
" linkId=" +
id.toString() +
": ignoring " + LINK_FEATTYP_NAME +
"=" + featTyp +
".");
391 log.trace(
" linkId=" +
id.toString() +
": ignoring " + LINK_FRCTYP_NAME +
"=" + linksType +
".");
395 if (this.ignoreFrcType8 && (7 < linksType)) {
396 log.trace(
" linkId=" +
id.toString() +
": ignoring " + LINK_FRCTYP_NAME +
"=" + linksType +
".");
401 if (this.ignoreFrcType7onewayN && ((linksType == 7) && oneway.equals(
"N"))) {
402 log.trace(
" linkId=" +
id.toString() +
": ignoring " + LINK_FRCTYP_NAME +
"=" + linksType +
" with " + LINK_ONEWAY_NAME
409 if (linksType <= this.maxFrcTypeForDoubleLaneLink) {
417 if (speed < minSpeedForNormalCapacity) {
426 if (oneway.equals(
" ") || oneway.equals(
"N")) {
441 }
else if (oneway.equals(
"FT")) {
449 }
else if (oneway.equals(
"TF")) {
458 throw new IllegalArgumentException(
"linkId=" +
id.toString() +
": " + LINK_ONEWAY_NAME +
"=" + oneway +
" not known!");
466 lCnt = network.
getLinks().size() - lCnt;
467 log.info(
" " + lCnt +
" links added to the network layer.");
468 log.info(
" " + ignoreCnt +
" links ignored from the input shape file.");
482 System.out.println(prefix +
"configuration of " + this.getClass().getName() +
":");
483 System.out.println(prefix +
" MATSim network:");
484 System.out.println(prefix +
" ignoreFrcType8: " + ignoreFrcType8);
485 System.out.println(prefix +
" ignoreFrcType7onewayN: " + ignoreFrcType7onewayN);
486 System.out.println(prefix +
" maxFrcTypeForDoubleLaneLink: " + maxFrcTypeForDoubleLaneLink);
487 System.out.println(prefix +
" minSpeedForNormalCapacity: " + minSpeedForNormalCapacity);
488 System.out.println(prefix +
" junction shape:");
489 System.out.println(prefix +
" jcShpFileName: " + jcShpFileName);
490 System.out.println(prefix +
" NODE_ID_NAME: " + NODE_ID_NAME);
491 System.out.println(prefix +
" NODE_FEATTYP_NAME: " + NODE_FEATTYP_NAME);
492 System.out.println(prefix +
" NODE_JNCTTYP_NAME: " + NODE_JNCTTYP_NAME);
493 System.out.println(prefix +
" network shape:");
494 System.out.println(prefix +
" nwShpFileName: " + nwShpFileName);
495 System.out.println(prefix +
" LINK_ID_NAME: " + LINK_ID_NAME);
496 System.out.println(prefix +
" LINK_FEATTYP_NAME: " + LINK_FEATTYP_NAME);
497 System.out.println(prefix +
" LINK_FERRYTYP_NAME: " + LINK_FERRYTYP_NAME);
498 System.out.println(prefix +
" LINK_FJNCTID_NAME: " + LINK_FJNCTID_NAME);
499 System.out.println(prefix +
" LINK_TJNCTID_NAME: " + LINK_TJNCTID_NAME);
500 System.out.println(prefix +
" LINK_LENGTH_NAME: " + LINK_LENGTH_NAME);
501 System.out.println(prefix +
" LINK_FRCTYP_NAME: " + LINK_FRCTYP_NAME);
502 System.out.println(prefix +
" LINK_ONEWAY_NAME: " + LINK_ONEWAY_NAME);
503 System.out.println(prefix +
" LINK_SPEED_NAME: " + LINK_SPEED_NAME);
504 System.out.println(prefix +
" LINK_LANES_NAME: " + LINK_LANES_NAME);
505 System.out.println(prefix +
"done.");
void setName(String name)
NetworkReaderTeleatlas(final Network network, final String jcShpFileName, final String nwShpFileName)
static void setOrigId(final Node node, final String id)
void setNumberOfLanes(double lanes)
Map< Id< Node >, ? extends Node > getNodes()
static final String LINK_FJNCTID_NAME
void setFreespeed(double freespeed)
static final String LINK_LANES_NAME
static final String NODE_ID_NAME
static final String LINK_ONEWAY_NAME
int maxFrcTypeForDoubleLaneLink
NetworkFactory getFactory()
static final String LINK_FERRYTYP_NAME
static< T > Id< T > create(final long key, final Class< T > type)
static final String LINK_FRCTYP_NAME
Link createLink(final Id< Link > id, final Node fromNode, final Node toNode)
void setLength(double length)
final void printInfo(final String prefix)
static final String LINK_SPEED_NAME
void readLinksFromNWshp()
void readNodesFromJCshp()
static final String NODE_FEATTYP_NAME
static final String NODE_JNCTTYP_NAME
static SimpleFeatureSource readDataFile(final String filename)
void setCapacityPeriod(double capPeriod)
static final String LINK_ID_NAME
Map< Id< Link >, ? extends Link > getLinks()
Node createNode(final Id< Node > id, final Coord coord)
final String nwShpFileName
static void setType(Node node, final String type)
static final String LINK_FEATTYP_NAME
int minSpeedForNormalCapacity
boolean ignoreFrcType7onewayN
final String jcShpFileName
static final String LINK_LENGTH_NAME
static final String LINK_TJNCTID_NAME
void setCapacity(double capacity)