static void Main(string[] args) { // OBJ Testing var objMetadataOutput = Path.Combine(Path.GetDirectoryName(objPath), "objSample.json"); if (File.Exists(objMetadataOutput)) { File.Delete(objMetadataOutput); } var objBinaryOutput = Path.Combine(Path.GetDirectoryName(objPath), "objSample.dat"); if (File.Exists(objBinaryOutput)) { File.Delete(objBinaryOutput); } var objBitmapOutput = Path.Combine(Path.GetDirectoryName(objPath), "objSample.bmp"); if (File.Exists(objBitmapOutput)) { File.Delete(objBitmapOutput); } var objConverter = new GeoObj(); objConverter.ConvertToHeightMap(objPath, objBinaryOutput, objMetadataOutput, objBitmapOutput); // Save metadata var outputManifestPath = Path.Combine(Path.GetDirectoryName(tiffPath), "tiffSample4.json"); if (File.Exists(outputManifestPath)) { File.Delete(outputManifestPath); } // Save image var outputPath = Path.Combine(Path.GetDirectoryName(tiffPath), "tiffSample4.dat"); if (File.Exists(outputPath)) { File.Delete(outputPath); } var bitmapPath = Path.Combine(Path.GetDirectoryName(tiffPath), "tiffSample4.bmp"); if (File.Exists(bitmapPath)) { File.Delete(bitmapPath); } using (GeoTiff tiffConverter = new GeoTiff()) { tiffConverter.ConvertToHeightMap(tiffPath, outputPath, outputManifestPath, bitmapPath); } }
// Rough implementation, support for zipped tiff's private IEnumerable <string> ConvertFiles(string filePath, string sourceName) { string workingDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")); Directory.CreateDirectory(workingDirectory); // If ZIP, extract first if (string.Equals(Path.GetExtension(sourceName), ".zip", StringComparison.OrdinalIgnoreCase)) { Trace.TraceInformation("Found zip file, decompressing."); ZipFile.ExtractToDirectory(filePath, workingDirectory); var files = Directory.GetFiles(workingDirectory); // Lets see if we have a tiff file for now var tiff = files.Where(f => string.Equals(Path.GetExtension(f), ".tif", StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (!string.IsNullOrEmpty(tiff)) { Trace.TraceInformation("Found tiff, converting."); var GeoTiff = new GeoTiff(); var outputRoot = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")); var outputBinary = outputRoot + ".dat"; var outputMetadata = outputRoot + ".json"; var outputThumbnail = outputRoot + ".jpg"; GeoTiff.ConvertToHeightMap(tiff, outputBinary, outputMetadata, outputThumbnail); try { if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } Directory.Delete(workingDirectory, true); } catch (Exception ex) { Trace.TraceWarning("Failed to cleanup working files. {0}", ex.ToString()); } return(new List <string> { outputBinary, outputMetadata, outputThumbnail }); } } return(null); }