Esempio n. 1
0
  /**
   * Randomly samples a coordinate from within a zone.
   *
   * <p>TODO This must still be implemented once we have a shapefile for the transport zones (TZs)
   * for City of Cape Town.
   *
   * @param zone
   * @return
   */
  private Coord sampleCoord(String zone, String activityType) {

    MyZone mz = null;
    if (zone.equals("") || zone.equals(" ")) {
      /* Do nothing; don't try and get a zone. */
    } else {
      mz = zoneMap.get(zone);
      if (mz == null) {
        LOG.error("Cannot find zone " + zone + " in Map.");
      }
    }

    /* Update the map indicating how many of each activity occurs in
     * each zone. */
    if (mz != null) {
      ObjectAttributes oa = mz.getObjectAttributes();
      Object o = oa.getAttribute(mz.getId().toString(), activityType);
      if (o == null) {
        oa.putAttribute(mz.getId().toString(), activityType, 1);
      } else {
        if (o instanceof Integer) {
          int oldValue = (int) o;
          oa.putAttribute(mz.getId().toString(), activityType, oldValue + 1);
        } else {
          LOG.error(
              "The activity count for zone "
                  + mz.getId().toString()
                  + "'s activity type '"
                  + activityType
                  + " should of type Integer, but is "
                  + o.getClass().toString());
        }
      }
    }

    double x = 0.0;
    double y = 0.0;
    if (mz != null) {
      Point p = mz.sampleRandomInteriorPoint();
      x = p.getX();
      y = p.getY();
    } else {
      numberOfUnknownActivityLocations++;
    }
    Coord c = CoordUtils.createCoord(x, y);
    return c;
  }