--- src/org/openstreetmap/josm/data/gpx/GpxDistance.java	(nonexistent)
+++ src/org/openstreetmap/josm/data/gpx/GpxDistance.java	(working copy)
@@ -0,0 +1,174 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.data.gpx;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.Relation;
+import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.gui.MainApplication;
+import org.openstreetmap.josm.gui.layer.GpxLayer;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.LayerManager;
+
+/**
+ * A class to find the distance between an OsmPrimitive and a GPX point
+ *
+ * @author Taylor Smock
+ *
+ */
+public final class GpxDistance {
+    private GpxDistance() {
+        // This class should not be instantiated
+    }
+
+    /**
+     * @param p The OsmPrimitive that we are checking the maximum distance for
+     * @param maximumDistance The maximum distance from a GPX point to the OsmPrimitive
+     * @return true if the distance to the closest GPX point is lower than maximumDistance
+     */
+    public static boolean isCloseTo(OsmPrimitive p, double maximumDistance) {
+        double distance = getLowestDistance(p);
+        return (distance < maximumDistance);
+    }
+
+    /**
+     * Get the lowest distance from the layers to p
+     * @param p OsmPrimitive from which to get the lowest distance to a GPX point
+     * @return the lowest distance from any GpxLayer to p.
+     */
+    public static double getLowestDistance(OsmPrimitive p) {
+        LayerManager layerManager = MainApplication.getLayerManager();
+        List<Layer> layers = layerManager.getLayers();
+        double distance = Double.MAX_VALUE;
+        for (Layer layer : layers) {
+            double tdistance = getLowestDistance(p, layer);
+            if (tdistance < distance) distance = tdistance;
+        }
+        return distance;
+    }
+
+    /**
+     * Find the distance between a point and a layer of surveyed points
+     * @param p OsmPrimitive from which to get the lowest distance to a GPX point
+     * @param layer Layer from which to get the GPX points (currently, only GpxLayer is supported)
+     * @return The shortest distance
+     */
+    public static double getLowestDistance(OsmPrimitive p, Layer layer) {
+        if (layer instanceof GpxLayer) {
+            GpxLayer gpxLayer = (GpxLayer) layer;
+            GpxData gpxData = gpxLayer.data;
+            List<WayPoint> trackPoints = gpxData.getTrackPoints().collect(Collectors.toList());
+            double lowestDistance = Double.MAX_VALUE;
+            for (WayPoint trackPoint : trackPoints) {
+                double distance = getDistance(p, trackPoint);
+                if (distance >= 0.0 && distance < lowestDistance) lowestDistance = distance;
+            }
+            return lowestDistance;
+        }
+        return Double.MAX_VALUE;
+    }
+
+    /**
+     * Get the distance between an object and a waypoint
+     * @param p OsmPrimitive to get the distance to the WayPoint
+     * @param waypoint WayPoint to get the distance from
+     * @return The shortest distance between p and waypoint
+     */
+    public static double getDistance(OsmPrimitive p, WayPoint waypoint) {
+        if (p instanceof Node) {
+            return getDistanceNode((Node) p, waypoint);
+        } else if (p instanceof Way) {
+            return getDistanceWay((Way) p, waypoint);
+        } else if (p instanceof Relation) {
+            return getDistanceRelation((Relation) p, waypoint);
+        }
+        return Double.MAX_VALUE;
+    }
+
+    /**
+     * Get the shortest distance between a relation and a waypoint
+     * @param relation Relation to get the distance from
+     * @param waypoint WayPoint to get the distance to
+     * @return The distance between the relation and the waypoint
+     */
+    public static double getDistanceRelation(Relation relation, WayPoint waypoint) {
+        double shortestDistance = Double.MAX_VALUE;
+        List<Node> nodes = new ArrayList<>(relation.getMemberPrimitives(Node.class));
+        List<Way> ways = new ArrayList<>(relation.getMemberPrimitives(Way.class));
+        List<Relation> relations = new ArrayList<>(relation.getMemberPrimitives(Relation.class));
+        if (nodes.isEmpty() && ways.isEmpty() && relations.isEmpty()) return Double.MAX_VALUE;
+        for (Relation nrelation : relations) {
+            double distance = getDistanceRelation(nrelation, waypoint);
+            if (distance < shortestDistance) shortestDistance = distance;
+        }
+        for (Way way : ways) {
+            double distance = getDistanceWay(way, waypoint);
+            if (distance < shortestDistance) shortestDistance = distance;
+        }
+        for (Node node : nodes) {
+            double distance = getDistanceNode(node, waypoint);
+            if (distance < shortestDistance) shortestDistance = distance;
+        }
+        return shortestDistance;
+    }
+
+    /**
+     * Get the shortest distance between a way and a waypoint
+     * @param way Way to get the distance from
+     * @param waypoint WayPoint to get the distance to
+     * @return The distance between the way and the waypoint
+     */
+    public static double getDistanceWay(Way way, WayPoint waypoint) {
+        double shortestDistance = Double.MAX_VALUE;
+        LatLon coords = waypoint.getCoor();
+        for (int i = 0; i < way.getNodesCount() - 1; i++) {
+            LatLon first = way.getNode(i).getCoor();
+            LatLon second = way.getNode(i + 1).getCoor();
+            double distance = Double.MAX_VALUE;
+            if (first.isLatLonKnown() && second.isLatLonKnown()) {
+                double tdistance = ((coords.getX() - first.getX()) * (second.getX() - first.getX())
+                        + (coords.getY() - first.getY()) * (second.getY() - first.getY()))
+                        / (Math.pow(second.getX() - first.getX(), 2) + Math.pow(second.getY() - first.getY(), 2));
+                double x = first.getX() + tdistance * (second.getX() - first.getX());
+                double y = first.getY() + tdistance * (second.getY() - first.getY());
+                LatLon npoint = new LatLon(y, x);
+                distance = npoint.greatCircleDistance(coords);
+            } else if (first.isLatLonKnown() && !second.isLatLonKnown()) {
+                distance = getDistanceLatLon(first, waypoint);
+            } else if (!first.isLatLonKnown() && second.isLatLonKnown()) {
+                distance = getDistanceLatLon(second, waypoint);
+            } else if (!first.isLatLonKnown() && !second.isLatLonKnown()) {
+                distance = Double.MAX_VALUE;
+            }
+            if (distance < shortestDistance) shortestDistance = distance;
+
+        }
+        return shortestDistance;
+    }
+
+    /**
+     * Get the distance between a node and a waypoint
+     * @param node Node to get the distance from
+     * @param waypoint WayPoint to get the distance to
+     * @return The distance between the two points
+     */
+    public static double getDistanceNode(Node node, WayPoint waypoint) {
+        return getDistanceLatLon(node.getCoor(), waypoint);
+    }
+
+    /**
+     * Get the distance between coordinates (latitude longitude) and a waypoint
+     * @param latlon LatLon to get the distance from
+     * @param waypoint WayPoint to get the distance to
+     * @return The distance between the two points
+     */
+    public static double getDistanceLatLon(LatLon latlon, WayPoint waypoint) {
+        if (latlon == null || waypoint.getCoor() == null) return Double.MAX_VALUE;
+        return waypoint.getCoor().greatCircleDistance(latlon);
+    }
+}
Index: src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
===================================================================
--- src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java	(revision 14599)
+++ src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java	(working copy)
@@ -24,8 +24,10 @@
 import java.util.zip.CRC32;

 import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.gpx.GpxDistance;
 import org.openstreetmap.josm.data.osm.IPrimitive;
 import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.data.osm.search.SearchCompiler;
 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
@@ -519,6 +521,20 @@
         }

         /**
+         * Returns the lowest distance between the OSM object and a GPX point
+         * <p>
+         * @param env the environment
+         * @return the distance between the object and the closest gpx point or {@code Double.MAX_VALUE}
+         */
+        public static double gpx_distance(final Environment env) { // NO_UCD (unused code)
+            if (env.osm instanceof OsmPrimitive) {
+                return GpxDistance.getLowestDistance((OsmPrimitive) env.osm);
+            } else {
+                return Double.MAX_VALUE;
+            }
+        }
+
+        /**
          * Determines whether the object has a tag with the given key.
          * @param env the environment
          * @param key the OSM key
