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

女生的网名这么多〃 提交于 2020-01-01 03:28:22

问题


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?


回答1:


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

        }



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


来源:https://stackoverflow.com/questions/15678797/php-gdal-ogr-library-usage-which-approach-is-cleaner

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!