本文整理汇总了Java中com.vividsolutions.jts.geom.LineSegment类的典型用法代码示例。如果您正苦于以下问题:Java LineSegment类的具体用法?Java LineSegment怎么用?Java LineSegment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LineSegment类属于com.vividsolutions.jts.geom包,在下文中一共展示了LineSegment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ringFromSegments
import com.vividsolutions.jts.geom.LineSegment; //导入依赖的package包/类
private static LinearRing ringFromSegments(List<LineSegment> segments) {
GeometryFactory factory = new GeometryFactory();
int nSegs = segments.size();
if (nSegs < 3) {
return null;
}
int len = segments.size() + 1;
CoordinateSequence seq = factory.getCoordinateSequenceFactory().create(
len, 2);
int i = 0;
for (LineSegment line : segments) {
seq.setOrdinate(i, 0, line.p0.x);
seq.setOrdinate(i, 1, line.p0.y);
i++;
}
seq.setOrdinate(i, 0, segments.get(0).p0.x);
seq.setOrdinate(i, 1, segments.get(0).p0.y);
return factory.createLinearRing(seq);
}
示例2: computeMinDistance
import com.vividsolutions.jts.geom.LineSegment; //导入依赖的package包/类
private void computeMinDistance(LineString line, Point pt,
GeometryLocation[] locGeom) {
if (line.getEnvelopeInternal().distance(pt.getEnvelopeInternal())
> this.minDistance) {
return;
}
Coordinate[] coord0 = line.getCoordinates();
Coordinate coord = pt.getCoordinate();
// brute force approach!
for (int i = 0; i < coord0.length - 1; i++) {
double dist = CGAlgorithms.distancePointLine(
coord, coord0[i], coord0[i + 1]);
if (dist < this.minDistance) {
this.minDistance = dist;
LineSegment seg = new LineSegment(coord0[i], coord0[i + 1]);
Coordinate segClosestPoint = seg.closestPoint(coord);
locGeom[0] = new GeometryLocation(line, i, segClosestPoint);
locGeom[1] = new GeometryLocation(pt, 0, coord);
}
if (this.minDistance <= this.terminateDistance) {
return;
}
}
}
示例3: computeMinDistanceLinePoint
import com.vividsolutions.jts.geom.LineSegment; //导入依赖的package包/类
private void computeMinDistanceLinePoint(LineString line, Point point,
boolean flip) {
Coordinate[] lineCoord = line.getCoordinates();
Coordinate coord = point.getCoordinate();
// brute force approach!
for (int i = 0; i < lineCoord.length - 1; i++) {
double dist = CGAlgorithms3D.distancePointSegment(coord, lineCoord[i],
lineCoord[i + 1]);
if (dist < this.minDistance) {
LineSegment seg = new LineSegment(lineCoord[i], lineCoord[i + 1]);
Coordinate segClosestPoint = seg.closestPoint(coord);
this.updateDistance(dist,
new GeometryLocation(line, i, segClosestPoint),
new GeometryLocation(point, 0, coord),
flip);
}
if (this.isDone) {
return;
}
}
}
示例4: findFurthestPoint
import com.vividsolutions.jts.geom.LineSegment; //导入依赖的package包/类
private int findFurthestPoint(Coordinate[] pts, int i, int j, double[] maxDistance) {
LineSegment seg = new LineSegment();
seg.p0 = pts[i];
seg.p1 = pts[j];
double maxDist = -1.0;
int maxIndex = i;
for (int k = i + 1; k < j; k++) {
Coordinate midPt = pts[k];
double distance = seg.distance(midPt);
if (distance > maxDist) {
maxDist = distance;
maxIndex = k;
}
}
maxDistance[0] = maxDist;
return maxIndex;
}
示例5: densifyPoints
import com.vividsolutions.jts.geom.LineSegment; //导入依赖的package包/类
/**
* Densifies a coordinate sequence.
*
* @param pts
* @param distanceTolerance
* @return the densified coordinate sequence
*/
private static Coordinate[] densifyPoints(Coordinate[] pts,
double distanceTolerance, PrecisionModel precModel) {
LineSegment seg = new LineSegment();
CoordinateList coordList = new CoordinateList();
for (int i = 0; i < pts.length - 1; i++) {
seg.p0 = pts[i];
seg.p1 = pts[i + 1];
coordList.add(seg.p0, false);
double len = seg.getLength();
int densifiedSegCount = (int) (len / distanceTolerance) + 1;
if (densifiedSegCount > 1) {
double densifiedSegLen = len / densifiedSegCount;
for (int j = 1; j < densifiedSegCount; j++) {
double segFract = (j * densifiedSegLen) / len;
Coordinate p = seg.pointAlong(segFract);
precModel.makePrecise(p);
coordList.add(p, false);
}
}
}
coordList.add(pts[pts.length - 1], false);
return coordList.toCoordinateArray();
}
示例6: findSplitPoint
import com.vividsolutions.jts.geom.LineSegment; //导入依赖的package包/类
/**
* A basic strategy for finding split points when nothing extra is known about the geometry of
* the situation.
*
* @param seg the encroached segment
* @param encroachPt the encroaching point
* @return the point at which to split the encroached segment
*/
@Override
public Coordinate findSplitPoint(Segment seg, Coordinate encroachPt) {
LineSegment lineSeg = seg.getLineSegment();
double segLen = lineSeg.getLength();
double midPtLen = segLen / 2;
SplitSegment splitSeg = new SplitSegment(lineSeg);
Coordinate projPt = projectedSplitPoint(seg, encroachPt);
/**
* Compute the largest diameter (length) that will produce a split segment which is not
* still encroached upon by the encroaching point (The length is reduced slightly by a
* safety factor)
*/
double nonEncroachDiam = projPt.distance(encroachPt) * 2 * 0.8; // .99;
double maxSplitLen = nonEncroachDiam;
if (maxSplitLen > midPtLen) {
maxSplitLen = midPtLen;
}
splitSeg.setMinimumLength(maxSplitLen);
splitSeg.splitAt(projPt);
return splitSeg.getSplitPoint();
}
示例7: findMaxPerpDistance
import com.vividsolutions.jts.geom.LineSegment; //导入依赖的package包/类
private int findMaxPerpDistance(Coordinate[] pts, LineSegment seg, int startIndex) {
double maxPerpDistance = seg.distancePerpendicular(pts[startIndex]);
double nextPerpDistance = maxPerpDistance;
int maxIndex = startIndex;
int nextIndex = maxIndex;
while (nextPerpDistance >= maxPerpDistance) {
maxPerpDistance = nextPerpDistance;
maxIndex = nextIndex;
nextIndex = nextIndex(pts, maxIndex);
nextPerpDistance = seg.distancePerpendicular(pts[nextIndex]);
}
// found maximum width for this segment - update global min dist if appropriate
if (maxPerpDistance < this.minWidth) {
this.minPtIndex = maxIndex;
this.minWidth = maxPerpDistance;
this.minWidthPt = pts[this.minPtIndex];
this.minBaseSeg = new LineSegment(seg);
// System.out.println(minBaseSeg);
// System.out.println(minWidth);
}
return maxIndex;
}
示例8: computeSegmentForLine
import com.vividsolutions.jts.geom.LineSegment; //导入依赖的package包/类
private static LineSegment computeSegmentForLine(double a, double b, double c) {
Coordinate p0;
Coordinate p1;
/*
* Line eqn is ax + by = c
* Slope is a/b.
* If slope is steep, use y values as the inputs
*/
if (Math.abs(b) > Math.abs(a)) {
p0 = new Coordinate(0.0, c / b);
p1 = new Coordinate(1.0, c / b - a / b);
} else {
p0 = new Coordinate(c / a, 0.0);
p1 = new Coordinate(c / a - b / a, 1.0);
}
return new LineSegment(p0, p1);
}
示例9: indexOfFromStart
import com.vividsolutions.jts.geom.LineSegment; //导入依赖的package包/类
private double indexOfFromStart(Coordinate inputPt, double minIndex) {
double minDistance = Double.MAX_VALUE;
double ptMeasure = minIndex;
double segmentStartMeasure = 0.0;
LineSegment seg = new LineSegment();
LinearIterator it = new LinearIterator(this.linearGeom);
while (it.hasNext()) {
if (!it.isEndOfLine()) {
seg.p0 = it.getSegmentStart();
seg.p1 = it.getSegmentEnd();
double segDistance = seg.distance(inputPt);
double segMeasureToPt = this.segmentNearestMeasure(seg, inputPt, segmentStartMeasure);
if (segDistance < minDistance
&& segMeasureToPt > minIndex) {
ptMeasure = segMeasureToPt;
minDistance = segDistance;
}
segmentStartMeasure += seg.getLength();
}
it.next();
}
return ptMeasure;
}
示例10: isPointOnLineSegment
import com.vividsolutions.jts.geom.LineSegment; //导入依赖的package包/类
/**
* Checks if the point is located on the given {@link LineSegment} (including endpoints).
*/
public static boolean isPointOnLineSegment(Coordinate point, LineSegment line) {
double lengthOfLine = line.getLength();
double distFromEnd1 = point.distance(line.p0);
double distFromEnd2 = point.distance(line.p1);
// this seems to handle robustness errors (due to rounding) better
if (distFromEnd1 + distFromEnd2 == lengthOfLine) {
return true;
}
// Fallback to what should probably be the robust implementation (TODO: investigate precision issues)
LineIntersector lineIntersector = new RobustLineIntersector();
lineIntersector.computeIntersection(point, line.p0, line.p1);
return lineIntersector.hasIntersection();
}
示例11: EdgePair
import com.vividsolutions.jts.geom.LineSegment; //导入依赖的package包/类
public EdgePair(LineSegment edgeA, LineSegment edgeB) {
// determine the point where the edges would intersect if they were infinite lines
IntersectionCoordinate intersectionPoint = GeometryUtils.getIntersectionPoint(edgeA, edgeB);
this.edgeA = edgeA;
this.edgeB = edgeB;
// there will be 2 projected points at most
projected0 = getProjectedVertex(edgeA.p1, edgeB, intersectionPoint);
if (projected0.isNotValid()) {
projected0 = getProjectedVertex(edgeB.p0, edgeA, intersectionPoint);
}
projected1 = getProjectedVertex(edgeB.p1, edgeA, intersectionPoint);
if (projected1.isNotValid()) {
projected1 = getProjectedVertex(edgeA.p0, edgeB, intersectionPoint);
}
}
示例12: EdgePairSubpolygons
import com.vividsolutions.jts.geom.LineSegment; //导入依赖的package包/类
private EdgePairSubpolygons(LineSegment edgeA, LineSegment edgeB, ProjectedVertex projected0, ProjectedVertex projected1) {
this.edgeA = Objects.requireNonNull(edgeA, "Edge A is required");
this.edgeB = Objects.requireNonNull(edgeB, "Edge B is required");
// build triangles if corresponding projected points are valid
triangle1 = projected0.isValid() ? GeometryFactoryUtils.createTriangle(edgeA.p1, projected0, edgeB.p0) : null;
triangle2 = projected1.isValid() ? GeometryFactoryUtils.createTriangle(edgeA.p0, projected1, edgeB.p1) : null;
triangle1Area = triangle1 != null ? triangle1.getArea() : 0;
triangle2Area = triangle2 != null ? triangle2.getArea() : 0;
// build a trapezoid:
// 1) if projected1 is on edgeA, add projected1, else add edgeA.p0
// 2) if projected0 is on edgeA, add projected0, else add edgeA.p1
// 3) if projected0 is on edgeB, add projected0, else add edgeB.p0
// 4) if projected1 is on edgeB, add projected1, else add edgeB.p1
// 5) close the polygon
Coordinate coord1 = projected1.isOnEdge(edgeA) ? projected1 : edgeA.p0;
Coordinate coord2 = projected0.isOnEdge(edgeA) ? projected0 : edgeA.p1;
Coordinate coord3 = projected0.isOnEdge(edgeB) ? projected0 : edgeB.p0;
Coordinate coord4 = projected1.isOnEdge(edgeB) ? projected1 : edgeB.p1;
trapezoid = GeometryFactoryUtils.createPolygon(coord1, coord2, coord3, coord4);
trapezoidArea = trapezoid.getArea();
}
示例13: projectionForEdgesFormingATrapezoid
import com.vividsolutions.jts.geom.LineSegment; //导入依赖的package包/类
@Test
public void projectionForEdgesFormingATrapezoid() throws Exception {
LineSegment edgeA = new LineSegment(new Coordinate(0, 0), new Coordinate(10, 0)); // horizontal edge at y = 0, when x = [0; 10]
LineSegment edgeB = new LineSegment(new Coordinate(5, 1), new Coordinate(15, 1)); // horizontal edge at y = 1, when x = [5; 15]
Coordinate projectedPoint = GeometryUtils.getProjectedPoint(edgeB.p0, edgeA, null); // project point (5; 1) onto y = 0
assertEquals(5, projectedPoint.x, EXACT_PRECISION);
assertEquals(0, projectedPoint.y, EXACT_PRECISION);
projectedPoint = GeometryUtils.getProjectedPoint(edgeB.p1, edgeA, null); // project point (15; 1) onto y = 0
assertNull(projectedPoint);
projectedPoint = GeometryUtils.getProjectedPoint(edgeA.p0, edgeB, null); // project point (0; 0) onto y = 1
assertNull(projectedPoint);
projectedPoint = GeometryUtils.getProjectedPoint(edgeA.p1, edgeB, null); // project point (10; 0) onto y = 1
assertEquals(10, projectedPoint.x, EXACT_PRECISION);
assertEquals(1, projectedPoint.y, EXACT_PRECISION);
}
示例14: projectionForPerpendicularEdges
import com.vividsolutions.jts.geom.LineSegment; //导入依赖的package包/类
@Test
public void projectionForPerpendicularEdges() throws Exception {
LineSegment edgeA = new LineSegment(new Coordinate(0, 1), new Coordinate(0, 10)); // vertical edge at x = 0, when y = [1; 10]
LineSegment edgeB = new LineSegment(new Coordinate(2, 0), new Coordinate(7, 0)); // horizontal edge at y = 0, when x = [2; 7]
IntersectionCoordinate intersection = new IntersectionCoordinate(0, 0, edgeA, edgeB);
Coordinate projectedPoint = GeometryUtils.getProjectedPoint(edgeB.p0, edgeA, intersection); // project point (2; 0) onto y axis
assertEquals(0, projectedPoint.x, EXACT_PRECISION);
assertEquals(2, projectedPoint.y, EXACT_PRECISION);
projectedPoint = GeometryUtils.getProjectedPoint(edgeB.p1, edgeA, intersection); // project point (7; 0) onto y axis
assertEquals(0, projectedPoint.x, EXACT_PRECISION);
assertEquals(7, projectedPoint.y, EXACT_PRECISION);
projectedPoint = GeometryUtils.getProjectedPoint(edgeA.p0, edgeB, intersection); // project point (0; 1) onto x axis
assertNull(projectedPoint);
projectedPoint = GeometryUtils.getProjectedPoint(edgeA.p1, edgeB, intersection); // project point (0; 10) onto x axis
assertNull(projectedPoint);
}
示例15: projectionForIntersectingEdges
import com.vividsolutions.jts.geom.LineSegment; //导入依赖的package包/类
@Test
public void projectionForIntersectingEdges() throws Exception {
LineSegment edgeA = new LineSegment(new Coordinate(0, 0), new Coordinate(0, 40)); // vertical edge at x = 0, when y = [0; 40]
LineSegment edgeB = new LineSegment(new Coordinate(30, 10), new Coordinate(10, 20)); // sloping edge that would intersect edgeA if extended
IntersectionCoordinate intersection = new IntersectionCoordinate(0, 25, edgeA, edgeB);
Coordinate projectedPoint = GeometryUtils.getProjectedPoint(edgeB.p0, edgeA, intersection); // project point (30; 10) onto vertical edge
assertNull(projectedPoint);
projectedPoint = GeometryUtils.getProjectedPoint(edgeB.p1, edgeA, intersection); // project point (10; 20) onto vertical edge
assertEquals(0, projectedPoint.x, EXACT_PRECISION);
assertEquals(13.819660112501051, projectedPoint.y, EXACT_PRECISION);
projectedPoint = GeometryUtils.getProjectedPoint(edgeA.p0, edgeB, intersection); // project point (0; 0) onto sloping edge
assertEquals(22.360679774997898, projectedPoint.x, EXACT_PRECISION);
assertEquals(13.819660112501051, projectedPoint.y, EXACT_PRECISION);
projectedPoint = GeometryUtils.getProjectedPoint(edgeA.p1, edgeB, intersection); // project point (0; 20) onto sloping edge
assertNull(projectedPoint);
}