Changeset 32972 in osm for applications/editors/josm


Ignore:
Timestamp:
2016-09-11T13:47:23+02:00 (8 years ago)
Author:
nokutu
Message:

Improved sign system. Works in all countries and different sign packages.

Location:
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImage.java

    r32574 r32972  
    1616 */
    1717public class MapillaryImage extends MapillaryAbstractImage {
    18   /** Unique identifier of the object. */
     18  /**
     19   * Unique identifier of the object.
     20   */
    1921  private final String key;
    20   /** The user that made the image. */
     22  /**
     23   * The user that made the image.
     24   */
    2125  private String user;
    22   /** Set of traffic signs in the image. */
    23   private final List<String> signs = new ArrayList<>();
    24   /** Where the picture was taken. */
     26  /**
     27   * Set of traffic signs in the image.
     28   */
     29  private final List<MapillarySign> signs = new ArrayList<>();
     30  /**
     31   * Where the picture was taken.
     32   */
    2533  private String location;
    2634
     
    2836   * Main constructor of the class MapillaryImage
    2937   *
    30    * @param key The unique identifier of the image.
     38   * @param key    The unique identifier of the image.
    3139   * @param latLon The latitude and longitude where it is positioned.
    32    * @param ca The direction of the images in degrees, meaning 0 north.
     40   * @param ca     The direction of the images in degrees, meaning 0 north.
    3341   */
    3442  public MapillaryImage(final String key, final LatLon latLon, final double ca) {
     
    7078   * @param sign A {@code String} that identifies the type of sign.
    7179   */
    72   public void addSign(String sign) {
    73     this.signs.add(sign);
     80  public void addSign(MapillarySign sign) {
     81    if (sign != null) {
     82      this.signs.add(sign);
     83    }
    7484  }
    7585
     
    7989   * @return A {@link List} object containing the signs assigned to this image.
    8090   */
    81   public List<String> getSigns() {
     91  public List<MapillarySign> getSigns() {
    8292    return this.signs;
    8393  }
     
    104114  public String toString() {
    105115    return String.format(
    106       "Image[key=%s,lat=%f,lon=%f,ca=%f,location=%s,user=%s,capturedAt=%d]",
    107       key, latLon.lat(), latLon.lon(), ca, location, user, capturedAt
     116            "Image[key=%s,lat=%f,lon=%f,ca=%f,location=%s,user=%s,capturedAt=%d]",
     117            key, latLon.lat(), latLon.lon(), ca, location, user, capturedAt
    108118    );
    109119  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryFilterDialog.java

    r32653 r32972  
    1111import java.util.Arrays;
    1212import java.util.Calendar;
     13import java.util.regex.Pattern;
    1314
    1415import javax.swing.AbstractAction;
     
    3233import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    3334import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     35import org.openstreetmap.josm.plugins.mapillary.MapillarySign;
    3436import org.openstreetmap.josm.tools.ImageProvider;
    3537import org.openstreetmap.josm.tools.Shortcut;
     
    6971   * The list of sign names
    7072   */
    71   private static final String[] SIGN_TAGS = {"prohibitory_speed_limit",
    72           "priority_stop", "other_give_way", "mandatory_roundabout",
    73           "other_no_entry", "prohibitory_no_traffic_both_ways",
    74           "danger_intersection", "mandatory_go", "mandatory_keep",
    75           "danger_priority_next_intersection", "danger_uneven_road",
    76           "prohibitory_no_parking", "prohibitory_on_overtaking",
    77           "danger_pedestrian_crossing", "prohibitory_no_u_turn",
    78           "prohibitory_noturn"};
     73  private static final String[] SIGN_TAGS = {"prohibitory--maximum-speed-limit",
     74          "regulatory|priority--stop", "regulatory|priority--give_way|yield", "warning|mandatory--roundabout",
     75          "prohibitory|regulatory--no-entry|no-traffic-both-ways",
     76          "crossroads|junction", "mandatory--turn|straight", "uneven|slippery",
     77          "no-parking", "no_overtaking",
     78          "danger_pedestrian_crossing", "no_*_turn"};
    7979  /**
    8080   * The {@link JCheckBox} where the respective tag should be searched
     
    8282  private final JCheckBox[] SIGN_CHECKBOXES = {this.signFilter.maxSpeed,
    8383          this.signFilter.stop, this.signFilter.giveWay,
    84           this.signFilter.roundabout, this.signFilter.access,
    85           this.signFilter.access, this.signFilter.intersection,
    86           this.signFilter.direction, this.signFilter.direction,
    87           this.signFilter.intersection, this.signFilter.uneven,
     84          this.signFilter.roundabout, this.signFilter.access, this.signFilter.intersection,
     85          this.signFilter.direction, this.signFilter.uneven,
    8886          this.signFilter.noParking, this.signFilter.noOvertaking,
    89           this.signFilter.crossing, this.signFilter.noTurn, this.signFilter.noTurn};
     87          this.signFilter.crossing, this.signFilter.noTurn};
    9088
    9189  private MapillaryFilterDialog() {
     
    242240  }
    243241
    244   private static boolean checkSign(MapillaryImage img, JCheckBox signCheckBox, String singString) {
     242  private static boolean checkSign(MapillaryImage img, JCheckBox signCheckBox, String signTag) {
    245243    boolean contains = false;
    246     for (String sign : img.getSigns()) {
    247       if (sign.contains(singString))
     244    for (MapillarySign sign : img.getSigns()) {
     245      String[] parts = signTag.split("--");
     246      if (Pattern.compile(parts[0]).matcher(sign.getCategory()).find() &&
     247              Pattern.compile(parts[1]).matcher(sign.getType()).find()) {
    248248        contains = true;
     249      }
    249250    }
    250251    return contains == signCheckBox.isSelected() && contains;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryImageInfoDownloadThread.java

    r32341 r32972  
    6767              ((MapillaryImage) image).setUser(data.getString("user"));
    6868              ((MapillaryImage) image).setCapturedAt(data.getJsonNumber("captured_at").longValue());
     69              ((MapillaryImage) image).setLocation(data.getString("location"));
    6970            }
    7071          }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryTrafficSignDownloadThread.java

    r32069 r32972  
    1717import org.openstreetmap.josm.plugins.mapillary.MapillaryImage;
    1818import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     19import org.openstreetmap.josm.plugins.mapillary.MapillarySign;
    1920import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryURL;
    2021import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryURL.IMAGE_SELECTOR;
     
    2425 *
    2526 * @author nokutu
    26  *
    2727 */
    2828public class MapillaryTrafficSignDownloadThread extends Thread {
     
    3434   * Main constructor.
    3535   *
    36    * @param ex {@link ExecutorService} object that is executing this thread.
     36   * @param ex     {@link ExecutorService} object that is executing this thread.
    3737   * @param bounds the bounds in which the traffic signs should be downloaded
    38    * @param page the pagenumber of the results page that should be retrieved
     38   * @param page   the pagenumber of the results page that should be retrieved
    3939   */
    4040  public MapillaryTrafficSignDownloadThread(ExecutorService ex, Bounds bounds, int page) {
     
    4646  @Override
    4747  public void run() {
    48 
    4948    try (
    50       BufferedReader br = new BufferedReader(new InputStreamReader(
    51         MapillaryURL.searchImageInfoURL(bounds, page, IMAGE_SELECTOR.OBJ_REC_ONLY).openStream(), "UTF-8"
    52       ));
     49            BufferedReader br = new BufferedReader(new InputStreamReader(
     50                    MapillaryURL.searchImageInfoURL(bounds, page, IMAGE_SELECTOR.OBJ_REC_ONLY).openStream(), "UTF-8"
     51            ));
    5352    ) {
    5453      JsonObject jsonobj = Json.createReader(br).readObject();
     
    6059        JsonArray rects = jsonarr.getJsonObject(i).getJsonArray("rects");
    6160        JsonArray rectversions = jsonarr.getJsonObject(i).getJsonArray(
    62             "rectversions");
     61                "rectversions");
    6362        String key = jsonarr.getJsonObject(i).getString("key");
    6463        if (rectversions != null) {
     
    6867              JsonObject data = rects.getJsonObject(k);
    6968              for (MapillaryAbstractImage image : MapillaryLayer.getInstance().getData().getImages()) {
    70                 if (image instanceof MapillaryImage && ((MapillaryImage) image).getKey().equals(key))
    71                   ((MapillaryImage) image).addSign(data.getString("type"));
     69                if (image instanceof MapillaryImage && ((MapillaryImage) image).getKey().equals(key)) {
     70                  ((MapillaryImage) image).addSign(MapillarySign.getSign(data.getString("type"), rectversions.getJsonObject(j).getString("package").split("_")[1]));
     71                }
    7272              }
    7373            }
     
    8181            for (MapillaryAbstractImage image : MapillaryLayer.getInstance().getData().getImages()) {
    8282              if (image instanceof MapillaryImage && ((MapillaryImage) image).getKey().equals(key)) {
    83                 ((MapillaryImage) image).addSign(data.getString("type"));
     83                ((MapillaryImage) image).addSign(MapillarySign.getSign(data.getString("type"), data.getString("package").split("_")[1]));
    8484              }
    8585            }
     
    8787        }
    8888      }
    89     } catch (MalformedURLException e) {
    90       Main.error(e);
    9189    } catch (IOException e) {
    9290      Main.error(e);
Note: See TracChangeset for help on using the changeset viewer.