Search code examples
javagisjung

How to plot vertices using GIS coordinates in JUNG


I am trying to plot vertices using GIS latitude and longitude values, laying them out with a StaticLayout. The problem is that I have values with negative values, like:

40.742151  -73.640223
43.122041  -77.622466
32.812091  -96.840159

What is the best way to layout my vertices? Right now I am doing like:

Transformer<String, Point2D> locationTransformer = new Transformer<String, Point2D>() {
    @Override
    public Point2D transform(String npi) {
       Vertex doctor;
       if (doctors.containsKey(npi)) {
           doctor = doctors.get(npi);
       } else {
           doctor = referredDoctors.get(npi);
       }
       return new Point2D.Double((double) doctor.getXcor(i), (double) doctor.getYcor(i));
    }
};
StaticLayout<String, String> layout = new StaticLayout<>(g, locationTransformer);
Dimension preferredSize = new Dimension(400, 400);
layout.setSize(preferredSize);

the result, however, is not nice: only few nodes are displayed, and they are partly visible in the upper-left corner of the image. Any help more than welcome.


Solution

  • You will need to transform your GIS coordinates into the coordinate system that you're rendering in. In this case, that's a rectangle whose X and Y values go from 0 to 400.

    So, for example, you might choose to map lat = 0, long = 0 to the middle of the region (200,200).

    There are many different map projections (https://en.wikipedia.org/wiki/Map_projection) and you'll need to figure out which one best suits your needs. (If your points are all in Europe, for instance, your transformation might not need to be able to show all points on the surface of the Earth.)

    You may find this demo useful: http://jung.sourceforge.net/site/apidocs/edu/uci/ics/jung/samples/WorldMapGraphDemo.html