Hi Rajkumar

Welcome to GeoTools.

The company I work for, LISAsoft, sells developer support allowing me to answer 
direct emails, and fix bugs, promptly. If you email the geotools user list you 
will find that both myself and others are around to try and help.

When projecting from one CRS to another ... you need to have two coordinate 
reference systems, so your code is correct - your data is wrong :-)

I notice this line: 

> SimpleFeatureType TYPE = DataUtilities.createType("testtype",
> "shape:Geometry, name:String");

you should change it to specify the spatial reference system used - example 
"shape:Geometry:srid=4326"

As shown in the javadocs: 
http://docs.geotools.org/stable/javadocs/org/geotools/data/DataUtilities.html#createType(java.lang.String,%20java.lang.String)
 

Ask your data provider what the coordinate reference system is. Many 
organisations work with the same CRS all the time, and don't even both to write 
it down in the file. There is a DefaultGeographicCRS.WGS84 for lon/lat data for 
example.

For more information please review the tutorial on the subject.
http://docs.geotools.org/latest/tutorials/geometry/geometrycrs.html
-- 
Jody Garnett

On Saturday, 12 March 2011 at 12:37 AM, Rajkumar wrote: 
> 
> 
> Hi Jody,
> 
> Greetings. I am very new to geotools. Here is my code and when I try to
> click the mouse over a point, it is giving an exception.
> 
> EVERE: It was not possible to get a projected bounds estimate
> Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException:
> java.lang.IllegalArgumentException: Argument "sourceCRS" should not be
> null.
>  at org.geotools.swing.tool.InfoTool.onMouseClicked(InfoTool.java:178)
>  at
> org.geotools.swing.tool.MapToolManager.mouseClicked(MapToolManager.java:132)
> 
> Code:
> 
> 
> import com.vividsolutions.jts.geom.Geometry;
> import com.vividsolutions.jts.io.WKTReader;
> import java.awt.Color;
> import org.geotools.data.DataUtilities;
> import org.geotools.data.simple.SimpleFeatureCollection;
> import org.geotools.factory.CommonFactoryFinder;
> import org.geotools.feature.FeatureCollections;
> import org.geotools.feature.simple.SimpleFeatureBuilder;
> import org.geotools.map.DefaultMapContext;
> import org.geotools.map.MapContext;
> import org.geotools.referencing.crs.DefaultGeographicCRS;
> import org.geotools.styling.ExternalGraphic;
> import org.geotools.styling.FeatureTypeStyle;
> import org.geotools.styling.Graphic;
> import org.geotools.styling.PointSymbolizer;
> import org.geotools.styling.Rule;
> import org.geotools.styling.Stroke;
> import org.geotools.styling.Style;
> import org.geotools.styling.StyleBuilder;
> import org.geotools.styling.StyleFactory;
> import org.geotools.styling.Symbolizer;
> import org.geotools.swing.JMapFrame;
> import org.opengis.feature.simple.SimpleFeatureType;
> import org.opengis.filter.Filter;
> import org.opengis.filter.FilterFactory2;
> import org.opengis.filter.expression.Function;
> 
> 
> 
> 
> /*
>  * Creates some features having either Point or LineString as the
> Geometry and displays them
>  * in a single MapLayer
>  */
> public class LinesAndPointsOrig {
> 
>  public static void main(String[] args) throws Exception {
>  new LinesAndPointsOrig().displayFeatures();
>  }
> 
>  private void displayFeatures() throws Exception {
>  SimpleFeatureCollection features = createFeatureCollection();
>  Style style = createStyle("shape");
>  MapContext map = new DefaultMapContext(DefaultGeographicCRS.WGS84);
>  map.addLayer(features, style);
>  JMapFrame.showMap(map);
>  }
> 
>  private SimpleFeatureCollection createFeatureCollection() throws
> Exception {
>  SimpleFeatureCollection fc = FeatureCollections.newCollection();
>  SimpleFeatureType TYPE = DataUtilities.createType("testtype",
> "shape:Geometry, name:String");
>  SimpleFeatureBuilder fb = new SimpleFeatureBuilder(TYPE);
> 
>  Geometry g;
>  WKTReader reader = new WKTReader();
> 
>  g = reader.read("POINT(1 1)");
>  fc.add(fb.buildFeature(null, new Object[]{g, "p1"}));
> 
>  g = reader.read("POINT(2 2)");
>  fc.add(fb.buildFeature(null, new Object[]{g, "p2"}));
> 
>  g = reader.read("POINT(3 3)");
>  fc.add(fb.buildFeature(null, new Object[]{g, "p3"}));
> 
>  g = reader.read("POINT(4 4)");
>  fc.add(fb.buildFeature(null, new Object[]{g, "p4"}));
> 
>  g = reader.read("LINESTRING(1 2, 4 5)");
>  fc.add(fb.buildFeature(null, new Object[]{g, "line1"}));
> 
>  g = reader.read("LINESTRING(1 0, 4 3)");
>  fc.add(fb.buildFeature(null, new Object[]{g, "line1"}));
> 
>  return fc;
>  }
> 
>  private Style createStyle(String geomPropertyName) {
>  // private Style createStyle() {
>  StyleFactory sf = CommonFactoryFinder.getStyleFactory(null);
>  FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
> 
>  Rule pointRule = sf.createRule();
>  Function getGeomFn = ff.function("geometryType",
> ff.property(geomPropertyName));
>  Filter pointFilter = ff.equals(getGeomFn, ff.literal("Point"));
>  pointRule.setFilter(pointFilter);
>  pointRule.setElseFilter(false);
> 
>  Graphic graphic = sf.getDefaultGraphic();
>  graphic.graphicalSymbols().clear();
>  //ExternalGraphic external = sf.createExternalGraphic(
> "file:///C:/Users/rajkumar/riaexworkspace/metar/src/images/aircraftsmall.png",
> "image/gif");
> 
>  //ExternalGraphic eGr = sb.createExternalGraphic(SPRITE_IMAGE_URL,
> "image/png");
>  //graphic.graphicalSymbols().add( eGr );
> 
>  // graphic.graphicalSymbols().add(sf.getCircleMark());
>  graphic.graphicalSymbols().add(sf.getTriangleMark());
> 
>  //graphic.graphicalSymbols().add(external);
> 
>  Symbolizer sym = sf.createPointSymbolizer(graphic, geomPropertyName);
>  // Symbolizer sym =sf.createPointSymbolizer(graphic,"");
>  pointRule.symbolizers().add(sym);
> 
>  Rule lineRule = sf.createRule();
>  lineRule.setIsElseFilter(true);
>  Stroke stroke = sf.createStroke(ff.literal(Color.BLUE),
> ff.literal(1.0f));
>  Symbolizer lineSym = sf.createLineSymbolizer(stroke,
> geomPropertyName);
>  lineRule.symbolizers().add(lineSym);
> 
>  FeatureTypeStyle fts = sf.createFeatureTypeStyle(new
> Rule[]{pointRule, lineRule});
>  Style style = sf.createStyle();
>  style.featureTypeStyles().add(fts);
>  return style;
>  }
> }
> 
> I greatly appreciate your help.
> 
> Thanks
> Rajkumar
> 
------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to