本文整理了Java中org.locationtech.jts.geom.GeometryFactory.createLineString()
方法的一些代码示例,展示了GeometryFactory.createLineString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GeometryFactory.createLineString()
方法的具体详情如下:
包路径:org.locationtech.jts.geom.GeometryFactory
类名称:GeometryFactory
方法名:createLineString
[英]Creates a LineString using the given CoordinateSequence. A null or empty CoordinateSequence creates an empty LineString.
[中]使用给定的坐标序列创建一个线条字符串。空或空的CoordinateSequence创建空的LineString。
代码示例来源:origin: graphhopper/graphhopper
private Geometry lineStringFromEdges(List<Label.Transition> transitions) {
List<Coordinate> coordinates = new ArrayList<>();
final Iterator<Label.Transition> iterator = transitions.iterator();
iterator.next();
coordinates.addAll(toCoordinateArray(iterator.next().edge.edgeIteratorState.fetchWayGeometry(3)));
iterator.forEachRemaining(transition -> coordinates.addAll(toCoordinateArray(transition.edge.edgeIteratorState.fetchWayGeometry(2))));
return geometryFactory.createLineString(coordinates.toArray(new Coordinate[coordinates.size()]));
}
代码示例来源:origin: graphhopper/graphhopper
public Shape (GTFSFeed feed, String shape_id) {
Map<Fun.Tuple2<String, Integer>, ShapePoint> points =
feed.shape_points.subMap(new Fun.Tuple2(shape_id, null), new Fun.Tuple2(shape_id, Fun.HI));
Coordinate[] coords = points.values().stream()
.map(point -> new Coordinate(point.shape_pt_lon, point.shape_pt_lat))
.toArray(i -> new Coordinate[i]);
geometry = geometryFactory.createLineString(coords);
shape_dist_traveled = points.values().stream().mapToDouble(point -> point.shape_dist_traveled).toArray();
}
}
代码示例来源:origin: graphhopper/graphhopper
public LineString getStraightLineForStops(String trip_id) {
CoordinateList coordinates = new CoordinateList();
LineString ls = null;
Trip trip = trips.get(trip_id);
Iterable<StopTime> stopTimes;
stopTimes = getOrderedStopTimesForTrip(trip.trip_id);
if (Iterables.size(stopTimes) > 1) {
for (StopTime stopTime : stopTimes) {
Stop stop = stops.get(stopTime.stop_id);
Double lat = stop.stop_lat;
Double lon = stop.stop_lon;
coordinates.add(new Coordinate(lon, lat));
}
ls = gf.createLineString(coordinates.toCoordinateArray());
}
// set ls equal to null if there is only one stopTime to avoid an exception when creating linestring
else{
ls = null;
}
return ls;
}
代码示例来源:origin: prestodb/presto
return GEOMETRY_FACTORY.createMultiLineString();
return GEOMETRY_FACTORY.createLineString();
lineStrings[i] = GEOMETRY_FACTORY.createLineString(readCoordinates(input, partLengths[i]));
代码示例来源:origin: graphhopper/graphhopper
public LineString toLineString(boolean includeElevation) {
GeometryFactory gf = new GeometryFactory();
Coordinate[] coordinates = new Coordinate[getSize() == 1 ? 2 : getSize()];
for (int i = 0; i < getSize(); i++) {
coordinates[i] = includeElevation ?
new Coordinate(
round6(getLongitude(i)),
round6(getLatitude(i)),
round2(getElevation(i))) :
new Coordinate(
round6(getLongitude(i)),
round6(getLatitude(i)));
}
// special case as just 1 point is not supported in the specification #1412
if (getSize() == 1)
coordinates[1] = coordinates[0];
return gf.createLineString(coordinates);
}
代码示例来源:origin: geotools/geotools
/**
*
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated modifiable
*/
public Object parse(ElementInstance instance, Node node, Object value) throws Exception {
CoordinateSequence coordinates =
(CoordinateSequence) node.getChildValue(KML.coordinates.getLocalPart());
return geometryFactory.createLineString(coordinates);
}
代码示例来源:origin: org.elasticsearch/elasticsearch
static ArrayList<LineString> decomposeS4J(GeometryFactory factory, Coordinate[] coordinates, ArrayList<LineString> strings) {
for(Coordinate[] part : decompose(+DATELINE, coordinates)) {
for(Coordinate[] line : decompose(-DATELINE, part)) {
strings.add(factory.createLineString(line));
}
}
return strings;
}
代码示例来源:origin: geotools/geotools
private LineString parseLineString(int dimension, CoordinateReferenceSystem crs)
throws XmlPullParserException, IOException, NoSuchAuthorityCodeException,
FactoryException {
parser.require(START_TAG, GML.NAMESPACE, GML.LineString.getLocalPart());
crs = crs(crs);
Coordinate[] coordinates = parseLineStringInternal(dimension, crs);
parser.require(END_TAG, GML.NAMESPACE, GML.LineString.getLocalPart());
LineString geom = geomFac.createLineString(coordinates);
geom.setUserData(crs);
return geom;
}
代码示例来源:origin: geotools/geotools
/**
* Creates a LineString using a LiteCoordinateSequence with 2 3D coordinates.
*
* @return a 3D LineString
*/
public static LineString lineStringLite3D() {
return liteGF.createLineString(liteCSF.create(new double[] {1, 2, 100, 3, 4, 200}, 3));
}
代码示例来源:origin: geotools/geotools
public static Geometry reverseGeometry(Geometry geom, boolean modify) {
if (geom instanceof Point) return (geom);
if (geom instanceof LineString) {
Coordinate[] reversed = reverseCoordinates(geom.getCoordinates(), modify);
if (modify) return (geom);
else return (gf().createLineString(reversed));
}
return (null);
}
代码示例来源:origin: geotools/geotools
@Override
public Geometry build(final int pointNode) throws CQLException {
// Retrieve the linestirng points
Stack<Coordinate> pointStack = popCoordinatesOf(pointNode);
// now pointStack has the coordinate in the correct order
// the next code creates the coordinate array used to create
// the lineString
Coordinate[] coordinates = asCoordinate(pointStack);
LineString line = getGeometryFactory().createLineString(coordinates);
return line;
}
}
代码示例来源:origin: geotools/geotools
/**
* Creates a line from the specified (<var>x</var>,<var>y</var>) coordinates. The coordinates
* are stored in a flat array.
*/
public LineString line(int[] xy) {
Coordinate[] coords = new Coordinate[xy.length / 2];
for (int i = 0; i < xy.length; i += 2) {
coords[i / 2] = new Coordinate(xy[i], xy[i + 1]);
}
return gf.createLineString(coords);
}
代码示例来源:origin: geotools/geotools
@Test
public void testCoordinateDimensionLineString1D() {
Geometry geom =
gf.createLineString(
new Coordinate[] {
new Coordinate(1, Coordinate.NULL_ORDINATE),
new Coordinate(3, Coordinate.NULL_ORDINATE)
});
assertEquals(1, CoordinateSequences.coordinateDimension(geom));
}
代码示例来源:origin: geotools/geotools
public void testIntersectsFilterFunctionUnreferencedGeometry() throws Exception {
GeometryFactory gf = new GeometryFactory();
LineString ls =
gf.createLineString(
new Coordinate[] {new Coordinate(10, 15), new Coordinate(20, 25)});
Function intersects = ff.function("intersects", ff.property("geom"), ff.literal(ls));
Function clone = (Function) intersects.accept(reprojector, null);
assertNotSame(intersects, clone);
assertEquals(clone.getParameters().get(0), intersects.getParameters().get(0));
assertEquals(clone.getParameters().get(1), intersects.getParameters().get(1));
}
代码示例来源:origin: geotools/geotools
@Test
public void testDecimate3DLine() throws Exception {
LineString ls =
gf.createLineString(
csf.create(new double[] {0, 0, 1, 1, 2, 1, 3, 3, 4, 4, 5, 5}, 3));
assertEquals(4, ls.getNumPoints());
Decimator d = new Decimator(identity, new Rectangle(0, 0, 5, 5), 0.8);
d.decimateTransformGeneralize(ls, identity);
assertEquals(4, ls.getNumPoints());
assertEquals(2, ls.getCoordinateSequence().getDimension());
}
代码示例来源:origin: geotools/geotools
public void testEncode3DLineFromLiteCS() throws Exception {
LineStringEncoder encoder = new LineStringEncoder(gtEncoder, "gml", GML.NAMESPACE);
LiteCoordinateSequence cs =
new LiteCoordinateSequence(new double[] {0, 0, 50, 120, 0, 100}, 3);
LineString geometry = new GeometryFactory().createLineString(cs);
Document doc = encode(encoder, geometry);
// print(doc);
assertEquals("0 0 50 120 0 100", xpath.evaluate("//gml:posList", doc));
}
}
代码示例来源:origin: geotools/geotools
public void testEncodeLineMFromLiteCSNoMeasuresEncoded() throws Exception {
// create a linestring with M values and encode it in GML
LiteCoordinateSequence cs =
new LiteCoordinateSequence(new double[] {0, 1, -1.5, 3, 4, -2.5}, 3, 1);
LineString geometry = new GeometryFactory().createLineString(cs);
LineStringEncoder encoder = new LineStringEncoder(gtEncoder, "gml", GML.NAMESPACE);
Document document = encode(encoder, geometry, false, "line");
// check that we got the expected result
XpathEngine xpath = XMLUnit.newXpathEngine();
assertEquals("0 1 3 4", xpath.evaluate("//gml:posList", document));
}
代码示例来源:origin: geotools/geotools
public void testEncodeLineZMFromLiteCSNoMeasuresEncoded() throws Exception {
// create a linestring with ZM values and encode it in GML 3.1
LiteCoordinateSequence cs =
new LiteCoordinateSequence(new double[] {0, 1, 10, -1.5, 3, 4, 15, -2.5}, 4, 1);
LineString geometry = new GeometryFactory().createLineString(cs);
LineStringEncoder encoder = new LineStringEncoder(gtEncoder, "gml", GML.NAMESPACE);
Document document = encode(encoder, geometry, false, "line");
// check that we got the expected result
XpathEngine xpath = XMLUnit.newXpathEngine();
assertEquals("0 1 10 3 4 15", xpath.evaluate("//gml:posList", document));
}
代码示例来源:origin: geotools/geotools
@Test
public void testDisjoint() {
Coordinate[] coords = new Coordinate[] {new Coordinate(0, 0), new Coordinate(10, 10)};
LineString lineString = new GeometryFactory().createLineString(coords);
Filter filter = ff.disjoint(ff.property("name"), ff.literal(lineString));
Envelope env = (Envelope) filter.accept(visitor, null);
assertEquals(infinity, env);
}
代码示例来源:origin: geotools/geotools
public void testIntersectsUnreferencedGeometry() throws Exception {
GeometryFactory gf = new GeometryFactory();
LineString ls =
gf.createLineString(
new Coordinate[] {new Coordinate(10, 15), new Coordinate(20, 25)});
// see if coordinates gets flipped, urn forces lat/lon interpretation
Intersects original = ff.intersects(ff.property("geom"), ff.literal(ls));
Filter clone = (Filter) original.accept(reprojector, null);
assertNotSame(original, clone);
assertEquals(original, clone);
}
内容来源于网络,如有侵权,请联系作者删除!