|
26 | 26 | # DEALINGS IN THE SOFTWARE.
|
27 | 27 | ###############################################################################
|
28 | 28 |
|
29 |
| -# This requires the EPSG database to be loaded. |
30 |
| -# See https://trac.osgeo.org/geotiff/browser/trunk/libgeotiff/csv/README |
| 29 | +# To be run with GDAL 3.1 |
31 | 30 |
|
32 |
| -from osgeo import ogr |
33 |
| -ds = ogr.Open('PG:dbname=epsg') |
34 |
| - |
35 |
| -sql_lyr = ds.ExecuteSQL("""SELECT * |
36 |
| -FROM epsg_coordinatereferencesystem |
37 |
| -WHERE coord_sys_code IN |
38 |
| -( |
39 |
| - SELECT CAA.coord_sys_code |
40 |
| - FROM epsg_coordinateaxis AS CAA |
41 |
| - INNER JOIN epsg_coordinateaxis AS CAB ON CAA.coord_sys_code = CAB.coord_sys_code |
42 |
| - WHERE |
43 |
| - CAA.coord_axis_order=1 AND CAB.coord_axis_order=2 |
44 |
| - AND |
45 |
| - ( |
46 |
| - ( CAA.coord_axis_orientation ILIKE 'north%' AND CAB.coord_axis_orientation ILIKE 'east%' ) |
47 |
| - OR |
48 |
| - ( CAA.coord_axis_orientation ILIKE 'south%' AND CAB.coord_axis_orientation ILIKE 'west%' ) |
49 |
| - ) |
50 |
| -) AND coord_ref_sys_code <= 32767 |
51 |
| -ORDER BY coord_ref_sys_code""") |
| 31 | +from osgeo import gdal, osr |
52 | 32 |
|
| 33 | +sr = osr.SpatialReference() |
53 | 34 | print('epsg_code')
|
54 |
| -for f in sql_lyr: |
55 |
| - print(f['coord_ref_sys_code']) |
56 |
| - |
57 |
| - |
58 |
| -# Could work but GDAL doesn't support 3D geographical SRS at the moment |
59 |
| -if False: |
60 |
| - from osgeo import gdal, osr |
61 |
| - |
62 |
| - sr = osr.SpatialReference() |
63 |
| - print('epsg_code') |
64 |
| - for code in range(32767): |
65 |
| - gdal.PushErrorHandler() |
66 |
| - ret = sr.ImportFromEPSGA(code) |
67 |
| - gdal.PopErrorHandler() |
68 |
| - if ret == 0 and (sr.EPSGTreatsAsLatLong() or sr.EPSGTreatsAsNorthingEasting()): |
| 35 | +for code in range(32767): |
| 36 | + gdal.PushErrorHandler() |
| 37 | + ret = sr.ImportFromEPSGA(code) |
| 38 | + gdal.PopErrorHandler() |
| 39 | + if ret == 0 and sr.GetAxesCount() >= 2: |
| 40 | + first_axis = sr.GetAxisOrientation(None, 0) |
| 41 | + second_axis = sr.GetAxisOrientation(None, 1) |
| 42 | + if first_axis == osr.OAO_North and second_axis == osr.OAO_East: |
| 43 | + print(code) |
| 44 | + elif first_axis == osr.OAO_South and second_axis == osr.OAO_West: |
69 | 45 | print(code)
|
0 commit comments