|
From: George T. <geo...@ya...> - 2012-07-12 09:20:00
|
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); } |