Ignore:
Timestamp:
2016-09-02T21:32:04+02:00 (8 years ago)
Author:
donvip
Message:

fix #josm13508 - support CSV format with lat/lon couple in a single column named "Geo Point"

Location:
applications/editors/josm/plugins/opendata
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/OdConstants.java

    r32545 r32898  
    102102    public static final String X_STRING = "X|LON|LONGI|.*LONGITUDE.*|EASTING";
    103103    public static final String Y_STRING = "Y|LAT|LATI|.*LATITUDE.*|NORTHING";
     104    public static final String XY_STRING = "POINT";
    104105
    105106    // The list of all ProjectionPatterns (filled at each constructor call)
     
    107108
    108109    // CHECKSTYLE.OFF: LineLength
    109     public static final ProjectionPatterns PRJ_WGS84 = new ProjectionPatterns("GPS|WGS84|°décimaux", Projections.getProjectionByCode("EPSG:4326"));
     110    public static final ProjectionPatterns PRJ_WGS84 = new ProjectionPatterns("GPS|WGS84|°décimaux|GEO", Projections.getProjectionByCode("EPSG:4326"));
    110111    public static final ProjectionPatterns PRJ_LAMBERT_93 = new ProjectionPatterns("LAMB93|L93", Projections.getProjectionByCode("EPSG:2154"));
    111112    public static final ProjectionPatterns PRJ_LAMBERT_CC_9_ZONES = new LambertCC9ZonesProjectionPatterns("LAMBZ|CC(42|43|44|45|46|47|48|49|50)");
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/ProjectionPatterns.java

    r30723 r32898  
    1111    private final Pattern xPattern;
    1212    private final Pattern yPattern;
     13    private final Pattern xyPattern;
    1314    private final Projection projection;
    14    
    15     public ProjectionPatterns(Pattern xPattern, Pattern yPattern, Projection projection) {
     15
     16    public ProjectionPatterns(Pattern xPattern, Pattern yPattern, Pattern xyPattern, Projection projection) {
    1617        this.xPattern = xPattern;
    1718        this.yPattern = yPattern;
     19        this.xyPattern = xyPattern;
    1820        this.projection = projection;
    1921        OdConstants.PROJECTIONS.add(this);
    2022    }
    2123
    22     public ProjectionPatterns(Pattern xPattern, Pattern yPattern) {
    23         this(xPattern, yPattern, null);
    24     }
    25 
    2624    public ProjectionPatterns(String proj, Projection projection) {
    27         this(getCoordinatePattern(OdConstants.X_STRING, proj), getCoordinatePattern(OdConstants.Y_STRING, proj), projection);
     25        this(getCoordinatePattern(OdConstants.X_STRING, proj),
     26             getCoordinatePattern(OdConstants.Y_STRING, proj),
     27             getCoordinatePattern(OdConstants.XY_STRING, proj), projection);
    2828    }
    2929
    3030    public ProjectionPatterns(String proj) {
    31         this(getCoordinatePattern(OdConstants.X_STRING, proj), getCoordinatePattern(OdConstants.Y_STRING, proj), null);
     31        this(proj, null);
    3232    }
    33    
     33
    3434    public final Pattern getXPattern() {
    3535        return xPattern;
    3636    }
    37    
     37
    3838    public final Pattern getYPattern() {
    3939        return yPattern;
     40    }
     41
     42    public final Pattern getXYPattern() {
     43        return xyPattern;
    4044    }
    4145
     
    5862    @Override
    5963    public String toString() {
    60         return "[xPattern=" + xPattern + ", yPattern=" + yPattern + ", projection=" + projection + "]";
     64        return "[xPattern=" + xPattern + ", yPattern=" + yPattern + ", xyPattern=" + xyPattern + ", projection=" + projection + ']';
    6165    }
    6266}
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/SpreadSheetReader.java

    r32545 r32898  
    1515import java.util.Locale;
    1616import java.util.Map;
     17import java.util.regex.Matcher;
     18import java.util.regex.Pattern;
    1719
    1820import org.openstreetmap.josm.Main;
     
    3234    private static final NumberFormat formatUK = NumberFormat.getInstance(Locale.UK);
    3335
     36    private static final String COOR = "(\\-?\\d+(?:[\\.,]\\d+)?)";
     37    private static final Pattern LATLON_PATTERN = Pattern.compile("^"+COOR+"[,;]?\\s*"+COOR+"$");
     38
    3439    protected final SpreadSheetHandler handler;
    3540
     
    6873        @Override
    6974        public String toString() {
    70             return "CoordinateColumns [proj=" + proj + ", xCol=" + xCol + ", yCol=" + yCol + "]";
     75            return "CoordinateColumns [proj=" + proj + ", xCol=" + xCol + ", yCol=" + yCol + ']';
    7176        }
    7277    }
     
    9196                }
    9297                CoordinateColumns col = columns.isEmpty() ? null : columns.get(columns.size()-1);
    93                 if (pp.getXPattern().matcher(header[i]).matches()) {
     98                if (pp.getXYPattern().matcher(header[i]).matches()) {
     99                    CoordinateColumns coorCol = addCoorColIfNeeded(columns, col);
     100                    coorCol.xCol = i;
     101                    coorCol.yCol = i;
     102                    break;
     103                } else if (pp.getXPattern().matcher(header[i]).matches()) {
    94104                    addCoorColIfNeeded(columns, col).xCol = i;
    95105                    break;
     
    184194                    for (CoordinateColumns c : columns) {
    185195                        EastNorth en = ens.get(c);
    186                         if (i == c.xCol) {
     196                        if (i == c.xCol && i == c.yCol) {
     197                            Matcher m = LATLON_PATTERN.matcher(fields[i]);
     198                            if (m.matches()) {
     199                                coordinate = true;
     200                                ens.put(c, new EastNorth(parseDouble(m.group(2)), parseDouble(m.group(1))));
     201                                if (handler != null) {
     202                                    handler.setXCol(i);
     203                                    handler.setYCol(i);
     204                                }
     205                            }
     206                        } else if (i == c.xCol) {
    187207                            coordinate = true;
    188208                            ens.put(c, new EastNorth(parseDouble(fields[i]), en.north()));
  • applications/editors/josm/plugins/opendata/test/unit/org/openstreetmap/josm/plugins/opendata/core/io/tabular/CsvReaderTest.java

    r32545 r32898  
    5656
    5757    /**
     58     * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/13508">#13508</a>
     59     * @throws IOException if an error occurs during reading
     60     */
     61    @Test
     62    public void testTicket13508() throws IOException, XMLStreamException, FactoryConfigurationError {
     63        try (InputStream is = TestUtils.getRegressionDataStream(13508, "arrets-de-bus0.csv")) {
     64            NonRegFunctionalTests.testGeneric("#13508", CsvReader.parseDataSet(is, newHandler("EPSG:4326"), null));
     65        }
     66    }
     67
     68    /**
    5869     * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/10214">#10214</a>
    5970     * @throws IOException if an error occurs during reading
Note: See TracChangeset for help on using the changeset viewer.