Search code examples
phpgdalogr

PHP GDAL/OGR library usage, which approach is cleaner?


I will be using gdal/ogr for a new project. I want a lean but fully functional app, so will not be using other implementations such as mapserver, because they have extraneous components that I doubt will be needed in the application, even in the future. For the record, it is a GIS, but I am asking here on SO because there as so few examples of a GIS in php that uses GDAL/OGR

I basically have three options in mind:

  • use php's exec() function to run command line conversion utilities

  • Use swig to generate a .dll and load it as an extension on php

  • Use the php wrapper written by geonfr @https://github.com/geonef/php5-gdal/wiki

Which do you think is the most effective way to implement the library?


Solution

  • I wound up using the exec functions, mostly because there was no time to get into swig or php extension development, which were the preferred methods for me, personally. // here is a small sample snippet of it's usage, hopefully it will come in handy for someone else

    public function convertToNewFormat($format)
            {
                    return(
                        exec('ogr2ogr -f '
                            .$format
                            .' '.self::setNewFileLocation()
                            .' '.self::setOldFileLocation()));
    
            }