DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

Aligning/Rotating an Image so it matches GPS data:

Started by aqua, December 26, 2007, 06:16:13 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aqua

Designcad 13.13

The macro below uses different code to my other post on the subject

This macro can be utilised to align/scale/move an image so it aligns with other data - for example GPS data.

However- it will rotate the image in lots of whole degrees only
i.e it can't rotate data say 12.4 deg, it would rotate in 12 degrees.
This is a limit of the Designcad program and how it handles images.
The Designcad part that handles images was created by others.

In discussions sometime back - there was a method via macro code that could get around this.

Does anyone know the code that would solve this issue?


Regards Frank



'FTM-27/12/2007
'This function scales, moves and rotates an aerial or contour image so it aligns with GPS data
'User must Prepare the surveyor/gps data first, then have loaded and selected the image

'Disable other functions
sys(470)=1

'If image not selected - provide message plus then ensure image layers are unlocked, then end
Message "Align Image (scale-move-rotate) will rotate to the image to match your data. As a result - the image may not be square to the page"
If Sys(80) < 1 Then
    Message "You must select the image first! Select the image again then press F3"
layer(100)=6
layer(104)=6
    End
End If

'Check an image has been slected - and that only one item has been selected
GetSelect 1, j
GetAttr j, etype
If (etype <> 90) or (Sys(80)>1) Then
    Message "Please select ONLY the image to be aligned."
    End
End If

FirstPair:
SetPoint "Set a specific point on the survey data, then a matching point on the image: ", 2
If Sys(1) = 0 Then End
If Sys(1) < 2 Then Goto FirstPair

PointVal xd1 yd1 zd1 1
PointVal xi1 yi1 zi1 2

NextPair:
SetPoint "Set a second point on the survey data, and a matching point on the image: ", 2
If Sys(1)  = 0 Then End
If Sys(1) < 2 Then Goto NextPair

PointVal xd2 yd2 zd2 1
PointVal xi2 yi2 zi2 2

'Turn on silent mode
sys(36)=1
>SetHandle
{
    <Pointxyz [xi1, yi1, 0]
    <Pointxyz [xi2, yi2, 0]
}

dist1 = sqrt((xd2-xd1)*(xd2-xd1) + (yd2-yd1)*(yd2-yd1))
dist2 = sqrt((xi2-xi1)*(xi2-xi1) + (yi2-yi1)*(yi2-yi1))

angle1 = Angle(xd2-xd1, yd2-yd1)
angle2 = Angle(xi2-xi1, yi2-yi1)

factor = dist1/dist2
>SelectScaleOrtho
{
    <Zoomfactor [factor]
}

'Issue here: Only rotates in whole degrees:
'Need to adjust code so that it rotates exact correct amount

>Rotate
{
    <Pointxyz [xi1, yi1, 0]
    <Angle [angle1 - angle2]
    <Axis 2
    <Dragmode 0
}

>Move
{
    <Pointxyz [xd1, yd1, 0]
}

>MoveToBack
{
}

sys(80)=0
>Fittowindow
{
}
>Regenerate
{
}
'Turn off Silent Mode
sys(36)=0
End   

glking

Hi, Frank.

Although I have done a lot of Visual Basic programming, I never got into BasicCAD, so I'm pretty weak in that realm. 

I have, however, imported many an aerial photo or topographic map into my map-based DesignCAD projects...all done manually.  My method was to import the image into a blank DC drawing and to choose two points on the photo/topo image and set Drawing Handles.  I always put the image into the layer where I wanted it to end up in the primary drawing and saved the drawing.  I then merged it into the primary drawing using the LOAD SYMBOL command, setting points on the drawing that corresponded to the Drawing Handles.  Unclick the "use original scale" check box and Viola'! all the rotation and scaling was done.  Well, at least to the extent that the map and the image were in the same map projection to start with. 

Golden Software's "Didger 4" is an excellent program for georeferencing an image or translating an image from one projection to another.  For instance, you might start out by georeferencing an aerial photo using your GPS point data and then warping the image to a real map projection.  Of course, if you are working with small plats, this is probably all irrelevant.  My drawings typically cover at least a square mile and usually comprise much larger areas.

In any case, even when the image projection did not match the map projection, at least the Drawing Handles got set down in the primary drawing where I clicked.  That says to me that the LOAD SYMBOL command rotates in fractional degrees.

Gary King
Gary King
Earth-Data-Graphics

aqua

Gary

I saved the image as a seperate drawing - with handles - and with a box drawn around the edges of the image.

Then loaded this symbol - and aligned it to the GPS handles.

Image still locked into 1 degree amount - which the box confimed
i.e the box was now no longer exactly around the image.

Tried using block insert - no luck either

regards Frank

Lar

Frank, maybe you can use Texture Mapping (Tools menu) to map the image onto a plane of the size you need, then rotate the plane. You would have to switch to 3D mode for this.

Lar

bdeck

#4
I'm not certain I follow the intent here. You appear to be working in 2d.

Why not just lose the rotate and the zoom, and use the duplicate or move command to do the alignment and resizing?

Images aligned with duplicate or move do not appear to be limited to 1 degree increments in my versions.

See:

http://forum.designcad.com/index.php?topic=938.0

or

http://forum.designcad.com/index.php?topic=322.0

The rescale flag can be set in M macro, if needed.

aqua

Designcad 13.13

Just confirming - I have purchased versions 14, 15, 16, 17 & 18
However - myself and some clients I help are working with 13
13 is reliable and solid - with only a OLE freeze and this image 1 degree rotation limitation
Each of the new version hasn't offered anything new that we could make use of - and adds some new bugs as a bonus.
We live with the occasional OLE freeze because it is better than other issues in 18.


So I trying to align an image to existing data via scale/rotate/move.
i.e we load the image out to the right.
Then we need to scale it to match the existing data, rotate it as well, then move it into position.
i.e it will then sit underneath the existing data.

We normally set 2 points on the image that match 2 points on the data - 4 points in total.
From this we can calculate the scaling, rotation angle and the moving.

Yes - only working in 2D.

The limitation - Designcad 13 will only rotate an image in 1 degree increments.

The solution - well - sometime back  -a smart cookie who knew a fair amount about Designcad and macros - put forward some macro code that could get around this limitation.

I went with working plane rotations at the time - to get around the issue - because it would keep the image square to the page.
I still use working planes - however - now we have a need for this code.
Unfortunately - the old forum doesn't go back far enough - so the code appears lost.

I will review all the suggestions put forward - although I know some don't solve this issue as I have checked them out already.

Regards Frank

bdeck

Quote from: aqua on December 27, 2007, 06:12:27 PM
Designcad 13.13

Oops,

Sorry, I missed that.

I confirmed in my Version 14 that duping or pasting to a rotated workplane still restrains the image to 1 degree increments.

Seems even prl coundnt fix that problem in the old forum.

http://forums.upperspace.com/topic.asp?TOPIC_ID=4323&SearchTerms=workplane

BD






aqua

Designcad 13.13

I discovered how to access the archived post in the old forum.
Couldn't find the mystery code.

Designcad 13 is limited to rotating images in 1 deg increments.
Symbols, Blocks, Handles, Rotate, Move - none of these will defeat it

So we have had to look at it a second way.
Paint.net can rotate and crop images.

So my updated macro advises the rotation angle.
Then it opens Paintnet.

I run into the issue of the flexible path again - refer other post.
i.e I can start an outside program using run
But I can't use
run "C:\Program Files\Paint.NET\PaintDotNet.exe  Existingimagepath$"
as Paint.Net will be trying to open Existingimagepath$ rather than the path that this contains.

Does anyone know how to resolve this issue.

Regards Frank














'FTM-27/12/2007

'This function advises the rotation angle to align an image to existing data
'If image not selected - provide message plus then ensure image layers are unlocked, then end
Message "Align Image - Advise rotation angle will advise the angle to rotate the image to match your data. As a result - when you reload the image - the edges will not be square to the page unless you crop it as well."
If Sys(80) < 1 Then
    Message "You must select the image first! Select the image again then press F3"
layer(100)=6
layer(104)=6
    End
End If

'Check an image has been selected - and that only one item has been selected
GetSelect 1, j
GetAttr j, etype
If (etype <> 90) or (Sys(80)>1) Then
    Message "Please select ONLY the image to be aligned."
    End
End If

FirstPair:
SetPoint "Set a specific point on the survey data, then a matching point on the image: ", 2
If Sys(1) = 0 Then End
If Sys(1) < 2 Then Goto FirstPair

PointVal xd1 yd1 zd1 1
PointVal xi1 yi1 zi1 2

NextPair:
SetPoint "Set a second point on the survey data, and a matching point on the image: ", 2
If Sys(1)  = 0 Then End
If Sys(1) < 2 Then Goto NextPair

PointVal xd2 yd2 zd2 1
PointVal xi2 yi2 zi2 2

dist1 = sqrt((xd2-xd1)*(xd2-xd1) + (yd2-yd1)*(yd2-yd1))
dist2 = sqrt((xi2-xi1)*(xi2-xi1) + (yi2-yi1)*(yi2-yi1))

angle1 = Angle(xd2-xd1, yd2-yd1)
angle2 = Angle(xi2-xi1, yi2-yi1)

Precision 2
Imagerotationangle$ = angle1 - angle2
Message "Now open image with Paint.net and rotate by the angle:",Imagerotationangle$, " Then save this rotated version of the image and reload it into your drawing. Select the new image then use Align Image (Scale-Move). Delete the original image."

Macro complete to here - need to resolve the issue of basiccad starting outside programs then being able to use the flexible path

'Also need to identify full path of existing drawing
'Existingdrawingpath = sys$(2)

'Now remove drawing name from end
'Existingdrawingfolder$ =

'Need to identify file name of selected image
'Selectedimagename$ =

'Spacer$ = "/"

'Now need to put the above together
'Existingimagepath$ = Existingdrawingfolder$ + Spacer$ + Selectedimagename$

'Current code
run "C:\Program Files\Paint.NET\PaintDotNet.exe"

'Proposed code - need to resolve the issue of being able to run a flexible path for outside programs for the interested file
'run "C:\Program Files\Paint.NET\PaintDotNet.exe  Existingimagepath$"

aqua

Lar

designcad 13.13

Tried the texture mapping.
Could do it in 2D or 3D.

Texture Mapping disappears though as soon as you change your zoom.
Not sure if there is setting to keep this displayed.
Will not help if we can't see it all the time.

Regards Frank

DrollTroll

#9
Run command:

Try something like
pr$ = "C:\Windows\System32\mspaint.exe "
img$ = """C:\Documents and Settings\Current User\My Documents\My Pictures\sample.jpg""""
cmd$ = pr$, img$
Run cmd$
End


Note the extra quotes around the image path, which contained spaces. I'm not sure what you'll do if your exe path has spaces too -- maybe use the old 8.3 path notation (like "c:\progra~1\longpa~1\etc.exe")

Newer versions have better ways to format strings, and specify command lines for programs. But I know you've got your reasons for staying with 13.13.
25 years with DesignCAD

aqua

Droll Troll

What you have proposed is a hard wired path - i.e you have written the exact path down.
I am looking for a flexible path - which will vary depending on where the drawing/image etc is stored.
So I get a Filepath$ = "sys(20)$ + etc..."
I can run/start an outside program and I can get it to open a particular file if I give it a hardwired file path.
But put a variable path in - and it is then the outside program that is trying to understand basiccad.
It cannot understand what Filepath$ means - that isn't a file to it.

It appears that we need to write out the run command/file path to an outside mini program or create an exe. Then we have basic cad run the outside file we created - which knows to start which program and the file path.

Regards Frank

drgroen

Frank,

This may be a long way around, but how about....

1.  Writing write out a batch file into a fixed location (PaintNet.bat)

2.  The contents of the file would be something like

         C:\Program Files\Paint.NET\PaintDotNet.exe  Existingimagepath$

    You would of course replace the "Existingimagepath$" with its value.

3.  Run Paintnet.bat from BasicCad

HTH

Dave Groen



aqua

One thousand Apoligies to Droll Troll.
Actually - 998, I'LL take a couple off since you offered a fixed path


'My original code idea:
run ""C:\Program Files\Aquaflow\Folders\GPS Utility\gpsu420.exe  Textdrawingpath$"

This didn't work because GPSU couldn't recognize what Textrawingpath$ meant


Droll Troll's Suggestion
pr$ = "C:\Windows\System32\mspaint.exe "
img$ = """C:\Documents and Settings\Current User\My Documents\My Pictures\sample.jpg""""
cmd$ = pr$, img$
Run cmd$
End

This did not include the required flexible path - so didn't solve the issue


Revised Code: Droll Troll's with flexible path added
pr$ = "C:\Program Files\Aquaflow\Folders\GPS Utility\gpsu420.exe "
cmd$ = pr$, Textdrawingpath$
Run cmd$


Cheers Frank

[ ;D]

DrollTroll

I provided the hard-coded img$ path as an example only, to show how to put the two variables together.

Looks like you now have it surrounded, so glad I could help!
25 years with DesignCAD

Dr PR

aqua,

DesignCAD V15 does allow rotating bitmaps in fractions of a degree, at least in 0.01 degree incrememnts (maybe smaller).

I have used just about every version since Prodesign in 1987 and V15.3 is far and away the most stable version that I have seen. It also will save the drawing in V13 format. Have you tried working in V15 and then saving the drawing in V13? If so, does V13 reposition the bitmap to 1 degree rotation increments?
DesignCAD user since 1987