So i tried it with Swing and Quickstart and it works fine with Shapefiles. With WMSLayer on the other hand, i can't get it to work, even with Swing. For some reason i need the line mapcontent.getViewport.setBounds(displaylayer.getBounds()), so the WMSLayer is rendered without exceptions. Without it, the CRS doesn't change, but also the WMSLayer isn't displayed, and it crashes after clicking zoom extent.
If you would be so kind, and have a look at this, maybe you can tell me how to be able to render the wmslayer without changing the CRS, which i assume setting the bounds of the viewport to the layerbounds does. public class WMSLab extends JFrame { public static void main(String[] args) throws Exception { WebMapServer wms = new WebMapServer(new URL(" https://sgx.geodatenzentrum.de/wms_clc5_2018")); List<Layer> wmsLayers = WMSLayerChooser.showSelectLayer(wms); if (wmsLayers == null) { JOptionPane.showMessageDialog(null, "Could not connect - check url"); System.exit(0); } MapContent mapContent = new MapContent(); mapContent.setTitle(wms.getCapabilities().getService().getTitle()); mapContent.getViewport().setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84); System.out.println("before adding layer " + mapcontent.getViewport().getCoordinateReferenceSystem()); for (Layer wmsLayer : wmsLayers) { WMSLayer displayLayer = new WMSLayer(wms, wmsLayer); mapContent.addLayer(displayLayer); //try with and without this line mapContent.getViewport().setBounds(displayLayer.getBounds()); } System.out.println("after adding layer " + mapcontent.getViewport().getCoordinateReferenceSystem()); JMapFrame.showMap(mapContent); } } Am Mi., 9. Dez. 2020 um 15:40 Uhr schrieb Ian Turton <ijtur...@gmail.com>: > Sorry, I always assume people are using the supported modules unless they > say otherwise. I've no idea what SWT does. > > Ian > > On Wed, 9 Dec 2020 at 14:38, Jonas Schrottenbaum < > jonesang...@googlemail.com> wrote: > >> The quickstart is with the swing module, right? I'm using SWT, so maybe >> there is the problem. Thanks for your help so far. Have to look into that. >> >> Am Mi., 9. Dez. 2020 um 15:37 Uhr schrieb Ian Turton <ijtur...@gmail.com >> >: >> >>> I've just experimented with adding the line >>> >>> >>> map.getViewport().setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84); >>> >>> at line 53 of the GeoTools quickstart and opening a shapefile in >>> EPSG:27700, the map is displayed in EPSG:4326 when the display is made >>> visible. >>> >>> Ian >>> >>> On Wed, 9 Dec 2020 at 14:19, Jonas Schrottenbaum < >>> jonesang...@googlemail.com> wrote: >>> >>>> So i also tried mapPane.setCrs(CRS.decode("EPSG:4326")) >>>> and >>>> mapContent.getViewport().setCoordinateReferenceSystem(CRS.decode("EPSG:4326")), >>>> which both change the CRS you get by >>>> calling mapContent.getCoordinateReferenceSystem(), but as soon as the first >>>> layer comes, it overwrites it with it's own (EPSG:23700) >>>> >>>> Am Mi., 9. Dez. 2020 um 14:50 Uhr schrieb Jonas Schrottenbaum < >>>> jonesang...@googlemail.com>: >>>> >>>>> Oh, how do i set the map CRS? I thought it was >>>>> mapPane.setCRS(DefaultGeographicCRS.WGS84) but that had no effect. >>>>> >>>>> Am Mi., 9. Dez. 2020 um 14:43 Uhr schrieb Ian Turton < >>>>> ijtur...@gmail.com>: >>>>> >>>>>> You can set the map CRS to what ever you want, if you don't specify >>>>>> it then it defaults to the first layer's CRS >>>>>> >>>>>> Ian >>>>>> >>>>>> On Wed, 9 Dec 2020 at 13:33, Jonas Schrottenbaum via >>>>>> GeoTools-GT2-Users <geotools-gt2-users@lists.sourceforge.net> wrote: >>>>>> >>>>>>> Hello, >>>>>>> >>>>>>> is it possible to transform all incoming layers into for example >>>>>>> epsg:4326? >>>>>>> So no matter what the CRS of a WMSLayer, or FeatureLayer is, they >>>>>>> can always be overlaid? >>>>>>> >>>>>>> Default seems to be that the first incoming layer specifies which >>>>>>> CRS is used, and all other layers coming after that are transformed into >>>>>>> the CRS of the first one. >>>>>>> >>>>>>> Best regards >>>>>>> _______________________________________________ >>>>>>> GeoTools-GT2-Users mailing list >>>>>>> GeoTools-GT2-Users@lists.sourceforge.net >>>>>>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >>>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Ian Turton >>>>>> >>>>> >>> >>> -- >>> Ian Turton >>> >> > > -- > Ian Turton >
_______________________________________________ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users