use of org.locationtech.jts.geom.LineString in project yyl_example by Relucent.
the class JtsGeometryExample2 method equalsGeo.
/**
* 两个几何对象是否是重叠的
* @return 是否是重叠的
* @throws ParseException
*/
public static boolean equalsGeo() 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(5 0, 0 0)");
// true
return geometry1.equals(geometry2);
}
use of org.locationtech.jts.geom.LineString in project yyl_example by Relucent.
the class JtsGeometryExample1 method createMLine.
/**
* create multiLine
* @return 多线
*/
public static MultiLineString createMLine() {
Coordinate[] coords1 = new Coordinate[] { new Coordinate(2, 2), new Coordinate(2, 2) };
LineString line1 = GEOMETRY_FACTORY.createLineString(coords1);
Coordinate[] coords2 = new Coordinate[] { new Coordinate(2, 2), new Coordinate(2, 2) };
LineString line2 = GEOMETRY_FACTORY.createLineString(coords2);
LineString[] lineStrings = new LineString[2];
lineStrings[0] = line1;
lineStrings[1] = line2;
MultiLineString ms = GEOMETRY_FACTORY.createMultiLineString(lineStrings);
return ms;
}
use of org.locationtech.jts.geom.LineString in project jena by apache.
the class GeometryReverse method reverseGeometry.
/**
* Reverses coordinate order of the supplied geometry and produces a new
* geometry.
*
* @param geometry
* @return Geometry in x,y coordinate order.
*/
public static Geometry reverseGeometry(Geometry geometry) {
if (geometry.isEmpty()) {
return geometry.copy();
}
GeometryFactory factory = geometry.getFactory();
Geometry finalGeometry;
Coordinate[] coordinates;
String type = geometry.getGeometryType();
switch(type) {
case "LineString":
coordinates = getReversedCoordinates(geometry);
finalGeometry = factory.createLineString(coordinates);
break;
case "LinearRing":
coordinates = getReversedCoordinates(geometry);
finalGeometry = factory.createLinearRing(coordinates);
break;
case "MultiPoint":
coordinates = getReversedCoordinates(geometry);
finalGeometry = factory.createMultiPointFromCoords(coordinates);
break;
case "Polygon":
finalGeometry = reversePolygon(geometry, factory);
break;
case "Point":
coordinates = getReversedCoordinates(geometry);
finalGeometry = factory.createPoint(coordinates[0]);
break;
case "MultiPolygon":
Polygon[] polygons = unpackPolygons((GeometryCollection) geometry);
finalGeometry = factory.createMultiPolygon(polygons);
break;
case "MultiLineString":
LineString[] lineString = unpackLineStrings((GeometryCollection) geometry);
finalGeometry = factory.createMultiLineString(lineString);
break;
case "GeometryCollection":
Geometry[] geometries = unpackGeometryCollection((GeometryCollection) geometry);
finalGeometry = factory.createGeometryCollection(geometries);
break;
default:
finalGeometry = geometry;
break;
}
return finalGeometry;
}
use of org.locationtech.jts.geom.LineString in project jena by apache.
the class WKTReader method splitLineStrings.
private LineString[] splitLineStrings(String[] splitCoordinates) {
LineString[] lineStrings = new LineString[splitCoordinates.length];
for (int i = 0; i < splitCoordinates.length; i++) {
CustomCoordinateSequence sequence = new CustomCoordinateSequence(dims, clean(splitCoordinates[i]));
LineString lineString = GEOMETRY_FACTORY.createLineString(sequence);
lineStrings[i] = lineString;
}
return lineStrings;
}
use of org.locationtech.jts.geom.LineString in project jena by apache.
the class WKTWriter method expand.
private static String expand(final Geometry geometry, final CoordinateSequenceDimensions dimensions) {
String wktString = "";
String dimensionString = CoordinateSequenceDimensions.convertDimensions(dimensions);
switch(geometry.getGeometryType()) {
case "Point":
Point point = (Point) geometry;
wktString = buildWKT("POINT", point.getCoordinateSequence(), dimensionString);
break;
case "LineString":
case "LinearRing":
LineString lineString = (LineString) geometry;
wktString = buildWKT("LINESTRING", lineString.getCoordinateSequence(), dimensionString);
break;
case "Polygon":
Polygon polygon = (Polygon) geometry;
wktString = buildPolygon(polygon, true, dimensionString);
break;
case "MultiPoint":
MultiPoint multiPoint = (MultiPoint) geometry;
wktString = buildMultiPoint(multiPoint, dimensionString);
break;
case "MultiLineString":
MultiLineString multiLineString = (MultiLineString) geometry;
wktString = buildMultiLineString(multiLineString, dimensionString);
break;
case "MultiPolygon":
MultiPolygon multiPolygon = (MultiPolygon) geometry;
wktString = buildMultiPolygon(multiPolygon, dimensionString);
break;
case "GeometryCollection":
GeometryCollection geometryCollection = (GeometryCollection) geometry;
wktString = buildGeometryCollection(geometryCollection, dimensions);
break;
}
return wktString;
}
Aggregations