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


Java LineString.getLength方法代码示例

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

示例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);
  }
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:37,代码来源:LineDensification.java

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

示例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);
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:48,代码来源:LineDensification.java


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