I'm quite new to geotools and I'm trying to get to grips with it. Trying to load some shapefiles (see attachment) into a MapContent which in turn is associated with a SwtMapPane I always get an exception that suggests that there's something wrong with the current CRS of the map pane:

java.lang.IllegalArgumentException: Argument "sourceCRS" should not be null.
        at org.geotools.referencing.CRS.findMathTransform(CRS.java:1205)
        at org.geotools.referencing.CRS.findMathTransform(CRS.java:1173)
        at org.geotools.swt.SwtMapPane.setCrs(SwtMapPane.java:436)
        at org.geotools.swt.SwtMapPane.layerAdded(SwtMapPane.java:812)
        at org.geotools.map.MapContent.fireLayerAdded(MapContent.java:468)
        at org.geotools.map.MapContent.addLayer(MapContent.java:369)
        at org.geotools.JSurveyMvn.App.fileOpen(App.java:87)
        at org.geotools.JSurveyMvn.App$1.widgetSelected(App.java:113)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3540)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3161)
        at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
        at org.eclipse.jface.window.Window.open(Window.java:801)
        at org.geotools.JSurveyMvn.App.<init>(App.java:47)
        at org.geotools.JSurveyMvn.App.main(App.java:58)

When trying to explicitly set a CRS directly after associating the (empty) MapContent to the map pane (see line 149), I'll get a NullPointerException like that:

        at org.geotools.swt.SwtMapPane.setCrs(SwtMapPane.java:433)
        at org.geotools.JSurveyMvn.App.createContents(App.java:152)
        at org.eclipse.jface.window.Window.create(Window.java:431)
        at org.eclipse.jface.window.Window.open(Window.java:790)
        at org.geotools.JSurveyMvn.App.<init>(App.java:47)
        at org.geotools.JSurveyMvn.App.main(App.java:58)

I'm quite desperate of being unable to solve that problem. Can you please give me a hand to make it work?

Obviously it's not possible to attach files here. So here's my original post to the Geotools-gt2-users list which seems to be inactive but allows adding code and map samples: http://sourceforge.net/p/geotools/mailman/message/34635944/ Attached is the source code of an example application that demonstrates the problem (run under linux (amd64) using getools v. 13.3 or 14.0) as well as the shapefile.

  • please paste the relevant piece of code (preferably the shortest working example) that shows the error into the question – Ian Turton Nov 23 '15 at 9:11

I had the same problem, and it might be that you did not set the display area beforehand:


If you look at the SwtMapPane#setCrs(), you see that it triggers the recomputations of the internal screen<-->world transforms, which require having set a .. screen area:

430  ReferencedEnvelope rEnv = getDisplayArea();
433  CoordinateReferenceSystem sourceCRS = rEnv.getCoordinateReferenceSystem();

(your rEnv is throwing the NPE)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.