Esempio n. 1
0
int QgsIDWInterpolator::interpolatePoint( double x, double y, double& result )
{
  if ( !mDataIsCached )
  {
    cacheBaseData();
  }

  double currentWeight;
  double distance;

  double sumCounter = 0;
  double sumDenominator = 0;

  Q_FOREACH ( const vertexData& vertex_it, mCachedBaseData )
  {
    distance = sqrt(( vertex_it.x - x ) * ( vertex_it.x - x ) + ( vertex_it.y - y ) * ( vertex_it.y - y ) );
    if (( distance - 0 ) < std::numeric_limits<double>::min() )
    {
      result = vertex_it.z;
      return 0;
    }
    currentWeight = 1 / ( pow( distance, mDistanceCoefficient ) );
    sumCounter += ( currentWeight * vertex_it.z );
    sumDenominator += currentWeight;
  }
void QgsTINInterpolator::initialize()
{
  if ( !mDataIsCached )
  {
    cacheBaseData();
  }

  //create DualEdgeTriangulation

  DualEdgeTriangulation* theDualEdgeTriangulation = new DualEdgeTriangulation( mCachedBaseData.size(), 0 );
  mTriangulation = theDualEdgeTriangulation;

  //add all the vertices to the triangulation
  QVector<vertexData>::const_iterator vertex_it = mCachedBaseData.constBegin();
  for ( ; vertex_it != mCachedBaseData.constEnd(); ++vertex_it )
  {
    Point3D* thePoint = new Point3D( vertex_it->x, vertex_it->y, vertex_it->z );
    mTriangulation->addPoint( thePoint );
  }

  mTriangleInterpolator = new LinTriangleInterpolator( theDualEdgeTriangulation );

  mIsInitialized = true;
}