예제 #1
0
static bool longValidator(const QString str, double & val)
{
	QStringList myList;
	QRegExp exp1("^[oOwWeElL][ ]\\d\\d?\\d?[ ]?\\d\\d?[ ]?\\d?\\d?\\.?[0-9]?" );
	QRegExp exp2("^[oOwWeElL][;]\\d\\d?\\d?[;]?\\d\\d?[;]?\\d?\\d?\\.?[0-9]?" ); 
	QRegExp exp3("^[oOwWeElL][:]\\d\\d?\\d?[:]?\\d\\d?[:]?\\d?\\d?\\.?[0-9]?" ); 
	QRegExp exp4("^[+-]?\\d\\d?\\d?\\.?[0-9]*" ); 

	double grauDec;

    if ( exp1.exactMatch( str ) )
	{
		myList = str.split(" ");
	}
	else if ( exp2.exactMatch( str ) )
	{
		myList = str.split(";");
	}
	else if ( exp3.exactMatch( str ) )
	{
		myList = str.split(":");
	}
	else if ( exp4.exactMatch( str ) )
	{
		grauDec = str.toDouble();
		if ((grauDec >= -180.0 && grauDec <=180.0))
		{
			val = grauDec * TeCDR;
			return true;
		}
		else
			return false;
	}
	else
		return false;

	int nelementos = myList.count();
	short graus, minutos = 0;
	float segundos = 0.0;
	
	graus = myList[1].toShort();

	if (nelementos > 2)
		minutos = myList[2].toShort();
	
	if (nelementos > 3)
		segundos = myList[3].toFloat();

	if (TeLongDMS2DD(myList[0].at(0).toAscii(),graus, minutos, segundos, grauDec))
	{
		val = grauDec * TeCDR;
		return true;
	}
	else
		return false;
}
예제 #2
0
    void eval_geometry_calc()
    {
      QgsPolyline polyline, polygon_ring;
      polyline << QgsPoint( 0, 0 ) << QgsPoint( 10, 0 );
      polygon_ring << QgsPoint( 2, 1 ) << QgsPoint( 10, 1 ) << QgsPoint( 10, 6 ) << QgsPoint( 2, 6 ) << QgsPoint( 2, 1 );
      QgsPolygon polygon;
      polygon << polygon_ring;
      QgsFeature fPolygon, fPolyline;
      fPolyline.setGeometry( QgsGeometry::fromPolyline( polyline ) );
      fPolygon.setGeometry( QgsGeometry::fromPolygon( polygon ) );

      QgsExpression exp1( "$area" );
      QVariant vArea = exp1.evaluate( &fPolygon );
      QCOMPARE( vArea.toDouble(), 40. );

      QgsExpression exp2( "$length" );
      QVariant vLength = exp2.evaluate( &fPolyline );
      QCOMPARE( vLength.toDouble(), 10. );

      QgsExpression exp3( "$perimeter" );
      QVariant vPerimeter = exp3.evaluate( &fPolygon );
      QCOMPARE( vPerimeter.toDouble(), 26. );

      QgsExpression exp4( "bounds_width($geometry)" );
      QVariant vBoundsWidth = exp4.evaluate( &fPolygon );
      QCOMPARE( vBoundsWidth.toDouble(), 8.0 );

      QgsExpression exp5( "bounds_height($geometry)" );
      QVariant vBoundsHeight = exp5.evaluate( &fPolygon );
      QCOMPARE( vBoundsHeight.toDouble(), 5.0 );

      QgsExpression exp6( "xmin($geometry)" );
      QVariant vXMin = exp6.evaluate( &fPolygon );
      QCOMPARE( vXMin.toDouble(), 2.0 );

      QgsExpression exp7( "xmax($geometry)" );
      QVariant vXMax = exp7.evaluate( &fPolygon );
      QCOMPARE( vXMax.toDouble(), 10.0 );

      QgsExpression exp8( "ymin($geometry)" );
      QVariant vYMin = exp8.evaluate( &fPolygon );
      QCOMPARE( vYMin.toDouble(), 1.0 );

      QgsExpression exp9( "ymax($geometry)" );
      QVariant vYMax = exp9.evaluate( &fPolygon );
      QCOMPARE( vYMax.toDouble(), 6.0 );
    }