|
From: George T. <geo...@ya...> - 2012-07-16 14:59:43
|
Hello geotools users,
to summarize the possibility of overlaying a shapefile and a WMS with different projections in a JMapFrame:
It doesn't work.
Instead I am now using the following workaround:
I first render the shapefile with the correct projection using a GTRenderer. Next I request the image from the WMS Server using a GetMapRequest which has the correct projection set. Finally the WMS image can be drawn on top of the rendered shapefile.
The JMapFrame ignores the projection setting, when the individual layers are requested.
HTH
George
________________________________
Von: George Taylor <geo...@ya...>
An: "geo...@li..." <geo...@li...>
Gesendet: 10:41 Freitag, 13.Juli 2012
Betreff: Re: [Geotools-gt2-users] define projection when overlaying WMS and shapefile in JMapFrame
Hello Michael,
thank you for your suggestions. I have replaced MapContext with MapContent.
The JMapFrame shows GCS_WGS_1984 in the CRS button. If I click it to choose "4326: WGS 84" and force a redraw of the map, nothing changes.
I have also added 'map.getViewport().setCoordinateReferenceSystem(CRS.decode("EPSG:4326"));' immediately after 'map=new MapContent();' and also before 'mapFrame=new JMapFrame(map);'.
With this change nothing at all is displayed. Same for 'mapFrame.getMapPane().setDisplayArea(bounds);'.
Probably it is asked too much. But I would greatly appreciate if somebody modifies my code snippet or sends another example how to overlay a shapefile and a WMS such that the coordinates match.
Thank you
George
--- new code: ---
private void
displayWmsAndShapefile() throws Exception {
File sourceFile;
SimpleFeatureSource featureSource;
MapContent 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 MapContent();
//map.getViewport().setCoordinateReferenceSystem(CRS.decode("EPSG:4326"));
Style coastStyle = SLD.createSimpleStyle(featureSource.getSchem$
map.addLayer(new FeatureLayer(featureSource,coastStyle));
//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 $
System.exit(0);
}
for( Layer wmsLayer : wmsLayers ){
WMSLayer displayLayer = new WMSLayer(wms, wmsLayer );
map.addLayer( displayLayer );
}
//map.getViewport().setCoordinateReferenceSystem(CRS.decode("EPSG:4326"));
// Create a JMapFrame with custom toolbar buttons
JMapFrame mapFrame = new JMapFrame(map);
mapFrame.getMapPane().setD
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);
}
----------------- |