Author Topic: Insert world tiff files  (Read 9989 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7526
Insert world tiff files
« 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.
« Last Edit: August 23, 2016, 09:06:13 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Daniel Eiszele

  • Newt
  • Posts: 85
Re: Insert world tiff files
« Reply #1 on: April 11, 2011, 06:56:24 AM »
Five years after the fact, but this turned out to be very useful.  Thanks Ron  :-D

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Insert world tiff files
« Reply #2 on: April 11, 2011, 10:34:23 AM »
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.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Daniel Eiszele

  • Newt
  • Posts: 85
Re: Insert world tiff files
« Reply #3 on: April 11, 2011, 06:47:35 PM »
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!

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Insert world tiff files
« Reply #4 on: April 12, 2011, 10:44:01 AM »
Code has been updated ... enjoy  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

nunopotier

  • Guest
Re: Insert world tiff files
« Reply #5 on: October 11, 2011, 10:15:39 AM »
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
Code: [Select]
0.200000
0.000000
-0.000000
-0.200000
55147.12762217
17048.62172333

Your tfw
Code: [Select]
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 :)

Atook

  • Swamp Rat
  • Posts: 1027
  • AKA Tim
Re: Insert world tiff files
« Reply #6 on: October 11, 2011, 10:44:51 AM »
hello, new guy here :)...
Our tfw
Code: [Select]
0.200000
0.000000
-0.000000
-0.200000
55147.12762217
17048.62172333
Your tfw
Code: [Select]
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...

Quote from: wikipedia
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

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Insert world tiff files
« Reply #7 on: October 11, 2011, 12:24:58 PM »
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.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

nunopotier

  • Guest
Re: Insert world tiff files
« Reply #8 on: October 11, 2011, 12:29:31 PM »
hurray :D

I´m the one that says thank you, since you saved me quite a bit of work :)

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Insert world tiff files
« Reply #9 on: October 11, 2011, 12:32:47 PM »
Please test it out and make sure you're getting accurate results.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

nunopotier

  • Guest
Re: Insert world tiff files
« Reply #10 on: October 11, 2011, 01:09:47 PM »
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.

Code: [Select]
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 :)

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Insert world tiff files
« Reply #11 on: October 11, 2011, 01:36:20 PM »
I would say that would be the result of (rtos 2 16) combined with the rounding of doubles  :wink: