Changeset 30768 in osm
- Timestamp:
- 2014-10-28T00:52:45+01:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/ColumbusCSV
- Files:
-
- 1 added
- 8 edited
-
.settings/org.eclipse.jdt.core.prefs (modified) (1 diff)
-
.settings/org.eclipse.jdt.ui.prefs (added)
-
build.xml (modified) (1 diff)
-
src/org/openstreetmap/josm/plugins/columbusCSV/ColumbusCSVImporter.java (modified) (1 diff)
-
src/org/openstreetmap/josm/plugins/columbusCSV/ColumbusCSVPlugin.java (modified) (1 diff)
-
src/org/openstreetmap/josm/plugins/columbusCSV/ColumbusCSVPreferences.java (modified) (4 diffs)
-
src/org/openstreetmap/josm/plugins/columbusCSV/ColumbusCSVReader.java (modified) (21 diffs)
-
src/org/openstreetmap/josm/plugins/columbusCSV/ColumbusCSVUtils.java (modified) (1 diff)
-
src/org/openstreetmap/josm/plugins/columbusCSV/WayPointHelper.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ColumbusCSV/.settings/org.eclipse.jdt.core.prefs
r30416 r30768 1 1 eclipse.preferences.version=1 2 org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled 3 org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore 4 org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull 5 org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault 6 org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable 7 org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled 2 8 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 9 org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 3 10 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 11 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 4 12 org.eclipse.jdt.core.compiler.compliance=1.7 13 org.eclipse.jdt.core.compiler.debug.lineNumber=generate 14 org.eclipse.jdt.core.compiler.debug.localVariable=generate 15 org.eclipse.jdt.core.compiler.debug.sourceFile=generate 16 org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning 5 17 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 18 org.eclipse.jdt.core.compiler.problem.autoboxing=ignore 19 org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning 20 org.eclipse.jdt.core.compiler.problem.deadCode=warning 21 org.eclipse.jdt.core.compiler.problem.deprecation=warning 22 org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled 23 org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled 24 org.eclipse.jdt.core.compiler.problem.discouragedReference=warning 25 org.eclipse.jdt.core.compiler.problem.emptyStatement=warning 6 26 org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 27 org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning 28 org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore 29 org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled 30 org.eclipse.jdt.core.compiler.problem.fieldHiding=warning 31 org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning 32 org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning 33 org.eclipse.jdt.core.compiler.problem.forbiddenReference=error 34 org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning 35 org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled 36 org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning 37 org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning 38 org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore 39 org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore 40 org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning 41 org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore 42 org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore 43 org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled 44 org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore 45 org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore 46 org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled 47 org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore 48 org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore 49 org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning 50 org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning 51 org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore 52 org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning 53 org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error 54 org.eclipse.jdt.core.compiler.problem.nullReference=warning 55 org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error 56 org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning 57 org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning 58 org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore 59 org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore 60 org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore 61 org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore 62 org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning 63 org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning 64 org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore 65 org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning 66 org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore 67 org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore 68 org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore 69 org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled 70 org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning 71 org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled 72 org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled 73 org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled 74 org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore 75 org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning 76 org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled 77 org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning 78 org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning 79 org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore 80 org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning 81 org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore 82 org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore 83 org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore 84 org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore 85 org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled 86 org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled 87 org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled 88 org.eclipse.jdt.core.compiler.problem.unusedImport=warning 89 org.eclipse.jdt.core.compiler.problem.unusedLabel=warning 90 org.eclipse.jdt.core.compiler.problem.unusedLocal=warning 91 org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning 92 org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore 93 org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled 94 org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled 95 org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled 96 org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning 97 org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore 98 org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning 99 org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning 7 100 org.eclipse.jdt.core.compiler.source=1.7 -
applications/editors/josm/plugins/ColumbusCSV/build.xml
r30416 r30768 1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <project name="ColumbusCSV" default="dist" basedir="."> 3 <!-- enter the SVN commit message -->4 <property name="commit.message" value="Commit message"/>3 <!-- enter the SVN commit message --> 4 <property name="commit.message" value="Commit message"/> 5 5 <!-- Enter the *lowest* JOSM version this plugin is currently compatible with --> 6 6 <property name="plugin.main.version" value="7001"/> 7 8 <!-- Plugin meta data -->7 8 <!-- Plugin meta data --> 9 9 <property name="plugin.author" value="Oliver Wieland"/> 10 10 <property name="plugin.class" value="org.openstreetmap.josm.plugins.columbusCSV.ColumbusCSVPlugin"/> 11 11 <property name="plugin.description" value="Imports proprietary CSV files of the Columbus/Visiontac V-900 GPS logger into a GPX layer."/> 12 12 <property name="plugin.link" value="http://wiki.openstreetmap.org/wiki/JOSM/Plugins/ColumbusCSV"/> 13 <!-- Plugin icon -->13 <!-- Plugin icon --> 14 14 <property name="plugin.icon" value="images/colcsvicon.png"/> 15 16 <!-- Plugin version info -->17 <property name="plugin.version" value="${version.entry.commit.revision}"/>18 <property name="plugin.stage" value="60"/>15 16 <!-- Plugin version info --> 17 <property name="plugin.version" value="${version.entry.commit.revision}"/> 18 <property name="plugin.stage" value="60"/> 19 19 20 20 <!-- ** include targets that all plugins have in common ** --> 21 <import file="../build-common.xml"/> 21 <import file="../build-common.xml"/> 22 22 </project> -
applications/editors/josm/plugins/ColumbusCSV/src/org/openstreetmap/josm/plugins/columbusCSV/ColumbusCSVImporter.java
r29854 r30768 40 40 public static final String COLUMBUS_FILE_EXT_DOT = "." + COLUMBUS_FILE_EXT; 41 41 42 /** 43 * Constructs a new {@code ColumbusCSVImporter}. 44 */ 42 45 public ColumbusCSVImporter() { 43 super(new ExtensionFileFilter(COLUMBUS_FILE_EXT, COLUMBUS_FILE_EXT, 44 tr("Columbus V-900 CSV Files") + " (*" + COLUMBUS_FILE_EXT_DOT 45 + ")")); 46 super(new ExtensionFileFilter(COLUMBUS_FILE_EXT, COLUMBUS_FILE_EXT, 47 tr("Columbus V-900 CSV Files") + " (*" + COLUMBUS_FILE_EXT_DOT + ")")); 46 48 } 47 49 48 50 @Override 49 51 public boolean acceptFile(File pathname) { 50 try { 51 // do some deep packet inspection... 52 boolean ok = super.acceptFile(pathname) 53 && ColumbusCSVReader.isColumbusFile(pathname); 54 return ok; 55 } catch (Exception ex) { 56 return false; 57 } 52 try { 53 // do some deep packet inspection... 54 return super.acceptFile(pathname) 55 && ColumbusCSVReader.isColumbusFile(pathname); 56 } catch (Exception ex) { 57 return false; 58 } 58 59 } 59 60 60 /*61 * (non-Javadoc)62 *63 * @see org.openstreetmap.josm.io.FileImporter#importData(java.io.File,64 * org.openstreetmap.josm.gui.progress.ProgressMonitor)65 */66 61 @Override 67 62 public void importData(File file, ProgressMonitor progressMonitor) 68 throws IOException, IllegalDataException { 69 String fn = file.getPath(); 70 71 if (progressMonitor == null) { // make sure that there is a progress 72 // monitor... 73 progressMonitor = NullProgressMonitor.INSTANCE; 74 } 75 76 progressMonitor.beginTask(String.format( 77 tr("Importing CSV file ''%s''..."), file.getName(), 4)); 78 progressMonitor.setTicksCount(1); 79 80 if (fn.toLowerCase().endsWith(COLUMBUS_FILE_EXT_DOT)) { 81 try { 82 ColumbusCSVReader r = new ColumbusCSVReader(); 83 84 // transform CSV into GPX 85 GpxData gpxData = r.transformColumbusCSV(fn); 86 assert (gpxData != null); 87 progressMonitor.setTicksCount(1); 88 89 r.dropBufferLists(); 90 91 progressMonitor.setTicksCount(2); 92 93 GpxLayer gpxLayer = new GpxLayer(gpxData, file.getName()); 94 assert (gpxLayer != null); 95 96 // add layer to show way points 97 Main.main.addLayer(gpxLayer); 98 99 progressMonitor.setTicksCount(3); 100 101 // ... and scale view appropriately - if wished by user 102 if (ColumbusCSVPreferences.zoomAfterImport()) { 103 AutoScaleAction action = new AutoScaleAction("data"); 104 action.autoScale(); 105 } 106 progressMonitor.setTicksCount(4); 107 108 if (Main.pref.getBoolean("marker.makeautomarkers", true)) { 109 try { 110 MarkerLayer ml = new MarkerLayer(gpxData, 111 tr("Markers of ") + file.getName(), file, 112 gpxLayer); 113 114 assert (ml != null); 115 assert (ml.data != null); 116 117 System.out.println("Layer: " + ml); 118 System.out.println("Data: " + ml.data != null); 119 System.out.println("Data size: " + ml.data.size()); 120 121 Main.main.addLayer(ml); 122 if (ml.data.size() > 0) { 123 124 } else { 125 System.out 126 .println("Warning: File contains no markers."); 127 } 128 } catch (Exception exLayer) { 129 System.out.println(exLayer); 130 exLayer.printStackTrace(System.err); 131 } 132 } else { 133 System.out 134 .println("Warning: Option 'marker.makeautomarkers' is not set; audio marker layer is not created."); 135 } 136 } catch (Exception e) { 137 // catch and forward exception 138 e.printStackTrace(System.err); 139 throw new IllegalDataException(e); 140 } finally { // take care of monitor... 141 progressMonitor.finishTask(); 142 } 143 } else { 144 throw new IOException( 145 tr(String 146 .format("Unsupported file extension (file '%s' does not end with '%s')!", 147 file.getName(), COLUMBUS_FILE_EXT))); 148 } 63 throws IOException, IllegalDataException { 64 String fn = file.getPath(); 65 66 if (progressMonitor == null) { // make sure that there is a progress monitor... 67 progressMonitor = NullProgressMonitor.INSTANCE; 68 } 69 70 progressMonitor.beginTask(String.format( 71 tr("Importing CSV file ''%s''..."), file.getName(), 4)); 72 progressMonitor.setTicksCount(1); 73 74 if (fn.toLowerCase().endsWith(COLUMBUS_FILE_EXT_DOT)) { 75 try { 76 ColumbusCSVReader r = new ColumbusCSVReader(); 77 78 // transform CSV into GPX 79 GpxData gpxData = r.transformColumbusCSV(fn); 80 assert gpxData != null; 81 progressMonitor.setTicksCount(1); 82 83 r.dropBufferLists(); 84 85 progressMonitor.setTicksCount(2); 86 87 GpxLayer gpxLayer = new GpxLayer(gpxData, file.getName()); 88 assert gpxLayer != null; 89 90 // add layer to show way points 91 Main.main.addLayer(gpxLayer); 92 93 progressMonitor.setTicksCount(3); 94 95 // ... and scale view appropriately - if wished by user 96 if (ColumbusCSVPreferences.zoomAfterImport()) { 97 AutoScaleAction action = new AutoScaleAction("data"); 98 action.autoScale(); 99 } 100 progressMonitor.setTicksCount(4); 101 102 if (Main.pref.getBoolean("marker.makeautomarkers", true)) { 103 try { 104 MarkerLayer ml = new MarkerLayer(gpxData, 105 tr("Markers of ") + file.getName(), file, gpxLayer); 106 107 assert ml != null; 108 assert ml.data != null; 109 110 Main.info("Layer: " + ml); 111 Main.info("Data size: " + ml.data.size()); 112 113 Main.main.addLayer(ml); 114 if (ml.data.isEmpty()) { 115 Main.warn("File contains no markers."); 116 } 117 } catch (Exception exLayer) { 118 Main.error(exLayer); 119 } 120 } else { 121 Main.warn("Option 'marker.makeautomarkers' is not set; audio marker layer is not created."); 122 } 123 } catch (Exception e) { 124 // catch and forward exception 125 Main.error(e); 126 throw new IllegalDataException(e); 127 } finally { // take care of monitor... 128 progressMonitor.finishTask(); 129 } 130 } else { 131 throw new IOException( 132 tr(String.format("Unsupported file extension (file '%s' does not end with '%s')!", 133 file.getName(), COLUMBUS_FILE_EXT))); 134 } 149 135 } 150 136 } -
applications/editors/josm/plugins/ColumbusCSV/src/org/openstreetmap/josm/plugins/columbusCSV/ColumbusCSVPlugin.java
r23795 r30768 27 27 */ 28 28 public class ColumbusCSVPlugin extends Plugin { 29 private static PreferenceSetting columbusSettings;30 /*31 * Plugin constructor (adds menu entry to file menu).32 */33 public ColumbusCSVPlugin(PluginInformation info) {34 super(info);35 36 ExtensionFileFilter.importers.add(new ColumbusCSVImporter());37 }38 39 /**29 private static PreferenceSetting columbusSettings; 30 /* 31 * Plugin constructor (adds menu entry to file menu). 32 */ 33 public ColumbusCSVPlugin(PluginInformation info) { 34 super(info); 35 36 ExtensionFileFilter.importers.add(new ColumbusCSVImporter()); 37 } 38 39 /** 40 40 * Called in the preferences dialog to create a preferences page for the plugin, 41 41 * if any available. 42 42 */ 43 43 public PreferenceSetting getPreferenceSetting() { 44 if (columbusSettings == null) {45 columbusSettings = new ColumbusCSVPreferences();46 }47 return columbusSettings;44 if (columbusSettings == null) { 45 columbusSettings = new ColumbusCSVPreferences(); 46 } 47 return columbusSettings; 48 48 } 49 49 } -
applications/editors/josm/plugins/ColumbusCSV/src/org/openstreetmap/josm/plugins/columbusCSV/ColumbusCSVPreferences.java
r29500 r30768 77 77 Main.pref.put(IGNORE_VDOP, colCSVIgnoreVDOP.isSelected()); 78 78 Main.pref.put(WARN_CONVERSION_ERRORS, colCSVWarnConversionErrors.isSelected()); 79 Main.pref.put(WARN_MISSING_AUDIO, colCSVWarnMissingAudio.isSelected()); 79 Main.pref.put(WARN_MISSING_AUDIO, colCSVWarnMissingAudio.isSelected()); 80 80 return false; 81 81 } … … 86 86 */ 87 87 public static boolean showSummary() { 88 return Main.pref.getBoolean(SHOW_SUMMARY, true);88 return Main.pref.getBoolean(SHOW_SUMMARY, true); 89 89 } 90 90 … … 94 94 */ 95 95 public static boolean zoomAfterImport() { 96 return Main.pref.getBoolean(ZOOM_AFTER_IMPORT, true);96 return Main.pref.getBoolean(ZOOM_AFTER_IMPORT, true); 97 97 } 98 98 … … 150 150 } 151 151 152 public boolean isExpert() {153 return false;154 }152 public boolean isExpert() { 153 return false; 154 } 155 155 156 156 } -
applications/editors/josm/plugins/ColumbusCSV/src/org/openstreetmap/josm/plugins/columbusCSV/ColumbusCSVReader.java
r29178 r30768 30 30 import java.util.HashMap; 31 31 import java.util.List; 32 import java.util.Map; 32 33 import java.util.StringTokenizer; 33 34 import java.util.zip.DataFormatException; 34 35 36 import org.openstreetmap.josm.Main; 35 37 import org.openstreetmap.josm.data.coor.LatLon; 36 38 import org.openstreetmap.josm.data.gpx.GpxData; … … 96 98 private int firstVoxNumber = -1, lastVoxNumber = -1; 97 99 98 private HashMap<String, WayPoint> voxFiles = new HashMap<String, WayPoint>();99 private Collection<Collection<WayPoint>> allTrackPts = new ArrayList< Collection<WayPoint>>();100 private List<WayPoint> trackPts = new ArrayList< WayPoint>();101 private List<WayPoint> allWpts = new ArrayList< WayPoint>();100 private final Map<String, WayPoint> voxFiles = new HashMap<>(); 101 private final Collection<Collection<WayPoint>> allTrackPts = new ArrayList<>(); 102 private final List<WayPoint> trackPts = new ArrayList<>(); 103 private final List<WayPoint> allWpts = new ArrayList<>(); 102 104 private String fileDir; 103 105 … … 110 112 * @throws DataFormatException 111 113 */ 112 public GpxData transformColumbusCSV(String fileName) throws IOException, 113 IllegalDataException { 114 if (fileName == null || fileName.length() == 0) { 115 throw new IllegalArgumentException( 116 "File name must not be null or empty"); 117 } 118 119 // GPX data structures 120 GpxData gpxData = new GpxData(); 121 122 File f = new File(fileName); 123 fileDir = f.getParent(); 124 FileInputStream fstream = new FileInputStream(fileName); 125 // Get the object of DataInputStream 126 DataInputStream in = new DataInputStream(fstream); 127 BufferedReader br = new BufferedReader(new InputStreamReader(in)); 128 String strLine; 129 // Initial values 130 int line = 1; 131 initImport(); 132 dropBufferLists(); 133 134 int waypts = 0, trkpts = 0, audiopts = 0, missaudio = 0, rescaudio = 0; 135 try { 136 // Read File Line By Line 137 while ((strLine = br.readLine()) != null) { 138 String[] csvFields = getCSVLine(strLine); // Get the columns of 139 // the current line 140 if (csvFields.length == 0 || line <= 1) { // Skip, if line is 141 // header or contains 142 // no data 143 ++line; 144 continue; 145 } 146 147 try { 148 WayPoint wpt = createWayPoint(csvFields, fileDir); 149 String wptType = (String) wpt.attr.get(TYPE_TAG); 150 String oldWptType = csvFields[1]; 151 152 if ("T".equals(wptType)) { // point of track (T) 153 trackPts.add(wpt); 154 trkpts++; 155 } else { // way point (C) / have voice file: V) 156 if (!wptType.equals(oldWptType)) { // type changed? 157 if ("V".equals(oldWptType)) { // missing audiofile 158 missaudio++; 159 } 160 if ("C".equals(oldWptType)) { // rescued audiofile 161 rescaudio++; 162 } 163 } else { 164 if ("V".equals(wptType)) { // wpt with vox 165 audiopts++; 166 } 167 } 168 169 gpxData.waypoints.add(wpt); // add the waypoint to the 170 // track 171 waypts++; 172 } 173 174 allWpts.add(wpt); 175 176 wpt.attr.remove(TYPE_TAG); 177 } catch (Exception ex) { 178 br.close(); 179 throw new IllegalDataException(tr("Error in line " + line 180 + ": " + ex.toString())); 181 } 182 ++line; 183 } 184 } finally { 185 // Close the input stream 186 br.close(); 187 } 188 189 // do some sanity checks 190 assert (trackPts.size() == trkpts); 191 assert (gpxData.waypoints.size() == waypts); 192 assert (firstVoxNumber <= lastVoxNumber); 193 194 rescaudio += searchForLostAudioFiles(gpxData); 195 196 // compose the track 197 allTrackPts.add(trackPts); 198 GpxTrack trk = new ImmutableGpxTrack(allTrackPts, 199 Collections.<String, Object> emptyMap()); 200 gpxData.tracks.add(trk); 201 202 assert (gpxData.routes.size() == 1); 203 204 // Issue conversion warning, if needed 205 if (ColumbusCSVPreferences.warnConversion() 206 && (dateConversionErrors > 0 || dopConversionErrors > 0)) { 207 String message = String.format( 208 "%d date conversion faults and %d DOP conversion errors", 209 dateConversionErrors, dopConversionErrors); 210 ColumbusCSVUtils.showWarningMessage(tr(message)); 211 } 212 // Show summary 213 if (ColumbusCSVPreferences.showSummary()) { 214 showSummary(waypts, trkpts, audiopts, missaudio, rescaudio); 215 } 216 217 String desc = String.format( 218 "Converted by ColumbusCSV plugin from track file '%s'", 219 f.getName()); 220 gpxData.attr.put(GpxData.META_DESC, desc); 221 gpxData.storageFile = f; 222 return gpxData; 114 public GpxData transformColumbusCSV(String fileName) throws IOException, IllegalDataException { 115 if (fileName == null || fileName.length() == 0) { 116 throw new IllegalArgumentException( 117 "File name must not be null or empty"); 118 } 119 120 // GPX data structures 121 GpxData gpxData = new GpxData(); 122 123 File f = new File(fileName); 124 fileDir = f.getParent(); 125 FileInputStream fstream = new FileInputStream(fileName); 126 // Get the object of DataInputStream 127 DataInputStream in = new DataInputStream(fstream); 128 BufferedReader br = new BufferedReader(new InputStreamReader(in)); 129 String strLine; 130 // Initial values 131 int line = 1; 132 initImport(); 133 dropBufferLists(); 134 135 int waypts = 0, trkpts = 0, audiopts = 0, missaudio = 0, rescaudio = 0; 136 try { 137 // Read File Line By Line 138 while ((strLine = br.readLine()) != null) { 139 String[] csvFields = getCSVLine(strLine); // Get the columns of 140 // the current line 141 if (csvFields.length == 0 || line <= 1) { // Skip, if line is 142 // header or contains 143 // no data 144 ++line; 145 continue; 146 } 147 148 try { 149 WayPoint wpt = createWayPoint(csvFields, fileDir); 150 String wptType = (String) wpt.attr.get(TYPE_TAG); 151 String oldWptType = csvFields[1]; 152 153 if ("T".equals(wptType)) { // point of track (T) 154 trackPts.add(wpt); 155 trkpts++; 156 } else { // way point (C) / have voice file: V) 157 if (!wptType.equals(oldWptType)) { // type changed? 158 if ("V".equals(oldWptType)) { // missing audiofile 159 missaudio++; 160 } 161 if ("C".equals(oldWptType)) { // rescued audiofile 162 rescaudio++; 163 } 164 } else { 165 if ("V".equals(wptType)) { // wpt with vox 166 audiopts++; 167 } 168 } 169 170 gpxData.waypoints.add(wpt); // add the waypoint to the track 171 waypts++; 172 } 173 174 allWpts.add(wpt); 175 176 wpt.attr.remove(TYPE_TAG); 177 } catch (Exception ex) { 178 br.close(); 179 throw new IllegalDataException(tr("Error in line " + line 180 + ": " + ex.toString()), ex); 181 } 182 ++line; 183 } 184 } finally { 185 // Close the input stream 186 br.close(); 187 } 188 189 // do some sanity checks 190 assert trackPts.size() == trkpts; 191 assert gpxData.waypoints.size() == waypts; 192 assert firstVoxNumber <= lastVoxNumber; 193 194 rescaudio += searchForLostAudioFiles(gpxData); 195 196 // compose the track 197 allTrackPts.add(trackPts); 198 GpxTrack trk = new ImmutableGpxTrack(allTrackPts, 199 Collections.<String, Object> emptyMap()); 200 gpxData.tracks.add(trk); 201 202 assert gpxData.routes.size() == 1; 203 204 // Issue conversion warning, if needed 205 if (ColumbusCSVPreferences.warnConversion() 206 && (dateConversionErrors > 0 || dopConversionErrors > 0)) { 207 String message = String.format( 208 "%d date conversion faults and %d DOP conversion errors", 209 dateConversionErrors, dopConversionErrors); 210 ColumbusCSVUtils.showWarningMessage(tr(message)); 211 } 212 // Show summary 213 if (ColumbusCSVPreferences.showSummary()) { 214 showSummary(waypts, trkpts, audiopts, missaudio, rescaudio); 215 } 216 217 String desc = String.format( 218 "Converted by ColumbusCSV plugin from track file '%s'", 219 f.getName()); 220 gpxData.attr.put(GpxData.META_DESC, desc); 221 gpxData.storageFile = f; 222 return gpxData; 223 223 } 224 224 … … 232 232 */ 233 233 public static boolean isColumbusFile(File file) throws IOException { 234 if (file == null) return false;235 236 FileInputStream fstream = new FileInputStream(file);237 // Get the object of DataInputStream238 DataInputStream in = new DataInputStream(fstream);239 BufferedReader br = new BufferedReader(new InputStreamReader(in));240 String strLine;241 // Initial values242 int line = 0;243 int columbusLines = 0;244 try {245 // Read File Line By Line until we either exceed the maximum scan246 // lines or we are sure that we have a columbus file247 while ((strLine = br.readLine()) != null248 && (line < MAX_SCAN_LINES || columbusLines > MIN_SCAN_LINES)) {249 String[] csvFields = getCSVLine(strLine); // Get the columns of250 // the current line251 ++line;252 if (csvFields.length == 0 || line <= 1) { // Skip, if line is253 // header or contains254 // no data255 continue;256 }257 258 String wptType = csvFields[1];259 // Check for columbus tag260 if ("T".equals(wptType) || "V".equals(wptType)261 || "C".equals(wptType)) {262 // ok, we found one line but still not convinced ;-)263 columbusLines++;264 }265 }266 } finally {267 // Close the input stream268 br.close();269 }270 271 return columbusLines > MIN_SCAN_LINES;234 if (file == null) return false; 235 236 FileInputStream fstream = new FileInputStream(file); 237 // Get the object of DataInputStream 238 DataInputStream in = new DataInputStream(fstream); 239 BufferedReader br = new BufferedReader(new InputStreamReader(in)); 240 String strLine; 241 // Initial values 242 int line = 0; 243 int columbusLines = 0; 244 try { 245 // Read File Line By Line until we either exceed the maximum scan 246 // lines or we are sure that we have a columbus file 247 while ((strLine = br.readLine()) != null 248 && (line < MAX_SCAN_LINES || columbusLines > MIN_SCAN_LINES)) { 249 String[] csvFields = getCSVLine(strLine); // Get the columns of 250 // the current line 251 ++line; 252 if (csvFields.length == 0 || line <= 1) { // Skip, if line is 253 // header or contains 254 // no data 255 continue; 256 } 257 258 String wptType = csvFields[1]; 259 // Check for columbus tag 260 if ("T".equals(wptType) || "V".equals(wptType) 261 || "C".equals(wptType)) { 262 // ok, we found one line but still not convinced ;-) 263 columbusLines++; 264 } 265 } 266 } finally { 267 // Close the input stream 268 br.close(); 269 } 270 271 return columbusLines > MIN_SCAN_LINES; 272 272 } 273 273 … … 281 281 */ 282 282 private int searchForLostAudioFiles(GpxData gpx) { 283 HashMap<String, WayPoint> voxFiles = getVoxFileMap(); 284 285 int first, last; 286 first = getFirstVoxNumber(); 287 last = getLastVoxNumber(); 288 289 int rescuedFiles = 0; 290 291 for (int i = first; i < last; i++) { 292 String voxFile = String.format("vox%05d.wav", i); 293 String nextVoxFile = String.format("vox%05d.wav", i + 1); 294 if (!voxFiles.containsKey(voxFile)) { 295 System.out.println("Found lost vox file " + voxFile); 296 297 File f = getVoxFilePath(voxFile); 298 WayPoint nearestWpt = null; 299 List<WayPoint> wpts = getAllWayPoints(); 300 // Attach recording to the way point right before the next vox 301 // file 302 if (voxFiles.containsKey(nextVoxFile)) { 303 WayPoint nextWpt = voxFiles.get(nextVoxFile); 304 int idx = getAllWayPoints().indexOf(nextWpt) - 5; 305 if (idx >= 0) { 306 nearestWpt = wpts.get(idx); 307 } else { 308 nearestWpt = wpts.get(0); 309 } 310 } else { // attach to last way point 311 nearestWpt = wpts.get(wpts.size() - 1); 312 } 313 314 // Add link to found way point 315 if (nearestWpt != null) { 316 if (addLinkToWayPoint(nearestWpt, "*" + voxFile + "*", f)) { 317 System.out.println(String.format( 318 "Linked file %s to position %s", voxFile, 319 nearestWpt.getCoor().toDisplayString())); 320 // Add linked way point to way point list of GPX; 321 // otherwise 322 // it would not be shown correctly 323 gpx.waypoints.add(nearestWpt); 324 rescuedFiles++; 325 } else { 326 System.err 327 .println(String 328 .format("Could not link vox file %s due to invalid parameters.", 329 voxFile)); 330 } 331 } 332 } 333 } 334 335 return rescuedFiles; 336 } 337 338 /** 339 * 340 */ 283 Map<String, WayPoint> voxFiles = getVoxFileMap(); 284 285 int first, last; 286 first = getFirstVoxNumber(); 287 last = getLastVoxNumber(); 288 289 int rescuedFiles = 0; 290 291 for (int i = first; i < last; i++) { 292 String voxFile = String.format("vox%05d.wav", i); 293 String nextVoxFile = String.format("vox%05d.wav", i + 1); 294 if (!voxFiles.containsKey(voxFile)) { 295 Main.info("Found lost vox file " + voxFile); 296 297 File f = getVoxFilePath(voxFile); 298 WayPoint nearestWpt = null; 299 List<WayPoint> wpts = getAllWayPoints(); 300 // Attach recording to the way point right before the next vox 301 // file 302 if (voxFiles.containsKey(nextVoxFile)) { 303 WayPoint nextWpt = voxFiles.get(nextVoxFile); 304 int idx = getAllWayPoints().indexOf(nextWpt) - 5; 305 if (idx >= 0) { 306 nearestWpt = wpts.get(idx); 307 } else { 308 nearestWpt = wpts.get(0); 309 } 310 } else { // attach to last way point 311 nearestWpt = wpts.get(wpts.size() - 1); 312 } 313 314 // Add link to found way point 315 if (nearestWpt != null) { 316 if (addLinkToWayPoint(nearestWpt, "*" + voxFile + "*", f)) { 317 Main.info(String.format( 318 "Linked file %s to position %s", voxFile, 319 nearestWpt.getCoor().toDisplayString())); 320 // Add linked way point to way point list of GPX; otherwise it would not be shown correctly 321 gpx.waypoints.add(nearestWpt); 322 rescuedFiles++; 323 } else { 324 Main.error(String.format("Could not link vox file %s due to invalid parameters.", voxFile)); 325 } 326 } 327 } 328 } 329 330 return rescuedFiles; 331 } 332 333 /** 334 * 335 */ 341 336 private void initImport() { 342 dateConversionErrors = 0;343 dopConversionErrors = 0;344 firstVoxNumber = Integer.MAX_VALUE;345 lastVoxNumber = Integer.MIN_VALUE;337 dateConversionErrors = 0; 338 dopConversionErrors = 0; 339 firstVoxNumber = Integer.MAX_VALUE; 340 lastVoxNumber = Integer.MIN_VALUE; 346 341 } 347 342 … … 350 345 */ 351 346 void dropBufferLists() { 352 allTrackPts.clear();353 trackPts.clear();354 voxFiles.clear();347 allTrackPts.clear(); 348 trackPts.clear(); 349 voxFiles.clear(); 355 350 } 356 351 … … 370 365 */ 371 366 private void showSummary(int waypts, int trkpts, int audiopts, 372 int missaudio, int rescaudio) { 373 String message = ""; 374 if (missaudio > 0) { 375 message = String 376 .format("Imported %d track points and %d way points (%d with audio, %d rescued).\nNote: %d audio files could not be found, please check marker comments!", 377 trkpts, waypts, audiopts, rescaudio, missaudio); 378 } else { 379 message = String 380 .format("Imported %d track points and %d way points (%d with audio, %d rescued).", 381 trkpts, waypts, audiopts, rescaudio); 382 } 383 ColumbusCSVUtils.showInfoMessage(tr(message)); 367 int missaudio, int rescaudio) { 368 String message = ""; 369 if (missaudio > 0) { 370 message = String 371 .format("Imported %d track points and %d way points (%d with audio, %d rescued).%n"+ 372 "Note: %d audio files could not be found, please check marker comments!", 373 trkpts, waypts, audiopts, rescaudio, missaudio); 374 } else { 375 message = String 376 .format("Imported %d track points and %d way points (%d with audio, %d rescued).", 377 trkpts, waypts, audiopts, rescaudio); 378 } 379 ColumbusCSVUtils.showInfoMessage(tr(message)); 384 380 } 385 381 … … 394 390 * @throws DataFormatException 395 391 */ 396 private WayPoint createWayPoint(String[] csvLine, String fileDir) 397 throws IOException { 398 // Sample line in simple mode 399 // INDEX,TAG,DATE,TIME,LATITUDE N/S,LONGITUDE 400 // E/W,HEIGHT,SPEED,HEADING,VOX 401 // 1,T,090430,194134,48.856330N,009.089779E,318,20,0, 402 403 // Sample line in extended mode 404 // INDEX,TAG,DATE,TIME,LATITUDE N/S,LONGITUDE 405 // E/W,HEIGHT,SPEED,HEADING,FIX MODE,VALID,PDOP,HDOP,VDOP,VOX 406 // 1,T,090508,191448,48.856928N,009.091153E,330,3,0,3D,SPS ,1.4,1.2,0.8, 407 if (csvLine.length != 10 && csvLine.length != 15) 408 throw new IOException("Invalid number of tokens: " + csvLine.length); 409 boolean isExtMode = csvLine.length > 10; 410 411 // Extract latitude/longitude first 412 String lat = csvLine[4]; 413 double latVal = Double.parseDouble(lat.substring(0, lat.length() - 1)); 414 if (lat.endsWith("S")) { 415 latVal = -latVal; 416 } 417 418 String lon = csvLine[5]; 419 double lonVal = Double.parseDouble(lon.substring(0, lon.length() - 1)); 420 if (lon.endsWith("W")) { 421 lonVal = -lonVal; 422 } 423 LatLon pos = new LatLon(latVal, lonVal); 424 WayPoint wpt = new WayPoint(pos); 425 426 // set wpt type 427 wpt.attr.put(TYPE_TAG, csvLine[1]); 428 429 // Check for audio file and link it, if present 430 String voxFile = null; 431 if (isExtMode) { 432 voxFile = csvLine[14]; 433 } else { 434 voxFile = csvLine[9]; 435 } 436 437 if (!ColumbusCSVUtils.isStringNullOrEmpty(voxFile)) { 438 voxFile = voxFile + ".wav"; 439 File file = getVoxFilePath(fileDir, voxFile); 440 if (file != null && file.exists()) { 441 // link vox file 442 int voxNum = getNumberOfVoxfile(voxFile); 443 lastVoxNumber = Math.max(voxNum, lastVoxNumber); 444 firstVoxNumber = Math.min(voxNum, firstVoxNumber); 445 446 addLinkToWayPoint(wpt, voxFile, file); 447 448 if (!"V".equals(csvLine[1])) { 449 System.out 450 .println("Rescued unlinked audio file " + voxFile); 451 } 452 voxFiles.put(voxFile, wpt); 453 454 // set type to way point with vox 455 wpt.attr.put(TYPE_TAG, "V"); 456 } else { // audio file not found -> issue warning 457 System.err.println("File " + voxFile + " not found!"); 458 String warnMsg = tr("Missing audio file") + ": " + voxFile; 459 System.err.println(warnMsg); 460 if (ColumbusCSVPreferences.warnMissingAudio()) { 461 ColumbusCSVUtils.showInfoMessage(warnMsg); 462 } 463 wpt.attr.put(ColumbusCSVReader.COMMENT_TAG, warnMsg); 464 // set type to ordinary way point 465 wpt.attr.put(TYPE_TAG, "C"); 466 } 467 468 } 469 470 // Extract date/time 471 SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyMMdd/HHmmss"); 472 Date d = null; 473 474 try { 475 476 d = sdf.parse(csvLine[2] + "/" + csvLine[3]); 477 // format date according to GPX 478 SimpleDateFormat f = new SimpleDateFormat( 479 "yyyy-MM-dd'T'HH:mm:ss'Z'"); 480 481 wpt.attr.put(ColumbusCSVReader.TIME_TAG, f.format(d).toString()); 482 wpt.setTime(); 483 } catch (ParseException ex) { 484 dateConversionErrors++; 485 System.err.println(ex); 486 } 487 488 // Add further attributes 489 // Elevation height (altitude provided by GPS signal) 490 wpt.attr.put(ColumbusCSVReader.ELEVATIONHEIGHT_TAG, csvLine[6]); 491 492 // Add data of extended mode, if applicable 493 if (isExtMode && !ColumbusCSVPreferences.ignoreDOP()) { 494 addExtendedGPSData(csvLine, wpt); 495 } 496 497 return wpt; 392 private WayPoint createWayPoint(String[] csvLine, String fileDir) throws IOException { 393 // Sample line in simple mode 394 // INDEX,TAG,DATE,TIME,LATITUDE N/S,LONGITUDE 395 // E/W,HEIGHT,SPEED,HEADING,VOX 396 // 1,T,090430,194134,48.856330N,009.089779E,318,20,0, 397 398 // Sample line in extended mode 399 // INDEX,TAG,DATE,TIME,LATITUDE N/S,LONGITUDE 400 // E/W,HEIGHT,SPEED,HEADING,FIX MODE,VALID,PDOP,HDOP,VDOP,VOX 401 // 1,T,090508,191448,48.856928N,009.091153E,330,3,0,3D,SPS ,1.4,1.2,0.8, 402 if (csvLine.length != 10 && csvLine.length != 15) 403 throw new IOException("Invalid number of tokens: " + csvLine.length); 404 boolean isExtMode = csvLine.length > 10; 405 406 // Extract latitude/longitude first 407 String lat = csvLine[4]; 408 double latVal = Double.parseDouble(lat.substring(0, lat.length() - 1)); 409 if (lat.endsWith("S")) { 410 latVal = -latVal; 411 } 412 413 String lon = csvLine[5]; 414 double lonVal = Double.parseDouble(lon.substring(0, lon.length() - 1)); 415 if (lon.endsWith("W")) { 416 lonVal = -lonVal; 417 } 418 LatLon pos = new LatLon(latVal, lonVal); 419 WayPoint wpt = new WayPoint(pos); 420 421 // set wpt type 422 wpt.attr.put(TYPE_TAG, csvLine[1]); 423 424 // Check for audio file and link it, if present 425 String voxFile = null; 426 if (isExtMode) { 427 voxFile = csvLine[14]; 428 } else { 429 voxFile = csvLine[9]; 430 } 431 432 if (!ColumbusCSVUtils.isStringNullOrEmpty(voxFile)) { 433 voxFile = voxFile + ".wav"; 434 File file = getVoxFilePath(fileDir, voxFile); 435 if (file != null && file.exists()) { 436 // link vox file 437 int voxNum = getNumberOfVoxfile(voxFile); 438 lastVoxNumber = Math.max(voxNum, lastVoxNumber); 439 firstVoxNumber = Math.min(voxNum, firstVoxNumber); 440 441 addLinkToWayPoint(wpt, voxFile, file); 442 443 if (!"V".equals(csvLine[1])) { 444 Main.info("Rescued unlinked audio file " + voxFile); 445 } 446 voxFiles.put(voxFile, wpt); 447 448 // set type to way point with vox 449 wpt.attr.put(TYPE_TAG, "V"); 450 } else { // audio file not found -> issue warning 451 Main.error("File " + voxFile + " not found!"); 452 String warnMsg = tr("Missing audio file") + ": " + voxFile; 453 Main.error(warnMsg); 454 if (ColumbusCSVPreferences.warnMissingAudio()) { 455 ColumbusCSVUtils.showInfoMessage(warnMsg); 456 } 457 wpt.attr.put(ColumbusCSVReader.COMMENT_TAG, warnMsg); 458 // set type to ordinary way point 459 wpt.attr.put(TYPE_TAG, "C"); 460 } 461 } 462 463 // Extract date/time 464 SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyMMdd/HHmmss"); 465 Date d = null; 466 467 try { 468 d = sdf.parse(csvLine[2] + "/" + csvLine[3]); 469 // format date according to GPX 470 SimpleDateFormat f = new SimpleDateFormat( 471 "yyyy-MM-dd'T'HH:mm:ss'Z'"); 472 473 wpt.attr.put(ColumbusCSVReader.TIME_TAG, f.format(d).toString()); 474 wpt.setTime(); 475 } catch (ParseException ex) { 476 dateConversionErrors++; 477 Main.error(ex); 478 } 479 480 // Add further attributes 481 // Elevation height (altitude provided by GPS signal) 482 wpt.attr.put(ColumbusCSVReader.ELEVATIONHEIGHT_TAG, csvLine[6]); 483 484 // Add data of extended mode, if applicable 485 if (isExtMode && !ColumbusCSVPreferences.ignoreDOP()) { 486 addExtendedGPSData(csvLine, wpt); 487 } 488 489 return wpt; 498 490 } 499 491 … … 508 500 */ 509 501 public File getVoxFilePath(String voxFile) { 510 return getVoxFilePath(getWorkingDirOfImport(), voxFile);502 return getVoxFilePath(getWorkingDirOfImport(), voxFile); 511 503 } 512 504 … … 521 513 */ 522 514 public File getVoxFilePath(String fileDir, String voxFile) { 523 // The FAT16 file name is interpreted differently from case-sensitive 524 // file systems, so we 525 // have to test several variants 526 String[] fileNameVariants = new String[] { voxFile, 527 voxFile.toLowerCase(), voxFile.toUpperCase() }; 528 529 for (int i = 0; i < fileNameVariants.length; i++) { 530 File file = new File(fileDir + File.separator + fileNameVariants[i]); 531 if (file.exists()) { 532 return file; 533 } 534 } 535 return null; // give up... 536 515 // The FAT16 file name is interpreted differently from case-sensitive 516 // file systems, so we 517 // have to test several variants 518 String[] fileNameVariants = new String[] { voxFile, 519 voxFile.toLowerCase(), voxFile.toUpperCase() }; 520 521 for (int i = 0; i < fileNameVariants.length; i++) { 522 File file = new File(fileDir + File.separator + fileNameVariants[i]); 523 if (file.exists()) { 524 return file; 525 } 526 } 527 return null; // give up... 537 528 } 538 529 … … 544 535 */ 545 536 private void addExtendedGPSData(String[] csvLine, WayPoint wpt) { 546 // Fix mode547 wpt.attr.put(FIX_TAG, csvLine[9].toLowerCase());548 549 Float f;550 // Position errors (dop = dilution of position)551 f = ColumbusCSVUtils.floatFromString(csvLine[11]);552 if (f != Float.NaN) {553 wpt.attr.put(ColumbusCSVReader.PDOP_TAG, f);554 } else {555 dopConversionErrors++;556 }557 558 f = ColumbusCSVUtils.floatFromString(csvLine[12]);559 if (f != Float.NaN) {560 wpt.attr.put(ColumbusCSVReader.HDOP_TAG, f);561 } else {562 dopConversionErrors++;563 }564 565 f = ColumbusCSVUtils.floatFromString(csvLine[13]);566 if (f != Float.NaN) {567 wpt.attr.put(ColumbusCSVReader.VDOP_TAG, f);568 } else {569 dopConversionErrors++;570 }537 // Fix mode 538 wpt.attr.put(FIX_TAG, csvLine[9].toLowerCase()); 539 540 Float f; 541 // Position errors (dop = dilution of position) 542 f = ColumbusCSVUtils.floatFromString(csvLine[11]); 543 if (f != Float.NaN) { 544 wpt.attr.put(ColumbusCSVReader.PDOP_TAG, f); 545 } else { 546 dopConversionErrors++; 547 } 548 549 f = ColumbusCSVUtils.floatFromString(csvLine[12]); 550 if (f != Float.NaN) { 551 wpt.attr.put(ColumbusCSVReader.HDOP_TAG, f); 552 } else { 553 dopConversionErrors++; 554 } 555 556 f = ColumbusCSVUtils.floatFromString(csvLine[13]); 557 if (f != Float.NaN) { 558 wpt.attr.put(ColumbusCSVReader.VDOP_TAG, f); 559 } else { 560 dopConversionErrors++; 561 } 571 562 } 572 563 … … 581 572 */ 582 573 public boolean addLinkToWayPoint(WayPoint wpt, String voxFile, File file) { 583 if (file == null || wpt == null || voxFile == null)584 return false;585 586 GpxLink lnk = new GpxLink(file.toURI().toString());587 lnk.type = ColumbusCSVReader.AUDIO_WAV_LINK;588 lnk.text = voxFile;589 590 // JOSM expects a collection of links here...591 Collection<GpxLink> linkList = new ArrayList<GpxLink>(1);592 linkList.add(lnk);593 594 wpt.attr.put(GpxData.META_LINKS, linkList);595 wpt.attr.put(ColumbusCSVReader.COMMENT_TAG, "Audio recording");596 wpt.attr.put(ColumbusCSVReader.DESC_TAG, voxFile);597 return true;574 if (file == null || wpt == null || voxFile == null) 575 return false; 576 577 GpxLink lnk = new GpxLink(file.toURI().toString()); 578 lnk.type = ColumbusCSVReader.AUDIO_WAV_LINK; 579 lnk.text = voxFile; 580 581 // JOSM expects a collection of links here... 582 Collection<GpxLink> linkList = new ArrayList<>(1); 583 linkList.add(lnk); 584 585 wpt.attr.put(GpxData.META_LINKS, linkList); 586 wpt.attr.put(ColumbusCSVReader.COMMENT_TAG, "Audio recording"); 587 wpt.attr.put(ColumbusCSVReader.DESC_TAG, voxFile); 588 return true; 598 589 } 599 590 … … 605 596 */ 606 597 private static String[] getCSVLine(String line) { 607 if (line == null || line.length() == 0)608 return EMPTY_LINE;609 610 StringTokenizer st = new StringTokenizer(line, SEPS, false);611 int n = st.countTokens();612 613 String[] res = new String[n];614 for (int i = 0; i < n; i++) {615 res[i] = st.nextToken().trim();616 }617 return res;598 if (line == null || line.length() == 0) 599 return EMPTY_LINE; 600 601 StringTokenizer st = new StringTokenizer(line, SEPS, false); 602 int n = st.countTokens(); 603 604 String[] res = new String[n]; 605 for (int i = 0; i < n; i++) { 606 res[i] = st.nextToken().trim(); 607 } 608 return res; 618 609 } 619 610 … … 628 619 */ 629 620 private int getNumberOfVoxfile(String fileName) { 630 if (fileName == null) 631 return -1; 632 633 try { 634 String num = fileName.substring(3); 635 int val = Integer.parseInt(num); 636 return val; 637 } catch (NumberFormatException e) { 638 return -1; 639 } 621 if (fileName == null) 622 return -1; 623 624 try { 625 String num = fileName.substring(3); 626 return Integer.parseInt(num); 627 } catch (NumberFormatException e) { 628 return -1; 629 } 640 630 } 641 631 … … 646 636 */ 647 637 public int getNumberOfDateConversionErrors() { 648 return dateConversionErrors;638 return dateConversionErrors; 649 639 } 650 640 … … 655 645 */ 656 646 public int getNumberOfDOPConversionErrors() { 657 return dopConversionErrors;647 return dopConversionErrors; 658 648 } 659 649 … … 664 654 */ 665 655 public int getFirstVoxNumber() { 666 return firstVoxNumber;656 return firstVoxNumber; 667 657 } 668 658 … … 673 663 */ 674 664 public int getLastVoxNumber() { 675 return lastVoxNumber;665 return lastVoxNumber; 676 666 } 677 667 … … 681 671 * @return 682 672 */ 683 public HashMap<String, WayPoint> getVoxFileMap() {684 return voxFiles;673 public Map<String, WayPoint> getVoxFileMap() { 674 return voxFiles; 685 675 } 686 676 … … 691 681 */ 692 682 public List<WayPoint> getAllWayPoints() { 693 return allWpts;683 return allWpts; 694 684 } 695 685 … … 700 690 */ 701 691 public String getWorkingDirOfImport() { 702 return fileDir;692 return fileDir; 703 693 } 704 694 } -
applications/editors/josm/plugins/ColumbusCSV/src/org/openstreetmap/josm/plugins/columbusCSV/ColumbusCSVUtils.java
r23708 r30768 20 20 import org.openstreetmap.josm.Main; 21 21 22 /** 23 * Utility functions. 24 * @author Oliver Wieland <oliver.wieland@online.de> 25 * 26 */ 22 27 public class ColumbusCSVUtils { 23 /**24 * Private constructor for the utility class.25 */26 private ColumbusCSVUtils() {27 28 }29 30 /**31 * Shows an error message.32 * @param txt Message to show.33 */34 public static void showErrorMessage(String txt) {35 showMessage(txt, tr("Error"), JOptionPane.ERROR_MESSAGE);36 }37 38 /**39 * Shows an information message.40 * @param txt Message to show.41 */42 public static void showInfoMessage(String txt) {43 showMessage(txt, tr("Information"), JOptionPane.INFORMATION_MESSAGE);44 }45 46 /**47 * Shows a warning message.48 * @param txt Message to show.49 */50 public static void showWarningMessage(String txt) {51 showMessage(txt, tr("Warning"), JOptionPane.WARNING_MESSAGE);52 }53 54 /**55 * Generic method to show a message.56 * @param txt Message to show57 * @param caption Title of message box58 * @param icon Icon to show (question, warning,...)59 */60 public static void showMessage(String txt, String caption, int icon) {61 if (isStringNullOrEmpty(txt)) return;62 63 JOptionPane.showMessageDialog(Main.parent, tr(txt), caption, icon);64 }65 66 /**67 * Check, if a string is either null or empty.68 *69 * @param txt70 * . The text to check for.71 * @return True, if given text is either null or empty.72 */73 public static boolean isStringNullOrEmpty(String txt) {74 return txt == null || txt.length() == 0;75 }76 77 /**78 * Parses a float number from a string.79 * @param txt80 * @return The corresponding float instance or Float.NaN, if txt was empty or contained an invalid float number.81 */82 public static Float floatFromString(String txt) {83 Float f;84 85 if (isStringNullOrEmpty(txt)) return Float.NaN;86 87 try {88 f = Float.parseFloat(txt);89 } catch (NumberFormatException nex) {90 f = Float.NaN;91 }92 return f;93 } 28 /** 29 * Private constructor for the utility class. 30 */ 31 private ColumbusCSVUtils() { 32 33 } 34 35 /** 36 * Shows an error message. 37 * @param txt Message to show. 38 */ 39 public static void showErrorMessage(String txt) { 40 showMessage(txt, tr("Error"), JOptionPane.ERROR_MESSAGE); 41 } 42 43 /** 44 * Shows an information message. 45 * @param txt Message to show. 46 */ 47 public static void showInfoMessage(String txt) { 48 showMessage(txt, tr("Information"), JOptionPane.INFORMATION_MESSAGE); 49 } 50 51 /** 52 * Shows a warning message. 53 * @param txt Message to show. 54 */ 55 public static void showWarningMessage(String txt) { 56 showMessage(txt, tr("Warning"), JOptionPane.WARNING_MESSAGE); 57 } 58 59 /** 60 * Generic method to show a message. 61 * @param txt Message to show 62 * @param caption Title of message box 63 * @param icon Icon to show (question, warning,...) 64 */ 65 public static void showMessage(String txt, String caption, int icon) { 66 if (isStringNullOrEmpty(txt)) return; 67 68 JOptionPane.showMessageDialog(Main.parent, tr(txt), caption, icon); 69 } 70 71 /** 72 * Check, if a string is either null or empty. 73 * 74 * @param txt 75 * . The text to check for. 76 * @return True, if given text is either null or empty. 77 */ 78 public static boolean isStringNullOrEmpty(String txt) { 79 return txt == null || txt.length() == 0; 80 } 81 82 /** 83 * Parses a float number from a string. 84 * @param txt 85 * @return The corresponding float instance or Float.NaN, if txt was empty or contained an invalid float number. 86 */ 87 public static Float floatFromString(String txt) { 88 Float f; 89 90 if (isStringNullOrEmpty(txt)) return Float.NaN; 91 92 try { 93 f = Float.parseFloat(txt); 94 } catch (NumberFormatException nex) { 95 f = Float.NaN; 96 } 97 return f; 98 } 94 99 } -
applications/editors/josm/plugins/ColumbusCSV/src/org/openstreetmap/josm/plugins/columbusCSV/WayPointHelper.java
r23795 r30768 25 25 import java.util.List; 26 26 27 import org.openstreetmap.josm.Main; 27 28 import org.openstreetmap.josm.data.coor.LatLon; 28 29 import org.openstreetmap.josm.data.gpx.WayPoint; … … 33 34 */ 34 35 public class WayPointHelper { 35 /**36 * The name of the elevation height of a way point.37 */38 public static final String HEIGHT_ATTRIBUTE = "ele";36 /** 37 * The name of the elevation height of a way point. 38 */ 39 public static final String HEIGHT_ATTRIBUTE = "ele"; 39 40 41 private static final double R = 6378135; 42 43 private WayPointHelper() { 44 // Private constructor for the utility class. 45 } 40 46 41 /**42 * Gets the elevation (Z coordinate) of a JOSM way point.43 *44 * @param wpt45 * The way point instance.46 * @return The x coordinate or 0, if the given way point is null or contains47 * not height attribute.48 */49 public static double getElevation(WayPoint wpt) {50 if (wpt != null) {51 if (!wpt.attr.containsKey(HEIGHT_ATTRIBUTE)) {52 return 0;53 }47 /** 48 * Gets the elevation (Z coordinate) of a JOSM way point. 49 * 50 * @param wpt 51 * The way point instance. 52 * @return The x coordinate or 0, if the given way point is null or contains 53 * not height attribute. 54 */ 55 public static double getElevation(WayPoint wpt) { 56 if (wpt != null) { 57 if (!wpt.attr.containsKey(HEIGHT_ATTRIBUTE)) { 58 return 0; 59 } 54 60 55 String height = wpt.getString(WayPointHelper.HEIGHT_ATTRIBUTE); 56 try { 57 double z = Double.parseDouble(height); 61 String height = wpt.getString(WayPointHelper.HEIGHT_ATTRIBUTE); 62 try { 63 return Double.parseDouble(height); 64 } catch (NumberFormatException e) { 65 Main.error(String.format( 66 "Cannot parse double from '%s': %s", height, e 67 .getMessage())); 68 } 69 } 70 return 0; 71 } 72 73 public static double getLonDist(WayPoint w1, WayPoint w2) { 74 LatLon ll = new LatLon(w1.getCoor().lat(), w2.getCoor().lon()); 75 return w1.getCoor().greatCircleDistance(ll); 76 } 77 78 public static double getLatDist(WayPoint w1, WayPoint w2) { 79 LatLon ll = new LatLon(w2.getCoor().lat(), w1.getCoor().lon()); 80 return w1.getCoor().greatCircleDistance(ll); 81 } 82 83 /** 84 * Moves a given lat/lon coordinate by a given amount of meters in 85 * x and y direction. 86 * @param src The original lat/lon coordinate. 87 * @param dlat The distance in latitude direction in meters 88 * @param dlon The distance in longitude direction in meters 89 * @return 90 */ 91 public static LatLon moveLatLon(LatLon src, double dlat, double dlon) { 92 double lat1 = toRadians(src.lat()); 93 double lon1 = toRadians(src.lon()); 94 95 double dlonsin2 = sin(dlon/2 / R); 96 double dlatsin2 = sin(dlat/2 / R); 97 double dlatcos = cos(lon1); 98 99 double lon2rad = 2 * asin(sqrt(dlonsin2 * dlonsin2 / dlatcos/dlatcos)) + lon1; 100 double lat2rad = 2 * asin(dlatsin2) + lat1; 101 102 double lon2 = toDegrees(lon2rad); 103 double lat2 = toDegrees(lat2rad); 104 105 return new LatLon(lat2, lon2); 106 } 58 107 59 return z; 60 } catch (NumberFormatException e) { 61 System.err.println(String.format( 62 "Cannot parse double from '%s': %s", height, e 63 .getMessage())); 64 return 0; 65 } 66 } else { 67 return 0; 68 } 69 } 70 71 public static double getLonDist(WayPoint w1, WayPoint w2) { 72 LatLon ll = new LatLon(w1.getCoor().lat(), w2.getCoor().lon()); 73 return w1.getCoor().greatCircleDistance(ll); 74 } 75 76 public static double getLatDist(WayPoint w1, WayPoint w2) { 77 LatLon ll = new LatLon(w2.getCoor().lat(), w1.getCoor().lon()); 78 return w1.getCoor().greatCircleDistance(ll); 79 } 80 81 /** 82 * Moves a given lat/lon coordinate by a given amount of meters in 83 * x and y direction. 84 * @param src The original lat/lon coordinate. 85 * @param dlat The distance in latitude direction in meters 86 * @param dlon The distance in longitude direction in meters 87 * @return 88 */ 89 public static LatLon moveLatLon(LatLon src, double dlat, double dlon) { 90 final double R = 6378135; 91 92 double lat1 = toRadians(src.lat()); 93 double lon1 = toRadians(src.lon()); 94 95 double dlonsin2 = sin(dlon/2 / R); 96 double dlatsin2 = sin(dlat/2 / R); 97 double dlatcos = cos(lon1); 98 99 double lon2rad = 2 * asin(sqrt(dlonsin2 * dlonsin2 / dlatcos/dlatcos)) + lon1; 100 double lat2rad = 2 * asin(dlatsin2) + lat1; 101 102 double lon2 = toDegrees(lon2rad); 103 double lat2 = toDegrees(lat2rad); 104 105 LatLon llmoved = new LatLon(lat2, lon2); 106 107 //double d2 = llmoved.greatCircleDistance(src); 108 109 return llmoved; 110 } 108 /** 109 * Reduces a given list of way points to the specified target size. 110 * 111 * @param origList 112 * The original list containing the way points. 113 * @param targetSize 114 * The desired target size of the list. The resulting list may 115 * contain fewer items, so targetSize should be considered as 116 * maximum. 117 * @return A list containing the reduced list. 118 */ 119 public static List<WayPoint> downsampleWayPoints(List<WayPoint> origList, 120 int targetSize) { 121 if (origList == null) 122 return null; 123 if (targetSize <= 0) 124 throw new IllegalArgumentException( 125 "targetSize must be greater than zero"); 111 126 112 /** 113 * Reduces a given list of way points to the specified target size. 114 * 115 * @param origList 116 * The original list containing the way points. 117 * @param targetSize 118 * The desired target size of the list. The resulting list may 119 * contain fewer items, so targetSize should be considered as 120 * maximum. 121 * @return A list containing the reduced list. 122 */ 123 public static List<WayPoint> downsampleWayPoints(List<WayPoint> origList, 124 int targetSize) { 125 if (origList == null) 126 return null; 127 if (targetSize <= 0) 128 throw new IllegalArgumentException( 129 "targetSize must be greater than zero"); 127 int origSize = origList.size(); 128 if (origSize <= targetSize) { 129 return origList; 130 } 130 131 131 int origSize = origList.size(); 132 if (origSize <= targetSize) { 133 return origList; 134 } 132 int delta = (int) Math.max(Math.ceil(origSize / targetSize), 2); 135 133 136 int delta = (int) Math.max(Math.ceil(origSize / targetSize), 2); 134 List<WayPoint> res = new ArrayList<>(targetSize); 135 for (int i = 0; i < origSize; i += delta) { 136 res.add(origList.get(i)); 137 } 137 138 138 List<WayPoint> res = new ArrayList<WayPoint>(targetSize); 139 for (int i = 0; i < origSize; i += delta) { 140 res.add(origList.get(i)); 141 } 142 143 return res; 144 } 139 return res; 140 } 145 141 }
Note:
See TracChangeset
for help on using the changeset viewer.
