Author Topic: Insert image GeoTiff  (Read 7931 times)

0 Members and 1 Guest are viewing this topic.

FELIX

  • Bull Frog
  • Posts: 241
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

  • Water Moccasin
  • Posts: 1631
  • 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

  • Bull Frog
  • Posts: 241
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: 185
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.         (progn
  20.           ;;(dumpall iprop)
  21.           (setq idata (getall iprop))
  22.           (princ "\nData")
  23.           ;;(dumpall idata)
  24.         ) ;_ end of progn
  25.       ) ;_ end of if
  26.  ;_ end of if
  27.     ) ;_ end of progn
  28.   ) ;_ end of if
  29. (rel)
  30. idata
  31. ) ;_ end of defun
  32.  
  33. (defun getall (collection / err x valuelist name prop)
  34.   (vlax-for x collection
  35.     (setq name (vl-catch-all-apply '(lambda nil (vlax-get-property x 'name))))
  36.     (setq prop (vl-catch-all-apply '(lambda nil (vlax-variant-value (vlax-get-property x 'value)))))
  37.       (setq valuelist (cons (cons name prop) valuelist))
  38.     ) ;_ end of if
  39.     ;;(vlax-dump-object x T)
  40.  ;_ end of setq
  41.   ) ;_ end of vlax-for
  42.   (if (listp valuelist)
  43.     ;;(null (vl-catch-all-error-p err))
  44.     (reverse valuelist)
  45.   ) ;_ end of if
  46. ) ;_ end of defun
  47. (defun rel ()
  48.   (foreach obj (list iprop imgObj)
  49.     (if (= 'vla-object (type obj))
  50.       (vlax-release-object obj)
  51.     ) ;_ end of if
  52.   ) ;_ end of foreach
  53. )
  54.  
  55.  
"All models are wrong, some models are useful" - George Box

FELIX

  • Bull Frog
  • Posts: 241
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: 185
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.
"All models are wrong, some models are useful" - George Box

FELIX

  • Bull Frog
  • Posts: 241
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

  • Bull Frog
  • Posts: 241
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: 185
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.
"All models are wrong, some models are useful" - George Box

FELIX

  • Bull Frog
  • Posts: 241
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: 185
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?
"All models are wrong, some models are useful" - George Box

Rod

  • Newt
  • Posts: 185
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
"All models are wrong, some models are useful" - George Box

FELIX

  • Bull Frog
  • Posts: 241
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: 636
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

  • Bull Frog
  • Posts: 241
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.