- Timestamp:
- May 19, 2019, 3:33:49 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/geometry_tools.py
r2545 r2546 428 428 yval: value to use to cut the polygon 429 429 keep: part to keep from the height ('bottom', default) 430 'bottom': below the height 431 'above': above the height 430 432 Nadd: additional points to add to draw the line (20, default) 431 433 """ … … 433 435 434 436 N = polygon.shape[0] 437 availkeeps = ['bottom', 'above'] 438 439 if not gen.searchInlist(availkeeps, keep): 440 print errormsg 441 print ' ' + fname + ": wring keep '" + keep + "' value !!" 442 print ' available ones:', availkeeps 443 quit(-1) 435 444 436 445 ipt = None … … 469 478 dd = yval - polygon[ip,0] 470 479 ipt = [yval, polygon[ip,1]+dx*dd/dy] 471 print ip, 'Lluis pi:', polygon[ip,:], 'pi+1', polygon[eep,:]472 print ' yval', yval, 'dx', dx, 'dy', dy473 print ' ipt', ipt474 480 475 481 if polygon[ip,0] >= yval and polygon[eep,0] <= yval: … … 479 485 dd = yval - polygon[ip,0] 480 486 ept = [yval, polygon[ip,1]+dx*dd/dy] 481 print ip, 'Lluis pi:', polygon[ip,:], 'pi+1', polygon[eep,:]482 print ' yval', yval, 'dx', dx, 'dy', dy483 print ' ept', ept484 487 485 488 if ipt is None or ept is None: … … 488 491 irmv = 0 489 492 rmpolygon = [] 490 for ip in range(N): 491 if polygon[ip,0] > yval: 492 rmpolygon.append([gen.fillValueF, gen.fillValueF]) 493 else: 494 rmpolygon.append(polygon[ip,:]) 493 if keep == 'bottom': 494 for ip in range(N): 495 if polygon[ip,0] > yval: 496 rmpolygon.append([gen.fillValueF, gen.fillValueF]) 497 else: 498 rmpolygon.append(polygon[ip,:]) 499 else: 500 for ip in range(N): 501 if polygon[ip,0] < yval: 502 rmpolygon.append([gen.fillValueF, gen.fillValueF]) 503 else: 504 rmpolygon.append(polygon[ip,:]) 505 495 506 Npts = len(rmpolygon) 496 507 cutpolygon = np.array(rmpolygon) 497 508 else: 498 Npts = icut + (N-ecut) + Nadd 499 500 cutpolygon = np.zeros((Npts,2), dtype=np.float) 501 if type(polygon) == type(gen.mamat): 502 cutpolygon[0:icut+1,:] = polygon[0:icut+1,:].filled(gen.fillValueF) 509 if keep == 'bottom': 510 Npts = icut + (N-ecut) + Nadd 511 512 cutpolygon = np.zeros((Npts,2), dtype=np.float) 513 if type(polygon) == type(gen.mamat): 514 cutpolygon[0:icut+1,:] = polygon[0:icut+1,:].filled(gen.fillValueF) 515 else: 516 cutpolygon[0:icut+1,:] = polygon[0:icut+1,:] 517 iip = icut+1 503 518 else: 504 cutpolygon[0:icut+1,:] = polygon[0:icut+1,:] 519 Npts = ecut - icut + Nadd-1 520 521 cutpolygon = np.zeros((Npts,2), dtype=np.float) 522 if type(polygon) == type(gen.mamat): 523 cutpolygon[0:ecut-icut-1,:] = polygon[icut+1:ecut,:].filled(gen.fillValueF) 524 else: 525 cutpolygon[0:ecut-icut-1,:] = polygon[icut+1:ecut,:] 526 iip = ecut-icut-1 505 527 506 528 # cutting line … … 512 534 cutline[ip,:] = ipt + np.array([dy*ip,dx*ip]) 513 535 cutline[Nadd-1,:] = ept 514 cutpolygon[icut+1:icut+1+Nadd,:] = cutline 515 cutpolygon[icut+1+Nadd:Npts,:] = polygon[ecut+1:N,:] 536 cutpolygon[iip:iip+Nadd,:] = cutline 537 if keep == 'bottom': 538 cutpolygon[iip+Nadd:Npts,:] = polygon[ecut+1:N,:] 516 539 517 540 cutpolygon = ma.masked_equal(cutpolygon, gen.fillValueF)
Note: See TracChangeset
for help on using the changeset viewer.