Re: [Geotools-gt2-users] Problems with the unsupported SWT module
Does your shapefile have a .prj file? It's worth testing with say the states.shp file from GeoServer or the Natural Earth datasets. Ian On Wed, 22 Apr 2020 at 16:05, Jonas Schrottenbaum via GeoTools-GT2-Users < geotools-gt2-users@lists.sourceforge.net> wrote: > Hello, > > i managed to get an e4 application with geotools 20.5 and also the swt > module on 20.5 to run. But i still get exceptions when adding shapefiles or > wms-layers to the map. > The next step will be an attempt to upgrade the swt module version by > version. Before that i would like to be able to display a shapefile layer > and a wms layer on the same mappane, without problems, as a proof of > concept. > > When adding a shapefile layer, i get the exception enclosed in > exception1.txt. > > When adding a wms layer i get the exception enclosed in exception2.txt. > > Part code: > @PostConstruct > public void postConstruct(Composite parent, IEclipseContext context) { > handleImages(); > MapContent content = new MapContent(); > SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL | SWT.NULL); > Composite mainComposite = sashForm; > MapLayerComposite mapLayerTable = new MapLayerComposite(mainComposite, > SWT.BORDER); > mapPane = new SwtMapPane(mainComposite, SWT.BORDER | > SWT.NO_BACKGROUND); > mapPane.setMapContent(content); > mapLayerTable.setMapPane(mapPane); > sashForm.setWeights(new int[] { 1, 3 }); > > mapPane.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); > StreamingRenderer renderer = new StreamingRenderer(); > mapPane.setRenderer(renderer); > context.set(SwtMapPane.class, mapPane); > } > > Import shapefile code: > @Execute > public void execute(SwtMapPane mapPane) { > Display display = Display.getCurrent(); > Shell shell = new Shell(display); > File file = JFileDataStoreChooser.showOpenFile(new String[] { "*.shp" > }, shell); > try { > if (file != null && file.exists()) { >MapContent mapContent = mapPane.getMapContent(); >FileDataStore store = FileDataStoreFinder.getDataStore(file); >SimpleFeatureSource featureSource = store.getFeatureSource(); >Style style = Utils.createStyle(file, featureSource); >Layer layer = new FeatureLayer(featureSource, style); >//Add viewport line here >mapContent.addLayer(layer); >mapPane.redraw(); > } > ... > } > > Import WMS code: > @Execute > public void execute(SwtMapPane mapPane) { > WebMapServer wms = null; > try { > wms = new WebMapServer(new URL(" > http://ows.mundialis.de/services/service?;)); > } catch ... > } > WMSCapabilities capabilities = wms.getCapabilities(); > MapContent mapContent = mapPane.getMapContent(); > WMSLayer layer = new WMSLayer(wms, capabilities.getLayerList().get(1)); > //Add viewport line here > mapContent.addLayer(displayLayer); > mapPane.redraw(); > } > > I noticed that the SwtMapPane::getDisplayArea method (which is called > here: at org.geotools.swt.SwtMapPane.setCrs(SwtMapPane.java:428)) returns > a ReferencedEnvelope where the crs is null, because the viewport of the > mapcontent is still null. > So i thought i need to initialize it somewhere somehow, but this is not > shown in any tutorial i think. So maybe i'm just missing a simple line in > the part code? > > I found out that adding the line > mapContent.getViewport().setBounds(layer.getBounds()); in the shapefile/wms > code as indicated by the comments is a quick fix for the exception, but not > a solution because it just works for one layer. > > When only using shapefiles, as soon as a second one is added (from the > same example dataset so a assume same crs) the bounds of the first one are > overwritten by the second one and if they happen to be samller, the borders > of the first shapefile are not displayed correctly anymore. > And if i try to combine both, there are obviously major problems, because > of, i assume, different crs and so on. > When trying to display a wms layer on top of a shapefile layer, the wms > layer is stretched and as soon as i try to change anything, like visibility > i get an exception (enclosed in exception3.txt) and the layers won't render > again. > Same when trying to display a shapefile layer on top of a wmslayer, i also > get an exception (enclosed in exception4.txt). But those are expected, as > my "fix" only takes one layer into account. > > So the final question is: What am i missing to avoid those "sourceCRS > can't be null" exceptions and what do i have to do to correctly overlay > multiple different layers like shapefile and WMS? > And should i follow the developers guide when trying to update the swt > module and talk to the dev mailing list and get the contributers license > and so on? > > Best regards > Jones > > > ___ > GeoTools-GT2-Users mailing list >
Re: [Geotools-gt2-users] Problems with the unsupported SWT module
Hello, i managed to get an e4 application with geotools 20.5 and also the swt module on 20.5 to run. But i still get exceptions when adding shapefiles or wms-layers to the map. The next step will be an attempt to upgrade the swt module version by version. Before that i would like to be able to display a shapefile layer and a wms layer on the same mappane, without problems, as a proof of concept. When adding a shapefile layer, i get the exception enclosed in exception1.txt. When adding a wms layer i get the exception enclosed in exception2.txt. Part code: @PostConstruct public void postConstruct(Composite parent, IEclipseContext context) { handleImages(); MapContent content = new MapContent(); SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL | SWT.NULL); Composite mainComposite = sashForm; MapLayerComposite mapLayerTable = new MapLayerComposite(mainComposite, SWT.BORDER); mapPane = new SwtMapPane(mainComposite, SWT.BORDER | SWT.NO_BACKGROUND); mapPane.setMapContent(content); mapLayerTable.setMapPane(mapPane); sashForm.setWeights(new int[] { 1, 3 }); mapPane.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); StreamingRenderer renderer = new StreamingRenderer(); mapPane.setRenderer(renderer); context.set(SwtMapPane.class, mapPane); } Import shapefile code: @Execute public void execute(SwtMapPane mapPane) { Display display = Display.getCurrent(); Shell shell = new Shell(display); File file = JFileDataStoreChooser.showOpenFile(new String[] { "*.shp" }, shell); try { if (file != null && file.exists()) { MapContent mapContent = mapPane.getMapContent(); FileDataStore store = FileDataStoreFinder.getDataStore(file); SimpleFeatureSource featureSource = store.getFeatureSource(); Style style = Utils.createStyle(file, featureSource); Layer layer = new FeatureLayer(featureSource, style); //Add viewport line here mapContent.addLayer(layer); mapPane.redraw(); } ... } Import WMS code: @Execute public void execute(SwtMapPane mapPane) { WebMapServer wms = null; try { wms = new WebMapServer(new URL(" http://ows.mundialis.de/services/service?;)); } catch ... } WMSCapabilities capabilities = wms.getCapabilities(); MapContent mapContent = mapPane.getMapContent(); WMSLayer layer = new WMSLayer(wms, capabilities.getLayerList().get(1)); //Add viewport line here mapContent.addLayer(displayLayer); mapPane.redraw(); } I noticed that the SwtMapPane::getDisplayArea method (which is called here: at org.geotools.swt.SwtMapPane.setCrs(SwtMapPane.java:428)) returns a ReferencedEnvelope where the crs is null, because the viewport of the mapcontent is still null. So i thought i need to initialize it somewhere somehow, but this is not shown in any tutorial i think. So maybe i'm just missing a simple line in the part code? I found out that adding the line mapContent.getViewport().setBounds(layer.getBounds()); in the shapefile/wms code as indicated by the comments is a quick fix for the exception, but not a solution because it just works for one layer. When only using shapefiles, as soon as a second one is added (from the same example dataset so a assume same crs) the bounds of the first one are overwritten by the second one and if they happen to be samller, the borders of the first shapefile are not displayed correctly anymore. And if i try to combine both, there are obviously major problems, because of, i assume, different crs and so on. When trying to display a wms layer on top of a shapefile layer, the wms layer is stretched and as soon as i try to change anything, like visibility i get an exception (enclosed in exception3.txt) and the layers won't render again. Same when trying to display a shapefile layer on top of a wmslayer, i also get an exception (enclosed in exception4.txt). But those are expected, as my "fix" only takes one layer into account. So the final question is: What am i missing to avoid those "sourceCRS can't be null" exceptions and what do i have to do to correctly overlay multiple different layers like shapefile and WMS? And should i follow the developers guide when trying to update the swt module and talk to the dev mailing list and get the contributers license and so on? Best regards Jones When adding a wms layer i get the following exception: Apr 21, 2020 7:33:45 PM org.geotools.xml.resolver.SchemaCache resolveLocation INFORMATION: Cached XML schema: http://schemas.opengis.net/sld/1.1.0/sld_capabilities.xsd java.lang.IllegalArgumentException: Argument "sourceCRS" should not be null. at org.geotools.referencing.operation.AbstractCoordinateOperationFactory.ensureNonNull(AbstractCoordinateOperationFactory.java:789) at org.geotools.referencing.operation.BufferedCoordinateOperationFactory.createOperation(BufferedCoordinateOperationFactory.java:228) at
Re: [Geotools-gt2-users] Problems with the unsupported SWT module
The API changed a bit over time, and the deprecated interfaces and methods used by the swt module have no doubt been removed. To have an easier time upgrading, march forward release by release cleaning up deprecation warnings. The key change will be to MapView which was refactored into several classes as outlined here: - https://github.com/geotools/geotools/wiki/MapContext-Refactor - http://old.geotools.org/MapContext-Refactor_154468593.html On Fri, Apr 10, 2020 at 11:19 AM Jody Garnett wrote: > Please upgrade it! I am happy to review > > On Fri, Apr 10, 2020 at 11:00 AM Jonas Schrottenbaum via > GeoTools-GT2-Users wrote: > >> Hello, >> i'm working on an E4 RCP application and need the unsupported SWT module. >> >> Unfortunately it is still on v20.5 of GeoTools. >> >> In the long run, i probably have to either upgrade it to 24-snapshot, or >> write the functionality myself. >> >> To get started, i wanted to do the tutorial from the documentation ( >> https://docs.geotools.org/latest/userguide/unsupported/swt/index.html) >> to get familiar with everything, but it is also very outdated. >> I was not able to get it to run with GeoTools 24-snapshot, because "The >> type org.geotools.map.event.MapLayerListListener cannot be resolved." (from >> mapPane.setRenderer(renderer);) >> It seems like it was once there, and now is in >> org.geotools.map.MapLayerListListener, so without the event, but the >> SwtMapPane class doesn't know about it. >> >> Without an idea on how to fix the problem, i tried using everything on >> version 20.5, (just now at the start,) to be able to get familiar with >> everything. >> >> At first it seems to work, but a little bit in the tutorial there are >> lines like "SwtMapPane mapPane = ((MapView) view).getMapPane();" or >> "MapView mapView = (MapView) activePage.findView(MapView.ID);" and i have >> the problem, that "MapView cannot be resolved to a type". And i can't find >> any documentation on a MapView from GeoTools. In which module was it back >> in the 20.5 days? >> I don't know how to continue from here. >> >> Best regards, >> Jones >> ___ >> GeoTools-GT2-Users mailing list >> GeoTools-GT2-Users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >> > -- > -- > Jody Garnett > ___ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
Re: [Geotools-gt2-users] Problems with the unsupported SWT module
Please upgrade it! I am happy to review On Fri, Apr 10, 2020 at 11:00 AM Jonas Schrottenbaum via GeoTools-GT2-Users wrote: > Hello, > i'm working on an E4 RCP application and need the unsupported SWT module. > > Unfortunately it is still on v20.5 of GeoTools. > > In the long run, i probably have to either upgrade it to 24-snapshot, or > write the functionality myself. > > To get started, i wanted to do the tutorial from the documentation ( > https://docs.geotools.org/latest/userguide/unsupported/swt/index.html) to > get familiar with everything, but it is also very outdated. > I was not able to get it to run with GeoTools 24-snapshot, because "The > type org.geotools.map.event.MapLayerListListener cannot be resolved." (from > mapPane.setRenderer(renderer);) > It seems like it was once there, and now is in > org.geotools.map.MapLayerListListener, so without the event, but the > SwtMapPane class doesn't know about it. > > Without an idea on how to fix the problem, i tried using everything on > version 20.5, (just now at the start,) to be able to get familiar with > everything. > > At first it seems to work, but a little bit in the tutorial there are > lines like "SwtMapPane mapPane = ((MapView) view).getMapPane();" or > "MapView mapView = (MapView) activePage.findView(MapView.ID);" and i have > the problem, that "MapView cannot be resolved to a type". And i can't find > any documentation on a MapView from GeoTools. In which module was it back > in the 20.5 days? > I don't know how to continue from here. > > Best regards, > Jones > ___ > GeoTools-GT2-Users mailing list > GeoTools-GT2-Users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > -- -- Jody Garnett ___ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
[Geotools-gt2-users] Problems with the unsupported SWT module
Hello, i'm working on an E4 RCP application and need the unsupported SWT module. Unfortunately it is still on v20.5 of GeoTools. In the long run, i probably have to either upgrade it to 24-snapshot, or write the functionality myself. To get started, i wanted to do the tutorial from the documentation ( https://docs.geotools.org/latest/userguide/unsupported/swt/index.html) to get familiar with everything, but it is also very outdated. I was not able to get it to run with GeoTools 24-snapshot, because "The type org.geotools.map.event.MapLayerListListener cannot be resolved." (from mapPane.setRenderer(renderer);) It seems like it was once there, and now is in org.geotools.map.MapLayerListListener, so without the event, but the SwtMapPane class doesn't know about it. Without an idea on how to fix the problem, i tried using everything on version 20.5, (just now at the start,) to be able to get familiar with everything. At first it seems to work, but a little bit in the tutorial there are lines like "SwtMapPane mapPane = ((MapView) view).getMapPane();" or "MapView mapView = (MapView) activePage.findView(MapView.ID);" and i have the problem, that "MapView cannot be resolved to a type". And i can't find any documentation on a MapView from GeoTools. In which module was it back in the 20.5 days? I don't know how to continue from here. Best regards, Jones ___ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users