當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。