当前位置: 首页>>代码示例>>Java>>正文


Java LineSegment.getLength方法代码示例

本文整理汇总了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();
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:31,代码来源:Densifier.java

示例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();
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:33,代码来源:NonEncroachingSplitPointFinder.java

示例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;
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:25,代码来源:LengthIndexOfPoint.java

示例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();
}
 
开发者ID:grimsa,项目名称:polysplit,代码行数:19,代码来源:GeometryUtils.java

示例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();
}
 
开发者ID:Semantive,项目名称:jts,代码行数:32,代码来源:NonEncroachingSplitPointFinder.java

示例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;
}
 
开发者ID:Semantive,项目名称:jts,代码行数:25,代码来源:LengthIndexOfPoint.java

示例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();
}
 
开发者ID:GitHubDroid,项目名称:geodroid_master_update,代码行数:32,代码来源:NonEncroachingSplitPointFinder.java

示例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();
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:14,代码来源:LengthIndexOfPoint.java

示例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();
}
 
开发者ID:Semantive,项目名称:jts,代码行数:12,代码来源:LengthIndexOfPoint.java

示例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;
}
 
开发者ID:Semantive,项目名称:jts,代码行数:10,代码来源:SegmentPointComparatorFullTest.java

示例11: SplitSegment

import com.vividsolutions.jts.geom.LineSegment; //导入方法依赖的package包/类
public SplitSegment(LineSegment seg) {
    this.seg = seg;
    this.segLen = seg.getLength();
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:5,代码来源:SplitSegment.java

示例12: SplitSegment

import com.vividsolutions.jts.geom.LineSegment; //导入方法依赖的package包/类
public SplitSegment(LineSegment seg) {
    this.seg = seg;
    segLen = seg.getLength();
}
 
开发者ID:Semantive,项目名称:jts,代码行数:5,代码来源:SplitSegment.java

示例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()]));
}
 
开发者ID:PGWelch,项目名称:com.opendoorlogistics,代码行数:45,代码来源:LinestringFraction.java


注:本文中的com.vividsolutions.jts.geom.LineSegment.getLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。