|
From: Michael B. <mic...@gm...> - 2012-07-12 23:53:55
|
Hello George, Firstly, with GeoTools 8 I'd recommend that you use MapContent in your own code instead of the deprecated MapContext class. There should be a status bar item (right hand side; you might need to widen the frame to see it) to show or set the CRS for the display. Programmatically you can do the same thing: MapContent map = new MapContent(); // add layers, then... map.getViewport().setCoordinateReferenceSystem( myDisplayCRS ); See the MapViewport javadocs for more info: http://docs.geotools.org/latest/javadocs/org/geotools/map/MapViewport.html Yet another way to do it is: JMapFrame frame = ... ReferencedEnvelope bounds = ... // create ReferencedEnvelope with desired CRS frame.getMapPane().setDisplayArea( bounds ); Hope this helps. Michael On 12 July 2012 19:19, George Taylor <geo...@ya...> wrote: > Hello, > I am looking for some information how to set the projection correctly for a > MapContext or JMapFrame, such that all layer overlays are correctly > displayed. I am running displayWmsAndShapefile() (code below) to display a > shapefile (110m_coastline.shp from > http://www.naturalearthdata.com/downloads/110m-physical-vectors/) and the > "Ocean Coastline" layer from the WMS at > http://atlas.gc.ca/cgi-bin/atlaswms_en?VERSION=1.1.1&Request=GetCapabilities&Service=WMS. > > The result shows that the two layers don't match: http://imagebin.org/220454 > If I show the shapefile alone, the JMapFrame sets the CRS to GCS_WGS_1984. > If I show the WMS alone, the JMapFrame sets the CRS to EPSG:4326. How can I > force the JMapFrame to paint everything using EPSG:4326? > > More generally, how can I choose the CRS that is requested from a WMS server > if the server supports several CRSs? Using a GetMapRequest I could use the > setSRS() method. But in the code below there is no GetMapRequest involved. > Can I still force the JMapFrame to request the WMS Layer in a different CRS? > > Thank you > George > > --- code snippet (using geotools-8.0-RC2) --- > > private void displayWmsAndShapefile() throws Exception { > File sourceFile; > SimpleFeatureSource featureSource; > MapContext map; > > sourceFile = JFileDataStoreChooser.showOpenFile("shp", null); > if (sourceFile == null) { > return; > } > FileDataStore store = FileDataStoreFinder.getDataStore(sourceFile); > featureSource = store.getFeatureSource(); > > // Create a map context and add our shapefile to it > map = new DefaultMapContext(); > map.addLayer(featureSource, null); > > //WMS Stuff: > URL capabilitiesURL = WMSChooser.showChooseWMS(); > if( capabilitiesURL == null ){ > System.exit(0); // canceled > } > WebMapServer wms = new WebMapServer( capabilitiesURL ); > > List<Layer> wmsLayers = WMSLayerChooser.showSelectLayer( wms ); > if( wmsLayers == null ){ > JOptionPane.showMessageDialog(null, "Could not connect - check > url"); > System.exit(0); > } > > for( Layer wmsLayer : wmsLayers ){ > WMSMapLayer displayLayer = new WMSMapLayer(wms, wmsLayer ); > map.addLayer( displayLayer ); > } > > // Create a JMapFrame with custom toolbar buttons > JMapFrame mapFrame = new JMapFrame(map); > mapFrame.enableToolBar(true); > mapFrame.enableStatusBar(true); > > // Display the map frame. When it is closed the application will > exit > mapFrame.setSize(800, 600); > mapFrame.setVisible(true); > } > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > GeoTools-GT2-Users mailing list > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > |