Author Topic: Clip Boundaries for a Raster  (Read 32431 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: Clip Boundaries for a Raster
« Reply #15 on: November 14, 2007, 04:25:14 PM »
Yes, 30 +- in each direction, All 4 directions for calcing the points
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Bob Wahr

  • Guest
Re: Clip Boundaries for a Raster
« Reply #16 on: November 14, 2007, 04:30:04 PM »

Do I still need 9 points?

Mark
and yes, you still need an array (0 to 9), ten numbers for a 4 sided shape.  You need to close AFAIK*



*caveat - everything I'm giving you here is from reading what you have and typing a response that seems logical to me.  I'm not playing along on the home version.  Everything I'm giving you, I'm giving as guidelines.  It is most definitely NOT test and most likely not functioning code.

ML

  • Guest
Re: Clip Boundaries for a Raster
« Reply #17 on: November 14, 2007, 06:07:01 PM »

Cool

Thanks again guys!

Unfortunately I got pulled away for other things but I will certainly get back to it tomorrow

This is very cool stuff.

I appreciate all the help!

Mark

ML

  • Guest
Re: Clip Boundaries for a Raster
« Reply #18 on: November 14, 2007, 11:32:25 PM »

I thought I would give it a shot tonight but still no luck.
Starting from the midpoint, this is what I used but it did not work as I hoped

Code: [Select]
'Clip boundary = 2.5' from mdpnt to edges. 5' boundary
  clipPoints(0) = mdpnt(0) + 2.5: clipPoints(1) = mdpnt(1) + 2.5
  clipPoints(2) = mdpnt(0): clipPoints(3) = mdpnt(1)
  clipPoints(4) = mdpnt(0): clipPoints(5) = mdpnt(1) + 5
  clipPoints(6) = mdpnt(0) + 5: clipPoints(7) = mdpnt(1) + 5
  clipPoints(8) = mdpnt(0) + 5: clipPoints(9) = mdpnt(1)

Can someone please tell me where I am going wrong?

Thank you

Mark

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: Clip Boundaries for a Raster
« Reply #19 on: November 14, 2007, 11:36:17 PM »
what did u declare ClipPoints as? Integer, double ?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: Clip Boundaries for a Raster
« Reply #20 on: November 14, 2007, 11:36:40 PM »
Im also assuming your working in feet not inches
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

ML

  • Guest
Re: Clip Boundaries for a Raster
« Reply #21 on: November 15, 2007, 10:06:39 AM »

Hey CM,

I declared them as:

Dim clipPoints(0 To 9) As Double

And yes, you are correct; I am working in feet.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: Clip Boundaries for a Raster
« Reply #22 on: November 15, 2007, 10:12:45 AM »
Can someone please tell me where I am going wrong?
It looks like you are close, but you need to use some negative numbers as well to get the left side of the MidPt

OK, lets say for arguments sake, your user picks 10,10 for LL and 90,80 for UR
The midpoint of those 2 points is (X1+X2)/2 , (Y1+Y2)/2 = 10+90=100/2=50, 10+80=90/2=45 so the MP is 50,45 (with me so far?)
Now to center a 60x60 clip boundary on the point 50,45 you need to add 30 and subtract 30 from the appropriate points
So LL is going to be 20,15 and UR is 80,75 Does this make sense so far?

Given those 2 points, we can derive UpperLeft= 20,75 and LowerRight=80,15
thus the ClipBoundary points are from LL counterclockwise in order of X & Y=
LL pt (20,15)
LR pt (80,15)
UR pt (80,75)
UL pt (20,75)
LL again to close (20,15)
« Last Edit: November 15, 2007, 10:18:13 AM by CmdrDuh »
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

ML

  • Guest
Re: Clip Boundaries for a Raster
« Reply #23 on: November 15, 2007, 10:15:20 AM »

CM,
Let me give you more info;
This is not the entire module but the critical part:

OK, assume that the raster is already inserted,scaled and all of that stuff
Now we move onto prompting the user to pick two point on the raster

Code: [Select]
Dim llpnt As Variant  'lower left point
Dim urpnt As Variant  'upper right point
Dim mdpnt(0 To 2) As Double
Dim clipPoints(0 To 9) As Double

     
With ThisDrawing.Utility
 llpnt = .GetPoint(, vbCrLf & "Select Lower Left : ")
 urpnt = .GetPoint(, vbCrLf & "Select Upper Right: ")
End With

 mdpnt(0) = llpnt(0) + ((urpnt(0) - llpnt(0)) / 2) 'Midpoint (X) = (The point in the far left direction) - (The point in the far right direction) / 2
 mdpnt(1) = llpnt(1) + ((urpnt(1) - llpnt(1)) / 2) 'Midpoint (Y) = (The point in the far top direction) - (The point in the far bottom direction) / 2
 mdpnt(2) = 0 'Z = 0

[b]'Here is where I need help:[/b]
'Clip boundary = 2.5' from mdpnt to edges. 5' boundary
'  clipPoints(0) = mdpnt(0) - 2.5: clipPoints(1) = mdpnt(1) - 2.5
'  clipPoints(2) = mdpnt(0) + 0: clipPoints(3) = mdpnt(1) + 5
'  clipPoints(4) = mdpnt(0) + 5: clipPoints(5) = mdpnt(1) + 0
'  clipPoints(6) = mdpnt(0) + 0: clipPoints(7) = mdpnt(1) - 5
'  clipPoints(8) = mdpnt(0) - 5: clipPoints(9) = mdpnt(1) + 0

'Clip the image
RastImg.ClipBoundary clipPoints
   
'Enable the display of the clip
RastImg.ClippingEnabled = True
 
 
ThisDrawing.Regen acActiveViewport

Thanks
Mark

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: Clip Boundaries for a Raster
« Reply #24 on: November 15, 2007, 10:23:33 AM »
Code: [Select]
...
 mdpnt(0) = llpnt(0) + ((urpnt(0) - llpnt(0)) / 2) 'Midpoint (X) = (The point in the far left direction) - (The point in the far right direction) / 2
 mdpnt(1) = llpnt(1) + ((urpnt(1) - llpnt(1)) / 2) 'Midpoint (Y) = (The point in the far top direction) - (The point in the far bottom direction) / 2
 mdpnt(2) = 0 'Z = 0
.....
Thanks
Mark
This is where I see a problem.  I am having trouble following your logic in deriving the MP.  You just need (X1+X2)/2   Not (X1+(X2-X1))/2
I think your creating to small a number there.  Try changing to just (X1+X2)/2
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: Clip Boundaries for a Raster
« Reply #25 on: November 15, 2007, 10:27:05 AM »
Here is another thought, AND I dont know if this can be done through code!!  What if you just "drew" a rectangle through code, Which would need the MP and width/height both of which would be 60.  Can you pick existing rectangle and make a clipping window?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

ML

  • Guest
Re: Clip Boundaries for a Raster
« Reply #26 on: November 15, 2007, 10:30:52 AM »
OK,

I do understand your explanations CM and thank you.
As far as the midpoint; it seems to be working fine.
I'm not sure if you tried that code that I sent you yesterday; but here it is again.
Using this code, pick 2 simple points, like a 5' x 5' rectangle, lower left and upper right points, then look at your immediate window.
I think you will find that the midpoint is being calculated fine.
I will also try again to make sure

Mark

Code: [Select]
Sub Getpoints()

Dim llpnt As Variant 'lower left point
Dim urpnt As Variant 'upper right point
Dim xpnts As Variant
Dim ypnts As Variant
Dim mdpnt(0 To 2) As Double

With ThisDrawing.Utility
 llpnt = .GetPoint(, vbCrLf & "Select Lower Left Limits of your Project Area: ")
 urpnt = .GetPoint(, vbCrLf & "Select Upper Right Limits of your Project Area: ")
End With

xpnts = llpnt(0) + urpnt(0)
ypnts = llpnt(1) + urpnt(1)

mdpnt(0) = llpnt(0) + ((urpnt(0) - llpnt(0)) / 2) 'Midpoint (X) = (The point in the far left direction) - (The point in the far right direction) / 2
mdpnt(1) = llpnt(1) + ((urpnt(1) - llpnt(1)) / 2) 'Midpoint (Y) = (The point in the far top direction) - (The point in the far bottom direction) / 2
mdpnt(2) = 0 'Z = 0

Debug.Print "Lower left point: "; llpnt(0) & "," & llpnt(1)
Debug.Print "Upper right point: "; urpnt(0) & "," & urpnt(1)
Debug.Print "Xpoints: "; xpnts
Debug.Print "Ypoints: "; ypnts
Debug.Print "Midpoint: "; mdpnt(0) & "," & mdpnt(1)

End Sub

ML

  • Guest
Re: Clip Boundaries for a Raster
« Reply #27 on: November 15, 2007, 10:33:14 AM »

I think what you are suggesting is this:

Code: [Select]
NewMidpnt = llpnt(0) + urpnt(0)\2
NewMidpnt = llpnt(1) + urpnt(1)\2

ML

  • Guest
Re: Clip Boundaries for a Raster
« Reply #28 on: November 15, 2007, 10:40:10 AM »

This is pretty cool too for getting points returned to you in the immediate window

Code: [Select]
Sub GetpointsAll()

Dim pnt1 As Variant
Dim pnt2 As Variant
Dim pnt3 As Variant
Dim pnt4 As Variant
Dim pnt5 As Variant
Dim pnt6 As Variant
Dim pnt7 As Variant
Dim pnt8 As Variant
Dim pnt9 As Variant

On Error Resume Next
With ThisDrawing.Utility
 pnt1 = .GetPoint(, vbCrLf & "pnt1 ")
 pnt2 = .GetPoint(, vbCrLf & "pnt2 ")
 pnt3 = .GetPoint(, vbCrLf & "pnt3 ")
 pnt4 = .GetPoint(, vbCrLf & "pnt4 ")
 pnt5 = .GetPoint(, vbCrLf & "pnt5 ")
 pnt6 = .GetPoint(, vbCrLf & "pnt6 ")
 pnt7 = .GetPoint(, vbCrLf & "pnt7 ")
 pnt8 = .GetPoint(, vbCrLf & "pnt8 ")
 pnt9 = .GetPoint(, vbCrLf & "pnt9 ")
End With


Debug.Print "Pnt1: "; pnt1(0) & "," & pnt1(1)
Debug.Print "Pnt2: "; pnt2(0) & "," & pnt2(1)
Debug.Print "Pnt3: "; pnt3(0) & "," & pnt3(1)
Debug.Print "Pnt4: "; pnt4(0) & "," & pnt4(1)
Debug.Print "Pnt5: "; pnt5(0) & "," & pnt5(1)
Debug.Print "Pnt6: "; pnt6(0) & "," & pnt6(1)
Debug.Print "Pnt7: "; pnt7(0) & "," & pnt7(1)
Debug.Print "Pnt8: "; pnt8(0) & "," & pnt8(1)
Debug.Print "Pnt9: "; pnt9(0) & "," & pnt9(1)

End Sub


The On Error Resume Next takes care of un picked points, you will just need to enter through any points you don't pick
So, for example; if you pick Pnt1,Pnt2,Pnt3 and Pnt4; you will need to press enter 5 times to get to the end of the sub.
I'm sure I could do more to address un picked points but this was just down and dirty to get some results

Mark

Bob Wahr

  • Guest
Re: Clip Boundaries for a Raster
« Reply #29 on: November 15, 2007, 11:04:27 AM »
Try this on for size.
Code: [Select]
Sub GetpointsAll()

Dim pnt As Variant
Dim i As Integer
On Error GoTo Boom
i = 1
Do
  pnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "pnt" & i)
  Debug.Print "Pnt" & i & ": "; pnt(0) & "," & pnt(1)
  i = i + 1
Loop

Boom:
  Select Case Err.Number
    Case Else
      Debug.Print Err.Number
      Err.Clear
      Exit Sub
  End Select
End Sub
will work if you need 1 or 100