Leadtools Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
GeoKeys Property
See Also  Example
Leadtools Namespace > RasterImage Class : GeoKeys Property



The collection of GeoKeys used when reading and writing Geo TIFF files.

Syntax

Visual Basic (Declaration)  
Public ReadOnly Property GeoKeys As RasterCollection(Of RasterTagMetadata)
Visual Basic (Usage) Copy Code
Dim instance As RasterImage
Dim value As RasterCollection(Of RasterTagMetadata)
 
value = instance.GeoKeys
C#  
public RasterCollection<RasterTagMetadata> GeoKeys {get;}
C++/CLI  
public:
property RasterCollection<RasterTagMetadata>^ GeoKeys {
   RasterCollection<RasterTagMetadata>^ get();
}

Return Value

A collection of RasterTagMetadata GeoKeys used when reading and writing Geo TIFF files.

Example

Visual Basic Copy Code
Private Sub DisplayGeoKey(ByVal key As RasterTagMetadata)
   Select Case key.DataType
      Case RasterTagMetadataDataType.Ascii
         MessageBox.Show("Key " & key.Id.ToString() & " = " & key.ToAscii())
      Case RasterTagMetadataDataType.Byte
         MessageBox.Show("Key " & key.Id.ToString() & " = " & key.ToByte()(0).ToString())
   End Select
End Sub
Public Sub GeoKeysExample()
   RasterCodecs.Startup()
   Dim codecs As RasterCodecs = New RasterCodecs()
   Dim image As RasterImage = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1.CMP")

   ' Ascii
   Dim keyDataAscii As RasterTagMetadata = New RasterTagMetadata()
   ' set the GTCitationGeoKey key, for more info, refer to the Geo TIFF spec.
   keyDataAscii.Id = 1026
   keyDataAscii.DataType = RasterTagMetadataDataType.Ascii
   keyDataAscii.FromAscii("Test String")
   image.GeoKeys.Add(keyDataAscii)

   codecs.Options.Save.GeoKeys = True
   codecs.Save(image, LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1_GEOKEY.TIF", RasterImageFormat.GeoTiff, 0)

   ' load the GeoKeys together with the image
   Dim key As RasterTagMetadata = codecs.ReadGeoKey(LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1_GEOKEY.TIF", 1, keyDataAscii.Id)
   DisplayGeoKey(key)

   codecs.Dispose()
   RasterCodecs.Shutdown()
End Sub
C# Copy Code
private void DisplayGeoKey(RasterTagMetadata key) 

   switch(key.DataType) 
   { 
      case RasterTagMetadataDataType.Ascii: 
         MessageBox.Show("Key " + key.Id.ToString() + " = " + key.ToAscii()); 
         break; 
      case RasterTagMetadataDataType.Byte: 
         MessageBox.Show("Key " + key.Id.ToString() + " = " + key.ToByte()[0].ToString()); 
         break; 
   } 

public void GeoKeysExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   RasterImage image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1.CMP"); 
 
   // Ascii 
   RasterTagMetadata keyDataAscii = new RasterTagMetadata(); 
   // set the GTCitationGeoKey key, for more info, refer to the Geo TIFF spec. 
   keyDataAscii.Id = 1026; 
   keyDataAscii.DataType = RasterTagMetadataDataType.Ascii; 
   keyDataAscii.FromAscii("Test String"); 
   image.GeoKeys.Add(keyDataAscii); 
 
   codecs.Options.Save.GeoKeys = true; 
   codecs.Save(image, LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1_GEOKEY.TIF", RasterImageFormat.GeoTiff, 0); 
 
   // load the GeoKeys together with the image 
   RasterTagMetadata key = codecs.ReadGeoKey(LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1_GEOKEY.TIF", 1, keyDataAscii.Id); 
   DisplayGeoKey(key); 
 
   codecs.Dispose(); 
   RasterCodecs.Shutdown(); 
}

Remarks

GeoTIFF files are TIFF files containing a few extra TIFF tags describing the image location, scale at which the picture was taken and many other information useful for topographic applications.

Any GeoTIFF file that you save will include the GeoKey data set until you clear the GeoKey data. To save this data to a file, save RasterImageFormat.GeoTiff files.

For more information, refer to Implementing GeoKeys (GeoTIFF tags).

To write the GeoKey data directly to an existing file, call RasterCodecs.WriteGeoKey. Note that LEADTOOLS does not verify the validity of the GeoKeys that you set. It is your responsibility to make sure you write correct values according to the GeoTIFF specification.

You can manipulate the GeoKeys of an image by adding/removing RasterTagMetadata objects to this collection.

By setting the CodecsSaveOptions.GeoKeys property to true before calling RasterCodecs.Save, you can save the GeoKeys in this collection when the image is saved into a file.

By setting the CodecsLoadOptions.Markers property to true before calling RasterCodecs.Load, you can load all the markers (if any) into this collection when an image is loaded from a file.

You can use the RasterCodecs.WriteGeoKeys method to save GeoKeys tags directly to an existing file and the RasterCodecs.EnumGeoKeys to load the GeoKeys stored in an existing file.

For more information on GeoKeys, refer to Implementing GeoKeys (GeoTIFF tags).

For more information, refer to Non Image Data.

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also