red: fixed M2a で、trksegが3つ認識されない現象が解決した。
1 parent 69a8d53 commit b6299c76f564214255224b4c92a107f997de531c
@hayashi hayashi authored on 27 Jun 2017
Showing 5 changed files
View
36
importPicture/src/osm/jp/gpx/ElementMapTRKSEG.java
import org.xml.sax.SAXException;
 
@SuppressWarnings("serial")
public class ElementMapTRKSEG extends TreeMap<Date, ElementMapTRKPT> {
/**
* TESTing
* @throws ParseException
* @throws ParserConfigurationException
* @throws IOException
* @throws SAXException
* @throws DOMException
*/
public static void main(String[] argv) throws DOMException, SAXException, IOException, ParserConfigurationException, ParseException {
ElementMapTRKSEG mapTRKSEG = null;
mapTRKSEG = new ElementMapTRKSEG();
mapTRKSEG.parse(new File("testdata/cameradata/separate.gpx"));
mapTRKSEG.printinfo();
}
public ElementMapTRKSEG() {
super(new TimeComparator());
}
factory.setIgnoringElementContentWhitespace(true);
factory.setIgnoringComments(true);
factory.setValidating(true);
Element trk = null;
Node gpx = builder.parse(gpxFile).getFirstChild();
Document document = gpx.getOwnerDocument();
NodeList nodes = gpx.getChildNodes();
for (int i=0; i < nodes.getLength(); i++) {
Node node2 = nodes.item(i);
if (node2.getNodeName().equals("trk")) {
trk = (Element) node2;
Element trk = (Element) node2;
NodeList nodes1 = trk.getChildNodes();
for (int i1=0; i1 < nodes1.getLength(); i1++) {
Node nodeTRKSEG = nodes1.item(i1);
public void put(Node nodeTRKSEG) throws DOMException, ParseException {
if (nodeTRKSEG.getNodeName().equals("trkseg")) {
NodeList nodes2 = nodeTRKSEG.getChildNodes();
Date trksegStartTime = new Date(); // 対象とする開始時刻(現在時刻)
ElementMapTRKPT mapTRKPT = new ElementMapTRKPT();
for (int i2 = 0; i2 < nodes2.getLength(); i2++) {
Node nodeTRKPT = nodes2.item(i2);
if (nodeTRKPT.getNodeName().equals("trkpt")) {
if (ImportPicture.param_GpxNoFirstNode && (i2 == 0)) {
continue;
}
Date time = mapTRKPT.put((Element)nodeTRKPT);
if (trksegStartTime.compareTo(time) < 0) {
trksegStartTime = time;
}
mapTRKPT.put((Element)nodeTRKPT);
}
}
this.put(trksegStartTime, mapTRKPT);
this.put(mapTRKPT);
}
}
/**
*/
public void put(ElementMapTRKPT value) {
for (Date key : value.keySet()) {
this.put(key, value);
return;
}
}
public void printinfo() {
System.out.println(" |--------------------|--------------------|");
System.out.println(" +--------------------+--------------------|");
System.out.println(" GPS logging time | First Time | Last Time |");
System.out.println("|--------------------------------+--------------------+--------------------|");
 
for (java.util.Map.Entry<Date, ElementMapTRKPT> map : this.entrySet()) {
System.out.println("|--------------------------------|--------------------|--------------------|");
ElementMapTRKPT mapTRKPT = map.getValue();
mapTRKPT.printinfo();
}
System.out.println("|--------------------------------|--------------------|--------------------|");
System.out.println("|--------------------------------+--------------------+--------------------|");
System.out.println();
}
 
}
View
106
importPicture/src/osm/jp/gpx/ImportPicture.java
public boolean param_GpxReuse = false;
public boolean param_GpxOutputWpt = true;
public boolean param_ImgOutputAll = false;
public String param_GpxSourceFolder = ".";
Document document;
public static final String TIME_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ss";
public static final SimpleDateFormat dfjp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static final SimpleDateFormat dfuk = new SimpleDateFormat(TIME_FORMAT_STRING +"'Z'");
 
@Override
public void run() {
/**
*
* @throws ImageReadException
* @throws TransformerException
*/
void procGPXfile(File gpxFile) throws ParserConfigurationException, SAXException, IOException, ParseException, ImageReadException, ImageWriteException, TransformerException {
DocumentBuilderFactory factory;
DocumentBuilder builder;
DocumentBuilderFactory factory = null;
DocumentBuilder builder = null;
ElementMapTRKSEG mapTRKSEG = null;
Node gpx = null;
System.gc();
 
String fileName = gpxFile.getName();
String iStr = fileName.substring(0, fileName.length() - 4);
 
factory.setIgnoringComments(true);
factory.setValidating(true);
 
// GPXファイルをパースする
ElementMapTRKSEG mapTRKSEG = new ElementMapTRKSEG();
mapTRKSEG = new ElementMapTRKSEG();
document = mapTRKSEG.parse(gpxFile);
// パースされた mapTRKSEG の中身を出力する
mapTRKSEG.printinfo();
// GPX file --> Node root
Node gpx = builder.parse(gpxFile).getFirstChild();
gpx = builder.parse(gpxFile).getFirstChild();
 
// imgDir内の画像ファイルを処理する
System.out.println("|--------------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|");
System.out.println("| name | Camera Time | GPStime | Latitude | Longitude | ele |magvar| km/h |");
}
return ret;
}
static Document document;
 
 
/**
* 2012-06-10T05:09:46Z (日本時間の'2012-06-10T14:09:46')
*/
public static final String TIME_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ss";
public static SimpleDateFormat dfjp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static SimpleDateFormat dfuk = new SimpleDateFormat(TIME_FORMAT_STRING +"'Z'");
 
/**
* 対象は '*.JPG' のみ対象とする
* @return
* @param name
name.appendChild(document.createCDATASection("写真"));
wpt.appendChild(name);
 
Element link = document.createElement("link");
link.setAttribute("href", getShortPathName(imgDir, iFile));
link.setAttribute("href", ImportPicture.getShortPathName(imgDir, iFile));
Element text = document.createElement("text");
text.setTextContent(iFile.getName());
link.appendChild(text);
wpt.appendChild(link);
else {
return filePath;
}
}
 
public static Element getCopy(Document doc, Node node) {
Element root = doc.createElement(node.getNodeName());
 
NamedNodeMap nodeMap = node.getAttributes();
if (null != nodeMap) {
for (int j=0; j < nodeMap.getLength(); j++ ) {
root.setAttribute(nodeMap.item(j).getNodeName(), nodeMap.item(j).getNodeValue());
}
}
 
NodeList nodes = node.getChildNodes();
for (int i=0; i < nodes.getLength(); i++) {
Node node2 = nodes.item(i);
if (node2.getNodeType() == Node.ELEMENT_NODE) {
root.appendChild(getCopy(doc, node2));
}
else if (node2.getNodeType() == Node.TEXT_NODE) {
String str = node2.getNodeValue();
Text textContents = doc.createTextNode(str);
root.appendChild(textContents);
}
else if (node2.getNodeType() == Node.CDATA_SECTION_NODE) {
String str = node2.getNodeValue();
CDATASection cdataSection = doc.createCDATASection(str);
root.appendChild(cdataSection);
}
}
return root;
}
/**
* ファイル名の順序に並び替えるためのソートクラス
*
* @author hayashi
*/
static class FileSort implements Comparator<File>{
static class FileSort implements Comparator<File> {
@Override
public int compare(File src, File target){
int diff = src.getName().compareTo(target.getName());
return diff;
/**
* JPEGファイルフィルター
* @author yuu
*/
class JpegFileFilter implements FilenameFilter{
class JpegFileFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
if (name.toUpperCase().matches(".*\\.JPG$")) {
return true;
}
View
importPicture/test/osm/jp/gpx/ElementMapTRKSEGTest.java
View
importPicture/test/osm/jp/gpx/ImportPictureTest.java
View
importPicture/testdata/AdjustTime.M2b.separate.ini 0 → 100644