public void BuildXMPFiles() { if (m_images_gps5_list.Count < 1) { return; } BuildKMLFile(); var nodeFirst = m_images_gps5_list.First(); GPS5DataFile.GPS5Data gpsDataFirst = nodeFirst.Value; double latRef = gpsDataFirst.latitude; double lonRef = gpsDataFirst.longitude; foreach (var node in m_images_gps5_list) { GPS5DataFile.GPS5Data gpsData = node.Value; string filename = node.Key; string path = Path.GetDirectoryName(filename); string output_filename = Path.GetFileNameWithoutExtension(filename); output_filename += ".xmp"; output_filename = Path.Combine(path, output_filename); XMPFile xmp_file = new XMPFile(); xmp_file.LoadXML("Sample.xmp"); xmp_file.RemoveNode(100); xmp_file.RemoveNode(102); xmp_file.RemoveAttribute(1); // xmp_file.SetGroup(); // xmp_file.SetGPSData(gpsData.latitude, gpsData.longitude, gpsData.altitude); double posX; double posY; //geodeticOffsetInv(latRef, lonRef, gpsData.latitude, gpsData.longitude,out posX,out posY); posX = KMLFile.distanceEarth(latRef, lonRef, latRef, gpsData.longitude); if (lonRef > gpsData.longitude) { posX *= -1.0; } posY = KMLFile.distanceEarth(latRef, lonRef, gpsData.latitude, lonRef); if (latRef > gpsData.latitude) { posY *= -1.0; } posX *= 1000.0; posY *= 1000.0; xmp_file.SetPosition(posX, posY, gpsData.altitude); xmp_file.SaveXML(output_filename); } return; }
public void BuildXMPFile_LerpGPSData(string imgFolder) { if (imgFolder.Length < 3) { Program.AddLog("BuildXMPFile_LerpGPSData: wrong Path." + imgFolder); return; } if (!Directory.Exists(imgFolder)) { Program.AddLog("BuildXMPFile_LerpGPSData: No Path." + imgFolder); return; } if (m_gps_data.Count < 1) { return; } string[] files = Directory.GetFiles(imgFolder); GPSData firstGPSData = m_gps_data.First().Value; foreach (var file in files) { string ext = Path.GetExtension(file); ext = ext.ToLower(); if (ext == ".jpg") { string filename = Path.GetFileNameWithoutExtension(file); string keyword = ""; int idx = 0; bool isFilename = XMPGenerator.GetIndexAndKeyword(out keyword, out idx, filename); if (!isFilename) { continue; } string xmpFileName = Path.ChangeExtension(file, "xmp"); if (File.Exists(xmpFileName)) { File.Delete(xmpFileName); } idx -= 1; int gpsIdx = idx / 30; int gpsSecStep = idx % 30; gpsIdx += 1; int gpsIdxNext = gpsIdx + 1; if (!m_gps_data.ContainsKey(gpsIdx)) { continue; } if (!m_gps_data.ContainsKey(gpsIdxNext)) { continue; } GPSData gpsData = m_gps_data[gpsIdx]; GPSData gpsData2 = m_gps_data[gpsIdxNext]; double p = gpsSecStep / 30.0; double posX = (gpsData2.posX - gpsData.posX) * p + gpsData.posX; double posY = (gpsData2.posY - gpsData.posY) * p + gpsData.posY; double altitude = (gpsData2.altitude - gpsData.altitude) * p + gpsData.altitude; XMPFile xmp_file = new XMPFile(); xmp_file.LoadXML("Sample.xmp"); xmp_file.RemoveNode(100); xmp_file.RemoveNode(102); xmp_file.RemoveAttribute(1); xmp_file.SetPosition(posX, posY, altitude); xmp_file.SaveXML(xmpFileName); } } }
public void BuildTotalImagesFolder(double gapLimit) { if (!Directory.Exists(destFolder)) { Directory.CreateDirectory(destFolder); } //string removeImgFolder = Path.Combine(destFolder, "Remove"); //if (!Directory.Exists(removeImgFolder)) //{ // Directory.CreateDirectory(removeImgFolder); //} var gpsFirstNode = m_total_gps_data_list.First(); GPS5DataFile.GPS5Data gpsDataFirst = gpsFirstNode.Value; double latRef = gpsDataFirst.latitude; double lonRef = gpsDataFirst.longitude; double lastPosX = 0; double lastPosY = 0; double lastPosZ = 0; bool gapCheck = false; foreach (var node in m_total_images) { int idx = node.Key; string imageName = node.Value; //Caculate XYZ; GPS5DataFile.GPS5Data gpsData = m_total_gps_data_list[imageName]; double posX; double posY; posX = KMLFile.distanceEarth(latRef, lonRef, latRef, gpsData.longitude); if (lonRef > gpsData.longitude) { posX *= -1.0; } posY = KMLFile.distanceEarth(latRef, lonRef, gpsData.latitude, lonRef); if (latRef > gpsData.latitude) { posY *= -1.0; } // km -> m posX *= 1000.0; posY *= 1000.0; //Check gap limit if (!gapCheck) { lastPosX = posX; lastPosY = posY; lastPosZ = gpsData.altitude; gapCheck = true; } else { double dist = (posX - lastPosX) * (posX - lastPosX) + (posY - lastPosY) * (posY - lastPosY) + (gpsData.altitude - lastPosZ) * (gpsData.altitude - lastPosZ); dist = Math.Sqrt(dist); if (dist < gapLimit) { continue; } else { lastPosX = posX; lastPosY = posY; lastPosZ = gpsData.altitude; } } //string filename = Path.GetFileName(imageName); string newFilename = m_total_new_image_name[imageName]; string destImgFilename = Path.Combine(destFolder, newFilename); File.Move(imageName, destImgFilename); Program.AddLog("Move: " + imageName + " To " + destImgFilename); string xmpFilename = Path.GetFileNameWithoutExtension(newFilename); xmpFilename += ".xmp"; xmpFilename = Path.Combine(destFolder, xmpFilename); XMPFile xmp_file = new XMPFile(); xmp_file.LoadXML("Sample.xmp"); xmp_file.RemoveNode(100); xmp_file.RemoveNode(102); xmp_file.RemoveAttribute(1); xmp_file.SetPosition(posX, posY, gpsData.altitude); xmp_file.SaveXML(xmpFilename); // Program.AddLog("Save XMP file: " + xmpFilename); } }