From: Govardhan <gov...@co...> - 2006-12-20 12:35:57
|
Dear Jody Garnett, Thanks for the reply.., I greatly appreciate it.... Answer to your questions: 1) Yes shapefiles have .prj files. 2) And shape files are in "WGS84/ UTM Zone 43N" 3) In UDIG these shapefiles are coming properly,for the = default(WGS84) as well as selected "WGS84/UTM Zone 43N" CRS. =20 Now I started using the CRS in my program, but still I am getting the = streched map image..... Following is the code I am using for this process:...... String code =3D "32643"; CoordinateReferenceSystem crs =3D = FactoryFinder.getCRSAuthorityFactory( "EPSG", null).createCoordinateReferenceSystem(code); =20 this.mapContext =3D new DefaultMapContext(crs); Envelope env =3D this.mapContext.getAreaOfInterest(); //map.addlayers.....adding all the shapefiles. //Rendering....=20 BufferedImage bufferedImage =3D null; bufferedImage =3D new BufferedImage(width, height, = BufferedImage.TYPE_INT_RGB); Graphics2D graphics2D =3D = (Graphics2D)bufferedImage.getGraphics(); graphics2D.setRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, = RenderingHints.VALUE_RENDER_SPEED)); graphics2D.setColor(Color.WHITE); graphics2D.fillRect(0, 0, width, height); =20 RenderingHints hints =3D 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 =3D new HashMap(); rendererParams.put("optimizedDataLoadingEnabled",new = Boolean(true)); streamingRenderer.setRendererHints(rendererParams); try { streamingRenderer.paint(graphics2D, new Rectangle(width, = height), env); } catch(Exception ex) { ex.printStackTrace(); } if (graphics2D!=3Dnull) graphics2D.dispose(); ServletOutputStream sos =3D res.getOutputStream(); ImageIO.write(bufferedImage,"jpg",sos); =20 //image is thrown out... here. Can you please suggest me what is that I am missing in my = program......?? Best Regards Govardhan ----- Original Message -----=20 From: "Jody Garnett" <jga...@re...> To: "Govardhan" <gov...@co...> Cc: <geo...@li...>; <gt...@mo...> Sent: Wednesday, December 20, 2006 10:18 AM Subject: Re: My map is looking streched... Please help me > Evening Mr Govardhan ... >=20 > I think you are going to have to use the CRS that matches your data,=20 > does your data have prj files? You may want to try out your shapefiles = > with uDig just to confirm they are working correctly. >=20 > 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. >> =20 >> I have attached the map image, please help me how to resolve this. >> =20 >> I am using the following code to create the map, >> =20 >> private void renderMap(MapHelper mapHelper, HttpServletRequest req,=20 >> HttpServletResponse res) >> throws ServletException, IOException { >> =20 >> StreamingRenderer streamingRenderer =3D new = StreamingRenderer(); >> MapContext mapContext =3D mapHelper.getMapContext(); >> streamingRenderer.setContext(mapContext); >> =20 >> System.out.println("inside rendermap"); >> =20 >> int width =3D 0; >> int height =3D 0; >> =20 >> if(req.getParameter("mapWidth") !=3D null) { >> width =3D Integer.parseInt(req.getParameter("mapWidth")); >> mapHelper.setImageWidth(width); >> } >> =20 >> if(req.getParameter("mapHeight") !=3D null) { >> height =3D Integer.parseInt(req.getParameter("mapHeight")); >> mapHelper.setImageHeight(height); >> } >> =20 >> System.out.println("imageWidth=3D" + width + ", = imageHeight=3D" +=20 >> height); >> =20 >> BufferedImage bufferedImage =3D null; >> bufferedImage =3D new BufferedImage(width, height,=20 >> BufferedImage.TYPE_INT_RGB); >> Graphics2D graphics2D =3D = (Graphics2D)bufferedImage.getGraphics(); >> graphics2D.setRenderingHints(new >> RenderingHints(RenderingHints.KEY_RENDERING,=20 >> RenderingHints.VALUE_RENDER_SPEED)); >> graphics2D.setColor(Color.WHITE); >> graphics2D.fillRect(0, 0, width, height); =20 >> RenderingHints hints =3D new=20 >> RenderingHints(RenderingHints.KEY_ANTIALIASING, >> RenderingHints.VALUE_ANTIALIAS_ON ); >> streamingRenderer.setJava2DHints(hints); >> =20 >> //we already do everything that the optimized data loading =20 >> does... >> //if we set it to true then it does it all twice... >> Map rendererParams =3D new HashMap(); >> rendererParams.put("optimizedDataLoadingEnabled",new=20 >> Boolean(true)); >> Envelope env =3D mapHelper.getEnvelope(); >> =20 >> =20 >> streamingRenderer.setRendererHints(rendererParams); >> try >> { >> System.out.println("long=3D" + env.centre().x + ", lat=3D" + = >> env.centre().y); >> private void renderMap(MapHelper mapHelper, HttpServletRequest req,=20 >> HttpServletResponse res) >> throws ServletException, IOException { >> =20 >> StreamingRenderer streamingRenderer =3D new = StreamingRenderer(); >> MapContext mapContext =3D mapHelper.getMapContext(); >> streamingRenderer.setContext(mapContext); >> =20 >> System.out.println("inside rendermap"); >> =20 >> int width =3D 0; >> int height =3D 0; >> =20 >> if(req.getParameter("mapWidth") !=3D null) { >> width =3D Integer.parseInt(req.getParameter("mapWidth")); >> mapHelper.setImageWidth(width); >> } >> =20 >> if(req.getParameter("mapHeight") !=3D null) { >> height =3D Integer.parseInt(req.getParameter("mapHeight")); >> mapHelper.setImageHeight(height); >> } >> =20 >> System.out.println("imageWidth=3D" + width + ", = imageHeight=3D" +=20 >> height); >> =20 >> BufferedImage bufferedImage =3D null; >> bufferedImage =3D new BufferedImage(width, height,=20 >> BufferedImage.TYPE_INT_RGB); >> Graphics2D graphics2D =3D = (Graphics2D)bufferedImage.getGraphics(); >> graphics2D.setRenderingHints(new >> RenderingHints(RenderingHints.KEY_RENDERING,=20 >> RenderingHints.VALUE_RENDER_SPEED)); >> graphics2D.setColor(Color.WHITE); >> graphics2D.fillRect(0, 0, width, height); =20 >> RenderingHints hints =3D new=20 >> RenderingHints(RenderingHints.KEY_ANTIALIASING, >> RenderingHints.VALUE_ANTIALIAS_ON ); >> streamingRenderer.setJava2DHints(hints); >> =20 >> //we already do everything that the optimized data loading =20 >> does... >> //if we set it to true then it does it all twice... >> Map rendererParams =3D new HashMap(); >> rendererParams.put("optimizedDataLoadingEnabled",new=20 >> Boolean(true)); >> Envelope env =3D mapHelper.getEnvelope(); >> =20 >> =20 >> streamingRenderer.setRendererHints(rendererParams); >> try >> { >> streamingRenderer.paint(graphics2D, new Rectangle(width,=20 >> height), env); >> =20 >> } catch(Exception ex) { >> ex.printStackTrace(); >> } >> =20 >> if (graphics2D!=3Dnull) graphics2D.dispose(); >> =20 >> ServletOutputStream sos =3D res.getOutputStream(); >> ImageIO.write(bufferedImage,"jpg",sos); >> sos.close(); >> =20 >> } } catch(Exception ex) { >> ex.printStackTrace(); >> } >> =20 >> if (graphics2D!=3Dnull) graphics2D.dispose(); >> =20 >> ServletOutputStream sos =3D res.getOutputStream(); >> ImageIO.write(bufferedImage,"jpg",sos); >> sos.close(); >> =20 >> } >> =20 >> =20 >> private MapHelper( ServletContext servletContext , HttpSession=20 >> httpSession) throws IOException{ >> =20 >> URL shapeURL1 =3D=20 >> = servletContext.getResource("/WEB-INF/data/bangalore2/District_Border_regi= on.shp"); >> URL sldURL1 =3D=20 >> = servletContext.getResource("/WEB-INF/data/bangalore2/District_Border_regi= on.sld"); =20 >> >> loadContext(shapeURL1, sldURL1, "District_Border_region"); >> =20 >> URL shapeURL2 =3D=20 >> = servletContext.getResource("/WEB-INF/data/bangalore2/District_Headquarter= _font_point.shp"); >> URL sldURL2 =3D=20 >> = servletContext.getResource("/WEB-INF/data/bangalore2/District_Headquarter= _font_point.sld"); =20 >> >> loadContext(shapeURL2, sldURL2, = "District_Headquarter_font_point"); >> =20 >> URL shapeURL3 =3D=20 >> = servletContext.getResource("/WEB-INF/data/bangalore2/Major_Road_polyline.= shp"); >> URL sldURL3 =3D=20 >> = servletContext.getResource("/WEB-INF/data/bangalore2/Major_Road_polyline.= sld"); =20 >> >> loadContext(shapeURL3, sldURL3, "Major_Road_polyline"); >> =20 >> URL shapeURL4 =3D=20 >> = servletContext.getResource("/WEB-INF/data/bangalore2/National_Highway_pol= yline.shp"); >> URL sldURL4 =3D=20 >> = servletContext.getResource("/WEB-INF/data/bangalore2/National_Highway_pol= yline.sld"); =20 >> >> loadContext(shapeURL4, sldURL4, "National_Highway_polyline"); >> =20 >> URL shapeURL5 =3D=20 >> = servletContext.getResource("/WEB-INF/data/bangalore2/State_Border_region.= shp"); >> URL sldURL5 =3D=20 >> = servletContext.getResource("/WEB-INF/data/bangalore2/State_Border_region.= sld"); =20 >> >> loadContext(shapeURL5, sldURL5, "State_Border_region"); >> =20 >> Envelope env =3D mapContext.getLayerBounds(); >> setEnvelope(env); >> if (mapContext =3D=3D null) >> { >> System.out.println("MapContext is not valid"); >> } >> =20 >> } >> /** >> * Load the data from the specified shapefile and construct a=20 >> {@linkplain <mailto:%7B@linkplain> 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=20 >> source. >> */ >> protected void loadContext(final URL url, final URL sld, String=20 >> layername) throws IOException, DataSourceException { >> =20 >> // Load the file >> if (url =3D=3D null) { >> throw new FileNotFoundException("Resource not found"); >> } >> final DataStore store =3D new ShapefileDataStore(url); >> final FeatureSource features =3D=20 >> store.getFeatureSource(store.getTypeNames()[0]); >> =20 >> // Create the style >> final Style style; >> if(sld !=3D null){ >> SLDParser styleReader =3D new=20 >> SLDParser(StyleFactoryFinder.createStyleFactory(), sld); >> style =3D styleReader.readXML()[0]; >> } >> else >> { >> final StyleBuilder builder =3D new StyleBuilder(); >> =20 >> Class geometryClass =3D=20 >> features.getSchema().getDefaultGeometry().getType(); >> if(LineString.class.isAssignableFrom(geometryClass) ||=20 >> MultiLineString.class.isAssignableFrom(geometryClass)) { >> style =3D=20 >> builder.createStyle(builder.createLineSymbolizer()); >> } else if(Point.class.isAssignableFrom(geometryClass) ||=20 >> MultiPoint.class.isAssignableFrom(geometryClass)) { >> style =3D=20 >> builder.createStyle(builder.createPointSymbolizer()); >> } else { >> style =3D=20 >> builder.createStyle(builder.createPolygonSymbolizer( >> Color.ORANGE, Color.BLACK, 1)); >> } >> } >> =20 >> // Create the context >> MapLayer layer =3D new DefaultMapLayer(features, style); >> layer.setTitle(layername); >> mapContext.addLayer(layer); >> } >> =20 >> =20 >> =20 >> =20 >> =20 >> Best Regards >> Govardhan >> >> = ------------------------------------------------------------------------ >> > |