Author Topic: Insert image GeoTiff  (Read 853 times)

0 Members and 1 Guest are viewing this topic.

FELIX

  • Newt
  • Posts: 167
Insert image GeoTiff
« on: January 31, 2019, 04:12:53 PM »
How to get the coordinates of a TIF (Geotiff) file. These coordinates are defined within the same Tif file because AutoCAD C3D with the MAPIINSERT command gets this information.
With these coordinates it is easy to insert inside AutoCAD.

Attached is a georeferenced TIF file and a file with the values of its coordinates ob- tained in AutoCAD C3D.
OK.

VovKa

  • Swamp Rat
  • Posts: 1087
  • Ukraine
Re: Insert image GeoTiff
« Reply #1 on: January 31, 2019, 05:27:36 PM »
the coordinates are stored as Exif data in 'Model Tie Point' key

FELIX

  • Newt
  • Posts: 167
Re: Insert image GeoTiff
« Reply #2 on: January 31, 2019, 08:22:57 PM »
Thanks Vovka but it does not help me anything because I need to first read the file and I do not know if I should do with Autolisp or if I should do with VB.NET
OK.

Rod

  • Newt
  • Posts: 109
Re: Insert image GeoTiff
« Reply #3 on: January 31, 2019, 10:09:59 PM »
This could be done with lisp (i think). My method uses the "Windows Image Aquisition" object so would only work with windows. You would also need to dig further into cracking open to Ivector Object.
The "Model tie point" is 33922 but again it is an Ivector object and you will need to work out how to extract the coordinates.
BTW 34737 is the coordinate system and 33550 is the pixel scale.

Here is the info I get

(("ImageWidth" . 1645)
("ImageHeight" . 4096)
("BitsPerSample" . #<VLA-OBJECT IVector 00000215fc6b81c0>)
("Compression" . 7)
("PhotometricInterp" . 2)
("SamplesPerPixel" . 3)
("PlanarConfig" . 1)
("TileWidth" . 256)
("TileLength" . 256)
("TileOffset" . #<VLA-OBJECT IVector 00000215fc6b8a10>)
("TileByteCounts" . #<VLA-OBJECT IVector 00000215fc6b8af0>)
("SampleFormat" . #<VLA-OBJECT IVector 00000215fc6b8d20>)
("347" . #<VLA-OBJECT IVector 00000215fc6b8ee0>)
("33550" . #<VLA-OBJECT IVector 00000215fc6b8c40>)
("33922" . #<VLA-OBJECT IVector 00000215fc6b8460>)
("34735" . #<VLA-OBJECT IVector 00000215fc6b8e00>)
("34736" . #<VLA-OBJECT IVector 00000215fc6b8150>)
("34737" . "SIRGAS-ROU98|SIRGAS-ROU98 / UTM zone 22S|"))

Code - Auto/Visual Lisp: [Select]
  1. (defun exifdata (file / idata)
  2.  ;;/ err idata iprop imgObj )
  3.  (if (and (setq file (findfile file))
  4.   (setq imgObj (vlax-create-object "WIA.Imagefile"))
  5.      ) ;_ end of and
  6.    (progn
  7.      (setq
  8. err (vl-catch-all-apply
  9.      (function
  10. (lambda nil
  11.  (vlax-invoke-method imgObj 'loadfile file)
  12.  (setq iprop (vlax-get-property imgObj 'properties))
  13.  (princ "\nProperties")
  14. ) ;_ end of lambda
  15.      ) ;_ end of function
  16.    ) ;_ end of vl-catch-all-apply
  17.      ) ;_ end of setq
  18.      (if (null (vl-catch-all-error-p err))
  19.  ;;(dumpall iprop)
  20.  (setq idata (getall iprop))
  21.  (princ "\nData")
  22.  ;;(dumpall idata)
  23. ) ;_ end of progn
  24.      ) ;_ end of if
  25. ;_ end of if
  26.    ) ;_ end of progn
  27.  ) ;_ end of if
  28. (rel)
  29. idata
  30. ) ;_ end of defun
  31.  
  32. (defun getall (collection / err x valuelist name prop)
  33.  (vlax-for x collection
  34.    (setq name (vl-catch-all-apply '(lambda nil (vlax-get-property x 'name))))
  35.    (setq prop (vl-catch-all-apply '(lambda nil (vlax-variant-value (vlax-get-property x 'value)))))
  36.      (setq valuelist (cons (cons name prop) valuelist))
  37.    ) ;_ end of if
  38.    ;;(vlax-dump-object x T)
  39. ;_ end of setq
  40.  ) ;_ end of vlax-for
  41.  (if (listp valuelist)
  42.    ;;(null (vl-catch-all-error-p err))
  43.    (reverse valuelist)
  44.  ) ;_ end of if
  45. ) ;_ end of defun
  46. (defun rel ()
  47.  (foreach obj (list iprop imgObj)
  48.    (if (= 'vla-object (type obj))
  49.      (vlax-release-object obj)
  50.    ) ;_ end of if
  51.  ) ;_ end of foreach
  52. )
  53.  
  54.  
Standing on the toes of giants.

FELIX

  • Newt
  • Posts: 167
Re: Insert image GeoTiff
« Reply #4 on: February 01, 2019, 08:44:52 AM »
Excellent, I was able to generate the list.

I researched but could not find how to convert: "VLA-OBJECT IVector", can you inform me how?
OK.

Rod

  • Newt
  • Posts: 109
Re: Insert image GeoTiff
« Reply #5 on: February 03, 2019, 07:01:24 PM »
It seems the vector (binary data) holds a single dimensions array of 48 digits they are (unsigned 8 bit one byte decimal) either ANSI or unicode
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
123 82 149 98 55 49 27 65
2 69 211 172 177 213 89 65
0 0 0 0 0 0 0 0

If you split this into groups of 8 digits it probably corresponds to these 6 numbers
0 0 0 445517.8462 6771539.4103 0

I'm not really sure how they are encoded. Hopefully someone else can help? I vaguely remember reading about big / little endianness.
Standing on the toes of giants.

FELIX

  • Newt
  • Posts: 167
Re: Insert image GeoTiff
« Reply #6 on: February 03, 2019, 09:39:12 PM »
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
123 82 149 98 55 49 27 65
2 69 211 172 177 213 89 65
0 0 0 0 0 0 0 0

where did you get these digits?
OK.

FELIX

  • Newt
  • Posts: 167
Re: Insert image GeoTiff
« Reply #7 on: February 03, 2019, 09:41:25 PM »
Code: [Select]
(setq arq "d:\\testegeo.tif")
(setq lista (exifdata arq))
(foreach ll lista (print ll))

(setq vl1 (cdr (assoc "33922" lista)))
(setq vl2 (cdr (assoc "34737" lista)))
(setq vl3 (cdr (assoc "33550" lista)))

(setq vpt1 (..... vl1)) ; how to convert to coordinate point?
(setq vpt2 (..... vl2)) ; how to convert to coordinate point?
(setq vpt3 (..... vl3)) ; how to convert to coordinate point
.
.
.
OK.

Rod

  • Newt
  • Posts: 109
Re: Insert image GeoTiff
« Reply #8 on: February 03, 2019, 10:49:47 PM »
I got the list from this (vlax-safearray->list(vlax-variant-value(VLAX-GET-PROPERTY (cdr(assoc "33922" idata)) 'binarydata)))

The value associated with 34737 is a string of the coorinate system
The vector assocaited with 33550 is the x and y of the pixel scale and could be encoded differently

sorry I can't help you more.
Standing on the toes of giants.

FELIX

  • Newt
  • Posts: 167
Re: Insert image GeoTiff
« Reply #9 on: February 04, 2019, 07:35:09 PM »
123 82 149   98   55   49 27 65     --> 445517.8462
    2 69 211 172 177 213 89 65   --> 6771539.4103

1     2   3     4     5    6    7   8

how did this conversion? No need to program just explain briefly.
 
OK.

Rod

  • Newt
  • Posts: 109
Re: Insert image GeoTiff
« Reply #10 on: February 04, 2019, 09:29:24 PM »
Hi Felix I'm sorry if I wasn't clear.

I don't know the answer.

My guess was that they correspond but I'm not sure how they are encoded.
Do you have other tiff files that are in different locations? How are you getting the TIff files. Are you able to create them yourself?
Standing on the toes of giants.

Rod

  • Newt
  • Posts: 109
Re: Insert image GeoTiff
« Reply #11 on: February 04, 2019, 11:32:37 PM »
This appears to be stored as a double-precision floating point 64 bit number
Standing on the toes of giants.

FELIX

  • Newt
  • Posts: 167
Re: Insert image GeoTiff
« Reply #12 on: February 05, 2019, 07:28:36 PM »
All right, Rod, I was able to do this temporarily with GDALINFO (https://www.gdal.org). When I have time I will try again for your tip. I'll post the conversion here on the forum, maybe Lee Mac has a good suggestion.
OK.

lamarn

  • Swamp Rat
  • Posts: 592
Re: Insert image GeoTiff
« Reply #13 on: February 06, 2019, 04:19:24 AM »
Hi Felix,

Are you familiar with Qgis?
You can load in a geotif and assign an CRS very quick.
After that you can turn the geotiff into a polygon and 3D mesh..

Design is something you should do with both hands. My 2d hand , my 3d hand ..

FELIX

  • Newt
  • Posts: 167
Re: Insert image GeoTiff
« Reply #14 on: February 06, 2019, 09:51:09 AM »
Hi Felix,

Are you familiar with Qgis?
You can load in a geotif and assign an CRS very quick.
After that you can turn the geotiff into a polygon and 3D mesh..

Thank you for participating Lamarn. I know the QGIS yes but I need to make a program to be used in AutoCAD.

ROD already answered me how to convert the coordinates into another topic I posted.
OK.