Ejemplo n.º 1
0
 public GPSInfo getGPS(int FlightID, DateTime FileCreatedOn) {
     StringBuilder GPSInfo = new StringBuilder();
   String FromTime = Util.toSQLDate(FileCreatedOn.AddMinutes(-5).ToUniversalTime());
   String ToTime = Util.toSQLDate(FileCreatedOn.AddMinutes(5).ToUniversalTime());
   String ThisTime = Util.toSQLDate(FileCreatedOn.ToUniversalTime());
   String SQL = @"Select TOP 1 
     Latitude,
     Longitude,
     Altitude,
     ABS(DATEDIFF(SECOND, ReadTime,'" + ThisTime + @"')) as SortTime
   from 
     FlightMapData 
   where 
     flightid=" + FlightID + @" AND
     ReadTime >=  '" + FromTime + @"' AND
     ReadTime <=  '" + ToTime + @"'
   ORDER BY
     SortTime ASC,
     ReadTime DESC";
   var Row = Util.getDBRow(SQL);
   var theGPS = new GPSInfo();
   if (Row["hasRows"].ToString() == "True") {
     theGPS.Latitude = Util.toDouble(Row["Latitude"]);
     theGPS.Longitude = Util.toDouble(Row["Longitude"]);
     theGPS.Altitude = Util.toDouble(Row["Altitude"]);
   }
   return theGPS;
 }
Ejemplo n.º 2
0
    public bool setGPS(GPSInfo theGPS) {

      double latitude = theGPS.Latitude;
      double longitude = theGPS.Longitude;
      double altitude = theGPS.Altitude;

      //original image file
      string originalPath = _InputFileName;
      //image file after adding the GPS tags
      string outputPath = _OutputFileName;

      BitmapCreateOptions createOptions = BitmapCreateOptions.PreservePixelFormat | BitmapCreateOptions.IgnoreColorProfile;
      uint paddingAmount = 2048;

      //open the image file
      using (Stream originalFile = File.Open(originalPath, FileMode.Open, FileAccess.Read)) {
        BitmapDecoder original = BitmapDecoder.Create(originalFile, createOptions, BitmapCacheOption.None);

        //this becomes the new image that contains new metadata
        JpegBitmapEncoder output = new JpegBitmapEncoder();

        if (original.Frames[0] != null && original.Frames[0].Metadata != null) {
          //clone the metadata from the original input image so that it can be modified
          BitmapMetadata metadata = original.Frames[0].Metadata.Clone() as BitmapMetadata;

          //pad the metadata so that it can be expanded with new tags
          metadata.SetQuery("/app1/ifd/PaddingSchema:Padding", paddingAmount);
          metadata.SetQuery("/app1/ifd/exif/PaddingSchema:Padding", paddingAmount);
          metadata.SetQuery("/xmp/PaddingSchema:Padding", paddingAmount);


          GPSRational latitudeRational = new GPSRational(latitude);
          GPSRational longitudeRational = new GPSRational(longitude);
          metadata.SetQuery(GPSLatitudeQuery, latitudeRational.bytes);
          metadata.SetQuery(GPSLongitudeQuery, longitudeRational.bytes);
          if (latitude > 0) metadata.SetQuery(GPSLatitudeRefQuery, "N");
          else metadata.SetQuery(GPSLatitudeRefQuery, "S");
          if (longitude > 0) metadata.SetQuery(GPSLongitudeRefQuery, "E");
          else metadata.SetQuery(GPSLongitudeRefQuery, "W");

          //denoninator = 1 for Rational
          Rational altitudeRational = new Rational((int)altitude, 1);
          metadata.SetQuery(GPSAltitudeQuery, altitudeRational.bytes);

          //create the output image using the image data, thumbnail, and metadata from the original image as modified above
          output.Frames.Add(
              BitmapFrame.Create(original.Frames[0], original.Frames[0].Thumbnail, metadata, original.Frames[0].ColorContexts));
        }//if (original.Frames[0] != null)

        //save the output image
        using (Stream outputFile = File.Open(outputPath, FileMode.Create, FileAccess.ReadWrite)) {
          output.Save(outputFile);
        }//using (Stream outputFile)

        //Delete the source file
        //System.IO.File.Delete(originalPath);
      }//using (Stream originalFile)

      return true;
    }//public bool GPS)
Ejemplo n.º 3
0
 public GPSInfo getGPS() {
   var myGPS = new GPSInfo();
   try {
     //_InputFileName = InputFileName;
     Image image = Image.FromFile(_InputFileName);
     myGPS.Latitude = GetLatitude(image);
     myGPS.Longitude = GetLongitude(image);
     myGPS.ImageTakenOn = GetPhotoTakenOn(image);
     image.Dispose();
     IsImage = true;
   } catch {
     //not an image;
     IsImage = false;
   }
   return myGPS;
 }