Thanks to Ian I've been able to resolve this issue. Anser is posted on stack 
exchange.
Peter

      From: Peter Borissow <peter.boris...@yahoo.com>
 To: geotools-gt2-users <geotools-gt2-users@lists.sourceforge.net> 
 Sent: Sunday, November 30, 2014 9:01 AM
 Subject: Re: Saving a map to image
   
I posted a question on stack exchange:
http://gis.stackexchange.com/questions/123903/how-to-create-a-map-and-save-it-to-an-image-with-geotools
Thanks,Peter

 

     From: Peter Borissow <peter.boris...@yahoo.com>
 To: geotools-gt2-users <geotools-gt2-users@lists.sourceforge.net> 
 Sent: Saturday, November 29, 2014 12:00 PM
 Subject: Re: Saving a map to image
   
After a little trial and error it appears that the map layers must be 
reprojected to the viewport. Is that right? 

Step 1: Create mapMapContent map = new MapContent();
map.setTitle("World");
Step 2: Set projectionCoordinateReferenceSystem crs = CRS.decode("EPSG:5070"); 
//Conic projection over US
MapViewport vp = map.getViewport();
vp.setCoordinateReferenceSystem(crs);

Step 3: Add layers to mapCoordinateReferenceSystem mapCRS = 
map.getCoordinateReferenceSystem();
map.addLayer(reproject(getPoliticalBoundaries(), mapCRS));
map.addLayer(reproject(getGraticules(), mapCRS));
Step 4: Save imagesaveImage(map, "/temp/graticules.jpg", 800);






 

     From: Peter Borissow <peter.boris...@yahoo.com>
 To: geotools-gt2-users <geotools-gt2-users@lists.sourceforge.net> 
 Sent: Friday, November 28, 2014 6:16 PM
 Subject: Saving a map to image
   
Hello-    I am trying to create a simple map and save it to a jpeg file. I 
found this tutorial on how to save a MapContent to an image: 

http://docs.geotools.org/latest/userguide/library/render/gtrenderer.html

As a test, I did something simple like this:
MapContent map = new MapContent();
map.setTitle("World");
map.addLayer(getGraticules());saveImage(map, "/temp/graticules.jpg", 800);
Works great! However, now I want to reproject the map and clip it to a specific 
AOI. Ideally, I was hoping for something like:
map.setBounds(envelope); 
map.setCoordinateReferenceSystem(crs);
...but of course these methods don't exist in the MapContent class. Instead, I 
see those methods implemented in the MapViewport. Is that what I should use to 
reproject and clip the map? Or do I need to reproject and clip individual 
layers before I add them to the map?


Thanks in advance,Peter


 

   

   

  
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to