←Select platform

ReadGeoKey(Stream,int,int) Method

Summary
Gets the specified GeoKey data from a TIFF stream.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public RasterTagMetadata ReadGeoKey( 
   Stream stream, 
   int pageNumber, 
   int id 
) 
- (nullable LTRasterTagMetadata *)readGeoKey:(NSUInteger)tagId  
                                  fromStream:(LTLeadStream *)stream  
                                  pageNumber:(NSInteger)pageNumber  
                                       error:(NSError **)error 
public RasterTagMetadata readGeoKey(ILeadStream stream, int pageNumber, int id) 
public: 
RasterTagMetadata^ ReadGeoKey(  
   Stream^ stream, 
   int pageNumber, 
   int id 
)  
def ReadGeoKey(self,stream,pageNumber,id): 

Parameters

stream
A Stream containing the input file data.

pageNumber
1-based index of the page from which to read the GeoKey.

id
GeoKey ID. Values of the GeoKey ID range between 0 and 65535. Possible ranges are:

Range Meaning
0..1023 Do not use; reserved for future use.
1024..2047 GeoTIFF Configuration Keys.
2048..3071 Geographic/Geocentric CS Parameter Keys.
3072..4095 Projected CS Parameter Keys.
4096..5119 Vertical CS Parameter Keys.
5120..32767 Reserved.
32768..65535 Private use - use to store your own data.

Return Value

The GeoKey data.

Remarks

You can use this method to obtain the GeoKey data from a particular file.

If no such GeoKey exists in the image, this method will return a null reference.

The most efficient way of reading the GeoKeys in a file is to enumerate them with EnumGeoKeys and then read each GeoKey with ReadGeoKey.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
 
IList<RasterTagMetadata> myGeoKeys; 
 
 
void EnumGeoKeysExample(string srcFileName, string destFileName) 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   geoKeySrcFileName = srcFileName; 
   myGeoKeys = new List<RasterTagMetadata>(); 
 
   codecs.GeoKeyFound += new EventHandler<CodecsEnumGeoKeysEventArgs>(codecs_GeyKeyFound); 
   codecs.EnumGeoKeys(srcFileName, 1); 
   codecs.GeoKeyFound -= new EventHandler<CodecsEnumGeoKeysEventArgs>(codecs_GeyKeyFound); 
 
   // We read all the tags now, save them to the file 
   Debug.WriteLine("{0} GeoKeys read, saving them to the destination file", myGeoKeys.Count); 
   codecs.WriteGeoKeys(destFileName, 1, myGeoKeys); 
 
   // Clean up 
   codecs.Dispose(); 
} 
 
void codecs_GeyKeyFound(object sender, CodecsEnumGeoKeysEventArgs e) 
{ 
   Debug.WriteLine("GeoKey: Id={0}, Count={1}, Type={2}, Data Length={3}, Data=, Cancel={4}", e.Id, e.Count, e.MetadataType, e.Buffer.Length, e.Cancel); 
 
   // Load this GeoKey 
   RasterCodecs codecs = sender as RasterCodecs; 
   RasterTagMetadata geoKey = codecs.ReadGeoKey(geoKeySrcFileName, 1, e.Id); 
   byte[] data = geoKey.GetData(); 
   for (int i = 0; i < data.Length; i++) 
      Debug.WriteLine("{0:X} ", data[i].ToString()); 
 
   // Add it to our collection 
   myGeoKeys.Add(geoKey); 
   e.ToRasterTagMetadata(); 
} 
 
import java.io.*; 
import java.net.*; 
import java.nio.file.Paths; 
import java.util.*; 
import java.time.Instant; 
import java.time.Duration; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.codecs.RasterCodecs.FeedCallbackThunk; 
import leadtools.drawing.internal.*; 
import leadtools.imageprocessing.*; 
import leadtools.imageprocessing.color.ChangeIntensityCommand; 
import leadtools.svg.*; 
 
 
RasterCollection<RasterTagMetadata> myGeoKeys; 
String geoKeySrcFileName; 
 
public void enumGeoKeysExample() throws IOException { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "raster_image_enum_geokey.tif"); 
   String destFileName = combine(LEAD_VARS_IMAGES_DIR, "raster_image_enum_geokeys_out.tif"); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   geoKeySrcFileName = srcFileName; 
   myGeoKeys = new RasterCollection<RasterTagMetadata>(); 
 
   codecs.addGeoKeyFoundListener(codecsGetKeyFound); 
   ILeadStream srcFileStream = LeadStreamFactory.create(srcFileName); 
 
   codecs.enumGeoKeys(srcFileStream, 1); 
   codecs.removeGeoKeyFoundListener(codecsGetKeyFound); 
 
   // We read all the tags now, save them to the file 
   System.out.println(myGeoKeys.getCount() + " GeoKeys read, saving them to the destination file"); 
   ILeadStream destFileStream = LeadStreamFactory.create(destFileName); 
   RasterImage srcImage = codecs.load(srcFileName); 
 
   codecs.save(srcImage, destFileStream, RasterImageFormat.TIF, 0); 
   codecs.writeGeoKeys(destFileStream, 1, myGeoKeys); 
 
   // Clean up 
   srcFileStream.close(); 
   destFileStream.close(); 
   codecs.dispose(); 
} 
 
CodecsGeoKeyFoundListener codecsGetKeyFound = new CodecsGeoKeyFoundListener() { 
 
   @Override 
   public void onGeoKeyFound(CodecsEnumGeoKeysEvent e) { 
      System.out.printf("GeoKey: Id=%s, Count=%s, Type=%s, Data Length=%s, Data=, Cancel=%s%n", e.getId(), 
            e.getCount(), e.getMetadataType(), e.getBuffer().getLength(), e.getCancel()); 
      // Load this GeoKey 
      RasterCodecs codecs = (RasterCodecs) e.getSource(); 
      ILeadStream geoStream = LeadStreamFactory.create(geoKeySrcFileName); 
      RasterTagMetadata geoKey = codecs.readGeoKey(geoStream, 1, e.getId()); 
      byte[] data = geoKey.getData(); 
      for (int i = 0; i < data.length; i++) 
         System.out.println(data[i]); 
 
      // Add it to our collection 
      myGeoKeys.add(geoKey); 
      e.toRasterTagMetadata(); 
      try { 
         geoStream.close(); 
      } catch (IOException e1) { 
         e1.printStackTrace(); 
      } 
   } 
 
}; 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.