createTransformations()
method.usa.ivl
file
is in Lambert Azimuthal Equal Area projection.Name of the Projection |
Lambert Azimuthal Equal Area |
Central Meridian |
100DW |
Central parallel |
40DN |
Measurement unit |
Meters (the default value) |
Offset |
0 (the default value) |
private void createTransformations() { // Create the projection. IlvProjection projection = new IlvLambertAzimuthalEqualAreaProjection(); projection.setEllipsoid(IlvEllipsoid.SPHERE); try { double centralMeridian = IlvAngularUnit.RADIAN.fromDMS("100DW"); double centralParallel = IlvAngularUnit.RADIAN.fromDMS("40DN"); projection.setCentralMeridian(centralMeridian); projection.setCentralParallel(centralParallel); } catch (IllegalArgumentException e) { System.out.println("wrong string passed to " + "IlvAngularUnit.RADIAN.fromDMS"); System.out.println("unable to create the projection for the file" + "usa.ivl"); System.exit(0); }
IlvAngularUnit.RADIAN.fromDMS()
to
achieve this goal.// Create the projected coordinate system. IlvProjectedCoordinateSystem projectedCS = new IlvProjectedCoordinateSystem("Lambert Azimutal Equal Area", projection);
// Create the geographic coordinate system. IlvGeographicCoordinateSystem geoCS = new IlvGeographicCoordinateSystem(IlvHorizontalShiftDatum.SPHERE_WGS84, IlvMeridian.GREENWICH);
// A coordinate transform. geo2projCT = IlvCoordinateTransformation.CreateTransformation(geoCS,projectedCS); // The inverse transform. proj2geoCT = geo2projCT.getInverse();
addCitites()
method adds
a number of cities on top of the imported map of the United States: private void addCities() { addCity("Washington", "39D11'N", "76D51W"); addCity("New York", "40D59'N", "73D39'W"); addCity("Miami", "25D58'N", "80D02'W"); addCity("San Francisco", "37D44'N", "122D20'W"); addCity("Seattle", "47D51'N", "122D01'W"); addCity("Denvers", "39D50'N", "104D53'W"); }
addCity()
method. private void addCity(String cityName, String lat, String lon) { try { double latitude = IlvAngularUnit.DEGREE.fromDMS(lat); double longitude = IlvAngularUnit.DEGREE.fromDMS(lon); IlvCoordinate coordinate = new IlvCoordinate(longitude, latitude);
IlvProjectionUtil.invertY()
method
is then called to invert the y-coordinate: in the JViews Maps manager coordinate system, the y-axis
is oriented downwards, whereas, in the projection coordinate system,
it is oriented upwards. geo2projCT.transform(coordinate,coordinate); IlvPoint p = new IlvPoint((float)coordinate.x, (float)coordinate.y); IlvProjectionUtil.invertY(p);
IlvPoint
is
allocated here. It will be used to create graphic objects (an IlvMarker
)
to represent the city. This graphic object is added to Layer #1 of
the manager (Layer #0 contains the boundaries of the USA). IlvMarker marker = new IlvMarker(p, IlvMarker.IlvMarkerFilledDiamond); marker.setSize(4); marker.setForeground(Color.red); manager.addObject(marker, 1, false); marker.setName(cityName); } catch (IlvCoordinateTransformationException e) { e.printStackTrace(); }
setViewInteractor()
method.private void setViewInteractor() { IlvSelectInteractor interactor = new IlvSelectInteractor(); interactor.setDragAllowed(false); interactor.setEditionAllowed(false); interactor.setMoveAllowed(false); interactor.setMultipleSelectionMode(false); manager.setSelectable(0, false); mgrview.pushInteractor(interactor);
IlvAngularUnit.DEGREE.toDMS()
method.// Display the position of the mouse. interactor.addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent e) { // Get the point in manager coordinates. IlvTransformer t = mgrview.getTransformer(); IlvPoint p = new IlvPoint(e.getX(), e.getY()); t.inverse(p); IlvProjectionUtil.invertY(p); // Display the mouse position. try { IlvCoordinate c = new IlvCoordinate(p.x,p.y); proj2geoCT.transform(c,c); llField.setText(IlvAngularUnit.DEGREE.toDMS(c.x,false) + " " + IlvAngularUnit.DEGREE.toDMS(c.x,true)); } catch (IlvCoordinateTransformationException ex) { System.out.println("Unable to inverse this point " + ex.getMessage()); } } });
manager.addManagerSelectionListener(new ManagerSelectionListener(){ public void selectionChanged(ManagerSelectionChangedEvent e) { IlvGraphic g = e.getGraphic(); if (g == null) return; String name = g.getName(); if (name != null) cityField.setText(name); } });