Search in sources :

Example 96 with LineString

use of org.locationtech.jts.geom.LineString in project jena by apache.

the class GeometryReverseTest method testCheckLineString.

/**
 * Test of check method, of class GeometryReverse.
 *
 * @throws org.opengis.util.FactoryException
 */
@Test
public void testCheckLineString() throws FactoryException {
    WKTReader reader = new WKTReader();
    try {
        LineString geometry = (LineString) reader.read("LINESTRING(0 0, 2 0, 5 0)");
        String srsURI = "http://www.opengis.net/def/crs/EPSG/0/4326";
        Geometry expResult = reader.read("LINESTRING(0 0, 0 2, 0 5)");
        Geometry result = GeometryReverse.check(geometry, srsURI);
        // 
        // 
        assertEquals(expResult, result);
    } catch (ParseException ex) {
        System.err.println("ParseException: " + ex.getMessage());
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) ParseException(org.locationtech.jts.io.ParseException) WKTReader(org.locationtech.jts.io.WKTReader) Test(org.junit.Test)

Example 97 with LineString

use of org.locationtech.jts.geom.LineString in project jena by apache.

the class GeometryReverse method unpackLineStrings.

private static LineString[] unpackLineStrings(GeometryCollection geoCollection) {
    GeometryFactory factory = geoCollection.getFactory();
    int count = geoCollection.getNumGeometries();
    LineString[] lineStrings = new LineString[count];
    for (int i = 0; i < count; i++) {
        Geometry geometry = geoCollection.getGeometryN(i);
        Coordinate[] coordinates = getReversedCoordinates(geometry);
        LineString lineString = factory.createLineString(coordinates);
        lineStrings[i] = lineString;
    }
    return lineStrings;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) LineString(org.locationtech.jts.geom.LineString) Coordinate(org.locationtech.jts.geom.Coordinate)

Example 98 with LineString

use of org.locationtech.jts.geom.LineString in project jena by apache.

the class GeometryReverse method reversePolygon.

private static Polygon reversePolygon(Geometry geometry, GeometryFactory factory) {
    Polygon finalGeometry;
    Polygon polygon = (Polygon) geometry;
    if (polygon.getNumInteriorRing() == 0) {
        // There are no interior rings so perform the standard reversal.
        Coordinate[] coordinates = getReversedCoordinates(geometry);
        finalGeometry = factory.createPolygon(coordinates);
    } else {
        LineString exteriorRing = polygon.getExteriorRing();
        Coordinate[] reversedExteriorCoordinates = getReversedCoordinates(exteriorRing);
        LinearRing reversedExteriorRing = factory.createLinearRing(reversedExteriorCoordinates);
        LinearRing[] reversedInteriorRings = new LinearRing[polygon.getNumInteriorRing()];
        for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
            LineString interiorRing = polygon.getInteriorRingN(i);
            Coordinate[] reversedInteriorCoordinates = getReversedCoordinates(interiorRing);
            LinearRing reversedInteriorRing = factory.createLinearRing(reversedInteriorCoordinates);
            reversedInteriorRings[i] = reversedInteriorRing;
        }
        finalGeometry = factory.createPolygon(reversedExteriorRing, reversedInteriorRings);
    }
    return finalGeometry;
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) Polygon(org.locationtech.jts.geom.Polygon) LinearRing(org.locationtech.jts.geom.LinearRing)

Example 99 with LineString

use of org.locationtech.jts.geom.LineString in project yyl_example by Relucent.

the class JtsGeometryExample2 method disjointGeo.

/**
 * 几何对象没有交点(相邻)
 * @return 是否不相交
 * @throws ParseException
 */
public static boolean disjointGeo() throws ParseException {
    WKTReader reader = new WKTReader(GEOMETRY_FACTORY);
    LineString geometry1 = (LineString) reader.read("LINESTRING(0 0, 2 0, 5 0)");
    LineString geometry2 = (LineString) reader.read("LINESTRING(0 1, 0 2)");
    return geometry1.disjoint(geometry2);
}
Also used : LineString(org.locationtech.jts.geom.LineString) WKTReader(org.locationtech.jts.io.WKTReader)

Example 100 with LineString

use of org.locationtech.jts.geom.LineString in project yyl_example by Relucent.

the class JtsGeometryExample1 method createGeoCollect.

/**
 * create GeometryCollection contain point or multiPoint or line or multiLine or polygon or multiPolygon
 * @return 图形集
 * @throws ParseException
 */
public static GeometryCollection createGeoCollect() throws ParseException {
    LineString line = createLine();
    Polygon poly = createPolygonByWKT();
    Geometry g1 = GEOMETRY_FACTORY.createGeometry(line);
    Geometry g2 = GEOMETRY_FACTORY.createGeometry(poly);
    Geometry[] garray = new Geometry[] { g1, g2 };
    GeometryCollection gc = GEOMETRY_FACTORY.createGeometryCollection(garray);
    return gc;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon)

Aggregations

LineString (org.locationtech.jts.geom.LineString)120 MultiLineString (org.locationtech.jts.geom.MultiLineString)48 Coordinate (org.locationtech.jts.geom.Coordinate)38 Geometry (org.locationtech.jts.geom.Geometry)35 Point (org.locationtech.jts.geom.Point)32 Test (org.junit.Test)24 Polygon (org.locationtech.jts.geom.Polygon)21 MultiPoint (org.locationtech.jts.geom.MultiPoint)19 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)14 WKTReader (org.locationtech.jts.io.WKTReader)13 ArrayList (java.util.ArrayList)12 CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)12 HashMap (java.util.HashMap)10 DimensionInfo (org.apache.jena.geosparql.implementation.DimensionInfo)9 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)9 ParseException (org.locationtech.jts.io.ParseException)9 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)8 GeometryNotSupportedException (eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException)7 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6