Ticket #17227: poly-v2.patch

File poly-v2.patch, 43.9 KB (added by GerdP, 7 years ago)

unit test for exporter, further clean up

  • .classpath

     
    1 <?xml version="1.0" encoding="UTF-8"?>
    2 <classpath>
    3         <classpathentry kind="src" path="src"/>
    4         <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
    5         <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/>
    6         <classpathentry kind="output" path="bin"/>
    7 </classpath>
     1<?xml version="1.0" encoding="UTF-8"?>
     2<classpath>
     3        <classpathentry kind="src" path="src"/>
     4        <classpathentry kind="src" output="buildtest" path="test/unit">
     5                <attributes>
     6                        <attribute name="test" value="true"/>
     7                </attributes>
     8        </classpathentry>
     9        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
     10        <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/>
     11        <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
     12        <classpathentry kind="output" path="build"/>
     13</classpath>
  • .project

     
    33        <name>JOSM-Poly</name>
    44        <comment></comment>
    55        <projects>
     6                <project>josm</project>
    67        </projects>
    78        <buildSpec>
    89                <buildCommand>
  • src/poly/PolyExporter.java

     
    11// License: GPL. For details, see LICENSE file.
    22package poly;
    33
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
    46import java.io.BufferedWriter;
    57import java.io.File;
    6 import java.io.FileOutputStream;
    78import java.io.IOException;
    8 import java.io.OutputStreamWriter;
    9 import java.util.ArrayList;
    10 import java.util.LinkedHashMap;
    11 import java.util.List;
     9import java.nio.charset.StandardCharsets;
     10import java.nio.file.Files;
     11import java.util.HashSet;
    1212import java.util.Locale;
    13 import java.util.Map;
    14 import java.util.TreeMap;
     13import java.util.Set;
    1514
    1615import org.openstreetmap.josm.data.osm.DataSet;
    1716import org.openstreetmap.josm.data.osm.Node;
    18 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1917import org.openstreetmap.josm.data.osm.Relation;
    2018import org.openstreetmap.josm.data.osm.RelationMember;
    2119import org.openstreetmap.josm.data.osm.Way;
     
    2725 * Writes poly files.
    2826 *
    2927 * @author zverik
     28 * @author Gerd Petermann
    3029 */
    3130public class PolyExporter extends OsmExporter {
    3231
     32    /**
     33     * Create exporter.
     34     */
    3335    public PolyExporter() {
    3436        super(PolyType.FILE_FILTER);
    3537    }
     
    3739    @Override
    3840    public void exportData(File file, Layer layer) throws IOException {
    3941        if (layer instanceof OsmDataLayer) {
    40             try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF8"))) {
     42            if (((OsmDataLayer) layer).getDataSet().getWays().stream().anyMatch(w -> !w.isClosed())) {
     43                throw new IOException(tr("Data contains unclosed ways."));
     44            }
     45            try (BufferedWriter writer = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) {
    4146                DataSet ds = ((OsmDataLayer) layer).getDataSet();
    42                 Map<Way, Boolean> ways = new TreeMap<>();
    43                 String polygonName = file.getName();
    44                 if (polygonName.indexOf('.') > 0)
    45                     polygonName = polygonName.substring(0, polygonName.indexOf('.'));
    46                 for (Way w : ds.getWays()) {
    47                     if (w.isClosed()) {
    48                         boolean outer = isOuter(w);
    49                         ways.put(w, outer);
    50                         if (w.hasKey("name"))
    51                             polygonName = w.get("name").replace("\n", " ");
     47                HashSet<Way> written = new HashSet<>();
     48                boolean firstFile = true;
     49                String fileName = file.getName();
     50                if (fileName.lastIndexOf('.') > 0) {
     51                    // remove extension
     52                    fileName = fileName.substring(0, fileName.lastIndexOf('.'));
     53                }
     54
     55                for (Relation rel : ds.getRelations()) {
     56                    if (rel.isMultipolygon()) {
     57                        if (!firstFile) {
     58                            writer.newLine();
     59                        }
     60                        writeRelation(writer, fileName, rel, written);
     61                        firstFile = false;
    5262                    }
    5363                }
    54                 ways = sortOuterInner(ways);
    55 
     64               
     65                if (firstFile) {
     66                    writer.write(fileName);
     67                }
    5668                int counter = 1;
    57                 writer.write(polygonName);
    58                 writer.newLine();
    59                 for (Way w : ways.keySet()) {
    60                     if (!ways.get(w))
    61                         writer.write('!');
    62                     writer.write(String.valueOf(counter++));
    63                     writer.newLine();
    64                     for (Node n : w.getNodes()) {
    65                         writer.write(String.format(Locale.ENGLISH, "   %f   %f", n.getCoor().lon(), n.getCoor().lat()));
    66                         writer.newLine();
     69                for (Way w : ds.getWays()) {
     70                    if (!written.contains(w)) {
     71                        writeWay(writer, w, counter);
    6772                    }
    68                     writer.write("END");
    69                     writer.newLine();
    7073                }
    7174                writer.write("END");
    7275                writer.newLine();
     
    7477        }
    7578    }
    7679
    77     private boolean isOuter(Way w) {
    78         for (OsmPrimitive p : w.getReferrers()) {
    79             if (p instanceof Relation && ((Relation) p).isMultipolygon()) {
    80                 for (RelationMember m : ((Relation) p).getMembers()) {
    81                     if (m.refersTo(w) && "inner".equals(m.getRole())) {
    82                         return false;
    83                     }
    84                 }
     80    private static void writeRelation(BufferedWriter writer, String fileName, Relation rel, Set<Way> written) throws IOException {
     81        String polygonName = fileName;
     82        if (rel.getName() != null)
     83            polygonName = rel.getName();
     84        writer.write(polygonName);
     85        writer.newLine();
     86        int counter = 1;
     87        for (RelationMember rm: rel.getMembers()) {
     88            if (rm.isWay()) {
     89                if ("inner".equals(rm.getRole()))
     90                    writer.write('!');
     91                Way w = rm.getWay();
     92                counter = writeWay(writer, w, counter);
     93                written.add(w);
    8594            }
    8695        }
    87         return true;
    8896    }
    8997
    90     private Map<Way, Boolean> sortOuterInner(Map<Way, Boolean> ways) {
    91         LinkedHashMap<Way, Boolean> result = new LinkedHashMap<>(ways.size());
    92         List<Way> inner = new ArrayList<>();
    93         for (Way w : ways.keySet()) {
    94             Boolean outer = ways.get(w);
    95             if (outer)
    96                 result.put(w, outer);
    97             else
    98                 inner.add(w);
     98    private static int writeWay(BufferedWriter writer, Way w, int counter) throws IOException {
     99        String name = w.getName();
     100        if (name == null) {
     101            name = String.valueOf(counter++);
     102        }
     103        writer.write(name);
     104        writer.newLine();
     105
     106        for (Node n : w.getNodes()) {
     107            writer.write(String.format(Locale.ENGLISH, "   %f   %f", n.getCoor().lon(), n.getCoor().lat()));
     108            writer.newLine();
    99109        }
    100         for (Way w : inner) {
    101             result.put(w, Boolean.FALSE);
    102         }
    103         return result;
     110        writer.write("END");
     111        writer.newLine();
     112        return counter;
    104113    }
    105114}
  • src/poly/PolyImporter.java

     
    77import java.io.IOException;
    88import java.io.InputStream;
    99import java.io.InputStreamReader;
     10import java.nio.charset.StandardCharsets;
    1011import java.util.ArrayList;
    1112import java.util.List;
    1213
     
    2627import org.openstreetmap.josm.io.CachedFile;
    2728import org.openstreetmap.josm.io.IllegalDataException;
    2829import org.openstreetmap.josm.tools.CheckParameterUtil;
    29 import org.xml.sax.SAXException;
    3030
    3131/**
    3232 * Imports poly files.
    3333 *
    3434 * @author zverik
     35 * @author Gerd Petermann
    3536 */
    3637public class PolyImporter extends OsmImporter {
     38        /**
     39         * Create importer.
     40         */
    3741    public PolyImporter() {
    3842        super(PolyType.FILE_FILTER);
    3943    }
    4044
    41     protected DataSet parseDataSet(final String source) throws IOException, SAXException, IllegalDataException {
    42         return parseDataSet(new CachedFile(source).getInputStream(), NullProgressMonitor.INSTANCE);
     45    protected DataSet parseDataSet(final String source) throws IOException, IllegalDataException {
     46        try (CachedFile cf = new CachedFile(source)) {
     47            return parseDataSet(cf.getInputStream(), NullProgressMonitor.INSTANCE);
     48        }
    4349    }
    4450
    4551    @Override
     
    4854            progressMonitor = NullProgressMonitor.INSTANCE;
    4955        CheckParameterUtil.ensureParameterNotNull(in, "in");
    5056
    51         try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF8"))) {
    52             progressMonitor.beginTask(tr("Reading polygon filter file..."), 2);
     57        try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) {
     58            progressMonitor.beginTask(tr("Reading polygon filter file..."), 3);
    5359            progressMonitor.indeterminateSubTask(tr("Reading polygon filter file..."));
    5460            List<Area> areas = loadPolygon(reader);
    5561            progressMonitor.worked(1);
     
    6571        }
    6672    }
    6773
    68     private List<Area> loadPolygon(BufferedReader reader) throws IllegalDataException, IOException {
     74    private static List<Area> loadPolygon(BufferedReader reader) throws IllegalDataException, IOException {
    6975        String name = reader.readLine();
    7076        if (name == null || name.trim().length() == 0)
    7177            throw new IllegalDataException(tr("The file must begin with a polygon name"));
     
    7581        int fixedCoords = 0;
    7682        while (true) {
    7783            String line;
    78             do {
    79                 line = reader.readLine();
    80                 if (line == null)
    81                     throw new IllegalDataException("File ended prematurely without END record");
    82                 line = line.trim();
    83             } while (line.length() == 0);
    84 
    85             if (line.equals("END")) {
    86                 if (!parsingSection)
    87                     break;
    88                 else {
     84            line = reader.readLine();
     85            if (line == null)
     86                break;
     87            line = line.trim();
     88            if (line.isEmpty()) {
     89                // empty line is only allowed after a complete file (one or more rings belonging to one polygon)
     90                if (parsingSection)
     91                    throw new IllegalDataException(tr("Empty line in coordinate section"));
     92                area = null;
     93                parsingSection = false;
     94                name = null;
     95            } else if (line.equals("END")) {
     96                if (!parsingSection) {
     97                    area = null;
     98                } else {
    8999                    // an area has been read
    90100                    if (area.getNodeCount() < 2)
    91101                        throw new IllegalDataException(tr("There are less than 2 points in an area"));
    92102                    areas.add(area);
    93                     if (areas.size() == 1)
    94                         areas.get(0).setPolygonName(name);
     103                    area.setPolygonName(name);
    95104                    parsingSection = false;
    96105                }
    97             } else {
     106            } else if (name == null) {
     107                name = line;
     108            } else if (line.length() > 0) {
    98109                if (!parsingSection) {
     110                    if (line.indexOf(' ') >= 0) {
     111                        boolean coordInsteadOfName = false;
     112                        try {
     113                            LatLon ll = parseCoordinate(line);
     114                            if (ll.isValid()) {
     115                                coordInsteadOfName = true;
     116                            }
     117                        } catch (IllegalDataException e) {
     118                            coordInsteadOfName = false;
     119                        }
     120                        if (coordInsteadOfName) {
     121                            throw new IllegalDataException(tr("Found coordinates ''{0}'' instead of name", line));
     122                        }
     123                    }
    99124                    area = new Area(line);
    100125                    parsingSection = true;
    101126                } else {
    102                     // reading area, parse coordinates
    103                     String[] tokens = line.split("\\s+");
    104                     double[] coords = new double[2];
    105                     int tokenCount = 0;
    106                     for (String token : tokens) {
    107                         if (token.length() > 0) {
    108                             if (tokenCount > 2)
    109                                 throw new IllegalDataException(tr("A polygon coordinate line must contain exactly 2 numbers"));
    110                             try {
    111                                 coords[tokenCount++] = Double.parseDouble(token);
    112                             } catch (NumberFormatException e) {
    113                                 throw new IllegalDataException(tr("Unable to parse {0} as a number", token));
    114                             }
    115                         }
    116                     }
    117                     if (tokenCount < 2)
    118                         throw new IllegalDataException(tr("A polygon coordinate line must contain exactly 2 numbers"));
    119                     LatLon coord = new LatLon(coords[1], coords[0]);
     127                    LatLon coord = parseCoordinate(line);
    120128                    if (!coord.isValid()) {
    121129                        // fix small deviations
    122130                        double lat = coord.lat();
     
    125133                        if (lon > 180.0 && lon < 185.0) lon = 180.0;
    126134                        if (lat < -90.0 && lat > -95.0) lat = -90.0;
    127135                        if (lat > 90.0 && lat < 95.0) lat = 90.0;
     136                        coord = new LatLon(lat, lon);
    128137                        fixedCoords++;
    129                         coord = new LatLon(lat, lon);
    130138                        if (!coord.isValid())
    131139                            throw new IllegalDataException(tr("Invalid coordinates were found: {0}, {1}", coord.lat(), coord.lon()));
    132140                    }
    133                     area.addNode(coord);
     141                    area.addNode(parseCoordinate(line));
    134142                }
    135143            }
    136144        }
     
    140148        return areas;
    141149    }
    142150
    143     private DataSet constructDataSet(List<Area> areas) {
     151    /**
     152     * Parse a line that should contain two double values which describe a latitude/longitude pair.
     153     * @param line the line to parse
     154     * @return a new LatLon
     155     * @throws IllegalDataException in case of error
     156     */
     157    private static LatLon parseCoordinate(String line) throws IllegalDataException {
     158        String[] tokens = line.split("\\s+");
     159        double[] coords = new double[2];
     160        int tokenCount = 0;
     161        for (String token : tokens) {
     162            if (token.length() > 0) {
     163                if (tokenCount > 2)
     164                    break;
     165                try {
     166                    coords[tokenCount++] = Double.parseDouble(token);
     167                } catch (NumberFormatException e) {
     168                    throw new IllegalDataException(tr("Unable to parse {0} as a number", token));
     169                }
     170            }
     171        }
     172        if (tokenCount != 2)
     173            throw new IllegalDataException(tr("A polygon coordinate line must contain exactly 2 numbers"));
     174        return new LatLon(coords[1], coords[0]);
     175    }
     176
     177    private static DataSet constructDataSet(List<Area> areas) {
    144178        DataSet ds = new DataSet();
    145179        ds.setUploadPolicy(UploadPolicy.DISCOURAGED);
    146180
    147         boolean foundInner = false;
     181       
     182        List<Area> curretSet = new ArrayList<>();
     183       
    148184        for (Area area : areas) {
    149             if (!area.isOuter())
    150                 foundInner = true;
    151             area.constructWay(ds);
     185            if (!curretSet.isEmpty() && !area.polygonName.equals(curretSet.get(0).polygonName)) {
     186                constructPrimitive(ds, curretSet);
     187                curretSet.clear();
     188            }
     189            curretSet.add(area);
    152190        }
     191        if (!curretSet.isEmpty())
     192            constructPrimitive(ds, curretSet);
    153193
    154         if (foundInner) {
     194        return ds;
     195    }
     196
     197    private static void constructPrimitive(DataSet ds, List<Area> areas) {
     198        boolean isMultipolygon = areas.size() > 1;
     199        for (Area area : areas) {
     200            area.constructWay(ds, isMultipolygon);
     201        }
     202
     203        if (isMultipolygon) {
    155204            Relation mp = new Relation();
    156205            mp.put("type", "multipolygon");
     206            Area outer = areas.get(0);
     207            if (outer.polygonName != null) {
     208                mp.put("name", outer.polygonName);
     209            }
    157210            for (Area area : areas) {
    158211                mp.addMember(new RelationMember(area.isOuter() ? "outer" : "inner", area.getWay()));
    159212            }
    160213            ds.addPrimitive(mp);
    161214        }
    162 
    163         return ds;
    164215    }
    165216
    166217    private static class Area {
     
    177228                this.name = this.name.substring(1);
    178229            nodes = new ArrayList<>();
    179230            way = null;
    180             polygonName = null;
     231            polygonName = "";
    181232        }
    182233
    183234        public void setPolygonName(String polygonName) {
    184             this.polygonName = polygonName;
     235            if (polygonName != null) {
     236                this.polygonName = polygonName;
     237            }
    185238        }
    186239
    187240        public void addNode(LatLon node) {
     
    201254            return way;
    202255        }
    203256
    204         public void constructWay(DataSet ds) {
     257        public void constructWay(DataSet ds, boolean isMultipolygon) {
    205258            way = new Way();
    206259            for (LatLon coord : nodes) {
    207260                Node node = new Node(coord);
     
    209262                way.addNode(node);
    210263            }
    211264            way.addNode(way.getNode(0));
    212             if (polygonName != null)
    213                 way.put("name", polygonName);
     265            if (isMultipolygon && name != null)
     266                way.put("name", name);
     267            else {
     268                if (polygonName != null)
     269                    way.put("name", polygonName);
     270            }
    214271            ds.addPrimitive(way);
    215272        }
    216273    }
  • src/poly/PolyType.java

     
    99 * Extension and file filter for poly type.
    1010 *
    1111 * @author zverik
     12 * @author Gerd Petermann
    1213 */
    13 public interface PolyType {
    14     String EXTENSION = "poly";
    15     ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(
     14
     15final class PolyType {
     16    private static final String EXTENSION = "poly";
     17   
     18    /** filter for osmosis poly files */
     19    static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(
    1620            EXTENSION, EXTENSION, tr("Osmosis polygon filter files") + " (*." + EXTENSION + ")");
     21    private PolyType() {}
    1722}
  • test/data/australia_v.poly

     
     1australia_v
     21
     3     0.1446693E+03    -0.3826255E+02
     4     0.1446627E+03    -0.3825661E+02
     5     0.1446763E+03    -0.3824465E+02
     6     0.1446813E+03    -0.3824343E+02
     7     0.1446824E+03    -0.3824484E+02
     8     0.1446826E+03    -0.3825356E+02
     9     0.1446876E+03    -0.3825210E+02
     10     0.1446919E+03    -0.3824719E+02
     11     0.1447006E+03    -0.3824723E+02
     12     0.1447042E+03    -0.3825078E+02
     13     0.1446758E+03    -0.3826229E+02
     14     0.1446693E+03    -0.3826255E+02
     15END
     162
     17     0.1422436E+03    -0.3839315E+02
     18     0.1422496E+03    -0.3839070E+02
     19     0.1422543E+03    -0.3839025E+02
     20     0.1422574E+03    -0.3839155E+02
     21     0.1422467E+03    -0.3840065E+02
     22     0.1422433E+03    -0.3840048E+02
     23     0.1422420E+03    -0.3839857E+02
     24     0.1422436E+03    -0.3839315E+02
     25END
     26END
  • test/data/bremen-double-end.poly

     
     1none
     21
     3   8.509653E+00   5.347469E+01
     4   8.505762E+00   5.347047E+01
     5   8.491577E+00   5.347200E+01
     6   8.491656E+00   5.347549E+01
     7   8.501178E+00   5.349139E+01
     8   8.504218E+00   5.349441E+01
     9   8.511296E+00   5.350007E+01
     10   8.520366E+00   5.350472E+01
     11   8.551284E+00   5.351639E+01
     12   8.546220E+00   5.352130E+01
     13   8.558515E+00   5.352774E+01
     14   8.560064E+00   5.353183E+01
     15   8.559076E+00   5.353636E+01
     16   8.493468E+00   5.360245E+01
     17   8.493498E+00   5.360351E+01
     18   8.523178E+00   5.360744E+01
     19   8.525435E+00   5.360457E+01
     20   8.527368E+00   5.360641E+01
     21   8.533663E+00   5.360514E+01
     22   8.535422E+00   5.360772E+01
     23   8.581374E+00   5.359864E+01
     24   8.592972E+00   5.359386E+01
     25   8.601275E+00   5.359622E+01
     26   8.612262E+00   5.360352E+01
     27   8.623225E+00   5.360602E+01
     28   8.639793E+00   5.360518E+01
     29   8.643798E+00   5.360448E+01
     30   8.643166E+00   5.360603E+01
     31   8.644382E+00   5.360731E+01
     32   8.641847E+00   5.360889E+01
     33   8.642658E+00   5.361052E+01
     34   8.651924E+00   5.361063E+01
     35   8.654038E+00   5.360895E+01
     36   8.658592E+00   5.360983E+01
     37   8.660066E+00   5.360779E+01
     38   8.657775E+00   5.360268E+01
     39   8.653304E+00   5.360224E+01
     40   8.640072E+00   5.359466E+01
     41   8.641363E+00   5.359292E+01
     42   8.627218E+00   5.358420E+01
     43   8.620693E+00   5.357695E+01
     44   8.620204E+00   5.357422E+01
     45   8.625819E+00   5.356784E+01
     46   8.631574E+00   5.355619E+01
     47   8.635984E+00   5.355430E+01
     48   8.647419E+00   5.355588E+01
     49   8.645195E+00   5.354940E+01
     50   8.646030E+00   5.354024E+01
     51   8.642684E+00   5.354082E+01
     52   8.642332E+00   5.353640E+01
     53   8.639048E+00   5.353445E+01
     54   8.639099E+00   5.353337E+01
     55   8.640124E+00   5.352569E+01
     56   8.644103E+00   5.352311E+01
     57   8.646059E+00   5.351939E+01
     58   8.649762E+00   5.352007E+01
     59   8.652930E+00   5.351626E+01
     60   8.649244E+00   5.351386E+01
     61   8.651507E+00   5.351032E+01
     62   8.640633E+00   5.350679E+01
     63   8.637674E+00   5.350512E+01
     64   8.638345E+00   5.350340E+01
     65   8.636614E+00   5.350220E+01
     66   8.629345E+00   5.350097E+01
     67   8.628816E+00   5.349916E+01
     68   8.630505E+00   5.349675E+01
     69   8.629601E+00   5.349504E+01
     70   8.627630E+00   5.349518E+01
     71   8.626241E+00   5.349289E+01
     72   8.624468E+00   5.349323E+01
     73   8.619703E+00   5.349000E+01
     74   8.610639E+00   5.348680E+01
     75   8.604164E+00   5.348648E+01
     76   8.603295E+00   5.348379E+01
     77   8.597157E+00   5.348506E+01
     78   8.591864E+00   5.348421E+01
     79   8.584140E+00   5.348616E+01
     80   8.578344E+00   5.348486E+01
     81   8.575051E+00   5.348586E+01
     82   8.573728E+00   5.348781E+01
     83   8.539527E+00   5.347957E+01
     84   8.528859E+00   5.347938E+01
     85   8.517022E+00   5.347260E+01
     86   8.514411E+00   5.347464E+01
     87   8.509653E+00   5.347469E+01
     88END
     89END
     902
     91   8.615320E+00   5.319451E+01
     92   8.611878E+00   5.319620E+01
     93   8.613360E+00   5.319747E+01
     94   8.617090E+00   5.319582E+01
     95   8.616084E+00   5.319474E+01
     96   8.621347E+00   5.319577E+01
     97   8.621455E+00   5.319779E+01
     98   8.628186E+00   5.319891E+01
     99   8.631454E+00   5.319637E+01
     100   8.634298E+00   5.319689E+01
     101   8.640220E+00   5.319466E+01
     102   8.638992E+00   5.319207E+01
     103   8.643234E+00   5.319003E+01
     104   8.654726E+00   5.318801E+01
     105   8.656097E+00   5.318630E+01
     106   8.653511E+00   5.318502E+01
     107   8.658608E+00   5.318215E+01
     108   8.659425E+00   5.317822E+01
     109   8.662827E+00   5.317888E+01
     110   8.665359E+00   5.317716E+01
     111   8.669937E+00   5.317788E+01
     112   8.671074E+00   5.317964E+01
     113   8.674892E+00   5.317946E+01
     114   8.676175E+00   5.317598E+01
     115   8.678430E+00   5.317658E+01
     116   8.677812E+00   5.317772E+01
     117   8.679439E+00   5.317872E+01
     118   8.687234E+00   5.317970E+01
     119   8.691238E+00   5.318203E+01
     120   8.696560E+00   5.318333E+01
     121   8.699443E+00   5.318614E+01
     122   8.703409E+00   5.318151E+01
     123   8.701904E+00   5.317965E+01
     124   8.702337E+00   5.317844E+01
     125   8.705491E+00   5.317667E+01
     126   8.709726E+00   5.317874E+01
     127   8.709577E+00   5.318065E+01
     128   8.712246E+00   5.318135E+01
     129   8.714161E+00   5.318396E+01
     130   8.729187E+00   5.318128E+01
     131   8.732554E+00   5.317501E+01
     132   8.737198E+00   5.317394E+01
     133   8.739386E+00   5.317163E+01
     134   8.743869E+00   5.317217E+01
     135   8.744135E+00   5.317095E+01
     136   8.741523E+00   5.316645E+01
     137   8.741885E+00   5.316467E+01
     138   8.748036E+00   5.316664E+01
     139   8.755166E+00   5.316418E+01
     140   8.761751E+00   5.316588E+01
     141   8.771124E+00   5.316009E+01
     142   8.775121E+00   5.316210E+01
     143   8.782127E+00   5.316414E+01
     144   8.786732E+00   5.316372E+01
     145   8.790699E+00   5.316394E+01
     146   8.792599E+00   5.316377E+01
     147   8.797220E+00   5.316430E+01
     148   8.798689E+00   5.316347E+01
     149   8.814552E+00   5.316465E+01
     150   8.821277E+00   5.316418E+01
     151   8.829275E+00   5.316490E+01
     152   8.830586E+00   5.316307E+01
     153   8.831747E+00   5.316024E+01
     154   8.840334E+00   5.315818E+01
     155   8.845287E+00   5.314806E+01
     156   8.853117E+00   5.314419E+01
     157   8.858228E+00   5.314054E+01
     158   8.861722E+00   5.313843E+01
     159   8.862411E+00   5.313726E+01
     160   8.863432E+00   5.313216E+01
     161   8.874316E+00   5.313412E+01
     162   8.886153E+00   5.313363E+01
     163   8.897505E+00   5.313471E+01
     164   8.903128E+00   5.313923E+01
     165   8.907142E+00   5.313793E+01
     166   8.909629E+00   5.313346E+01
     167   8.912146E+00   5.313328E+01
     168   8.916077E+00   5.313719E+01
     169   8.915927E+00   5.313985E+01
     170   8.921400E+00   5.314221E+01
     171   8.920051E+00   5.314412E+01
     172   8.920491E+00   5.314503E+01
     173   8.930619E+00   5.314832E+01
     174   8.936901E+00   5.315175E+01
     175   8.939893E+00   5.315291E+01
     176   8.945054E+00   5.315276E+01
     177   8.956958E+00   5.314777E+01
     178   8.960158E+00   5.314312E+01
     179   8.971611E+00   5.313416E+01
     180   8.979324E+00   5.313148E+01
     181   8.983984E+00   5.312562E+01
     182   8.978232E+00   5.312289E+01
     183   8.966957E+00   5.312127E+01
     184   8.962749E+00   5.311908E+01
     185   8.948558E+00   5.311619E+01
     186   8.958218E+00   5.311157E+01
     187   8.961763E+00   5.310648E+01
     188   8.963470E+00   5.310114E+01
     189   8.969005E+00   5.310134E+01
     190   8.978750E+00   5.309913E+01
     191   8.982155E+00   5.309708E+01
     192   8.989558E+00   5.309878E+01
     193   8.991268E+00   5.309666E+01
     194   8.984503E+00   5.309262E+01
     195   8.965782E+00   5.308906E+01
     196   8.962445E+00   5.308526E+01
     197   8.966571E+00   5.308284E+01
     198   8.964914E+00   5.308017E+01
     199   8.965461E+00   5.307661E+01
     200   8.964578E+00   5.307212E+01
     201   8.965471E+00   5.307145E+01
     202   8.964611E+00   5.307028E+01
     203   8.966550E+00   5.306254E+01
     204   8.964580E+00   5.306036E+01
     205   8.966615E+00   5.305825E+01
     206   8.970870E+00   5.305670E+01
     207   8.973879E+00   5.305194E+01
     208   8.976998E+00   5.305204E+01
     209   8.980996E+00   5.304654E+01
     210   8.971601E+00   5.303863E+01
     211   8.966901E+00   5.303607E+01
     212   8.963457E+00   5.303639E+01
     213   8.952458E+00   5.303282E+01
     214   8.951431E+00   5.303079E+01
     215   8.946744E+00   5.303012E+01
     216   8.945654E+00   5.302762E+01
     217   8.947041E+00   5.302597E+01
     218   8.946119E+00   5.302427E+01
     219   8.938848E+00   5.302414E+01
     220   8.935836E+00   5.301299E+01
     221   8.929521E+00   5.301324E+01
     222   8.928204E+00   5.301220E+01
     223   8.922525E+00   5.301383E+01
     224   8.921712E+00   5.301149E+01
     225   8.917827E+00   5.301243E+01
     226   8.915746E+00   5.301034E+01
     227   8.896934E+00   5.301222E+01
     228   8.892659E+00   5.301356E+01
     229   8.883590E+00   5.302295E+01
     230   8.866418E+00   5.303223E+01
     231   8.865539E+00   5.302817E+01
     232   8.869883E+00   5.302480E+01
     233   8.867059E+00   5.302117E+01
     234   8.855103E+00   5.302045E+01
     235   8.852819E+00   5.301913E+01
     236   8.850924E+00   5.301616E+01
     237   8.848968E+00   5.301588E+01
     238   8.847454E+00   5.301602E+01
     239   8.846577E+00   5.301778E+01
     240   8.849042E+00   5.302341E+01
     241   8.844866E+00   5.302301E+01
     242   8.844202E+00   5.302154E+01
     243   8.840843E+00   5.302033E+01
     244   8.838031E+00   5.301747E+01
     245   8.830788E+00   5.302052E+01
     246   8.822030E+00   5.302016E+01
     247   8.817499E+00   5.302183E+01
     248   8.815214E+00   5.302582E+01
     249   8.810032E+00   5.302825E+01
     250   8.808574E+00   5.303036E+01
     251   8.785725E+00   5.303773E+01
     252   8.782499E+00   5.303719E+01
     253   8.777443E+00   5.303883E+01
     254   8.775875E+00   5.304264E+01
     255   8.772064E+00   5.304466E+01
     256   8.770096E+00   5.305205E+01
     257   8.762022E+00   5.304996E+01
     258   8.764634E+00   5.304670E+01
     259   8.758404E+00   5.304314E+01
     260   8.756541E+00   5.304336E+01
     261   8.756123E+00   5.304252E+01
     262   8.757962E+00   5.304095E+01
     263   8.756901E+00   5.303846E+01
     264   8.751439E+00   5.303726E+01
     265   8.743301E+00   5.303993E+01
     266   8.741748E+00   5.303869E+01
     267   8.740454E+00   5.303905E+01
     268   8.737982E+00   5.303663E+01
     269   8.733200E+00   5.303650E+01
     270   8.735485E+00   5.303505E+01
     271   8.734242E+00   5.303297E+01
     272   8.729968E+00   5.303335E+01
     273   8.709331E+00   5.304517E+01
     274   8.706123E+00   5.305247E+01
     275   8.709702E+00   5.306855E+01
     276   8.709194E+00   5.307210E+01
     277   8.705708E+00   5.307561E+01
     278   8.701124E+00   5.308043E+01
     279   8.686927E+00   5.308522E+01
     280   8.674488E+00   5.308554E+01
     281   8.665954E+00   5.309124E+01
     282   8.664211E+00   5.309584E+01
     283   8.669353E+00   5.310219E+01
     284   8.653751E+00   5.310839E+01
     285   8.652751E+00   5.311112E+01
     286   8.654288E+00   5.311552E+01
     287   8.651881E+00   5.311567E+01
     288   8.649707E+00   5.311733E+01
     289   8.650273E+00   5.312153E+01
     290   8.647819E+00   5.312468E+01
     291   8.634341E+00   5.313348E+01
     292   8.630098E+00   5.313799E+01
     293   8.625879E+00   5.314537E+01
     294   8.622735E+00   5.316278E+01
     295   8.619494E+00   5.316638E+01
     296   8.611348E+00   5.316970E+01
     297   8.582453E+00   5.317270E+01
     298   8.556976E+00   5.318067E+01
     299   8.533636E+00   5.318623E+01
     300   8.522611E+00   5.319183E+01
     301   8.515308E+00   5.319723E+01
     302   8.512254E+00   5.319624E+01
     303   8.505858E+00   5.319947E+01
     304   8.500976E+00   5.320528E+01
     305   8.495432E+00   5.320903E+01
     306   8.490537E+00   5.321665E+01
     307   8.482431E+00   5.322288E+01
     308   8.480959E+00   5.322676E+01
     309   8.488865E+00   5.322891E+01
     310   8.490168E+00   5.322740E+01
     311   8.503920E+00   5.322966E+01
     312   8.506858E+00   5.322843E+01
     313   8.517307E+00   5.322909E+01
     314   8.518743E+00   5.322673E+01
     315   8.521242E+00   5.322672E+01
     316   8.521073E+00   5.322349E+01
     317   8.523079E+00   5.322355E+01
     318   8.523496E+00   5.322194E+01
     319   8.526415E+00   5.322205E+01
     320   8.530420E+00   5.321658E+01
     321   8.537112E+00   5.321534E+01
     322   8.541184E+00   5.321616E+01
     323   8.543892E+00   5.321398E+01
     324   8.547045E+00   5.321377E+01
     325   8.554182E+00   5.320877E+01
     326   8.566145E+00   5.321435E+01
     327   8.572005E+00   5.321167E+01
     328   8.578437E+00   5.321813E+01
     329   8.599362E+00   5.321342E+01
     330   8.600150E+00   5.321098E+01
     331   8.597396E+00   5.320713E+01
     332   8.582182E+00   5.319914E+01
     333   8.585757E+00   5.319609E+01
     334   8.581361E+00   5.319330E+01
     335   8.581800E+00   5.319125E+01
     336   8.584542E+00   5.319106E+01
     337   8.584954E+00   5.319017E+01
     338   8.589129E+00   5.319038E+01
     339   8.593007E+00   5.318786E+01
     340   8.592324E+00   5.318661E+01
     341   8.593501E+00   5.318500E+01
     342   8.608214E+00   5.318922E+01
     343   8.608342E+00   5.319322E+01
     344   8.615320E+00   5.319451E+01
     345END
     346END
  • test/data/holes.poly

     
     1holes
     2o1
     3  2.285156e+00  4.126465e+01
     4  2.285156e+00  4.161621e+01
     5  1.757813e-01  4.161621e+01
     6  1.757813e-01  4.258301e+01
     7  -3.515625e-01  4.258301e+01
     8  -3.515625e-01  4.267090e+01
     9  -1.142578e+00  4.267090e+01
     10  -1.142578e+00  4.293457e+01
     11  -1.494141e+00  4.293457e+01
     12  -1.494141e+00  4.302246e+01
     13  -6.328125e+00  4.302246e+01
     14  -6.328125e+00  4.521973e+01
     15  -6.152344e+00  4.521973e+01
     16  -6.152344e+00  4.671387e+01
     17  -6.328125e+00  4.671387e+01
     18  -6.328125e+00  5.084473e+01
     19  -2.724609e+00  5.084473e+01
     20  -2.724609e+00  5.075684e+01
     21  -7.910156e-01  5.075684e+01
     22  -7.910156e-01  5.137207e+01
     23  2.988281e+00  5.137207e+01
     24  2.988281e+00  5.084473e+01
     25  3.251953e+00  5.084473e+01
     26  3.251953e+00  5.093262e+01
     27  4.394531e+00  5.093262e+01
     28  4.394531e+00  5.040527e+01
     29  5.449219e+00  5.040527e+01
     30  5.449219e+00  4.979004e+01
     31  6.591797e+00  4.979004e+01
     32  6.591797e+00  4.952637e+01
     33  7.382813e+00  4.952637e+01
     34  7.382813e+00  4.935059e+01
     35  8.349609e+00  4.935059e+01
     36  8.349609e+00  4.873535e+01
     37  8.437500e+00  4.873535e+01
     38  8.437500e+00  4.864746e+01
     39  8.085938e+00  4.864746e+01
     40  8.085938e+00  4.855957e+01
     41  7.998047e+00  4.855957e+01
     42  7.998047e+00  4.829590e+01
     43  7.822266e+00  4.829590e+01
     44  7.822266e+00  4.803223e+01
     45  9.843750e+00  4.803223e+01
     46  9.843750e+00  4.662598e+01
     47  7.382813e+00  4.662598e+01
     48  7.382813e+00  4.645020e+01
     49  7.207031e+00  4.645020e+01
     50  7.207031e+00  4.592285e+01
     51  9.843750e+00  4.592285e+01
     52  9.843750e+00  4.442871e+01
     53  9.404297e+00  4.442871e+01
     54  9.404297e+00  4.337402e+01
     55  9.843750e+00  4.337402e+01
     56  9.843750e+00  4.126465e+01
     57  8.261719e+00  4.126465e+01
     58  8.261719e+00  4.196777e+01
     59  7.910156e+00  4.196777e+01
     60  7.910156e+00  4.179199e+01
     61  6.064453e+00  4.179199e+01
     62  6.064453e+00  4.144043e+01
     63  4.833984e+00  4.144043e+01
     64  4.833984e+00  4.258301e+01
     65  4.570313e+00  4.258301e+01
     66  4.570313e+00  4.126465e+01
     67  2.285156e+00  4.126465e+01
     68END
     69!inner1
     70  4.394531e+00  5.014160e+01
     71  4.394531e+00  5.022949e+01
     72  4.306641e+00  5.022949e+01
     73  4.306641e+00  5.014160e+01
     74  4.394531e+00  5.014160e+01
     75END
     76!inner2
     77  -4.394531e+00  4.873535e+01
     78  -4.394531e+00  4.882324e+01
     79  -4.746094e+00  4.882324e+01
     80  -4.746094e+00  4.873535e+01
     81  -4.394531e+00  4.873535e+01
     82END
     83!inner3
     84  -2.021484e+00  4.521973e+01
     85  -2.021484e+00  4.601074e+01
     86  -2.109375e+00  4.601074e+01
     87  -2.109375e+00  4.521973e+01
     88  -2.021484e+00  4.521973e+01
     89END
     90END
  • test/data/multi-concat.poly

     
     1first
     21
     3   109.116270   -19.754965
     4   134.560899   -8.865515
     5   155.225021   -11.445777
     6   178.973341   -34.767630
     7   178.819131   -47.479347
     8   122.378319   -49.422367
     9   103.873134   -24.186817
     10   109.116270   -19.754965
     11END
     12END
     13
     14second
     151
     16   -27.000000   75.000000
     17   -32.733610   39.048420
     18   -17.137840   31.093990
     19   -9.611205   35.985870
     20   -5.653329   35.894580
     21   -5.393482   35.987210
     22   -5.085261   36.046190
     23   3.541102   37.759810
     24   11.600370   37.778150
     25   11.600370   34.000000
     26   35.408480   33.992890
     27   35.408480   35.627900
     28   36.236940   35.806410
     29   36.768620   36.195300
     30   36.754060   36.570560
     31   39.193940   36.611490
     32   42.398570   37.054530
     33   44.328630   36.914900
     34   44.996930   37.199370
     35   45.000000   75.000000
     36   -27.000000   75.000000
     37END
     38!2
     39   9.890545E+00   4.822680E+01
     40   9.892534E+00   4.752921E+01
     41   1.130254E+01   4.753324E+01
     42   1.127072E+01   4.827977E+01
     43   9.890545E+00   4.822680E+01
     44END
     45END
     46
     47third
     481
     49   -179.915000   -60.347030
     50   -23.244010   -61.792990
     51   -23.834280   -16.230710
     52   -45.475220   10.055700
     53   -74.969470   13.604260
     54   -80.765080   3.298111
     55   -95.342020   3.287621
     56   -179.999900   -4.938220
     57   -179.999900   -60.347030
     58   -179.915000   -60.347030
     59END
     60END
  • test/data/name-missing.poly

     
     1multi-1
     21
     3   109.116270   -19.754965
     4   134.560899   -8.865515
     5   155.225021   -11.445777
     6   178.973341   -34.767630
     7   178.819131   -47.479347
     8   122.378319   -49.422367
     9   103.873134   -24.186817
     10   109.116270   -19.754965
     11END
     12   -179.915000   -60.347030
     13   -23.244010   -61.792990
     14   -23.834280   -16.230710
     15   -45.475220   10.055700
     16   -74.969470   13.604260
     17   -80.765080   3.298111
     18   -95.342020   3.287621
     19   -179.999900   -4.938220
     20   -179.999900   -60.347030
     21   -179.915000   -60.347030
     22END
     23END
  • test/data/simple.poly

     
     1simple
     21
     3   9.890545E+00   4.822680E+01
     4   9.892534E+00   4.752921E+01
     5   1.130254E+01   4.753324E+01
     6   1.127072E+01   4.827977E+01
     7   9.890545E+00   4.822680E+01
     8END
     9END
  • test/data/splitter.poly

     
     1area
     21
     3  7.382813  51.284180
     4  7.382813  51.679688
     5  6.635742  51.679688
     6  6.635742  52.690430
     7  6.416016  52.690430
     8  6.416016  54.184570
     9  8.920898  54.184570
     10  8.920898  54.140625
     11  10.502930  54.140625
     12  10.502930  53.964844
     13  11.645508  53.964844
     14  11.645508  51.459961
     15  10.546875  51.459961
     16  10.546875  51.284180
     17  7.382813  51.284180
     18END
     19END
  • test/unit/poly/PolyExporterTest.java

     
     1// License: GPL. For details, see LICENSE file.
     2package poly;
     3
     4import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertNotNull;
     6
     7import java.nio.file.Files;
     8import java.nio.file.Path;
     9
     10import org.junit.Rule;
     11import org.junit.Test;
     12import org.openstreetmap.josm.TestUtils;
     13import org.openstreetmap.josm.data.osm.DataSet;
     14import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     15import org.openstreetmap.josm.testutils.JOSMTestRules;
     16
     17/**
     18 * Unit tests for {@link PolyExporter}.
     19 * @author Gerd Petermann
     20 */
     21public class PolyExporterTest {
     22
     23    /**
     24     * Setup test.
     25     */
     26    @Rule
     27    public JOSMTestRules rules = new JOSMTestRules().preferences().timeout(20000);
     28
     29    /**
     30     * Import file, export it, import the exported file and compare content
     31     * @throws Exception if an error occurs
     32     */
     33    @Test
     34    public void testExport() throws Exception {
     35        DataSet dsIn1 = new PolyImporter().parseDataSet(TestUtils.getTestDataRoot() + "/holes.poly");
     36        assertNotNull(dsIn1);
     37        assertEquals(76, dsIn1.getNodes().size());
     38        assertEquals(4, dsIn1.getWays().size());
     39        assertEquals(1, dsIn1.getRelations().size());
     40
     41        Path out = Files.createTempFile("holes-out", "poly");
     42        new PolyExporter().exportData(out.toFile(), new OsmDataLayer(dsIn1, null, null));
     43        DataSet dsIn2 = new PolyImporter().parseDataSet(out.toString());
     44        assertNotNull(dsIn2);
     45        assertEquals(76, dsIn2.getNodes().size());
     46        assertEquals(4, dsIn2.getWays().size());
     47        assertEquals(1, dsIn2.getRelations().size());
     48       
     49        Files.delete(out);
     50    }
     51}
  • test/unit/poly/PolyImporterTest.java

     
     1// License: GPL. For details, see LICENSE file.
     2package poly;
     3
     4import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertNotNull;
     6import static org.junit.Assert.assertNull;
     7
     8import org.junit.Rule;
     9import org.junit.Test;
     10import org.openstreetmap.josm.TestUtils;
     11import org.openstreetmap.josm.data.osm.DataSet;
     12import org.openstreetmap.josm.io.IllegalDataException;
     13import org.openstreetmap.josm.testutils.JOSMTestRules;
     14
     15/**
     16 * Unit tests for {@link PolyImporter}.
     17 * @author Gerd Petermann
     18 */
     19public class PolyImporterTest {
     20
     21    /**
     22     * Setup test.
     23     */
     24    @Rule
     25    public JOSMTestRules rules = new JOSMTestRules().preferences();
     26
     27    /**
     28     * @throws Exception if an error occurs
     29     */
     30    @Test
     31    public void testSimple() throws Exception {
     32        DataSet ds = new PolyImporter().parseDataSet(TestUtils.getTestDataRoot() + "/simple.poly");
     33        assertNotNull(ds);
     34        assertEquals(4, ds.getNodes().size());
     35        assertEquals(1, ds.getWays().size());
     36        assertEquals(0, ds.getRelations().size());
     37    }
     38
     39    /**
     40     * File with human friendly coordinate format
     41     * @throws Exception if an error occurs
     42     */
     43    @Test
     44    public void testSimple2() throws Exception {
     45        DataSet ds = new PolyImporter().parseDataSet(TestUtils.getTestDataRoot() + "/splitter.poly");
     46        assertNotNull(ds);
     47        assertEquals(14, ds.getNodes().size());
     48        assertEquals(1, ds.getWays().size());
     49        assertEquals(0, ds.getRelations().size());
     50    }
     51
     52    /**
     53     * @throws Exception if an error occurs
     54     */
     55    @Test
     56    public void testHoles() throws Exception {
     57        DataSet ds = new PolyImporter().parseDataSet(TestUtils.getTestDataRoot() + "/holes.poly");
     58        assertNotNull(ds);
     59        assertEquals(76, ds.getNodes().size());
     60        assertEquals(4, ds.getWays().size());
     61        assertEquals(1, ds.getRelations().size());
     62    }
     63
     64    /**
     65     * @throws Exception if an error occurs
     66     */
     67    @Test
     68    public void testTwoOuter() throws Exception {
     69        DataSet ds = new PolyImporter().parseDataSet(TestUtils.getTestDataRoot() + "/australia_v.poly");
     70        assertNotNull(ds);
     71        assertEquals(18, ds.getNodes().size());
     72        assertEquals(2, ds.getWays().size());
     73        assertEquals(1, ds.getRelations().size());
     74    }
     75
     76    /**
     77     * @throws Exception if an error occurs
     78     */
     79    @Test
     80    public void testDoubleEnd() throws Exception {
     81        DataSet ds = new PolyImporter().parseDataSet(TestUtils.getTestDataRoot() + "/bremen-double-end.poly");
     82        assertNotNull(ds);
     83        assertEquals(337, ds.getNodes().size());
     84        assertEquals(2, ds.getWays().size());
     85        assertEquals(1, ds.getRelations().size());
     86    }
     87
     88    /**
     89     * @throws Exception if an error occurs
     90     */
     91    @Test
     92    public void testMultipleFile() throws Exception {
     93        DataSet ds = new PolyImporter().parseDataSet(TestUtils.getTestDataRoot() + "/multi-concat.poly");
     94        assertNotNull(ds);
     95        assertEquals(40, ds.getNodes().size());
     96        assertEquals(4, ds.getWays().size());
     97        assertEquals(1, ds.getRelations().size());
     98    }
     99
     100    /**
     101     * Should throw an IllegalDataException
     102     * @throws Exception if an error occurs
     103     */
     104    @Test (expected = IllegalDataException.class)
     105    public void testNameMissing() throws Exception {
     106        DataSet ds = new PolyImporter().parseDataSet(TestUtils.getTestDataRoot() + "/name-missing.poly");
     107        assertNull(ds);
     108    }
     109
     110}
  • test

  • .

    Property changes on: test
    ___________________________________________________________________
    Added: svn:ignore
    ## -0,0 +1,3 ##
    +build
    +jacoco.exec
    +report