| 157 | |
| 158 | == How do I flip coordinates when they are not in the expected order == |
| 159 | |
| 160 | The EPSG has a recommanded order for geographic SRS where the coordinates tuples of a geometry must appear in the (latitude, longitude) order, whereas most GIS will properly display such geometries if they appear in the (longitude, latitude) order. This issue can be often encountered in situation with GML3 files, WFS 1.1 data, etc... that adhere to the (latitude, longitude) order. |
| 161 | |
| 162 | When, for some reason, the coordinate order isn't the one that is wished, the following trick can be used to flip them : |
| 163 | |
| 164 | {{{ |
| 165 | ogr2ogr -s_srs "+proj=latlong +datum=WGS84 +axis=neu +wktext" |
| 166 | -t_srs "+proj=latlong +datum=WGS84 +axis=enu +wktext" dest.shp source.shp |
| 167 | }}} |
| 168 | |
| 169 | Note: this will work even if the SRS of your input data isn't using the WGS84 datum. The reason for the above magic incantation to work is that the values of -s_srs and -t_srs only differ by the value of the +axis parameter. |
| 170 | |
| 171 | This trick might also be used for some projected SRS that have unusual axis order. |
| 172 | |
| 173 | An alternative way of achieving the same result, providing using GDAL 2.0 compiled with Spatialite support to benefit from [http://gdal.org/ogr/ogr_sql_sqlite.html SQLite SQL dialect], is : |
| 174 | |
| 175 | {{{ |
| 176 | ogr2ogr -dialect SQLite -sql "SELECT SwapCoordinates(geometry) AS geometry, * FROM source" dest.shp source.shp |
| 177 | }}} |