Download the PHP package andriell/osm2sql without Composer

On this page you can find all versions of the php package andriell/osm2sql. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package osm2sql

Convert OSM XML file to SQL for MySQL

Quick start

Download OSM XML here https://download.bbbike.org/

Example 1

Convert OSM to SQL file

  1. Create database tables from file resources/mysql.sql

  2. Convert OSM to SQL inserts

    ini_set('memory_limit', '10M');
    // This class read big osm file
    $largeXmlReader = new LargeXmlReader();
    $largeXmlReader->setFilePath('/path/to/very/big/osm/xml/file.osm');
    
    // This class listens reader class and write data into file
    $listener = new FileReaderListener('/path/to/new/sql/file.sql');
    
    // Insert 500 rows in one operation
    $listener->setInsertSize(500);
    // Use INSERT IGNORE ...
    $listener->setInsertIgnore(true);
    $largeXmlReader->setListener($listener);
    $largeXmlReader->setProgressListener(function($readSize, $totalSize) use ($progress) {
        echo 'Completed ' . $readSize . ' Mb of ' . $totalSize . " Mb\n";
    });
    // Start parsing
    $largeXmlReader->parse();
  3. Import sql file in to database

    mysql -u username -p database_name < /path/to/new/sql/file.sql

Example 2

You can create your ReaderListener and write data directly to the database

class DbReaderListener extends AbstractReaderListener
{
    // ...
    protected function write($table, $sql)
    {
        $this->myDbConnection->query($sql);
    }
}

// ...
$largeXmlReader->setListener(new DbReaderListener());
// ...

Example 3

Write data directly to the database and calculate building, highway, place tables

ini_set('memory_limit', '100M');

include 'vendor/autoload.php';

$file = '/path/to/very/big/osm/xml/file.osm';

// This class read big osm file
$largeXmlReader = new \osm2sql\LargeXmlReader();

// This class listens reader class and write data into database
$listener = new \osm2sql\mysql\PdoDbBuilder('mysql:host=localhost;dbname=osm;port=3306', 'user', 'password');
// Insert 100 rows in one operation
$listener->setInsertSize(100);
// Use INSERT IGNORE ...
$listener->setInsertIgnore(true);
$listener->setProgressListener(function ($size, $total) {
    echo 'Update DB ' . $size . ' row of ' . $total . " rows\n";
});
$listener->setExceptionListener(function($e, $sqlStr) {
    echo $sqlStr . "\n";
    echo $e . "\n";
});
// Delete all relations, way, node in database
$listener->deleteRelation();
$listener->deleteWay();
$listener->deleteNode();

$largeXmlReader->setFilePath($file);
$largeXmlReader->setListener($listener);
$largeXmlReader->setProgressListener(function($readSize, $totalSize) {
    echo  'Read file ' . $readSize . ' Mb of ' . $totalSize . " Mb\n";
});
// Insert new relations, way, node from osm file to database
$largeXmlReader->parse();

// Clear and calculate highway, building, place
$listener->deleteHighway();
$listener->calculateHighway();
$listener->deleteBuilding();
$listener->calculateBuilding();
$listener->deletePlace();
$listener->calculatePlace();

echo 'Done';

You can create your DbBuilder class and use database connection in your framework

class MyDbBuilder extends \osm2sql\mysql\AbstractDbBuilder
{
    // ...
    protected function querySelect($sqlStr)
    {
        $rows = $this->myDbConnection->query($sqlStr);
        $r = [];
        foreach ($rows as $row) {
            $r[] = (array) $row;
        }
        return $r;
    }

    protected function queryUpdate($sqlStr)
    {
        return (int) $this->myDbConnection->exec($sqlStr);
    }
}

All versions of osm2sql with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package andriell/osm2sql contains the following files

Loading the files please wait ....