smindel / silverstripe-gis

Adds support for geographic types.
BSD 3-Clause "New" or "Revised" License
9 stars 5 forks source link

Getting SRID Of An Image Dependent on Version of gdalsrsinfo #31

Open gordonbanderson opened 2 years ago

gordonbanderson commented 2 years ago

hi,

I've been trying to get continuous integration working on this project with GitHub actions, as I am learning it and this module looked like a good challenge.

I've come across an issue with extracting the SRID from an image, I've tracked it down to the command created here:

https://github.com/smindel/silverstripe-gis/blob/master/src/Model/Raster.php#L38

The output parsed by https://github.com/smindel/silverstripe-gis/blob/master/src/Model/Raster.php#L45 is a failure with newer versions of gdalsrsinfo

With added debug, I see the following:

Debian 10, Buster (works)

T2: command=
                gdalsrsinfo  -o wkt /var/www/tests/php/RasterTest.tif
T3:GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]]

T4: MATCHES: Array
(
    [0] => ,AUTHORITY["EPSG","4326"]]
    [1] => 4326
)

Ubuntu (latest), GitHub Actions (fails)

I think this is the latest LTS, should double check. However the output changes to a multi line structure

T2: command=
                gdalsrsinfo  -o wkt /home/runner/work/silverstripe-gis/silverstripe-gis/tests/php/RasterTest.tif
T3:
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    ID["EPSG",4326]]

T5: No match!!

This fails the regular expression match.

Debian 11 (Bullseye, fails)

I rebuilt my local docker php command line to bullseye, and then added --single-line flag to the gdalsrsinfo command, this is incompatible with version 2 when I tested on Buster above. An error was returned instead.

One line is returned, but different info, and again the regular expression match fails:

T2: command=
                gdalsrsinfo --single-line  -o wkt /var/www/tests/php/RasterTest.tif
T3:GEOGCRS["WGS 84",DATUM["World Geodetic System 1984",ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],CS[ellipsoidal,2],AXIS["geodetic latitude (Lat)",north,ORDER[1],ANGLEUNIT["degree",0.0174532925199433]],AXIS["geodetic longitude (Lon)",east,ORDER[2],ANGLEUNIT["degree",0.0174532925199433]],ID["EPSG",4326]]

T5: No match!!

I am not sure what the best solution is here, but I guess running likes of gdalsrsinfo --version and if it is > 2, add the --single-line flag. After that, the regular expression match would need changed to work in all cases

Kind regards

Gordon

gordonbanderson commented 2 years ago

Apologies, I forgot gdalsrsinfo versions.

Debian 10: 2.4.0 (from memory, I would need to rebuild image to double check) GitHub Ubuntu Latest: 3.0.4 Debian 11: 3.2.2