org.postgresql.geometric.PGpoint Java Examples

The following examples show how to use org.postgresql.geometric.PGpoint. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PointType.java    From hibernate-postgresql with Apache License 2.0 5 votes vote down vote up
@Override
   public Object nullSafeGet(ResultSet resultSet, String[] names, SharedSessionContractImplementor sessionImplementor, Object owner) throws HibernateException, SQLException {
	if (names.length != 1)
		throw new IllegalArgumentException("names.length != 1, names = " + names);

	PGpoint value = (PGpoint) resultSet.getObject(names[0]);

	if (value == null) {
		return null;
	} else {
		return new Point(value.x, value.y);
	}
}
 
Example #2
Source File: PointType.java    From hibernate-postgresql with Apache License 2.0 5 votes vote down vote up
@Override
   public void nullSafeSet(PreparedStatement preparedStatement, Object value, int i, SharedSessionContractImplementor sessionImplementor) throws HibernateException, SQLException {
	if (value == null) {
		preparedStatement.setNull(i, java.sql.Types.OTHER);
	} else {
		preparedStatement.setObject(i, new PGpoint(((Point) value).getX(), ((Point) value).getY()));
	}
}
 
Example #3
Source File: PolygonType.java    From hibernate-postgresql with Apache License 2.0 5 votes vote down vote up
private Point[] convert( PGpoint[] points ) {
	Point[] newpoints = new Point[points.length];
	for (int i = 0; i < points.length; i++) {
		newpoints[i] = new Point(points[i].x, points[i].y);
	}
	return newpoints;
}
 
Example #4
Source File: PolygonType.java    From hibernate-postgresql with Apache License 2.0 5 votes vote down vote up
private PGpoint[] convert( Point[] points ) {
	PGpoint[] newpoints = new PGpoint[points.length];
	for (int i = 0; i < points.length; i++) {
		newpoints[i] = new PGpoint(points[i].getX(), points[i].getY());
	}
	return newpoints;
}
 
Example #5
Source File: DBLoader.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
private PGpolygon makePGpolygon(final double[][][] bezarr) {
	final PGpoint[] points = new PGpoint[bezarr[0][0].length * 3];
	final double[][] p_l = bezarr[0];
	final double[][] p = bezarr[1];
	final double[][] p_r = bezarr[2];
	for (int i=0, j=0; i<points.length; i+=3, j++) {
		points[i] = new PGpoint(p_l[0][j], p_l[1][j]);
		points[i+1] = new PGpoint(p[0][j], p[1][j]);
		points[i+2] = new PGpoint(p_r[0][j], p_r[1][j]);
	}
	return new PGpolygon(points);
}
 
Example #6
Source File: DBLoader.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
private PGpolygon makePGpolygon(final ArrayList al_points) {
	final PGpoint[] pol = new PGpoint[al_points.size()];
	for (int i=0; i<pol.length; i++) {
		Point p = (Point)al_points.get(i);
		pol[i] = new PGpoint(p.x, p.y);
	}
	return new PGpolygon(pol);
}
 
Example #7
Source File: PostgresITest.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void test_geo_types_arrays() throws Exception {
    try (Connection conn = DriverManager.getConnection(url(RW), properties)) {
        conn.createStatement().execute(
            "CREATE TABLE t (" +
            "   geo_points array(geo_point)," +
            "   geo_shapes array(geo_shape)" +
            ") " +
            "WITH (number_of_replicas = 0)");

        PreparedStatement preparedStatement = conn.prepareStatement(
            "INSERT INTO t (geo_points, geo_shapes) VALUES (?, ?)");
        preparedStatement.setArray(1, conn.createArrayOf(
            "point",
            new PGpoint[]{new PGpoint(1.1, 2.2), new PGpoint(3.3, 4.4)}));
        preparedStatement.setArray(2, conn.createArrayOf(
            "json",
            new Object[]{
                DataTypes.STRING.value(
                    Map.of(
                        "coordinates", new double[][]{{0, 0}, {1, 1}},
                        "type", "LineString"
                    )
                )
            }));
        preparedStatement.executeUpdate();
        conn.createStatement().execute("REFRESH TABLE t");

        ResultSet rs = conn.createStatement().executeQuery("SELECT geo_points, geo_shapes FROM t");
        assertThat(rs.next(), is(true));
        assertThat(
            (Object[]) rs.getArray(1).getArray(),
            arrayContaining(new PGpoint(1.1, 2.2), new PGpoint(3.3, 4.4)));

        var shape = new PGobject();
        shape.setType("json");
        shape.setValue("{\"coordinates\":[[0.0,0.0],[1.0,1.0]],\"type\":\"LineString\"}");
        assertThat((Object[]) rs.getArray(2).getArray(), arrayContaining(shape));
    } catch (BatchUpdateException e) {
        throw e.getNextException();
    }
}