本文整理汇总了Java中com.vividsolutions.jts.geom.LineString.getLength方法的典型用法代码示例。如果您正苦于以下问题:Java LineString.getLength方法的具体用法?Java LineString.getLength怎么用?Java LineString.getLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vividsolutions.jts.geom.LineString
的用法示例。
在下文中一共展示了LineString.getLength方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLength
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
public static double getLength(Geometry geom, Boolean inMeters) throws Exception
{
if (!(geom instanceof LineString))
throw new Exception("Specified geometry type is not supported.");
LineString ls = (LineString)geom;
if (ls.getNumPoints() == 0)
return 0.0;
if (inMeters)
{
double length = 0.0;
DistanceCalc dc = new DistanceCalcEarth();
Coordinate c0 = ls.getCoordinateN(0);
for (int i = 1; i < ls.getNumPoints(); ++i)
{
Coordinate c1 = ls.getCoordinateN(i);
length += dc.calcDist(c0.y, c0.x, c1.y, c1.x);
c0 = c1;
}
return length;
}
else
return ls.getLength();
}
示例2: densification
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
public static LineString densification(LineString ls, double pas) {
// coordonnees de la ligne initiale
Coordinate[] coords = ls.getCoordinates();
// table des coordonnees densifiees
int nbPoints = (int) (ls.getLength() / pas);
Coordinate[] coordsDens = new Coordinate[nbPoints + 1];
// remplissage
int iDens = 0;
double dist = 0.0, angle = 0.0, longueur;
for (int i = 0; i < coords.length - 1; i++) {
Coordinate coord0 = coords[i], coord1 = coords[i + 1];
longueur = coord0.distance(coord1);
if (dist <= longueur)
angle = Math.atan2(coord1.y - coord0.y, coord1.x - coord0.x);
while (dist <= longueur) {
// ajouter point a ligne densifiee
coordsDens[iDens] = new Coordinate(coord0.x + dist * Math.cos(angle),
coord0.y + dist * Math.sin(angle));
dist += pas;
iDens++;
}
dist -= longueur;
}
// le dernier point
coordsDens[nbPoints] = coords[coords.length - 1];
return new GeometryFactory().createLineString(coordsDens);
}
示例3: getProportion
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
private double getProportion(Coordinate coord, LineString ls) {
// coord is a point in line ls
Coordinate[] ends = ls.getCoordinates();
return coord.distance(ends[0]) / ls.getLength();
}
示例4: densification
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
/**
* Puts x vertices in the line where x is the length divided by the step
* parameter. Be careful, this method does not preserve the initial vertices!
* @param ls
* @param step
* @return
*/
public static LineString densification(LineString ls, double step) {
// coordonnees de la ligne initiale
Coordinate[] coords = ls.getCoordinates();
// table des coordonnees densifiees
int nbPoints = (int) (ls.getLength() / step);
Coordinate[] coordsDens = new Coordinate[nbPoints + 1];
if (nbPoints + 1 < coords.length)
return ls;
// remplissage
int iDens = 0;
double dist = 0.0, angle = 0.0, longueur;
for (int i = 0; i < coords.length - 1; i++) {
Coordinate coord0 = coords[i], coord1 = coords[i + 1];
longueur = coord0.distance(coord1);
if (dist <= longueur) {
angle = Math.atan2(coord1.y - coord0.y, coord1.x - coord0.x);
}
while (dist <= longueur) {
// ajouter point a ligne densifiee
coordsDens[iDens] = new Coordinate(coord0.x + dist * Math.cos(angle),
coord0.y + dist * Math.sin(angle));
dist += step;
iDens++;
}
dist -= longueur;
}
// le dernier point
coordsDens[nbPoints] = coords[coords.length - 1];
return new GeometryFactory().createLineString(coordsDens);
}