org.postgis.Polygon Java Examples

The following examples show how to use org.postgis.Polygon. 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: TestGisBulkWithin.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void testBulkWithinPolygon() throws SQLException {
    LinearRing linearRing1 = new LinearRing("0 0, 1 1, 1 2, 1 1, 0 0");
    Polygon polygon1 = new Polygon(new LinearRing[]{linearRing1});
    LinearRing linearRing2 = new LinearRing("1 1, 1 1, 1 2, 1 1, 1 1");
    Polygon polygon2 = new Polygon(new LinearRing[]{linearRing2});
    LinearRing linearRing3 = new LinearRing("2 2, 1 1, 1 2, 1 1, 2 2");
    Polygon polygon3 = new Polygon(new LinearRing[]{linearRing3});
    LinearRing linearRing4 = new LinearRing("1 3, 1 2, 2 2, 1 1, 1 3");
    Polygon polygon4 = new Polygon(new LinearRing[]{linearRing4});

    Vertex v1 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon1);
    Vertex v2 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon2);
    Vertex v3 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon3);
    Vertex v4 = this.sqlgGraph.addVertex(T.label, "Gis", "polygon", polygon4);
    this.sqlgGraph.tx().commit();
    List<Vertex> vertices = this.sqlgGraph.traversal().V().hasLabel("Gis").has("polygon", P.within(polygon1, polygon3, polygon4)).toList();
    Assert.assertEquals(3, vertices.size());
    Assert.assertTrue(Arrays.asList(v1, v3, v4).containsAll(vertices));
}
 
Example #2
Source File: GeometryConverterAdapter.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
@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 vote down vote up
@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 #4
Source File: PolygonTypeHandlerTest.java    From mybatis-typehandlers-postgis with Do What The F*ck You Want To Public License 5 votes vote down vote up
@Before
public void before() {
    table = "test_polygon";

    Point[] points = new Point[5];
    points[0] = new Point(123.45d, 23.45d);
    points[1] = new Point(124.45d, 23.45d);
    points[2] = new Point(124.45d, 24.45d);
    points[3] = new Point(123.45d, 24.45d);
    points[4] = new Point(123.45d, 23.45d);
    LinearRing linearRing = new LinearRing(points);
    t = new Polygon(new LinearRing[]{linearRing});
    t.setSrid(SRID);
}
 
Example #5
Source File: GeographyPolygon.java    From sqlg with MIT License 5 votes vote down vote up
public GeographyPolygon(Polygon polygon) {
    this.srid = polygon.srid;
    this.haveMeasure = polygon.haveMeasure;
    this.dimension = polygon.dimension;
    this.subgeoms = new Geometry[polygon.numGeoms()];
    for (int i = 0 ; i < polygon.numGeoms(); i++) {
        subgeoms[i] = polygon.getSubGeometry(i);
    }
}
 
Example #6
Source File: GeometryConverterAdapter.java    From importer-exporter with Apache License 2.0 5 votes vote down vote up
@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: PolygonTypeHandlerTest.java    From mybatis-typehandlers-postgis with Do What The F*ck You Want To Public License 4 votes vote down vote up
@Override
protected TypeHandler<Polygon> getTypeHandler() {
    return TYPE_HANDLER;
}
 
Example #8
Source File: GeometryConverterAdapter.java    From importer-exporter with Apache License 2.0 4 votes vote down vote up
private GeometryObject getPolygon(Polygon polygon) {
	return GeometryObject.createPolygon(getPolygonCoordinates(polygon), polygon.getDimension(), polygon.getSrid());
}