title: How to calculate the distance in meters between a geographic point and a given polygon?
body: <p>First of all, I'm new to GIS, so pardon any mistakes. I need to discover the distance between a latitude and longitude point and a latitude/longitude polygon (regular or not). Precisely, I need to discover the minimal distance from a given point to a point in the polygon's boundary, as illustrated below. In the example, the closer distance from point <code>p</code> to the polygon is <code>d</code>. Note: I don't need the point, just the minimum distance.</p>
  
  <p><a href="https://i.stack.imgur.com/zlC0x.png" rel="noreferrer"><img src="https://i.stack.imgur.com/zlC0x.png" alt="Problem Illustration"></a></p>
  
  <p>After some reading, I've come up with the following minimum working example using the GeoTools API. However, I think I'm messing up in the output. Can anyone enlight me on how to get the minimum distance between a point and polygon in mteres?</p>
  
  <p>MWE.java:</p>
  
  <pre><code>import com.vividsolutions.jts.geom.Coordinate;
  import com.vividsolutions.jts.geom.Geometry;
  import com.vividsolutions.jts.geom.GeometryFactory;
  import com.vividsolutions.jts.geom.Point;
  
  public class MWE {
  
      public static void main(String[] args) throws Exception {
          GeometryFactory gf = JTSFactoryFinder.getGeometryFactory();
  
          Coordinate[] c = new Coordinate[5];
          c[0] = new Coordinate(-49.242986, -16.662430);
          c[1] = new Coordinate(-49.241999, -16.664465);
          c[2] = new Coordinate(-49.239146, -16.663828);
          c[3] = new Coordinate(-49.239832, -16.661443);
          c[4] = new Coordinate(-49.242986, -16.662430);
  
          Geometry geo = gf.createPolygon(c);
  
          Point p = gf.createPoint(new Coordinate(-49.246870, -16.665493));
  
          double distance = geo.distance(p);
  
          System.out.println("Distance: " + distance);
  
      }
  }
  </code></pre>