TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ronjonp on March 03, 2006, 02:09:48 PM
-
I assembled this routine the other day to read TFW files to scale and place associated images correctly in AutoCAD. Thought someone might find it useful. Critisism is welcome as I already know it is far from perfect. ;D
*Updated 04-12-2011 ... Code will now write TFW files for selected images as well as support rotation.
*Update 10-11-2011 ... BUG FIX for basepoint placement.
-
Five years after the fact, but this turned out to be very useful. Thanks Ron :-D
-
Five years after the fact, but this turned out to be very useful. Thanks Ron :-D
Glad you could use it :) .. if you're interested, I'll post updated code to include rotations other than 0 and an option to write out the TFW file.
-
Five years after the fact, but this turned out to be very useful. Thanks Ron :-D
Glad you could use it :) .. if you're interested, I'll post updated code to include rotations other than 0 and an option to write out the TFW file.
I wouldn't say no :) I don't have a direct use for it at the moment but you never know when these things will come in handy.
Cheers!
-
Code has been updated ... enjoy :-)
-
hello, new guy here :)
I´ve been searching for days for a way to create tfw files for tif files in autocad and just found your post :D
I´m by no means pro and don´t mean to complain but the tfw file created by your routine is slightly diferent from what i supose it should be. Let me explain:
The last 2 lines of the tfw regarding the insertion coords are diferent from what i have. From what i was told on the x coordinate one needs to add half the value of ScaleX and in the y coordinate one needs to subtract half the value of ScaleY. (Hope this makes sense) I´ll give you an example of a tfw we have here and a tfw your lisp created:
Our tfw
0.200000
0.000000
-0.000000
-0.200000
55147.12762217
17048.62172333
Your tfw
0.200000
0.000000
-0.000000
-0.200000
55147.027622
17048.721723
So if, using Autocad MAP 3D, I insert the image using your tfw, it will be 0.1meters off.
Anyways, thanks a lot for your lisp :)
-
hello, new guy here :)...
Our tfw
0.200000
0.000000
-0.000000
-0.200000
55147.12762217
17048.62172333
Your tfw
0.200000
0.000000
-0.000000
-0.200000
55147.027622
17048.721723
So if, using Autocad MAP 3D, I insert the image using your tfw, it will be 0.1meters off...
Definition
Graphical view of world files parameters and computed values of the four first upper left pixels of an image.
World files do not specify a coordinate system; this information is generally stored somewhere else in the raster file itself or in another companion file. The generic meaning of world file parameters are:
Line 1: A: pixel size in the x-direction in map units/pixel
Line 2: D: rotation about y-axis
Line 3: B: rotation about x-axis
Line 4: E: pixel size in the y-direction in map units, almost always negative[3]
Line 5: C: x-coordinate of the center of the upper left pixel
Line 6: F: y-coordinate of the center of the upper left pixel
You're right! I always thought it was the top left corner of the image (top left of the top left pixel) As your example points out, it's not too big a deal with an image where one pixel is .2 meters, but with an image where 1 pixel is 3 meters, the error is measurable in the field.
I'm no LISP ninja like RonJon, but I know he's still around... hopefully he'll fix it. Talk about nit-picky, .5 pixels!! :D
-
nunopotier,
Thanks for the bug catch :ugly: and welcome to the swamp :-D. I've updated the code above to correct the insertion point based on the resolution.
-
hurray :D
I´m the one that says thank you, since you saved me quite a bit of work :)
-
Please test it out and make sure you're getting accurate results.
-
Alright so i tested it out and now the insertion point is working as it should :D
But, and not sure why, something is strange with the scale X and Y now.
0.1999999999997454
0
0
-0.1999999999997454
55174.88013481361
17070.99252425073
The image in autocad has 1189 width and 841 height and in pixels it has 5945 x 4205.
dividing 1189 by 5945 should give me 0.2 of scale and not 0.1999999999997454
same for 841 / 4205 = 0.2
As it is it works for me since i can´t really see anything wrong with the image inserted. Seems to be perfect even zooming in a lot, probably because 0.1999999999997454 is just allllllmmmmoooosst 0.2 lol
Anyways thanks for fixing it, let me know if you tune it up again and need a tester :)
-
I would say that would be the result of (rtos 2 16) combined with the rounding of doubles :wink: