5

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?

Community
  • 1
  • 1
Ego_I
  • 250
  • 2
  • 14
  • I would advice you to use php5-gdal. Why doing there work again? – hek2mgl Mar 28 '13 at 10:02
  • Yes I thought that would probably be the best option, but its not recommended in a production environment and its considered unstable..... – Ego_I Mar 28 '13 at 10:05
  • A custom solution will need the same alpha, beta, unstable, stable staging. And I expect you starting at alpha state (like everyone)) – hek2mgl Mar 28 '13 at 10:10
  • yeah, you are right.... looking through the source it seems extensible if there are other functions I want to implement... – Ego_I Mar 28 '13 at 12:05
  • Ok. You should consider to answer this question by yourself after finishing tests. Would be interesting to hear about your results. – hek2mgl Mar 28 '13 at 12:51
  • will do. Thanks for pointing me in the right direction – Ego_I Mar 28 '13 at 15:05
  • Hmm, I have to wonder about this: http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/php and http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/include – Mike T Apr 08 '13 at 04:51

2 Answers2

6

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()));

        }
Ego_I
  • 250
  • 2
  • 14
2

You can use the Symfony Process-Component, avoiding plain exec commands.
It has a great syntax and is very easy to use.

http://symfony.com/doc/current/components/process.html

$process = new Process('ls -lsa');
$process->run();

// executes after the command finishes
if (!$process->isSuccessful()) {
    throw new ProcessFailedException($process);
}

echo $process->getOutput();
rabbl
  • 83
  • 1
  • 8