1

I need to get the world map on the screen limited to the bounds like such latlon coordinates as below. Is it possible to convert these geocoordinates to pixels and then to set these pixels to the viewport or to do this in some other way? I try to manipulate with the Rectangle2D parameters, but it is not the solution of this problem. Maybe you can give some rescue suggestions, please?

The end result of this application should be the part of the world map in the stereographic projection limited to these coordinates and saved as a picture of at least 1600 x 1200 pixels in size and at the same time with acceptable image quality. The excess territory is needed to be removed. I saved the too large image of the world map (see picture), and then I used the MarvinImage library to remove the extra territory, but at the same time the quality of the final image is greatly reduced. Therefore, I try to enlarge the the desired area of ​​the world map, which is displayed in the JFrame, so it could be saved as a picture without additional cutting. In other words? I need to enlarge so the worl map to get the geocoordinate xy_1 in the left top corner of the JFrame, the xy_2 - in the right top corner and so on, and the size of JFrame must be close to the real size of the monitor screen.

  • I am sorry, may I ask wheather you could consider this question or not, because I am waiting for any response from you..? – asker Jun 13 at 9:25
  • This is a volunteer activity - I do sell commercial GeoTools support if that would help – Ian Turton Jun 13 at 9:42
  • please don't delete the useful parts of the question – Ian Turton Jun 13 at 10:38
0

The trick is to simply reproject your "box" into the new projection and take it's internal envelope and use that to set the bounds of the map.

enter image description here

So something like:

    Coordinate[] coord = new Coordinate[5];
    coord[0] = new Coordinate(-56.34, 46.33);
    coord[1] = new Coordinate(68.24, 58.42);
    coord[2] = new Coordinate(33.25, 26.21);
    coord[3] = new Coordinate(-21.36, 21.23);
    coord[4] = coord[0];
    Polygon poly = geometryFactory.createPolygon(coord);
    MathTransform trans = CRS.findMathTransform(DefaultGeographicCRS.WGS84, projCRS);
    poly = (Polygon) JTS.transform(poly, trans);
    poly = (Polygon) Densifier.densify(poly, 10000);


    org.geotools.map.MapViewport viewport = map.getViewport();

    viewport.setCoordinateReferenceSystem(projCRS);
    viewport.setBounds(new ReferencedEnvelope(poly.getEnvelopeInternal(), projCRS));
    this.setMapContent(map);
    map.setViewport(viewport);

I'm not entirely sure the densify step is necessary here but it general it's a useful step with Stereographic and Oblique projections as the edges can fall outside the "straight" edges when dealing with just corners.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.