Evening Mr Govardhan ...
I think you are going to have to use the CRS that matches your data,
does your data have prj files? You may want to try out your shapefiles
with uDig just to confirm they are working correctly.
Cheers,
Jody
> Dear Sir/Madam,
> I am having problem in bringing up my Georeferenced map on the screen.
> I am using DefaultMapContext() to create map, and not using any CRS.
>
> I have attached the map image, please help me how to resolve this.
>
> I am using the following code to create the map,
>
> private void renderMap(MapHelper mapHelper, HttpServletRequest req,
> HttpServletResponse res)
> throws ServletException, IOException {
>
> StreamingRenderer streamingRenderer = new StreamingRenderer();
> MapContext mapContext = mapHelper.getMapContext();
> streamingRenderer.setContext(mapContext);
>
> System.out.println("inside rendermap");
>
> int width = 0;
> int height = 0;
>
> if(req.getParameter("mapWidth") != null) {
> width = Integer.parseInt(req.getParameter("mapWidth"));
> mapHelper.setImageWidth(width);
> }
>
> if(req.getParameter("mapHeight") != null) {
> height = Integer.parseInt(req.getParameter("mapHeight"));
> mapHelper.setImageHeight(height);
> }
>
> System.out.println("imageWidth=" + width + ", imageHeight=" +
> height);
>
> BufferedImage bufferedImage = null;
> bufferedImage = new BufferedImage(width, height,
> BufferedImage.TYPE_INT_RGB);
> Graphics2D graphics2D = (Graphics2D)bufferedImage.getGraphics();
> graphics2D.setRenderingHints(new
> RenderingHints(RenderingHints.KEY_RENDERING,
> RenderingHints.VALUE_RENDER_SPEED));
> graphics2D.setColor(Color.WHITE);
> graphics2D.fillRect(0, 0, width, height);
> RenderingHints hints = new
> RenderingHints(RenderingHints.KEY_ANTIALIASING,
> RenderingHints.VALUE_ANTIALIAS_ON );
> streamingRenderer.setJava2DHints(hints);
>
> //we already do everything that the optimized data loading
> does...
> //if we set it to true then it does it all twice...
> Map rendererParams = new HashMap();
> rendererParams.put("optimizedDataLoadingEnabled",new
> Boolean(true));
> Envelope env = mapHelper.getEnvelope();
>
>
> streamingRenderer.setRendererHints(rendererParams);
> try
> {
> System.out.println("long=" + env.centre().x + ", lat=" +
> env.centre().y);
> private void renderMap(MapHelper mapHelper, HttpServletRequest req,
> HttpServletResponse res)
> throws ServletException, IOException {
>
> StreamingRenderer streamingRenderer = new StreamingRenderer();
> MapContext mapContext = mapHelper.getMapContext();
> streamingRenderer.setContext(mapContext);
>
> System.out.println("inside rendermap");
>
> int width = 0;
> int height = 0;
>
> if(req.getParameter("mapWidth") != null) {
> width = Integer.parseInt(req.getParameter("mapWidth"));
> mapHelper.setImageWidth(width);
> }
>
> if(req.getParameter("mapHeight") != null) {
> height = Integer.parseInt(req.getParameter("mapHeight"));
> mapHelper.setImageHeight(height);
> }
>
> System.out.println("imageWidth=" + width + ", imageHeight=" +
> height);
>
> BufferedImage bufferedImage = null;
> bufferedImage = new BufferedImage(width, height,
> BufferedImage.TYPE_INT_RGB);
> Graphics2D graphics2D = (Graphics2D)bufferedImage.getGraphics();
> graphics2D.setRenderingHints(new
> RenderingHints(RenderingHints.KEY_RENDERING,
> RenderingHints.VALUE_RENDER_SPEED));
> graphics2D.setColor(Color.WHITE);
> graphics2D.fillRect(0, 0, width, height);
> RenderingHints hints = new
> RenderingHints(RenderingHints.KEY_ANTIALIASING,
> RenderingHints.VALUE_ANTIALIAS_ON );
> streamingRenderer.setJava2DHints(hints);
>
> //we already do everything that the optimized data loading
> does...
> //if we set it to true then it does it all twice...
> Map rendererParams = new HashMap();
> rendererParams.put("optimizedDataLoadingEnabled",new
> Boolean(true));
> Envelope env = mapHelper.getEnvelope();
>
>
> streamingRenderer.setRendererHints(rendererParams);
> try
> {
> streamingRenderer.paint(graphics2D, new Rectangle(width,
> height), env);
>
> } catch(Exception ex) {
> ex.printStackTrace();
> }
>
> if (graphics2D!=null) graphics2D.dispose();
>
> ServletOutputStream sos = res.getOutputStream();
> ImageIO.write(bufferedImage,"jpg",sos);
> sos.close();
>
> } } catch(Exception ex) {
> ex.printStackTrace();
> }
>
> if (graphics2D!=null) graphics2D.dispose();
>
> ServletOutputStream sos = res.getOutputStream();
> ImageIO.write(bufferedImage,"jpg",sos);
> sos.close();
>
> }
>
>
> private MapHelper( ServletContext servletContext , HttpSession
> httpSession) throws IOException{
>
> URL shapeURL1 =
> servletContext.getResource("/WEB-INF/data/bangalore2/District_Border_region.shp");
> URL sldURL1 =
> servletContext.getResource("/WEB-INF/data/bangalore2/District_Border_region.sld");
>
>
> loadContext(shapeURL1, sldURL1, "District_Border_region");
>
> URL shapeURL2 =
> servletContext.getResource("/WEB-INF/data/bangalore2/District_Headquarter_font_point.shp");
> URL sldURL2 =
> servletContext.getResource("/WEB-INF/data/bangalore2/District_Headquarter_font_point.sld");
>
>
> loadContext(shapeURL2, sldURL2, "District_Headquarter_font_point");
>
> URL shapeURL3 =
> servletContext.getResource("/WEB-INF/data/bangalore2/Major_Road_polyline.shp");
> URL sldURL3 =
> servletContext.getResource("/WEB-INF/data/bangalore2/Major_Road_polyline.sld");
>
>
> loadContext(shapeURL3, sldURL3, "Major_Road_polyline");
>
> URL shapeURL4 =
> servletContext.getResource("/WEB-INF/data/bangalore2/National_Highway_polyline.shp");
> URL sldURL4 =
> servletContext.getResource("/WEB-INF/data/bangalore2/National_Highway_polyline.sld");
>
>
> loadContext(shapeURL4, sldURL4, "National_Highway_polyline");
>
> URL shapeURL5 =
> servletContext.getResource("/WEB-INF/data/bangalore2/State_Border_region.shp");
> URL sldURL5 =
> servletContext.getResource("/WEB-INF/data/bangalore2/State_Border_region.sld");
>
>
> loadContext(shapeURL5, sldURL5, "State_Border_region");
>
> Envelope env = mapContext.getLayerBounds();
> setEnvelope(env);
> if (mapContext == null)
> {
> System.out.println("MapContext is not valid");
> }
>
> }
> /**
> * Load the data from the specified shapefile and construct a
> [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> Context context}
> * with a default style.
> *
> * @param url The url of the shapefile to load.
> * @return Context The data from the shape file.
> * @throws IOException is a I/O error occured.
> * @throws DataSource if an error occured while reading the data
> source.
> */
> protected void loadContext(final URL url, final URL sld, String
> layername) throws IOException, DataSourceException {
>
> // Load the file
> if (url == null) {
> throw new FileNotFoundException("Resource not found");
> }
> final DataStore store = new ShapefileDataStore(url);
> final FeatureSource features =
> store.getFeatureSource(store.getTypeNames()[0]);
>
> // Create the style
> final Style style;
> if(sld != null){
> SLDParser styleReader = new
> SLDParser(StyleFactoryFinder.createStyleFactory(), sld);
> style = styleReader.readXML()[0];
> }
> else
> {
> final StyleBuilder builder = new StyleBuilder();
>
> Class geometryClass =
> features.getSchema().getDefaultGeometry().getType();
> if(LineString.class.isAssignableFrom(geometryClass) ||
> MultiLineString.class.isAssignableFrom(geometryClass)) {
> style =
> builder.createStyle(builder.createLineSymbolizer());
> } else if(Point.class.isAssignableFrom(geometryClass) ||
> MultiPoint.class.isAssignableFrom(geometryClass)) {
> style =
> builder.createStyle(builder.createPointSymbolizer());
> } else {
> style =
> builder.createStyle(builder.createPolygonSymbolizer(
> Color.ORANGE, Color.BLACK, 1));
> }
> }
>
> // Create the context
> MapLayer layer = new DefaultMapLayer(features, style);
> layer.setTitle(layername);
> mapContext.addLayer(layer);
> }
>
>
>
>
>
> Best Regards
> Govardhan
>
> ------------------------------------------------------------------------
>
-------------------------------------------------------------------------
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