コード例 #1
0
  /** @param contorno */
  public void addContorno(Contorno contorno) {
    // Conseguimos los punto a, b (bounding box del contorno)
    Coordenada a = null, b = null;
    {
      Iterator<Coordenada> it = contorno.getCoordenadas().iterator();
      while (it.hasNext()) {
        Coordenada c = it.next();
        if (a == null || b == null) {
          a = c.clone();
          b = c.clone();
        } else {
          if (a.getLatitud() > c.getLatitud()) {
            a.setLatitud(c.getLatitud());
          }
          if (a.getLongitud() > c.getLongitud()) {
            a.setLongitud(c.getLongitud());
          }
          if (b.getLatitud() < c.getLatitud()) {
            b.setLatitud(c.getLatitud());
          }
          if (b.getLongitud() < c.getLongitud()) {
            b.setLongitud(c.getLongitud());
          }
        }
      }
      // Normalizamos las coordenadas
      //            a.setLatitud(a.getLatitud()+90);
      //            a.setLongitud(b.getLongitud()+180);
      //            b.setLatitud(a.getLatitud()+90);
      //            b.setLongitud(b.getLongitud()+180);
      //            System.out.println("Bounding box: " + a + ", " + b);
    }

    // Añadimos las cuadriculas a las que el bounding box pertenece
    int ai = (int) ((a.getLongitud() + 180.0) / this.tamanoCuadricula);
    int aj = (int) ((a.getLatitud() + 90.0) / this.tamanoCuadricula);
    int bi = (int) ((b.getLongitud() + 180.0) / this.tamanoCuadricula);
    int bj = (int) ((b.getLatitud() + 90.0) / this.tamanoCuadricula);
    //        System.out.println("Bounding box local: (" + ai + ", " + aj + "), ("
    //                + bi + ", " + bj +")");
    for (int i = ai; i <= bi; ++i) {
      for (int j = aj; j <= bj; ++j) {
        // System.out.println("Contorno " + contorno + " añadido en (" +
        //        i + ", " + j + ")");
        contorno.addCuadricula(this.getCuadricula(i, j));
        this.getCuadricula(i, j).addContorno(contorno);
      }
    }
  }