org.postgis.PGgeometry Java Examples
The following examples show how to use
org.postgis.PGgeometry.
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: GeometryConverterAdapter.java From importer-exporter with Apache License 2.0 | 6 votes |
@Override public GeometryObject getGeometry(Object geomObj) throws SQLException { if (geomObj instanceof PGgeometry) { Geometry geometry = ((PGgeometry)geomObj).getGeometry(); switch (geometry.getType()) { case Geometry.POINT: return getPoint((Point)geometry); case Geometry.MULTIPOINT: return getMultiPoint((MultiPoint)geometry); case Geometry.LINESTRING: return getCurve((LineString)geometry); case Geometry.MULTILINESTRING: return getMultiCurve((MultiLineString)geometry); case Geometry.POLYGON: return getPolygon((Polygon)geometry); case Geometry.MULTIPOLYGON: return getMultiPolygon((MultiPolygon)geometry); default: throw new SQLException("Cannot convert PostGIS geometry type '" + geometry.getType() + "' to internal representation: Unsupported type."); } } return null; }
Example #2
Source File: GeometryConverterAdapter.java From importer-exporter with Apache License 2.0 | 6 votes |
@Override public GeometryObject getMultiPolygon(Object geomObj) throws SQLException { GeometryObject multiPolygon = null; if (geomObj instanceof PGgeometry) { Geometry geometry = ((PGgeometry)geomObj).getGeometry(); if (geometry.getType() == Geometry.MULTIPOLYGON) { multiPolygon = getMultiPolygon((MultiPolygon)geometry); } else if (geometry.getType() == Geometry.POLYGON) { Polygon polygonObj = (Polygon)geometry; double[][] coordinates = getPolygonCoordinates(polygonObj); int[] exteriorRings = new int[]{ 0 }; multiPolygon = GeometryObject.createMultiPolygon(coordinates, exteriorRings, polygonObj.getDimension(), polygonObj.getSrid()); } } return multiPolygon; }
Example #3
Source File: GeometryConverterAdapter.java From importer-exporter with Apache License 2.0 | 6 votes |
@Override public GeometryObject getMultiCurve(Object geomObj) throws SQLException { GeometryObject multiCurve = null; if (geomObj instanceof PGgeometry) { Geometry geometry = ((PGgeometry)geomObj).getGeometry(); if (geometry.getType() == Geometry.MULTILINESTRING) { multiCurve = getMultiCurve((MultiLineString)geometry); } else if (geometry.getType() == Geometry.LINESTRING) { LineString lineStringObj = (LineString)geometry; double[][] coordiantes = new double[1][]; coordiantes[0] = getCurveCoordinates(lineStringObj); multiCurve = GeometryObject.createMultiPoint(coordiantes, lineStringObj.getDimension(), lineStringObj.getSrid()); } } return multiCurve; }
Example #4
Source File: GeometryConverterAdapter.java From importer-exporter with Apache License 2.0 | 6 votes |
@Override public GeometryObject getMultiPoint(Object geomObj) throws SQLException { GeometryObject multiPoint = null; if (geomObj instanceof PGgeometry) { Geometry geometry = ((PGgeometry)geomObj).getGeometry(); if (geometry.getType() == Geometry.MULTIPOINT) { multiPoint = getMultiPoint((MultiPoint)geometry); } else if (geometry.getType() == Geometry.POINT) { Point pointObj = (Point)geometry; double[][] coordiantes = new double[1][]; coordiantes[0] = getPointCoordinates(pointObj); multiPoint = GeometryObject.createMultiPoint(coordiantes, pointObj.getDimension(), pointObj.getSrid()); } } return multiPoint; }
Example #5
Source File: AbstractGeometryTypeHandler.java From mybatis-typehandlers-postgis with Do What The F*ck You Want To Public License | 5 votes |
public T getNullableResult(ResultSet rs, String columnName) throws SQLException { PGgeometry pGgeometry = (PGgeometry) rs.getObject(columnName); if (pGgeometry == null) { return null; } return (T) pGgeometry.getGeometry(); }
Example #6
Source File: GeometryConverterAdapter.java From importer-exporter with Apache License 2.0 | 5 votes |
@Override public GeometryObject getPolygon(Object geomObj) throws SQLException { GeometryObject polygon = null; if (geomObj instanceof PGgeometry) { Geometry geometry = ((PGgeometry)geomObj).getGeometry(); if (geometry.getType() != Geometry.POLYGON) return null; polygon = getPolygon((Polygon)geometry); } return polygon; }
Example #7
Source File: GeometryConverterAdapter.java From importer-exporter with Apache License 2.0 | 5 votes |
@Override public GeometryObject getCurve(Object geomObj) throws SQLException { GeometryObject curve = null; if (geomObj instanceof PGgeometry) { Geometry geometry = ((PGgeometry)geomObj).getGeometry(); if (geometry.getType() != Geometry.LINESTRING) return null; curve = getCurve((LineString)geometry); } return curve; }
Example #8
Source File: GeometryConverterAdapter.java From importer-exporter with Apache License 2.0 | 5 votes |
@Override public GeometryObject getPoint(Object geomObj) throws SQLException { GeometryObject point = null; if (geomObj instanceof PGgeometry) { Geometry geometry = ((PGgeometry)geomObj).getGeometry(); if (geometry.getType() != Geometry.POINT) return null; point = getPoint((Point)geometry); } return point; }
Example #9
Source File: UtilAdapter.java From importer-exporter with Apache License 2.0 | 5 votes |
@Override protected BoundingBox transformBoundingBox(BoundingBox bbox, DatabaseSrs sourceSrs, DatabaseSrs targetSrs, Connection connection) throws SQLException { BoundingBox result = new BoundingBox(bbox); int sourceSrid = sourceSrs.getSrid(); int targetSrid = targetSrs.getSrid(); StringBuilder boxGeom = new StringBuilder() .append("SRID=").append(sourceSrid).append(";POLYGON((") .append(bbox.getLowerCorner().getX()).append(" ").append(bbox.getLowerCorner().getY()).append(",") .append(bbox.getLowerCorner().getX()).append(" ").append(bbox.getUpperCorner().getY()).append(",") .append(bbox.getUpperCorner().getX()).append(" ").append(bbox.getUpperCorner().getY()).append(",") .append(bbox.getUpperCorner().getX()).append(" ").append(bbox.getLowerCorner().getY()).append(",") .append(bbox.getLowerCorner().getX()).append(" ").append(bbox.getLowerCorner().getY()).append("))"); try (PreparedStatement psQuery = connection.prepareStatement("select ST_Transform(ST_GeomFromEWKT(?), " + targetSrid + ')')) { psQuery.setString(1, boxGeom.toString()); try (ResultSet rs = psQuery.executeQuery()) { if (rs.next()) { PGgeometry pgGeom = (PGgeometry) rs.getObject(1); if (!rs.wasNull() && pgGeom != null) { Geometry geom = pgGeom.getGeometry(); result.getLowerCorner().setX(geom.getPoint(0).x); result.getLowerCorner().setY(geom.getPoint(0).y); result.getUpperCorner().setX(geom.getPoint(2).x); result.getUpperCorner().setY(geom.getPoint(2).y); result.setSrs(targetSrs); } } } return result; } }
Example #10
Source File: PostgisGeometryParser.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
@Override public Geometry fromSqlObject( Object geomObject ) throws Exception { if (geomObject instanceof Geometry) { return (Geometry) geomObject; } else if (geomObject instanceof PGgeometry) { return getGeom((PGgeometry) geomObject); } throw new IllegalArgumentException("Geom object needs to be a JTS/PGGeometry geometry."); }
Example #11
Source File: PostgisGeometryParser.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private synchronized Geometry getGeom( PGgeometry pgGeometry ) throws SQLException, ParseException { String wkt = pgGeometry.toString(); String[] splitSRID = PGgeometry.splitSRID(wkt); Geometry geometry = wktReader.read(splitSRID[1]); try { int srid = Integer.parseInt(splitSRID[0].substring(5)); geometry.setSRID(srid); } catch (Exception e) { e.printStackTrace(); } return geometry; }
Example #12
Source File: PostgisGeometryParser.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
@Override public Geometry fromResultSet( IHMResultSet rs, int index ) throws Exception { Object object = rs.getObject(index); if (object instanceof PGgeometry) { PGgeometry pgGeometry = (PGgeometry) object; Geometry geometry = getGeom(pgGeometry); return geometry; } return null; }
Example #13
Source File: AbstractGeometryTypeHandlerTest.java From mybatis-typehandlers-postgis with Do What The F*ck You Want To Public License | 5 votes |
@Override @Test public void shouldSetParameter() throws Exception { getTypeHandler().setParameter(ps, 1, t, null); ArgumentCaptor<PGgeometry> argument = ArgumentCaptor.forClass(PGgeometry.class); verify(ps).setObject(eq(1), argument.capture()); assertEquals(t, argument.getValue().getGeometry()); }
Example #14
Source File: AbstractGeometryTypeHandler.java From mybatis-typehandlers-postgis with Do What The F*ck You Want To Public License | 5 votes |
public T getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { PGgeometry pGgeometry = (PGgeometry) cs.getObject(columnIndex); if (pGgeometry == null) { return null; } return (T) pGgeometry.getGeometry(); }
Example #15
Source File: AbstractGeometryTypeHandler.java From mybatis-typehandlers-postgis with Do What The F*ck You Want To Public License | 5 votes |
public T getNullableResult(ResultSet rs, int columnIndex) throws SQLException { PGgeometry pGgeometry = (PGgeometry) rs.getObject(columnIndex); if (pGgeometry == null) { return null; } return (T) pGgeometry.getGeometry(); }
Example #16
Source File: UtilAdapter.java From importer-exporter with Apache License 2.0 | 4 votes |
@Override protected BoundingBox createBoundingBoxes(List<Integer> objectClassIds, boolean onlyIfNull, Connection connection) throws SQLException { BoundingBox bbox = null; try { for (Integer classId : objectClassIds) { String call = "{? = call " + databaseAdapter.getSQLAdapter().resolveDatabaseOperationName("citydb_envelope.get_envelope_cityobjects") + "(?,1,?)}"; interruptableCallableStatement = connection.prepareCall(call); interruptableCallableStatement.registerOutParameter(1, databaseAdapter.getGeometryConverter().getNullGeometryType()); interruptableCallableStatement.setInt(2, classId); interruptableCallableStatement.setInt(3, onlyIfNull ? 1 : 0); interruptableCallableStatement.executeUpdate(); Position lowerCorner = new Position(Double.MAX_VALUE, Double.MAX_VALUE); Position upperCorner = new Position(-Double.MAX_VALUE, -Double.MAX_VALUE); Object geomObject = interruptableCallableStatement.getObject(1); if (geomObject instanceof PGgeometry) { Geometry geom = ((PGgeometry) geomObject).getGeometry(); double xmin, ymin, xmax, ymax; xmin = geom.getPoint(0).x; ymin = geom.getPoint(0).y; xmax = geom.getPoint(2).x; ymax = geom.getPoint(2).y; lowerCorner.setX(xmin); lowerCorner.setY(ymin); upperCorner.setX(xmax); upperCorner.setY(ymax); } if (!isInterrupted) { if (bbox == null) bbox = new BoundingBox(lowerCorner, upperCorner); else bbox.update(lowerCorner, upperCorner); } } } catch (SQLException e) { if (!isInterrupted) throw e; } finally { if (interruptableCallableStatement != null) { interruptableCallableStatement.close(); interruptableCallableStatement = null; } isInterrupted = false; } return bbox; }
Example #17
Source File: PostgisGeometryParser.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
@Override public Object toSqlObject( Geometry geometry ) throws Exception { org.postgis.Geometry pgGeometry = PGgeometry.geomFromString(geometry.toText()); pgGeometry.srid = geometry.getSRID(); return pgGeometry; }
Example #18
Source File: AbstractGeometryTypeHandler.java From mybatis-typehandlers-postgis with Do What The F*ck You Want To Public License | 4 votes |
public void setNonNullParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException { PGgeometry geometry = new PGgeometry(); geometry.setGeometry(parameter); ps.setObject(i, geometry); }