Simone,

I am attaching a test case for you. Before you spend too much time, I did notice as I was hacking away at my code that I left a deprecated instantiation in:

        mapContext = new DefaultMapContext();

It's on line 113 of what I am sending you. If you think that might be the cause, let me know and I'll get rid of it and test again. I know you guys are trying to get 2.3.0 out, and I've got other things to do, so this can wait.

Best regards,

Amy


Simone Giannecchini wrote:
Ciao Amy,

could you provide a self contained test-case (or something close to it
:-) ) for me to have a look at? I am no able from the information you
provide to provide a final statement on what is happening.

Ciao,
Simone.

On 11/30/06, Amy Johnson <[EMAIL PROTECTED]> wrote:
I'm compiling with 2.3.x and I did a straight replacement of
ReferencedEnvelope for Envelope in
StreamingRenderer.paint(|java.awt.Graphics2D graphics,
java.awt.Rectangle paintArea,
com.vividsolutions.jts.geom.Envelope mapArea). I am now getting the
following error:

Exception in thread "AWT-EventQueue-0"
java.lang.IllegalArgumentException: The provided envelope is outside the
source CRS definition area
   at
org.geotools.renderer.lite.RendererUtilities.calculateScale(RendererUtilities.java:500)
   at
org.geotools.renderer.lite.StreamingRenderer.paint(StreamingRenderer.java:636)
   at
org.geotools.renderer.lite.StreamingRenderer.paint(StreamingRenderer.java:419)

Here is my code:

        mapArea = mapContext.getAreaOfInterest();
           renderer = new StreamingRenderer();
         renderer.setContext(mapContext);

         RenderingHints hints = new
RenderingHints(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON );
         renderer.setJava2DHints(hints);

         Map rendererParams = new HashMap();
         rendererParams.put("optimizedDataLoadingEnabled",new
Boolean(true) );

         renderer.paint(g2, paintArea, mapArea);

I checked to see if mapArea was getting set correctly and it appears to
be. Am I doing something wrong? I'm not sure how to use
ReferencedEnvelope, but I thought it just extended the Envelope I was
using.  Any help is appreciated.

Regards,

Amy

|

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users




package test;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.RenderingHints;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;

import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import org.geotools.data.FeatureSource;
import org.geotools.map.DefaultMapContext;

import org.geotools.renderer.lite.StreamingRenderer;
import org.geotools.styling.BasicLineStyle;
import org.geotools.styling.LineSymbolizer;
import org.geotools.styling.Style;
import org.geotools.styling.StyleBuilder;

import org.geotools.coverage.grid.GridCoverage2D;

import org.geotools.geometry.jts.ReferencedEnvelope;
//import com.vividsolutions.jts.geom.Envelope;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import org.geotools.data.shapefile.indexed.IndexedShapefileDataStore;

import org.geotools.data.FeatureSource;

public class TestMapViewer extends JFrame{
  public static void main(String s[ ]) {
    TestMapViewer builder = new TestMapViewer();
  }

  public TestMapViewer(){
	    Dimension screendim = Toolkit.getDefaultToolkit().getScreenSize();
	    setSize(screendim.width-200, screendim.height-200);
	    setLocation(50,50);
	    MapDisplay myPanel = new MapDisplay();
	    getContentPane().setLayout(new BorderLayout());
	    getContentPane().add(myPanel);
	    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    setVisible(true);
		  JFileChooser fileChooser = new JFileChooser();
		  File filename = null;
		  int result = fileChooser.showOpenDialog(null);
		  if (result == JFileChooser.APPROVE_OPTION) {
			   filename = fileChooser.getSelectedFile();
			  } 
		  myPanel.setFileName(filename);

  }
}

class MapDisplay extends JPanel{
	File filename = null;
 	public MapDisplay(){
		setLayout(new BorderLayout());
		setVisible(true);
		repaint();
	}
 	
 	public void setFileName(File fn){
 		filename = fn;
 		repaint(); 
 	}
	
 	protected void paintComponent(Graphics g){
		Insets insets = getInsets();
		int screen_width = getWidth()-insets.left - insets.right;
		int screen_height = getHeight()-insets.top - insets.bottom;
		StreamingRenderer renderer;
		ReferencedEnvelope mapArea;
		FeatureSource featureSource = null;
		DefaultMapContext mapContext = null;
		Graphics2D g2 = (Graphics2D)g;
		g2.setColor(Color.BLACK);

		Rectangle paintArea = new Rectangle(screen_width, screen_height);

		g2.fillRect(0, 0, screen_width, screen_height);
		if (filename!=null){
		   ShapeReader shapeReader = new ShapeReader(filename);
		    shapeReader.readShapeData();
		    featureSource = shapeReader.getFeatureSource();
			// Prepare styles
			StyleBuilder sb = new StyleBuilder();

			// Create line symbolizer
			LineSymbolizer lineSymb =
				(LineSymbolizer) sb.createLineSymbolizer(Color.WHITE, 2);
			Style aStyle = sb.createStyle(lineSymb);
		  mapContext = new DefaultMapContext();
		  mapContext.addLayer(featureSource, aStyle);
          mapArea = mapContext.getAreaOfInterest();
  		  renderer = new StreamingRenderer();
		  renderer.setContext(mapContext);

	      RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
	      renderer.setJava2DHints(hints);

	      Map rendererParams = new HashMap();
	      rendererParams.put("optimizedDataLoadingEnabled",new Boolean(true) );

	      renderer.paint(g2, paintArea, mapArea);
		}
		}
}

class ShapeReader {
	private File shapeFile;
	private URL shapeURL = null;
	private boolean file_exists = false;
    private FeatureSource featureSource = null;


  public ShapeReader(File shapeFile){
   try{
	  shapeURL = shapeFile.toURL();
	  file_exists = true;
	} 
    catch(MalformedURLException murle){}
  }
  
  public boolean file_exists(){
	return file_exists;
  }
  
  public void readShapeData(){

//	    * creates a shapefile datastore from the URL and gets out the single feature type in this datastore;
//	    * prints out the feature type's non-geometric attributes name and type as a header;

//	 get feature results
	IndexedShapefileDataStore dataStore;
	String name;
	try{
		dataStore = new IndexedShapefileDataStore(shapeURL);
	  name = dataStore.getTypeNames()[0];
	  System.out.println("name is " + name);
	  try{
	    featureSource = dataStore.getFeatureSource(name);	
	  }
	  catch (IOException ioe){}
	}
	
	catch (MalformedURLException murle){}
	
  }
  
  public FeatureSource getFeatureSource(){
	  return featureSource;
  }
}

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to