示例#1
0
double QgsDistanceArea::measurePerimeter( const QgsGeometry* geometry )
{
  if ( !geometry )
    return 0.0;

  const unsigned char* wkb = geometry->asWkb();
  if ( !wkb )
    return 0.0;

  QgsConstWkbPtr wkbPtr( wkb + 1 );
  QGis::WkbType wkbType;
  wkbPtr >> wkbType;

  double res = 0.0, resTotal = 0.0;
  int count, i;

  // measure distance or area based on what is the type of geometry
  bool hasZptr = false;

  switch ( wkbType )
  {
    case QGis::WKBLineString25D:
    case QGis::WKBLineString:
    case QGis::WKBMultiLineString25D:
    case QGis::WKBMultiLineString:
      return 0.0;

    case QGis::WKBPolygon25D:
      hasZptr = true;
      //intentional fall-through
    case QGis::WKBPolygon:
      measurePolygon( wkb, 0, &res, hasZptr );
      QgsDebugMsg( "returning " + QString::number( res ) );
      return res;

    case QGis::WKBMultiPolygon25D:
      hasZptr = true;
      //intentional fall-through
    case QGis::WKBMultiPolygon:
      wkbPtr >> count;
      for ( i = 0; i < count; i++ )
      {
        wkbPtr = measurePolygon( wkbPtr, 0, &res, hasZptr );
        if ( !wkbPtr )
        {
          QgsDebugMsg( "measurePolygon returned 0" );
          break;
        }
        resTotal += res;
      }
      QgsDebugMsg( "returning " + QString::number( resTotal ) );
      return resTotal;

    default:
      QgsDebugMsg( QString( "measure: unexpected geometry type: %1" ).arg( wkbType ) );
      return 0;
  }
}
示例#2
0
double QgsDistanceArea::measurePerimeter( QgsGeometry* geometry )
{
    if ( !geometry )
        return 0.0;

    const unsigned char* wkb = geometry->asWkb();
    if ( !wkb )
        return 0.0;

    const unsigned char* ptr;
    unsigned int wkbType;
    double res = 0.0, resTotal = 0.0;
    int count, i;

    memcpy( &wkbType, ( wkb + 1 ), sizeof( wkbType ) );

    // measure distance or area based on what is the type of geometry
    bool hasZptr = false;

    switch ( wkbType )
    {
    case QGis::WKBLineString25D:
    case QGis::WKBLineString:
    case QGis::WKBMultiLineString25D:
    case QGis::WKBMultiLineString:
        return 0.0;

    case QGis::WKBPolygon25D:
        hasZptr = true;
    case QGis::WKBPolygon:
        measurePolygon( wkb, 0, &res, hasZptr );
        QgsDebugMsg( "returning " + QString::number( res ) );
        return res;

    case QGis::WKBMultiPolygon25D:
        hasZptr = true;
    case QGis::WKBMultiPolygon:
        count = *(( int* )( wkb + 5 ) );
        ptr = wkb + 9;
        for ( i = 0; i < count; i++ )
        {
            ptr = measurePolygon( ptr, 0, &res, hasZptr );
            if ( !ptr )
            {
                QgsDebugMsg( "measurePolygon returned 0" );
                break;
            }
            resTotal += res;
        }
        QgsDebugMsg( "returning " + QString::number( resTotal ) );
        return resTotal;

    default:
        QgsDebugMsg( QString( "measure: unexpected geometry type: %1" ).arg( wkbType ) );
        return 0;
    }
}
示例#3
0
double QgsDistanceArea::measurePolygon( const QgsCurveV2* curve ) const
{
  if ( !curve )
  {
    return 0.0;
  }

  QList<QgsPointV2> linePointsV2;
  curve->points( linePointsV2 );
  QList<QgsPoint> linePoints;
  QgsGeometry::convertPointList( linePointsV2, linePoints );
  return measurePolygon( linePoints );
}
示例#4
0
void QxrdImagePlot::setProcessor(QxrdDataProcessorWPtr proc)
{
  m_DataProcessor = proc;

  QxrdDataProcessorPtr dp(m_DataProcessor);

  if (dp) {
    QxrdCenterFinderPtr cf(dp->centerFinder());

    if (cf) {
      connect(m_CenterFinderPicker, SIGNAL(selected(QPointF)),
              cf.data(), SLOT(onCenterChanged(QPointF)));

      connect(m_Circles, SIGNAL(selected(QRectF)),
              dp.data(), SLOT(maskCircle(QRectF)));

      connect(m_Polygons, SIGNAL(selected(QVector<QPointF>)),
              dp.data(), SLOT(maskPolygon(QVector<QPointF>)));

      connect(m_Measurer, SIGNAL(selected(QVector<QPointF>)),
              dp.data(), SLOT(measurePolygon(QVector<QPointF>)));

      //  connect(m_Slicer, SIGNAL(selected(QVector<QPointF>)),
    //          m_DataProcessor, SLOT(slicePolygon(QVector<QPointF>)));

      connect(m_PowderPointPicker, SIGNAL(selected(QPointF)),
              cf.data(), SLOT(onPointSelected(QPointF)));

      onCenterChanged(QPointF(cf->get_CenterX(), cf->get_CenterY()));

      connect(cf->prop_MarkedPoints(), SIGNAL(valueChanged(QxrdPowderPointVector,int)),
              this, SLOT(onMarkedPointsChanged()));

      onMarkedPointsChanged();
    }
  }

  connect(m_Slicer, SIGNAL(selected(QVector<QPointF>)),
          this, SIGNAL(slicePolygon(QVector<QPointF>)));

  connect(m_HistogramSelector, SIGNAL(selected(QRectF)),
          this, SIGNAL(selectHistogram(QRectF)));
}
示例#5
0
double QgsDistanceArea::measure( const QgsAbstractGeometryV2* geomV2, MeasureType type ) const
{
  if ( !geomV2 )
  {
    return 0.0;
  }

  int geomDimension = geomV2->dimension();
  if ( geomDimension <= 0 )
  {
    return 0.0;
  }

  MeasureType measureType = type;
  if ( measureType == Default )
  {
    measureType = ( geomDimension == 1 ? Length : Area );
  }

  if ( !mEllipsoidalMode || mEllipsoid == GEO_NONE )
  {
    //no transform required
    if ( measureType == Length )
    {
      return geomV2->length();
    }
    else
    {
      return geomV2->area();
    }
  }
  else
  {
    //multigeom is sum of measured parts
    const QgsGeometryCollectionV2* collection = dynamic_cast<const QgsGeometryCollectionV2*>( geomV2 );
    if ( collection )
    {
      double sum = 0;
      for ( int i = 0; i < collection->numGeometries(); ++i )
      {
        sum += measure( collection->geometryN( i ), measureType );
      }
      return sum;
    }

    if ( measureType == Length )
    {
      const QgsCurveV2* curve = dynamic_cast<const QgsCurveV2*>( geomV2 );
      if ( !curve )
      {
        return 0.0;
      }

      QgsLineStringV2* lineString = curve->curveToLine();
      double length = measureLine( lineString );
      delete lineString;
      return length;
    }
    else
    {
      const QgsSurfaceV2* surface = dynamic_cast<const QgsSurfaceV2*>( geomV2 );
      if ( !surface )
        return 0.0;

      QgsPolygonV2* polygon = surface->surfaceToPolygon();

      double area = 0;
      const QgsCurveV2* outerRing = polygon->exteriorRing();
      area += measurePolygon( outerRing );

      for ( int i = 0; i < polygon->numInteriorRings(); ++i )
      {
        const QgsCurveV2* innerRing = polygon->interiorRing( i );
        area -= measurePolygon( innerRing );
      }
      delete polygon;
      return area;
    }
  }
}