Search in sources :

Example 31 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project hale by halestudio.

the class InteriorPointTest method testHalfmoon.

/**
 * Test with a polygon describing a rough half moon.
 *
 * @throws Exception if an error occurs
 */
@Test
public void testHalfmoon() throws Exception {
    LinearRing outer = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87359, 8.65558), new Coordinate(49.87307, 8.65649), new Coordinate(49.87239, 8.65812), new Coordinate(49.8724, 8.65586), new Coordinate(49.87294, 8.65431), new Coordinate(49.87402, 8.65378), new Coordinate(49.87541, 8.65358), new Coordinate(49.87671, 8.65437), new Coordinate(49.87751, 8.65659), new Coordinate(49.87683, 8.65548), new Coordinate(49.87583, 8.65489), new Coordinate(49.87448, 8.65505), new Coordinate(49.87359, 8.65558) });
    Polygon geom = factory.createPolygon(outer);
    testPointWithin(geom);
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Test(org.junit.Test)

Example 32 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project hale by halestudio.

the class InteriorPointTest method testMulti1.

/**
 * Test with a multi-polygon.
 *
 * @throws Exception if an error occurs
 */
@Test
public void testMulti1() throws Exception {
    LinearRing outer1 = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87585, 8.64984), new Coordinate(49.87597, 8.65059), new Coordinate(49.87557, 8.65071), new Coordinate(49.87545, 8.64993), new Coordinate(49.87585, 8.64984) });
    Polygon poly1 = factory.createPolygon(outer1);
    LinearRing outer2 = factory.createLinearRing(new Coordinate[] { new Coordinate(49.87599, 8.6507), new Coordinate(49.8761, 8.65147), new Coordinate(49.87568, 8.6516), new Coordinate(49.87558, 8.65081), new Coordinate(49.87599, 8.6507) });
    Polygon poly2 = factory.createPolygon(outer2);
    testPointWithin(factory.createMultiPolygon(new Polygon[] { poly1, poly2 }));
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Test(org.junit.Test)

Example 33 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project hale by halestudio.

the class InteriorPointTest method testProblemCase.

/**
 * Test with a problem case from real data.
 *
 * @throws Exception if an error occurs
 */
@Test
public void testProblemCase() throws Exception {
    LinearRing outer1 = factory.createLinearRing(new Coordinate[] { new Coordinate(466713.482, 5974979.283), new Coordinate(466737.125, 5974995.621), new Coordinate(466737.125, 5974995.621), new Coordinate(467230.558, 5975071.481), new Coordinate(467230.558, 5975071.481), new Coordinate(467309.28, 5975083.867), new Coordinate(467309.28, 5975083.867), new Coordinate(466776.829, 5975009.807), new Coordinate(466776.829, 5975009.807), new Coordinate(466742.764, 5974999.507), new Coordinate(466713.482, 5974979.283) });
    Polygon poly1 = factory.createPolygon(outer1);
    testPointWithin(factory.createMultiPolygon(new Polygon[] { poly1 }));
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Test(org.junit.Test)

Example 34 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project janusgraph by JanusGraph.

the class GeoshapeTest method testGeoJsonMultiPolygon.

@Test
public void testGeoJsonMultiPolygon() throws IOException {
    GeoshapeSerializer s = new GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" + "  \"type\": \"Feature\",\n" + "  \"geometry\": {\n" + "    \"type\": \"MultiPolygon\",\n" + "    \"coordinates\": [[[[102.0,2.0],[103.0,2.0],[103.0,3.0],[102.0,3.0],[102.0,2.0]]]," + "[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]],[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]]\n" + "  }" + "}", HashMap.class);
    assertEquals(HELPER.geoshape(GF.createMultiPolygon(new Polygon[] { GF.createPolygon(new Coordinate[] { new Coordinate(102, 2), new Coordinate(103, 2), new Coordinate(103, 3), new Coordinate(102, 3), new Coordinate(102, 2) }), GF.createPolygon(GF.createLinearRing(new Coordinate[] { new Coordinate(100, 0), new Coordinate(101, 0), new Coordinate(101, 1), new Coordinate(100, 1), new Coordinate(100, 0) }), new LinearRing[] { GF.createLinearRing(new Coordinate[] { new Coordinate(100.2, 0.2), new Coordinate(100.8, 0.2), new Coordinate(100.8, 0.8), new Coordinate(100.2, 0.8), new Coordinate(100.2, 0.2) }) }) })), s.convert(json));
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 35 with LinearRing

use of org.locationtech.jts.geom.LinearRing in project janusgraph by JanusGraph.

the class GeoshapeTest method testGeoJsonSerialization.

@Test
public void testGeoJsonSerialization() throws IOException {
    SimpleModule module = new SimpleModule();
    module.addSerializer(new Geoshape.GeoshapeGsonSerializerV2d0());
    final ObjectMapper om = new ObjectMapper();
    om.registerModule(module);
    JtsSpatialContext context = (JtsSpatialContext) Geoshape.getSpatialContext();
    assertEquals("{\"type\":\"Point\",\"coordinates\":[20.5,10.5]}", om.writeValueAsString(Geoshape.point(10.5, 20.5)));
    assertEquals("{\"type\":\"Polygon\",\"coordinates\":[[[20.5,10.5],[20.5,12.5],[22.5,12.5],[22.5,10.5],[20.5,10.5]]]}", om.writeValueAsString(Geoshape.box(10.5, 20.5, 12.5, 22.5)));
    assertEquals("{\"type\":\"Circle\",\"coordinates\":[20.5,10.5],\"radius\":30.5,\"properties\":{\"radius_units\":\"km\"}}", om.writeValueAsString(Geoshape.circle(10.5, 20.5, 30.5)));
    assertEquals("{\"type\":\"LineString\",\"coordinates\":[[20.5,10.5],[22.5,10.5],[22.5,12.5]]}", om.writeValueAsString(Geoshape.line(Arrays.asList(new double[][] { { 20.5, 10.5 }, { 22.5, 10.5 }, { 22.5, 12.5 } }))));
    assertEquals("{\"type\":\"Polygon\",\"coordinates\":[[[20.5,10.5],[21.75,8],[22.5,10.5],[25,11.75],[22.5,12.5],[21,15],[20.5,12.5],[18,11.75],[20.5,10.5]]]}", om.writeValueAsString(Geoshape.polygon(Arrays.asList(new double[][] { { 20.5, 10.5 }, { 21.75, 8 }, { 22.5, 10.5 }, { 25, 11.75 }, { 22.5, 12.5 }, { 21, 15 }, { 20.5, 12.5 }, { 18, 11.75 }, { 20.5, 10.5 } }))));
    assertEquals("{\"type\":\"MultiPoint\",\"coordinates\":[[100,0],[101,1]]}", om.writeValueAsString(Geoshape.geoshape(context.getShapeFactory().makeShapeFromGeometry(GF.createMultiPoint(new Coordinate[] { new Coordinate(100, 0), new Coordinate(101, 1) })))));
    assertEquals("{\"type\":\"MultiLineString\",\"coordinates\":[[[100,0],[101,1]],[[102,2],[103,3]]]}", om.writeValueAsString(Geoshape.geoshape(context.getShapeFactory().makeShapeFromGeometry(GF.createMultiLineString(new LineString[] { GF.createLineString(new Coordinate[] { new Coordinate(100, 0), new Coordinate(101, 1) }), GF.createLineString(new Coordinate[] { new Coordinate(102, 2), new Coordinate(103, 3) }) })))));
    assertEquals("{\"type\":\"MultiPolygon\",\"coordinates\":[[[[102,2],[103,2],[103,3],[102,3],[102,2]]],[[[100,0],[101,0],[101,1],[100,1],[100,0]],[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]]}", om.writeValueAsString(Geoshape.geoshape(context.getShapeFactory().makeShapeFromGeometry(GF.createMultiPolygon(new Polygon[] { GF.createPolygon(new Coordinate[] { new Coordinate(102, 2), new Coordinate(103, 2), new Coordinate(103, 3), new Coordinate(102, 3), new Coordinate(102, 2) }), GF.createPolygon(GF.createLinearRing(new Coordinate[] { new Coordinate(100, 0), new Coordinate(101, 0), new Coordinate(101, 1), new Coordinate(100, 1), new Coordinate(100, 0) }), new LinearRing[] { GF.createLinearRing(new Coordinate[] { new Coordinate(100.2, 0.2), new Coordinate(100.8, 0.2), new Coordinate(100.8, 0.8), new Coordinate(100.2, 0.8), new Coordinate(100.2, 0.2) }) }) })))));
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing) SimpleModule(org.apache.tinkerpop.shaded.jackson.databind.module.SimpleModule) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) JtsSpatialContext(org.locationtech.spatial4j.context.jts.JtsSpatialContext) Test(org.junit.jupiter.api.Test)

Aggregations

LinearRing (org.locationtech.jts.geom.LinearRing)66 Coordinate (org.locationtech.jts.geom.Coordinate)39 Polygon (org.locationtech.jts.geom.Polygon)33 Test (org.junit.Test)27 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)23 LineString (org.locationtech.jts.geom.LineString)14 CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)10 Geometry (org.locationtech.jts.geom.Geometry)10 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)8 Point (org.locationtech.jts.geom.Point)8 MultiPoint (org.locationtech.jts.geom.MultiPoint)7 ArrayList (java.util.ArrayList)6 DimensionInfo (org.apache.jena.geosparql.implementation.DimensionInfo)6 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)6 Test (org.junit.jupiter.api.Test)4 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)3 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)3 CRSDefinition (eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition)3 GeometryProperty (eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty)3 GeometryNotSupportedException (eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException)3