use of com.vividsolutions.jts.geom.Point in project hale by halestudio.
the class PostGISGeometries method configureGeometryColumnType.
@Override
public Class<? extends Geometry> configureGeometryColumnType(PGConnection connection, BaseColumn<?> column, DefaultTypeDefinition type) {
Connection con = (Connection) connection;
String columnValueName = column.getParent().getName();
String geometryType = null;
try {
Statement stmt = con.createStatement();
// Get the srid, dimension and geometry type
ResultSet rs = stmt.executeQuery("SELECT srid,type,coord_dimension FROM geometry_columns WHERE f_table_name = " + "'" + columnValueName + "'");
if (rs.next()) {
geometryType = rs.getString("type");
String dimension = rs.getString("coord_dimension");
// Get the epsg code for the srid
String srid = rs.getString("srid");
ResultSet r = stmt.executeQuery("SELECT auth_srid, auth_name, srtext FROM spatial_ref_sys WHERE srid = " + srid);
if (r.next()) {
// Create Constraint to save the informations
GeometryMetadata columnTypeConstraint = new GeometryMetadata(r.getString("auth_srid"), Integer.parseInt(dimension), r.getString("srtext"), r.getString("auth_name"));
type.setConstraint(columnTypeConstraint);
}
} else {
// XXX what if no SRID information is present? is that a case
// that may still be valid?
}
} catch (SQLException e) {
e.printStackTrace();
}
// In this case we have no geometry column information
if (geometryType == null) {
// use geometry even if no geometry column is present describing it
return Geometry.class;
}
// return the geometryType
if (geometryType.equalsIgnoreCase("MultiPolygon")) {
return MultiPolygon.class;
} else if (geometryType.equalsIgnoreCase("MultiPoint")) {
return MultiPoint.class;
} else if (geometryType.equalsIgnoreCase("MultiLineString")) {
return MultiLineString.class;
} else // TODO: shouldn't this be LineString instead?
if (geometryType.equalsIgnoreCase("LinearRing")) {
return LinearRing.class;
} else if (geometryType.equalsIgnoreCase("Point")) {
return Point.class;
} else if (geometryType.equalsIgnoreCase("Polygon")) {
return Polygon.class;
} else {
return Geometry.class;
}
}
use of com.vividsolutions.jts.geom.Point in project StreetComplete by westnordost.
the class GeoJsonReaderTest method testMultiPoint.
public void testMultiPoint() {
Geometry g = read("{\n" + " \"type\": \"MultiPoint\",\n" + " \"coordinates\": [[1,2],[2,4]]\n" + "}");
assertTrue(g instanceof MultiPoint);
MultiPoint m = (MultiPoint) g;
assertEquals(2, m.getNumGeometries());
Point p0 = (Point) m.getGeometryN(0);
Point p1 = (Point) m.getGeometryN(1);
assertEquals(1.0, p0.getX());
assertEquals(2.0, p0.getY());
assertEquals(2.0, p1.getX());
assertEquals(4.0, p1.getY());
}
use of com.vividsolutions.jts.geom.Point in project StreetComplete by westnordost.
the class GeoJsonReaderTest method testGeometryCollection.
public void testGeometryCollection() {
Geometry g = read("{\n" + " \"type\": \"GeometryCollection\",\n" + " \"geometries\":\n" + " [\n" + " {\n" + " \"type\": \"Point\",\n" + " \"coordinates\": [5,10]\n" + " },\n" + " {\n" + " \"type\": \"LineString\",\n" + " \"coordinates\": [[5,10],[10,5]]\n" + " }\n" + " ]\n" + "}");
assertTrue(g instanceof GeometryCollection);
assertEquals(2, g.getNumGeometries());
assertTrue(g.getGeometryN(0) instanceof Point);
assertTrue(g.getGeometryN(1) instanceof LineString);
assertEquals(3, g.getNumPoints());
}
use of com.vividsolutions.jts.geom.Point in project StreetComplete by westnordost.
the class GeoJsonReaderTest method test3DPoint.
public void test3DPoint() {
Geometry g = read("{\n" + " \"type\": \"Point\",\n" + " \"coordinates\": [1,2,3]\n" + "}");
assertTrue(g instanceof Point);
Point p = (Point) g;
assertEquals(1.0, p.getX());
assertEquals(2.0, p.getY());
assertEquals(3.0, p.getCoordinate().z);
}
use of com.vividsolutions.jts.geom.Point in project tutorials by eugenp.
the class HibernateSpatialTest method shouldSelectDisjointPoints.
@Test
public void shouldSelectDisjointPoints() throws ParseException {
insertPoint("POINT (1 2)");
insertPoint("POINT (3 4)");
insertPoint("POINT (5 6)");
Point point = (Point) wktToGeometry("POINT (3 4)");
Query query = session.createQuery("select p from PointEntity p " + "where disjoint(p.point, :point) = true", PointEntity.class);
query.setParameter("point", point);
assertEquals("POINT (1 2)", ((PointEntity) query.getResultList().get(0)).getPoint().toString());
assertEquals("POINT (5 6)", ((PointEntity) query.getResultList().get(1)).getPoint().toString());
}
Aggregations