All is in the title, with GeoTools if I do :

AxisOrder order = CRS.getAxisOrder(CRS.getAxisOrder("EPSG:4326"));

It returns EAST_NORTH (= LON_LAT), but EPSG:4326 is defined as ordering latitude first and then longitude, as stated here : http://spatialreference.org/ref/epsg/wgs-84/gml/

So, what is happening here ? Am I doing something wrong ?


To be honest EPSG:4326 is not really defined well at all, depending on which version of WMS oe when your CRS was defined you use it can be either way. The definitive statement for GeoTools is at http://docs.geotools.org/latest/userguide/library/referencing/order.html

So you may be able to get away with:

Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.FALSE);
CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints);
CoordinateReferenceSystem crs = factory.createCoordinateReferenceSystem("EPSG:4326");

In general if you are writing an application that accepts user input you need to add a bunch of checks around the use of EPSG:4326 and still end up hoping for the best.

if you want to be absolutely certain about axis order then use

 CoordinateReferenceSystem crs = factory.createCoordinateReferenceSystem("urn:x-ogc:def:crs:EPSG:4326");

which will give you NORTH_EAST for the axis order.

  • Thanks for answering (again :) ). It seems to be a real pain to support WMS 1.3.0, supposed to a be a "standard"... In the sample code you provided, how did you create the factory ?
    – Tim Autin
    Jul 10 '15 at 12:39
  • I've added more example code - that should help for 1.30
    – Ian Turton
    Jul 10 '15 at 12:50
  • Thanks, but the first returns EAST_NORTH, and the second a NoSuchAuthorityCodeException ("This factory only understand EPSG codes"). I may be missing some jar, what is this notation ?
    – Tim Autin
    Jul 10 '15 at 13:12
  • EPSG:4326 is well defined, it's defined by EPSG as epsg-registry.org/export.htm?wkt=urn:ogc:def:crs:EPSG::4326 or if you prefer GML as epsg-registry.org/export.htm?gml=urn:ogc:def:crs:EPSG::4326. OGC WMS 1.1.1 misuses it, it is correctly used in WMS 1.3.0.
    – nmtoken
    Feb 28 '19 at 11:56
  • Since both standards use the same code for different things I think it is poorly defined from a dev's and user's veiwpoint
    – Ian Turton
    Feb 28 '19 at 12:03

The new verion of GeoTools (11.0) has CRS.decode(string epsgCode,boolean longitudeFirst) by which you can make your Coordinate Reference System with desired axis order.

CoordinateReferenceSystem crs = CRS.decode("EPSG:4326",false);

Then it will has lat,lon order.
Your problem is discussed in [geotools user guide for axis order] in detail.

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.