Skip to content

Instantly share code, notes, and snippets.

@dck-jp
Created March 30, 2013 02:38
Show Gist options
  • Select an option

  • Save dck-jp/5275064 to your computer and use it in GitHub Desktop.

Select an option

Save dck-jp/5275064 to your computer and use it in GitHub Desktop.
Create EXIF Statics with LINQtoCSV
using LINQtoCSV;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LINQtoCSVTest
{
class ExifMini
{
[CsvColumn( FieldIndex = 1, Name = "FileName")]
public string Name { get; set; }
[CsvColumn(FieldIndex = 2, CanBeNull = true)]
public string Camera { get; set; }
[CsvColumn(FieldIndex = 3, CanBeNull = true)]
public string TimeStamp { get; set; }
[CsvColumn(FieldIndex = 4, CanBeNull = true)]
public double FocalLength { get; set; }
[CsvColumn(FieldIndex = 5, CanBeNull = true)]
public double FocalLength35mmEq { get; set; }
[CsvColumn(FieldIndex = 6, CanBeNull = true)]
public double Non { get; set; }
}
}
using LINQtoCSV;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LINQtoCSVTest
{
class Program
{
static void Main(string[] args)
{
var csvFileName = @"input.csv";
var outputFileName = @"output.csv";
var camera = @"LX2";
var inputFileDescription = new CsvFileDescription {
SeparatorChar = '\t'
, EnforceCsvColumnAttribute = true
, FirstLineHasColumnNames = false
};
var cc = new CsvContext();
IEnumerable<ExifMini> exifs = cc.Read<ExifMini>(csvFileName, inputFileDescription);
var CameraData =
from exif in exifs
where exif.Camera != null && exif.Camera.Contains(camera)
orderby exif.FocalLength35mmEq
select exif.FocalLength35mmEq;
var focalLengths = CameraData.Distinct();
var outputSb = new StringBuilder();
foreach (var focalLength in focalLengths)
{
var output =
from d in CameraData
where d == focalLength
select d;
var count = output.ToList<double>().Count();
outputSb.Append(focalLength.ToString()).Append("\t").AppendLine(count.ToString());
}
File.WriteAllText(outputFileName, outputSb.ToString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment