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

0 Members and 2 Guests are viewing this topic.

ML

  • Guest
Clip Boundaries for a Raster
« on: November 13, 2007, 03:04:49 PM »

I am having a bit of difficulty here, despite all my efforts
This is The VBA example, combined with some of my code
In the ClipPoints section, I kind of figured out what they are doing but after I insert my raster; the clip boundaries I set are not working.

I am inserting a raster at 0,0
Then I want to clip the raster to a 5', 5' Boundarie

Can someone tell me how I should correctly fill in the ClipPoints section (Points) to get that?

Thank you

Mark

Code: [Select]
Sub InstRast()

    Dim InsertPnt(0 To 2) As Double
    Dim scalefactor As Double
    Dim RotAngle As Double
    Dim Imgpth As String
    Dim Imgname As String
    Dim RastImg As AcadRasterImage
   
    Imgpth = "K:\AutoCAD\Work Related\"
    Imgname = "FtWashington600.tif"
   
    InsertPnt(0) = 0#: InsertPnt(1) = 0#: InsertPnt(2) = 0#
    scalefactor = 12#
    rotationAngle = 0
   
    On Error Resume Next
   
    Set RastImg = ThisDrawing.PaperSpace.AddRaster(Imgpth & Imgname, InsertPnt, scalefactor, RotAngle)
   
    RastImg.Name = Imgname
    RastImg.Name = Left(Imgname, Len(Imgname) - 4)
   
    If Err.Description = "Filer error" Then
        MsgBox ImageName & " could not be found."
        Exit Sub
    End If
   
    ZoomAll
       
    ' Establish the clip boundary with an array of points
    Dim clipPoints(0 To 9) As Double
    clipPoints(0) = 6: clipPoints(1) = 6.75
    clipPoints(2) = 7: clipPoints(3) = 6
    clipPoints(4) = 6: clipPoints(5) = 5
    clipPoints(6) = 5: clipPoints(7) = 6
    clipPoints(8) = 6: clipPoints(9) = 6.75
   
    ' Clip the image
    RastImg.ClipBoundary clipPoints
   
    ' Enable the display of the clip
    RastImg.ClippingEnabled = True
    ThisDrawing.Regen acActiveViewport
       
End Sub

Bob Wahr

  • Guest
Re: Clip Boundaries for a Raster
« Reply #1 on: November 13, 2007, 03:30:10 PM »
5'sq. centered on the image, from the insertion point, or something else?

From the insertion point would basically be
Code: [Select]
Sub InstRast()

    Dim InsertPnt(0 To 2) As Double
    Dim scalefactor As Double
    Dim RotAngle As Double
    Dim Imgpth As String
    Dim Imgname As String
    Dim RastImg As AcadRasterImage
   
    Imgpth = "K:\AutoCAD\Work Related\"
    Imgname = "FtWashington600.tif"
   
    InsertPnt(0) = 0#: InsertPnt(1) = 0#: InsertPnt(2) = 0#
    scalefactor = 12#
    rotationAngle = 0
   
    On Error Resume Next
   
    Set RastImg = ThisDrawing.PaperSpace.AddRaster(Imgpth & Imgname, InsertPnt, scalefactor, RotAngle)
   
    RastImg.Name = Imgname
    RastImg.Name = Left(Imgname, Len(Imgname) - 4)
   
    If Err.Description = "Filer error" Then
        MsgBox ImageName & " could not be found."
        Exit Sub
    End If
   
    ZoomAll
       
    ' Establish the clip boundary with an array of points
    Dim clipPoints(0 To 9) As Double
    clipPoints(0) = 0: clipPoints(1) = 0
    clipPoints(2) = 0: clipPoints(3) = 60
    clipPoints(4) = 60: clipPoints(5) = 60
    clipPoints(6) = 60: clipPoints(7) = 0
    clipPoints(8) = 0: clipPoints(9) = 0
   
    ' Clip the image
    RastImg.ClipBoundary clipPoints
   
    ' Enable the display of the clip
    RastImg.ClippingEnabled = True
    ThisDrawing.Regen acActiveViewport
       
End Sub

ML

  • Guest
Re: Clip Boundaries for a Raster
« Reply #2 on: November 13, 2007, 03:43:29 PM »

Bob;

Yes from insertion is fine.
I noticed you handled it in inches, I just changed the 60 to 5 as we are working in feet.
That is great! Thank you

Now I see how it is working!

It is going in a rect. direction bottom to top, left to right.

And that is where they get the 10 points from.

2 (points(x+y) x 4 sides = 8 + back to 0,0 = 10


Code: [Select]
Dim clipPoints(0 To 9) As Double
    clipPoints(0) = 0: clipPoints(1) = 0
    clipPoints(2) = 0: clipPoints(3) = 5
    clipPoints(4) = 5: clipPoints(5) = 5
    clipPoints(6) = 5: clipPoints(7) = 0
    clipPoints(8) = 0: clipPoints(9) = 0

Thanks you

Mark

Bob Wahr

  • Guest
Re: Clip Boundaries for a Raster
« Reply #3 on: November 13, 2007, 03:50:25 PM »
Wasn't sure what flavor you were so I went with inches.  I figured Civil would be smart enough to figure out the difference between feet and inches, Architects, probably not.

I don't think that it matters if you go clockwise or counter(anti)clockwise and I think it can be an irregular shape.  That's just a guess though, I haven't actually looked into it.  All you need to do is list XY coordinates to define a shape where the last point is the same as the first point.  The easiest way to do that is to think about how you would put a pline in without touching the mouse.

ML

  • Guest
Re: Clip Boundaries for a Raster
« Reply #4 on: November 13, 2007, 03:52:12 PM »

Yes you can do an irregular shape
Try VBA's Example, it is strange

Mark

Code: [Select]
Sub Example_ClippingEnabled()
    ' This example adds a raster image in model space.
    ' It then clips the image based on a clip boundary,
    ' and toggles the display of the clipping.
   
    Dim insertionPoint(0 To 2) As Double
    Dim scalefactor As Double
    Dim rotationAngle As Double
    Dim imageName As String
    Dim rasterObj As AcadRasterImage
   
    imageName = "C:\AutoCAD\sample\downtown.jpg"
    insertionPoint(0) = 5#: insertionPoint(1) = 5#: insertionPoint(2) = 0#
    scalefactor = 2#
    rotationAngle = 0
   
    On Error Resume Next
    ' Creates a raster image in model space
    Set rasterObj = ThisDrawing.ModelSpace.AddRaster(imageName, insertionPoint, scalefactor, rotationAngle)
   
    If Err.Description = "Filer error" Then
        MsgBox imageName & " could not be found."
        Exit Sub
    End If
   
    ZoomAll
    MsgBox "Clip the image?", , "ClipBoundary Example"
   
    ' Establish the clip boundary with an array of points
    Dim clipPoints(0 To 9) As Double
    clipPoints(0) = 6: clipPoints(1) = 6.75
    clipPoints(2) = 7: clipPoints(3) = 6
    clipPoints(4) = 6: clipPoints(5) = 5
    clipPoints(6) = 5: clipPoints(7) = 6
    clipPoints(8) = 6: clipPoints(9) = 6.75
   
    ' Clip the image
    rasterObj.clipBoundary clipPoints
   
    ' Enable the display of the clip
    rasterObj.ClippingEnabled = True
     ThisDrawing.Regen acActiveViewport
   MsgBox "Turn off the display of the clipped image.", , "ClippingEnabled Example"
   
    ' Disable the display of the clip
    rasterObj.ClippingEnabled = False
    ThisDrawing.Regen acActiveViewport
    MsgBox "Display off.", , "ClippingEnabled Example"
   
End Sub

Bob Wahr

  • Guest
Re: Clip Boundaries for a Raster
« Reply #5 on: November 13, 2007, 03:55:16 PM »
True.  Didn't actually mean irregular shape when I said it.  I meant more than four sided thingy.

ML

  • Guest
Re: Clip Boundaries for a Raster
« Reply #6 on: November 13, 2007, 04:25:50 PM »

Oh good point

Evidentially 4 sides are 10 points.
I would imagine you can do more but not sure

In ACAD, you can try the imageclip command if you are realy curious and see what it gives you

Mark

Bob Wahr

  • Guest
Re: Clip Boundaries for a Raster
« Reply #7 on: November 13, 2007, 08:54:28 PM »
Actually, 4 sides is 5 points.

Code: [Select]
1--------2
5        |
|        |
|        |
4--------3

Each point is defined by a coordinate.  Each coordinate is two ordinates (numbers), an X ordinate and a Y ordinate, so 0,1 is the first point, 2,3 the second, 4,5, the third, 6,7 the fourth, and 8,9 is the fifth which duplicates the first so that the boundary is closed.  Does that make sense to you?

ML

  • Guest
Re: Clip Boundaries for a Raster
« Reply #8 on: November 14, 2007, 09:56:30 AM »

Yes, of course it does and you are absolutely right
It is 5 point and 10 coorinates.

Thanks Bob! :)

ML

  • Guest
Re: Clip Boundaries for a Raster
« Reply #9 on: November 14, 2007, 02:51:03 PM »

Bob,
Let me ask you or anyone else this

I have this code

Code: [Select]
Dim llpnt As Variant 'lower left point
Dim urpnt As Variant 'upper right point

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

And I somehow need to make the lower left point and the upper right (picked) points of the raster = my 5' x 5' boundary that I defined with the clipboundary.
Any idea how I can make this happen?

Thank you

Mark

Bob Wahr

  • Guest
Re: Clip Boundaries for a Raster
« Reply #10 on: November 14, 2007, 03:07:24 PM »
Sure.  What you want to do is basically this
Code: [Select]
Dim llpnt As Variant 'lower left point
Dim urpnt As Variant 'upper right point

With ThisDrawing.Utility
 llpnt = .GetPoint(, vbCrLf & "Select Lower Left Point: ")
 urpnt = .GetPoint(, vbCrLf & "Select Upper Right Point: ")
End With
Dim clipPoints(0 To 9) As Double
    clipPoints(0) = llpnt(0): clipPoints(1) = llpnt(1)
    clipPoints(2) = llpnt(0): clipPoints(3) = urpnt(1)
    clipPoints(4) = urpnt(0): clipPoints(5) = urpnt(1)
    clipPoints(6) = urpnt(0): clipPoints(7) = llpnt(1)
    clipPoints(8) = llpnt(0): clipPoints(9) = llpnt(1)

ML

  • Guest
Re: Clip Boundaries for a Raster
« Reply #11 on: November 14, 2007, 03:17:41 PM »

Yes sir!

That was the ticket!

Thank you so much Bob!

Mark

ML

  • Guest
Re: Clip Boundaries for a Raster
« Reply #12 on: November 14, 2007, 03:50:49 PM »
Bob,
If you don't mind one more question?

That method works great for making the clip boundary your picked points.

Now check this out:

Code: [Select]
Dim llpnt As Variant 'lower left point
Dim urpnt As Variant 'upper right point

With ThisDrawing.Utility
 llpnt = .GetPoint(, vbCrLf & "Select Lower Left Point: ")
 urpnt = .GetPoint(, vbCrLf & "Select Upper Right Point: ")
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

I have my midpoint of the two picked points calculated;

Now I would like to make my clip boundary 5' from the midpoint in the x and y direction
Giving me a 5' x 5' clipboundary from the midpoint of the two picked points

I tried using your method to get it but no luck so far

Any ideas?

Thank you again

Mark


ML

  • Guest
Re: Clip Boundaries for a Raster
« Reply #13 on: November 14, 2007, 03:51:26 PM »

Do I still need 9 points?

Mark

ML

  • Guest
Re: Clip Boundaries for a Raster
« Reply #14 on: November 14, 2007, 03:54:10 PM »

Ooops sorry
It is midpoint +/- 30 in each direction

Mark