本文整理汇总了Java中com.vividsolutions.jts.geom.LineSegment.getLength方法的典型用法代码示例。如果您正苦于以下问题:Java LineSegment.getLength方法的具体用法?Java LineSegment.getLength怎么用?Java LineSegment.getLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vividsolutions.jts.geom.LineSegment
的用法示例。
在下文中一共展示了LineSegment.getLength方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: 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;
}
示例4: 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();
}
示例5: 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
*/
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();
}
示例6: 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(linearGeom);
while (it.hasNext()) {
if (!it.isEndOfLine()) {
seg.p0 = it.getSegmentStart();
seg.p1 = it.getSegmentEnd();
double segDistance = seg.distance(inputPt);
double segMeasureToPt = segmentNearestMeasure(seg, inputPt, segmentStartMeasure);
if (segDistance < minDistance
&& segMeasureToPt > minIndex) {
ptMeasure = segMeasureToPt;
minDistance = segDistance;
}
segmentStartMeasure += seg.getLength();
}
it.next();
}
return ptMeasure;
}
示例7: 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
*/
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();
}
示例8: segmentNearestMeasure
import com.vividsolutions.jts.geom.LineSegment; //导入方法依赖的package包/类
private double segmentNearestMeasure(LineSegment seg, Coordinate inputPt,
double segmentStartMeasure) {
// found new minimum, so compute location distance of point
double projFactor = seg.projectionFactor(inputPt);
if (projFactor <= 0.0) {
return segmentStartMeasure;
}
if (projFactor <= 1.0) {
return segmentStartMeasure + projFactor * seg.getLength();
}
// projFactor > 1.0
return segmentStartMeasure + seg.getLength();
}
示例9: segmentNearestMeasure
import com.vividsolutions.jts.geom.LineSegment; //导入方法依赖的package包/类
private double segmentNearestMeasure(LineSegment seg, Coordinate inputPt,
double segmentStartMeasure) {
// found new minimum, so compute location distance of point
double projFactor = seg.projectionFactor(inputPt);
if (projFactor <= 0.0)
return segmentStartMeasure;
if (projFactor <= 1.0)
return segmentStartMeasure + projFactor * seg.getLength();
// projFactor > 1.0
return segmentStartMeasure + seg.getLength();
}
示例10: computePoint
import com.vividsolutions.jts.geom.LineSegment; //导入方法依赖的package包/类
private Coordinate computePoint(LineSegment seg, double dist)
{
double dx = seg.p1.x - seg.p0.x;
double dy = seg.p1.y - seg.p0.y;
double len = seg.getLength();
Coordinate pt = new Coordinate(dist * dx / len, dist * dy / len);
pm.makePrecise(pt);
return pt;
}
示例11: SplitSegment
import com.vividsolutions.jts.geom.LineSegment; //导入方法依赖的package包/类
public SplitSegment(LineSegment seg) {
this.seg = seg;
this.segLen = seg.getLength();
}
示例12: SplitSegment
import com.vividsolutions.jts.geom.LineSegment; //导入方法依赖的package包/类
public SplitSegment(LineSegment seg) {
this.seg = seg;
segLen = seg.getLength();
}
示例13: calculateFraction
import com.vividsolutions.jts.geom.LineSegment; //导入方法依赖的package包/类
public static LineString calculateFraction(LineString l, double f){
if(f<0){
f=0;
}else if(f>1){
f=1;
}
double length = l.getLength();
double outLength = length * f;
ArrayList<Coordinate> coords = new ArrayList<Coordinate>();
Coordinate lastCoord = null;
int nc = l.getNumPoints();
double sum=0;
for(int i =0 ; i < nc ; i++){
Coordinate coord = l.getCoordinateN(i);
if(i==0){
coords.add(coord);
}
else{
LineSegment ls = new LineSegment(lastCoord,coord);
double len = ls.getLength();
if(sum + len < outLength || len==0){
sum += len;
coords.add(coord);
}else{
double remaining = outLength - sum;
if(remaining<0){
// should never happen...
remaining =0;
}
coords.add(ls.pointAlong(remaining / len));
break;
}
}
lastCoord = coord;
}
GeometryFactory factory = l.getFactory();
if(factory==null){
factory = new GeometryFactory();
}
return factory.createLineString(coords.toArray(new Coordinate[coords.size()]));
}