101101_raster_compareoperations.diff
| src/analysis/raster/qgsrastermatrix.cpp (Arbeitskopie) | ||
|---|---|---|
| 93 | 93 |
return twoArgumentOperation( opPOW, other ); |
| 94 | 94 |
} |
| 95 | 95 | |
| 96 |
bool QgsRasterMatrix::equal( const QgsRasterMatrix& other ) |
|
| 97 |
{
|
|
| 98 |
return twoArgumentOperation( opEQ, other ); |
|
| 99 |
} |
|
| 100 | ||
| 101 |
bool QgsRasterMatrix::notEqual( const QgsRasterMatrix& other ) |
|
| 102 |
{
|
|
| 103 |
return twoArgumentOperation( opNE, other ); |
|
| 104 |
} |
|
| 105 | ||
| 106 |
bool QgsRasterMatrix::greaterThan( const QgsRasterMatrix& other ) |
|
| 107 |
{
|
|
| 108 |
return twoArgumentOperation( opGT, other ); |
|
| 109 |
} |
|
| 110 | ||
| 111 |
bool QgsRasterMatrix::lesserThan( const QgsRasterMatrix& other ) |
|
| 112 |
{
|
|
| 113 |
return twoArgumentOperation( opLT, other ); |
|
| 114 |
} |
|
| 115 | ||
| 116 |
bool QgsRasterMatrix::greaterEqual( const QgsRasterMatrix& other ) |
|
| 117 |
{
|
|
| 118 |
return twoArgumentOperation( opGE, other ); |
|
| 119 |
} |
|
| 120 | ||
| 121 |
bool QgsRasterMatrix::lesserEqual( const QgsRasterMatrix& other ) |
|
| 122 |
{
|
|
| 123 |
return twoArgumentOperation( opLE, other ); |
|
| 124 |
} |
|
| 125 | ||
| 96 | 126 |
bool QgsRasterMatrix::squareRoot() |
| 97 | 127 |
{
|
| 98 |
if ( !mData )
|
|
| 128 |
if( !mData ) |
|
| 99 | 129 |
{
|
| 100 | 130 |
return false; |
| 101 | 131 |
} |
| 102 | 132 | |
| 103 | 133 |
int nEntries = mColumns * mRows; |
| 104 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 134 |
for( int i = 0; i < nEntries; ++i ) |
|
| 105 | 135 |
{
|
| 106 | 136 |
double value = mData[i]; |
| 107 |
if ( value >= 0 )
|
|
| 137 |
if( value >= 0 ) |
|
| 108 | 138 |
{
|
| 109 | 139 |
mData[i] = sqrt( value ); |
| 110 | 140 |
} |
| ... | ... | |
| 118 | 148 | |
| 119 | 149 |
bool QgsRasterMatrix::sinus() |
| 120 | 150 |
{
|
| 121 |
if ( !mData )
|
|
| 151 |
if( !mData ) |
|
| 122 | 152 |
{
|
| 123 | 153 |
return false; |
| 124 | 154 |
} |
| 125 | 155 | |
| 126 | 156 |
int nEntries = mColumns * mRows; |
| 127 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 157 |
for( int i = 0; i < nEntries; ++i ) |
|
| 128 | 158 |
{
|
| 129 | 159 |
mData[i] = sin( mData[i] ); |
| 130 | 160 |
} |
| ... | ... | |
| 133 | 163 | |
| 134 | 164 |
bool QgsRasterMatrix::asinus() |
| 135 | 165 |
{
|
| 136 |
if ( !mData )
|
|
| 166 |
if( !mData ) |
|
| 137 | 167 |
{
|
| 138 | 168 |
return false; |
| 139 | 169 |
} |
| 140 | 170 | |
| 141 | 171 |
int nEntries = mColumns * mRows; |
| 142 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 172 |
for( int i = 0; i < nEntries; ++i ) |
|
| 143 | 173 |
{
|
| 144 | 174 |
mData[i] = asin( mData[i] ); |
| 145 | 175 |
} |
| ... | ... | |
| 148 | 178 | |
| 149 | 179 |
bool QgsRasterMatrix::cosinus() |
| 150 | 180 |
{
|
| 151 |
if ( !mData )
|
|
| 181 |
if( !mData ) |
|
| 152 | 182 |
{
|
| 153 | 183 |
return false; |
| 154 | 184 |
} |
| 155 | 185 | |
| 156 | 186 |
int nEntries = mColumns * mRows; |
| 157 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 187 |
for( int i = 0; i < nEntries; ++i ) |
|
| 158 | 188 |
{
|
| 159 | 189 |
mData[i] = cos( mData[i] ); |
| 160 | 190 |
} |
| ... | ... | |
| 163 | 193 | |
| 164 | 194 |
bool QgsRasterMatrix::acosinus() |
| 165 | 195 |
{
|
| 166 |
if ( !mData )
|
|
| 196 |
if( !mData ) |
|
| 167 | 197 |
{
|
| 168 | 198 |
return false; |
| 169 | 199 |
} |
| 170 | 200 | |
| 171 | 201 |
int nEntries = mColumns * mRows; |
| 172 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 202 |
for( int i = 0; i < nEntries; ++i ) |
|
| 173 | 203 |
{
|
| 174 | 204 |
mData[i] = acos( mData[i] ); |
| 175 | 205 |
} |
| ... | ... | |
| 178 | 208 | |
| 179 | 209 |
bool QgsRasterMatrix::tangens() |
| 180 | 210 |
{
|
| 181 |
if ( !mData )
|
|
| 211 |
if( !mData ) |
|
| 182 | 212 |
{
|
| 183 | 213 |
return false; |
| 184 | 214 |
} |
| 185 | 215 | |
| 186 | 216 |
int nEntries = mColumns * mRows; |
| 187 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 217 |
for( int i = 0; i < nEntries; ++i ) |
|
| 188 | 218 |
{
|
| 189 | 219 |
mData[i] = tan( mData[i] ); |
| 190 | 220 |
} |
| ... | ... | |
| 193 | 223 | |
| 194 | 224 |
bool QgsRasterMatrix::atangens() |
| 195 | 225 |
{
|
| 196 |
if ( !mData )
|
|
| 226 |
if( !mData ) |
|
| 197 | 227 |
{
|
| 198 | 228 |
return false; |
| 199 | 229 |
} |
| 200 | 230 | |
| 201 | 231 |
int nEntries = mColumns * mRows; |
| 202 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 232 |
for( int i = 0; i < nEntries; ++i ) |
|
| 203 | 233 |
{
|
| 204 | 234 |
mData[i] = atan( mData[i] ); |
| 205 | 235 |
} |
| ... | ... | |
| 208 | 238 | |
| 209 | 239 |
bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMatrix& other ) |
| 210 | 240 |
{
|
| 211 |
if ( isNumber() && other.isNumber() )
|
|
| 241 |
if( isNumber() && other.isNumber() ) |
|
| 212 | 242 |
{
|
| 213 |
switch ( op )
|
|
| 243 |
switch( op ) |
|
| 214 | 244 |
{
|
| 215 | 245 |
case opPLUS: |
| 216 | 246 |
mData[0] = number() + other.number(); |
| ... | ... | |
| 222 | 252 |
mData[0] = number() * other.number(); |
| 223 | 253 |
break; |
| 224 | 254 |
case opDIV: |
| 225 |
if ( other.number() == 0 )
|
|
| 255 |
if( other.number() == 0 ) |
|
| 226 | 256 |
{
|
| 227 | 257 |
mData[0] = -10000; |
| 228 | 258 |
} |
| ... | ... | |
| 232 | 262 |
} |
| 233 | 263 |
break; |
| 234 | 264 |
case opPOW: |
| 235 |
if ( !testPowerValidity( mData[0], ( float ) other.number() ) )
|
|
| 265 |
if( !testPowerValidity( mData[0], ( float ) other.number() ) ) |
|
| 236 | 266 |
{
|
| 237 | 267 |
mData[0] = -10000; |
| 238 | 268 |
} |
| ... | ... | |
| 241 | 271 |
mData[0] = pow( mData[0], ( float ) other.number() ); |
| 242 | 272 |
} |
| 243 | 273 |
break; |
| 274 |
case opEQ: |
|
| 275 |
mData[0] = ( mData[0] == other.number() ? 1 : 0 ); |
|
| 276 |
break; |
|
| 277 |
case opNE: |
|
| 278 |
mData[0] = ( mData[0] == other.number() ? 0 : 1 ); |
|
| 279 |
break; |
|
| 280 |
case opGT: |
|
| 281 |
mData[0] = ( mData[0] > other.number() ? 1 : 0 ); |
|
| 282 |
break; |
|
| 283 |
case opLT: |
|
| 284 |
mData[0] = ( mData[0] < other.number() ? 1 : 0 ); |
|
| 285 |
break; |
|
| 286 |
case opGE: |
|
| 287 |
mData[0] = ( mData[0] >= other.number() ? 1 : 0 ); |
|
| 288 |
break; |
|
| 289 |
case opLE: |
|
| 290 |
mData[0] = ( mData[0] <= other.number() ? 1 : 0 ); |
|
| 291 |
break; |
|
| 244 | 292 |
} |
| 245 | 293 |
return true; |
| 246 | 294 |
} |
| 247 | 295 |
//two matrices |
| 248 |
if ( !isNumber() && !other.isNumber() )
|
|
| 296 |
if( !isNumber() && !other.isNumber() ) |
|
| 249 | 297 |
{
|
| 250 | 298 |
float* matrix = other.mData; |
| 251 | 299 |
int nEntries = mColumns * mRows; |
| 252 |
switch ( op )
|
|
| 300 |
switch( op ) |
|
| 253 | 301 |
{
|
| 254 | 302 |
case opPLUS: |
| 255 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 303 |
for( int i = 0; i < nEntries; ++i ) |
|
| 256 | 304 |
{
|
| 257 | 305 |
mData[i] = mData[i] + matrix[i]; |
| 258 | 306 |
} |
| 259 | 307 |
break; |
| 260 | 308 |
case opMINUS: |
| 261 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 309 |
for( int i = 0; i < nEntries; ++i ) |
|
| 262 | 310 |
{
|
| 263 | 311 |
mData[i] = mData[i] - matrix[i]; |
| 264 | 312 |
} |
| 265 | 313 |
break; |
| 266 | 314 |
case opMUL: |
| 267 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 315 |
for( int i = 0; i < nEntries; ++i ) |
|
| 268 | 316 |
{
|
| 269 | 317 |
mData[i] = mData[i] * matrix[i]; |
| 270 | 318 |
} |
| 271 | 319 |
break; |
| 272 | 320 |
case opDIV: |
| 273 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 321 |
for( int i = 0; i < nEntries; ++i ) |
|
| 274 | 322 |
{
|
| 275 |
if ( matrix[i] == 0 )
|
|
| 323 |
if( matrix[i] == 0 ) |
|
| 276 | 324 |
{
|
| 277 | 325 |
mData[i] = -10000; |
| 278 | 326 |
} |
| ... | ... | |
| 283 | 331 |
} |
| 284 | 332 |
break; |
| 285 | 333 |
case opPOW: |
| 286 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 334 |
for( int i = 0; i < nEntries; ++i ) |
|
| 287 | 335 |
{
|
| 288 |
if ( !testPowerValidity( mData[i], matrix[i] ) )
|
|
| 336 |
if( !testPowerValidity( mData[i], matrix[i] ) ) |
|
| 289 | 337 |
{
|
| 290 | 338 |
mData[i] = -10000; |
| 291 | 339 |
} |
| ... | ... | |
| 295 | 343 |
} |
| 296 | 344 |
} |
| 297 | 345 |
break; |
| 346 |
case opEQ: |
|
| 347 |
for( int i = 0; i < nEntries; ++i ) |
|
| 348 |
{
|
|
| 349 |
mData[i] = ( mData[i] == matrix[i] ? 1 : 0 ); |
|
| 350 |
} |
|
| 351 |
break; |
|
| 352 |
case opNE: |
|
| 353 |
for( int i = 0; i < nEntries; ++i ) |
|
| 354 |
{
|
|
| 355 |
mData[i] = ( mData[i] == matrix[i] ? 0 : 1 ); |
|
| 356 |
} |
|
| 357 |
break; |
|
| 358 |
case opGT: |
|
| 359 |
for( int i = 0; i < nEntries; ++i ) |
|
| 360 |
{
|
|
| 361 |
mData[i] = ( mData[i] > matrix[i] ? 1 : 0 ); |
|
| 362 |
} |
|
| 363 |
break; |
|
| 364 |
case opLT: |
|
| 365 |
for( int i = 0; i < nEntries; ++i ) |
|
| 366 |
{
|
|
| 367 |
mData[i] = ( mData[i] < matrix[i] ? 1 : 0 ); |
|
| 368 |
} |
|
| 369 |
break; |
|
| 370 |
case opGE: |
|
| 371 |
for( int i = 0; i < nEntries; ++i ) |
|
| 372 |
{
|
|
| 373 |
mData[i] = ( mData[i] >= matrix[i] ? 1 : 0 ); |
|
| 374 |
} |
|
| 375 |
break; |
|
| 376 |
case opLE: |
|
| 377 |
for( int i = 0; i < nEntries; ++i ) |
|
| 378 |
{
|
|
| 379 |
mData[i] = ( mData[i] <= matrix[i] ? 1 : 0 ); |
|
| 380 |
} |
|
| 381 |
break; |
|
| 298 | 382 |
} |
| 299 | 383 |
return true; |
| 300 | 384 |
} |
| 301 | 385 |
double value = 0; |
| 302 |
if ( isNumber() )
|
|
| 386 |
if( isNumber() ) |
|
| 303 | 387 |
{
|
| 304 | 388 |
float* matrix = other.mData; |
| 305 | 389 |
int nEntries = other.nColumns() * other.nRows(); |
| ... | ... | |
| 307 | 391 |
delete[] mData; |
| 308 | 392 |
mData = new float[nEntries]; mColumns = other.nColumns(); mRows = other.nRows(); |
| 309 | 393 | |
| 310 |
switch ( op )
|
|
| 394 |
switch( op ) |
|
| 311 | 395 |
{
|
| 312 | 396 |
case opPLUS: |
| 313 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 397 |
for( int i = 0; i < nEntries; ++i ) |
|
| 314 | 398 |
{
|
| 315 | 399 |
mData[i] = value + matrix[i]; |
| 316 | 400 |
} |
| 317 | 401 |
break; |
| 318 | 402 |
case opMINUS: |
| 319 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 403 |
for( int i = 0; i < nEntries; ++i ) |
|
| 320 | 404 |
{
|
| 321 | 405 |
mData[i] = value - matrix[i]; |
| 322 | 406 |
} |
| 323 | 407 |
break; |
| 324 | 408 |
case opMUL: |
| 325 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 409 |
for( int i = 0; i < nEntries; ++i ) |
|
| 326 | 410 |
{
|
| 327 | 411 |
mData[i] = value * matrix[i]; |
| 328 | 412 |
} |
| 329 | 413 |
break; |
| 330 | 414 |
case opDIV: |
| 331 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 415 |
for( int i = 0; i < nEntries; ++i ) |
|
| 332 | 416 |
{
|
| 333 |
if ( matrix[i] == 0 )
|
|
| 417 |
if( matrix[i] == 0 ) |
|
| 334 | 418 |
{
|
| 335 | 419 |
mData[i] = -10000; |
| 336 | 420 |
} |
| ... | ... | |
| 341 | 425 |
} |
| 342 | 426 |
break; |
| 343 | 427 |
case opPOW: |
| 344 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 428 |
for( int i = 0; i < nEntries; ++i ) |
|
| 345 | 429 |
{
|
| 346 |
if ( !testPowerValidity( value, matrix[i] ) )
|
|
| 430 |
if( !testPowerValidity( value, matrix[i] ) ) |
|
| 347 | 431 |
{
|
| 348 | 432 |
mData[i] = -10000; |
| 349 | 433 |
} |
| ... | ... | |
| 353 | 437 |
} |
| 354 | 438 |
} |
| 355 | 439 |
break; |
| 440 |
case opEQ: |
|
| 441 |
for( int i = 0; i < nEntries; ++i ) |
|
| 442 |
{
|
|
| 443 |
mData[i] = ( value == matrix[i] ? 1 : 0 ); |
|
| 444 |
} |
|
| 445 |
break; |
|
| 446 |
case opNE: |
|
| 447 |
for( int i = 0; i < nEntries; ++i ) |
|
| 448 |
{
|
|
| 449 |
mData[i] = ( value == matrix[i] ? 0 : 1 ); |
|
| 450 |
} |
|
| 451 |
break; |
|
| 452 |
case opGT: |
|
| 453 |
for( int i = 0; i < nEntries; ++i ) |
|
| 454 |
{
|
|
| 455 |
mData[i] = ( value > matrix[i] ? 1 : 0 ); |
|
| 456 |
} |
|
| 457 |
break; |
|
| 458 |
case opLT: |
|
| 459 |
for( int i = 0; i < nEntries; ++i ) |
|
| 460 |
{
|
|
| 461 |
mData[i] = ( value < matrix[i] ? 1 : 0 ); |
|
| 462 |
} |
|
| 463 |
break; |
|
| 464 |
case opGE: |
|
| 465 |
for( int i = 0; i < nEntries; ++i ) |
|
| 466 |
{
|
|
| 467 |
mData[i] = ( value >= matrix[i] ? 1 : 0 ); |
|
| 468 |
} |
|
| 469 |
break; |
|
| 470 |
case opLE: |
|
| 471 |
for( int i = 0; i < nEntries; ++i ) |
|
| 472 |
{
|
|
| 473 |
mData[i] = ( value <= matrix[i] ? 1 : 0 ); |
|
| 474 |
} |
|
| 475 |
break; |
|
| 356 | 476 |
} |
| 357 | 477 |
} |
| 358 |
else |
|
| 478 |
else //this matrix is a real matrix and the other a number
|
|
| 359 | 479 |
{
|
| 360 | 480 |
value = other.number(); |
| 361 | 481 |
int nEntries = mColumns * mRows; |
| 362 |
switch ( op )
|
|
| 482 |
switch( op ) |
|
| 363 | 483 |
{
|
| 364 | 484 |
case opPLUS: |
| 365 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 485 |
for( int i = 0; i < nEntries; ++i ) |
|
| 366 | 486 |
{
|
| 367 | 487 |
mData[i] = mData[i] + value; |
| 368 | 488 |
} |
| 369 | 489 |
break; |
| 370 | 490 |
case opMINUS: |
| 371 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 491 |
for( int i = 0; i < nEntries; ++i ) |
|
| 372 | 492 |
{
|
| 373 | 493 |
mData[i] = mData[i] - value; |
| 374 | 494 |
} |
| 375 | 495 |
break; |
| 376 | 496 |
case opMUL: |
| 377 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 497 |
for( int i = 0; i < nEntries; ++i ) |
|
| 378 | 498 |
{
|
| 379 | 499 |
mData[i] = mData[i] * value; |
| 380 | 500 |
} |
| 381 | 501 |
break; |
| 382 | 502 |
case opDIV: |
| 383 |
if ( value == 0 )
|
|
| 503 |
if( value == 0 ) |
|
| 384 | 504 |
{
|
| 385 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 505 |
for( int i = 0; i < nEntries; ++i ) |
|
| 386 | 506 |
{
|
| 387 | 507 |
mData[i] = -10000; |
| 388 | 508 |
} |
| 389 | 509 |
} |
| 390 | 510 |
else |
| 391 | 511 |
{
|
| 392 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 512 |
for( int i = 0; i < nEntries; ++i ) |
|
| 393 | 513 |
{
|
| 394 | 514 |
mData[i] = mData[i] / value; |
| 395 | 515 |
} |
| 396 | 516 |
} |
| 397 | 517 |
break; |
| 398 | 518 |
case opPOW: |
| 399 |
for ( int i = 0; i < nEntries; ++i )
|
|
| 519 |
for( int i = 0; i < nEntries; ++i ) |
|
| 400 | 520 |
{
|
| 401 |
if ( !testPowerValidity( mData[i], value ) )
|
|
| 521 |
if( !testPowerValidity( mData[i], value ) ) |
|
| 402 | 522 |
{
|
| 403 | 523 |
mData[i] = -10000; |
| 404 | 524 |
} |
| ... | ... | |
| 408 | 528 |
} |
| 409 | 529 |
} |
| 410 | 530 |
break; |
| 531 |
case opEQ: |
|
| 532 |
for( int i = 0; i < nEntries; ++i ) |
|
| 533 |
{
|
|
| 534 |
mData[i] = ( mData[i] == value ? 1 : 0 ); |
|
| 535 |
} |
|
| 536 |
break; |
|
| 537 |
case opNE: |
|
| 538 |
for( int i = 0; i < nEntries; ++i ) |
|
| 539 |
{
|
|
| 540 |
mData[i] = ( mData[i] == value ? 0 : 1 ); |
|
| 541 |
} |
|
| 542 |
break; |
|
| 543 |
case opGT: |
|
| 544 |
for( int i = 0; i < nEntries; ++i ) |
|
| 545 |
{
|
|
| 546 |
mData[i] = ( mData[i] > value ? 1 : 0 ); |
|
| 547 |
} |
|
| 548 |
break; |
|
| 549 |
case opLT: |
|
| 550 |
for( int i = 0; i < nEntries; ++i ) |
|
| 551 |
{
|
|
| 552 |
mData[i] = ( mData[i] < value ? 1 : 0 ); |
|
| 553 |
} |
|
| 554 |
break; |
|
| 555 |
case opGE: |
|
| 556 |
for( int i = 0; i < nEntries; ++i ) |
|
| 557 |
{
|
|
| 558 |
mData[i] = ( mData[i] >= value ? 1 : 0 ); |
|
| 559 |
} |
|
| 560 |
break; |
|
| 561 |
case opLE: |
|
| 562 |
for( int i = 0; i < nEntries; ++i ) |
|
| 563 |
{
|
|
| 564 |
mData[i] = ( mData[i] <= value ? 1 : 0 ); |
|
| 565 |
} |
|
| 566 |
break; |
|
| 411 | 567 |
} |
| 412 | 568 |
} |
| 413 | 569 |
return true; |
| ... | ... | |
| 415 | 571 | |
| 416 | 572 |
bool QgsRasterMatrix::testPowerValidity( double base, double power ) |
| 417 | 573 |
{
|
| 418 |
if (( base == 0 && power < 0 ) || ( power < 0 && ( power - floor( power ) ) > 0 ) )
|
|
| 574 |
if(( base == 0 && power < 0 ) || ( power < 0 && ( power - floor( power ) ) > 0 ) ) |
|
| 419 | 575 |
{
|
| 420 | 576 |
return false; |
| 421 | 577 |
} |
| src/analysis/raster/qgsrastercalcnode.cpp (Arbeitskopie) | ||
|---|---|---|
| 18 | 18 | |
| 19 | 19 |
QgsRasterCalcNode::~QgsRasterCalcNode() |
| 20 | 20 |
{
|
| 21 |
if ( mLeft )
|
|
| 21 |
if( mLeft ) |
|
| 22 | 22 |
{
|
| 23 | 23 |
delete mLeft; |
| 24 | 24 |
} |
| 25 |
if ( mRight )
|
|
| 25 |
if( mRight ) |
|
| 26 | 26 |
{
|
| 27 | 27 |
delete mRight; |
| 28 | 28 |
} |
| ... | ... | |
| 33 | 33 |
//if type is raster ref: return a copy of the corresponding matrix |
| 34 | 34 | |
| 35 | 35 |
//if type is operator, call the proper matrix operations |
| 36 |
if ( mType == tRasterRef )
|
|
| 36 |
if( mType == tRasterRef ) |
|
| 37 | 37 |
{
|
| 38 | 38 |
QMap<QString, QgsRasterMatrix*>::iterator it = rasterData.find( mRasterName ); |
| 39 |
if ( it == rasterData.end() )
|
|
| 39 |
if( it == rasterData.end() ) |
|
| 40 | 40 |
{
|
| 41 | 41 |
return false; |
| 42 | 42 |
} |
| ... | ... | |
| 47 | 47 |
result.setData(( *it )->nColumns(), ( *it )->nRows(), data ); |
| 48 | 48 |
return true; |
| 49 | 49 |
} |
| 50 |
else if ( mType == tOperator )
|
|
| 50 |
else if( mType == tOperator ) |
|
| 51 | 51 |
{
|
| 52 | 52 |
QgsRasterMatrix leftMatrix, rightMatrix; |
| 53 | 53 |
QgsRasterMatrix resultMatrix; |
| 54 |
if ( !mLeft || !mLeft->calculate( rasterData, leftMatrix ) )
|
|
| 54 |
if( !mLeft || !mLeft->calculate( rasterData, leftMatrix ) ) |
|
| 55 | 55 |
{
|
| 56 | 56 |
return false; |
| 57 | 57 |
} |
| 58 |
if ( mRight && !mRight->calculate( rasterData, rightMatrix ) )
|
|
| 58 |
if( mRight && !mRight->calculate( rasterData, rightMatrix ) ) |
|
| 59 | 59 |
{
|
| 60 | 60 |
return false; |
| 61 | 61 |
} |
| 62 | 62 | |
| 63 |
switch ( mOperator )
|
|
| 63 |
switch( mOperator ) |
|
| 64 | 64 |
{
|
| 65 | 65 |
case opPLUS: |
| 66 | 66 |
leftMatrix.add( rightMatrix ); |
| ... | ... | |
| 77 | 77 |
case opPOW: |
| 78 | 78 |
leftMatrix.power( rightMatrix ); |
| 79 | 79 |
break; |
| 80 |
case opEQ: |
|
| 81 |
leftMatrix.equal( rightMatrix ); |
|
| 82 |
break; |
|
| 83 |
case opNE: |
|
| 84 |
leftMatrix.notEqual( rightMatrix ); |
|
| 85 |
break; |
|
| 86 |
case opGT: |
|
| 87 |
leftMatrix.greaterThan( rightMatrix ); |
|
| 88 |
break; |
|
| 89 |
case opLT: |
|
| 90 |
leftMatrix.lesserThan( rightMatrix ); |
|
| 91 |
break; |
|
| 92 |
case opGE: |
|
| 93 |
leftMatrix.greaterEqual( rightMatrix ); |
|
| 94 |
break; |
|
| 95 |
case opLE: |
|
| 96 |
leftMatrix.lesserEqual( rightMatrix ); |
|
| 97 |
break; |
|
| 80 | 98 |
case opSQRT: |
| 81 | 99 |
leftMatrix.squareRoot(); |
| 82 | 100 |
break; |
| ... | ... | |
| 106 | 124 |
result.setData( newNColumns, newNRows, leftMatrix.takeData() ); |
| 107 | 125 |
return true; |
| 108 | 126 |
} |
| 109 |
else if ( mType == tNumber )
|
|
| 127 |
else if( mType == tNumber ) |
|
| 110 | 128 |
{
|
| 111 | 129 |
float* data = new float[1]; |
| 112 | 130 |
data[0] = mNumber; |
| ... | ... | |
| 118 | 136 | |
| 119 | 137 |
QgsRasterCalcNode* QgsRasterCalcNode::parseRasterCalcString( const QString& str, QString& parserErrorMsg ) |
| 120 | 138 |
{
|
| 121 |
extern QgsRasterCalcNode* localParseRasterCalcString( const QString& str, QString& parserErrorMsg );
|
|
| 139 |
extern QgsRasterCalcNode* localParseRasterCalcString( const QString & str, QString & parserErrorMsg );
|
|
| 122 | 140 |
return localParseRasterCalcString( str, parserErrorMsg ); |
| 123 | 141 |
} |
| 124 | 142 | |
| src/analysis/raster/qgsrastermatrix.h (Arbeitskopie) | ||
|---|---|---|
| 29 | 29 |
opMUL, |
| 30 | 30 |
opDIV, |
| 31 | 31 |
opPOW, |
| 32 |
opEQ, // = |
|
| 33 |
opNE, // != resp. <> |
|
| 34 |
opGT, // > |
|
| 35 |
opLT, // < |
|
| 36 |
opGE, // >= |
|
| 37 |
opLE, // <= |
|
| 32 | 38 |
}; |
| 33 | 39 | |
| 34 | 40 |
enum OneArgOperator |
| ... | ... | |
| 39 | 45 |
opTAN, |
| 40 | 46 |
opASIN, |
| 41 | 47 |
opACOS, |
| 42 |
opATAN |
|
| 48 |
opATAN,
|
|
| 43 | 49 |
}; |
| 44 | 50 | |
| 45 | 51 |
/**Takes ownership of data array*/ |
| ... | ... | |
| 70 | 76 |
bool multiply( const QgsRasterMatrix& other ); |
| 71 | 77 |
bool divide( const QgsRasterMatrix& other ); |
| 72 | 78 |
bool power( const QgsRasterMatrix& other ); |
| 79 |
bool equal( const QgsRasterMatrix& other ); |
|
| 80 |
bool notEqual( const QgsRasterMatrix& other ); |
|
| 81 |
bool greaterThan( const QgsRasterMatrix& other ); |
|
| 82 |
bool lesserThan( const QgsRasterMatrix& other ); |
|
| 83 |
bool greaterEqual( const QgsRasterMatrix& other ); |
|
| 84 |
bool lesserEqual( const QgsRasterMatrix& other ); |
|
| 73 | 85 | |
| 74 | 86 |
bool squareRoot(); |
| 75 | 87 |
bool sinus(); |
| src/analysis/raster/qgsrastercalcnode.h (Arbeitskopie) | ||
|---|---|---|
| 48 | 48 |
opTAN, |
| 49 | 49 |
opASIN, |
| 50 | 50 |
opACOS, |
| 51 |
opATAN |
|
| 51 |
opATAN, |
|
| 52 |
opEQ, // = |
|
| 53 |
opNE, //!= |
|
| 54 |
opGT, // > |
|
| 55 |
opLT, // < |
|
| 56 |
opGE, // >= |
|
| 57 |
opLE, // <= |
|
| 52 | 58 |
}; |
| 53 | 59 | |
| 54 | 60 |
QgsRasterCalcNode(); |
| src/analysis/raster/qgsrastercalclexer.ll (Arbeitskopie) | ||
|---|---|---|
| 58 | 58 |
"acos" { rasterlval.op = QgsRasterCalcNode::opACOS; return FUNCTION;}
|
| 59 | 59 |
"atan" { rasterlval.op = QgsRasterCalcNode::opATAN; return FUNCTION;}
|
| 60 | 60 | |
| 61 |
[+-/*^] { return yytext[0]; }
|
|
| 61 |
"!=" { return NE; }
|
|
| 62 |
"<=" { return LE; }
|
|
| 63 |
">=" { return GE; }
|
|
| 62 | 64 | |
| 65 |
[=><+-/*^] { return yytext[0]; }
|
|
| 66 | ||
| 67 | ||
| 63 | 68 |
[()] { return yytext[0]; }
|
| 64 | 69 | |
| 65 | 70 |
{number} { rasterlval.number = atof(rastertext); return NUMBER; }
|
| src/analysis/raster/qgsrastercalcparser.yy (Arbeitskopie) | ||
|---|---|---|
| 55 | 55 |
%type <node> root |
| 56 | 56 |
%type <node> raster_exp |
| 57 | 57 | |
| 58 |
%left NE |
|
| 59 |
%left GE |
|
| 60 |
%left LE |
|
| 61 | ||
| 62 |
%left '=' '<' '>' |
|
| 58 | 63 |
%left '+' '-' |
| 59 | 64 |
%left '*' '/' |
| 60 | 65 |
%left '^' |
| ... | ... | |
| 66 | 71 | |
| 67 | 72 |
raster_exp: |
| 68 | 73 |
FUNCTION '(' raster_exp ')' { $$ = new QgsRasterCalcNode($1, $3, 0); joinTmpNodes($$, $3, 0);}
|
| 74 |
| raster_exp '=' raster_exp { $$ = new QgsRasterCalcNode( QgsRasterCalcNode::opEQ, $1, $3 ); joinTmpNodes($$,$1,$3); }
|
|
| 75 |
| raster_exp NE raster_exp { $$ = new QgsRasterCalcNode( QgsRasterCalcNode::opNE, $1, $3 ); joinTmpNodes($$,$1,$3); }
|
|
| 76 |
| raster_exp '>' raster_exp { $$ = new QgsRasterCalcNode( QgsRasterCalcNode::opGT, $1, $3 ); joinTmpNodes($$, $1, $3); }
|
|
| 77 |
| raster_exp '<' raster_exp { $$ = new QgsRasterCalcNode( QgsRasterCalcNode::opLT, $1, $3 ); joinTmpNodes($$, $1, $3); }
|
|
| 78 |
| raster_exp GE raster_exp { $$ = new QgsRasterCalcNode( QgsRasterCalcNode::opGE, $1, $3 ); joinTmpNodes($$, $1, $3); }
|
|
| 79 |
| raster_exp LE raster_exp { $$ = new QgsRasterCalcNode( QgsRasterCalcNode::opLE, $1, $3 ); joinTmpNodes($$, $1, $3); }
|
|
| 69 | 80 |
| raster_exp '^' raster_exp { $$ = new QgsRasterCalcNode(QgsRasterCalcNode::opPOW, $1, $3); joinTmpNodes($$,$1,$3); }
|
| 70 | 81 |
| raster_exp '*' raster_exp { $$ = new QgsRasterCalcNode(QgsRasterCalcNode::opMUL, $1, $3); joinTmpNodes($$,$1,$3); }
|
| 71 | 82 |
| raster_exp '/' raster_exp { $$ = new QgsRasterCalcNode(QgsRasterCalcNode::opDIV, $1, $3); joinTmpNodes($$,$1,$3); }
|