Example #1
0
  @Test
  public void testPostgresExtensions() throws Exception {
    jOOQAbstractTest.reset = false;

    // [#2267] Try to execute some basic CRUD operations on PostGIS data
    // types. Even without formal support, jOOQ should allow to pass these
    // objects through to JDBC
    Point point = new Point(0, 0);
    point.setSrid(4326);
    PGgeometry geometry = new PGgeometry(point);

    // [#2267] Non-PostGIS geometry objects should work, too
    PGbox box = new PGbox(1.0, 1.0, 2.0, 2.0);
    PGInterval interval = new PGInterval(1, 2, 3, 4, 5, 6);

    TPgExtensionsRecord r1 = create().newRecord(T_PG_EXTENSIONS);
    r1.setPgGeometry(geometry);
    r1.setPgInterval(interval);
    r1.setPgBox(box);
    assertEquals(1, r1.store());
    assertEquals(1, (int) create().selectCount().from(T_PG_EXTENSIONS).fetchOne(0, int.class));

    TPgExtensionsRecord r2 = create().selectFrom(T_PG_EXTENSIONS).fetchOne();
    assertEquals(r1, r2);

    assertEquals(box, r2.getPgBox());
    assertEquals(geometry, r2.getPgGeometry());
    assertEquals(interval, r2.getPgInterval());
  }
  private Point parsePoint(ValueGetter data, boolean haveZ, boolean haveM) {
    double X = data.getDouble();
    double Y = data.getDouble();
    Point result;
    if (haveZ) {
      double Z = data.getDouble();
      result = new Point(X, Y, Z);
    } else {
      result = new Point(X, Y);
    }

    if (haveM) {
      result.setM(data.getDouble());
    }

    return result;
  }
  @Override
  public final Array apply(Array sourceArray, Item sourceColumn) throws RuleException {
    final int[] shape = getContext().getTargetVariable().getShape();
    final int sizeY = shape[1];
    final int sizeX = shape[2];
    final Array targetArray = createTargetArray(sizeY, sizeX);

    final Reader observationReader = getContext().getObservationReader();
    if (observationReader == null) {
      return targetArray;
    }

    final int recordNo = getContext().getObservation().getRecordNo();
    final GeoCoding geoCoding;
    try {
      geoCoding = observationReader.getGeoCoding(recordNo);
    } catch (IOException ignored) {
      return targetArray;
    }

    final Point point =
        getContext().getMatchup().getRefObs().getPoint().getGeometry().getFirstPoint();
    final double lon = point.getX();
    final double lat = point.getY();
    final PixelLocator pixelLocator = new GeoCodingWrapper(geoCoding);
    final Point2D p = new Point2D.Double();
    final boolean found = pixelLocator.getPixelLocation(lon, lat, p);
    if (found) {
      final Watermask watermask = Container.WATERMASK;
      final Index index = targetArray.getIndex();
      final int minX = (int) Math.max(p.getX() - sizeX / 2, 0.0);
      final int maxX =
          (int) Math.min(p.getX() + sizeX / 2, observationReader.getElementCount() - 1);
      final int minY = (int) Math.max(p.getY() - sizeY / 2, 0.0);
      final int maxY =
          (int) Math.min(p.getY() + sizeY / 2, observationReader.getScanLineCount() - 1);
      for (int y = minY, yi = 0; y <= maxY; y++, yi++) {
        for (int x = minX, xi = 0; x <= maxX; x++, xi++) {
          final byte waterFraction =
              watermask.getWaterFraction(x, y, pixelLocator, stepCountX, stepCountY);
          targetArray.setByte(index.set(0, yi, xi), waterFraction);
        }
      }
    }
    return targetArray;
  }
Example #4
0
 /**
  * Returns the string representation of the BoundingBox object
  *
  * @return string representation of the BoundingBox object
  */
 @Override
 public String toString() {
   return "nw:" + nw.toString() + " sw:" + nw.toString();
 }