georeferencing Tiff

georeferencing Tiff

dani-perez
Advocate Advocate
3,108 Views
14 Replies
Message 1 of 15

georeferencing Tiff

dani-perez
Advocate
Advocate

Hello all,

 

I am trying to georeference tiff images with a lisp, I found this lisp

 

; #######################################################################
;
; 		Inserta una imagen TIFF georreferenciada
;
;                 Autor: Francisco Navarrete Mandly
;	  		    Noviembre 2001
; 
; #######################################################################

(defun C:INSIMG (/ fichtif fichtfw fp ex ey rx ry x0 y0 ent info dimx dimy)

	; Pide ficheros
	(if (not (setq fichtif (getfiled "Imagen a Insertar" "*" "tif" 2))) (exit))
	(setq fichtfw (strcat (substr fichtif 1 (- (strlen fichtif) 2)) "fw"))

	; Lee parametros
	(setq fp (open fichtfw "r"))
	(setq ex (atof (read-line fp)))
	(setq rx (read-line fp))
	(setq ry (read-line fp))
	(setq ey (atof (read-line fp)))
	(setq x0 (atof (read-line fp)))
	(setq y0 (atof (read-line fp)))
	(close fp)
	(setq ey (* ey -1))

	; Inserta imagen
	(command "._-IMAGE" "" fichtif (list x0 y0) 1.0 0.0)

	; Modifica posicion
	(setq ent (entlast))
	(setq info (entget ent))
	(setq nx (cadr (assoc 13 info)) ny (caddr (assoc 13 info)))
	(setq dimx (* nx ex) dimy (* ny ey))
	(setq y0 (- y0 dimy))
	(setq info (subst (list 10 x0 y0 0.0) (assoc 10 info) info))

	; Modifica tamaño
	(setq info (subst (list 11 ex 0.0 0.0) (assoc 11 info) info))
	(setq info (subst (list 12 0.0 ey 0.0) (assoc 12 info) info))
	(entmod info)
	
	(princ)
)

But when I am trying to insert a tiff image I get an error: "Stringp nil"

 

I have been trying to fix the code but I don't know

 

Thanks all.

 

0 Likes
Accepted solutions (1)
3,109 Views
14 Replies
Replies (14)
Message 2 of 15

vladimir_michl
Advisor
Advisor
0 Likes
Message 3 of 15

Moshe-A
Mentor
Mentor

@dani-perez  hi,

 

you want to attach image with lisp? why IMAGEATTACH is not enough? 

 

anyhow this lisp can attach only one specific tif file, position and scale it base on some data text file contains these parameters. why i think it's only one specific? cause the data text file name is base on the image name plus "fw" and i can not image the author has prepared such data files to any image.

 

so when you say i found this lisp? are you sure you want to use it?

 

moshe

 

0 Likes
Message 4 of 15

ronjonp
Advisor
Advisor

You could try using THIS very old code.

0 Likes
Message 5 of 15

dani-perez
Advocate
Advocate

Hello 

 

I have other doubt: if the file has georreference metadata (as .ECW) is there a way to attach it at the correct coordinates using autocad if you dont have any worldfile? not civil3d or autocad map

0 Likes
Message 6 of 15

dani-perez
Advocate
Advocate

Hello Moshe-A

 

Thanks for replying.

With the codes posted by vladimir and rperez, I can attach a raster image in its correct georreference position using a wordfile. It's a very interesting step.

 

My idea is to attach an image and place it in its position (ortophoto for example). Now my idea is to attach it without that wordfile (just internal metadata) in order to solve all posibilities of this issue.

 

Thanks

0 Likes
Message 7 of 15

CodeDing
Advisor
Advisor

@dani-perez ,

 

What version/year of AutoCAD are you using? Ex: Civil 3D 2018? AutoCAD 2016? LT 2019?

0 Likes
Message 8 of 15

dani-perez
Advocate
Advocate

Hello CodeDing,

 

I am using AutoCAD 2019.

0 Likes
Message 9 of 15

CodeDing
Advisor
Advisor
Accepted solution

@dani-perez ,

 

In that case, I will not be offering a specific answer to your particular request but...

 

Unless you are being directly tasked with using your TIF, there are 2 perfectly acceptable alternative methods that I highly recommend...

 

1) AutoCAD's BING maps.

- since you have AutoCAD 2019, you have their built-in BING maps that allows you to import worldwide data using a selected coordinate system.

- With your assigned coordinate system, you can use other "GEO-" prefixed commands to interact with your coordinate system.

- Use the GEO command, but first be sure you are logged in to your Autodesk account...

image.png

 

2) Use ArcGIS for AutoCAD. ESRI and Autodesk have teamed up to bring you an awesome end-user experience for importing and saving maps within your drawings.

- the coordinate systems with ArcGIS are assigned to correct coordinates in model space, unlike having to choose with BING maps.

- you can snip and save raster-images of your selected coordinate system map. this allows you to move your map at-will if you would so like.

- Using ArcGIS also allows you to import ANY overlay that is available publicly from their REST services. You can link to a REST database and overlay their maps with more data than a basic map!

 

....... these 2 options are workflows that I use currently and they both allow for up-to-date imagery and ease-of-implementation. So in the essence of not trying to reinvent Civil 3D (somebody has already programmed coordinate systems for you! If you use coordinate systems frequently, just upgrade your license), you could use one or both of these methods to get your desired outcome.

 

Hope this helps.

 

Best,

~DD

 

 

0 Likes
Message 10 of 15

dani_cs
Advocate
Advocate

I downloaded the code but it is not working. Could anyone have a look?

0 Likes
Message 11 of 15

hak_vz
Advisor
Advisor

I just checked the code from original poster and it works ok.

What you need is Tiff file and corresponding tfw file with the same name as the tiff file.

Let say 221-4-3.tif and 221-4-3.tfw

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 12 of 15

dani_cs
Advocate
Advocate

Hello,

 

I try to load the lisp, but it gives me an error (translated from Spanish): "Error: wrong format input list"

0 Likes
Message 13 of 15

ronjonp
Advisor
Advisor

@dani_cs I've been using this code for years without issue.

0 Likes
Message 14 of 15

F.Camargo
Advisor
Advisor

Hello @ronjonp 

Could you please help me how to use your code?


I don't undersand about .twf file.


Thanks

0 Likes
Message 15 of 15

ronjonp
Advisor
Advisor

@F.Camargo The TFW file should be included with your aerial. It needs to have the same name as the TIF file and the code should correctly scale the image.

0 Likes