Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation about OSM adapter or some examples #3

Open
MurzNN opened this issue Oct 22, 2021 · 3 comments
Open

Add documentation about OSM adapter or some examples #3

MurzNN opened this issue Oct 22, 2021 · 3 comments

Comments

@MurzNN
Copy link

MurzNN commented Oct 22, 2021

In PR phayes#125 you've described the OSM adapter feature, can you please explain what it is and how to use it?
I'm searching the way to convert OSM relation object (from Overpass reply with geom) to GeoJSON or WKT, to get boundary polygon - is it possible with your improvements? If not, can you recommend me other PHP libs, that can do this? Thanks!

@MurzNN
Copy link
Author

MurzNN commented Oct 22, 2021

Here https://github.com/tyrasd/osmtogeojson is JS library, that do this "magic", and it is used on Overpass Turbo frontend.
Will be good to have same library on PHP language...

@MurzNN
Copy link
Author

MurzNN commented Oct 22, 2021

Now I've solved this task via launching Node.js script from PHP via subprocess:

use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

  function osmToGeojson(object $element) {
    // Needs the `yarn global add osmtogeojson` system action.
    $process = new Process(['osmtogeojson']);
    $process->setInput(json_encode($element));

    try {
      $process->run();
      $output = $process->getOutput();
      $elementGeojson = json_decode($output);
    }
    catch (ProcessFailedException $exception) {
      throw new \Exception('Error converting OSM element to GeoJSON using osmtogeojson executable', 0, $exception);
    }
    return $elementGeojson;
  }

But this is disgusting solution :(

@BathoryPeter
Copy link
Member

OSM adapter was an initial attempt, which I never completed. Beyond that I really like OSM, converting its data is full of difficulties. I mean for example the closed way conversion which depends on tagging.

Unfortunately I have less and less time for my OSS projects, but if someone would work on improving OSM adapter, I would happy to help.

I don't remember the details about the completeness, but I left comments in OSM.php:

This adapter is not ready yet. It lacks a relation writer, and the reader has problems with invalid multipolygons
Since geoPHP doesn't support metadata, it cannot read and write OSM tags.
(Note: since then I added metadata support, so we can extend the adapter with it.)

But you can give it a try. Just use the usual geoPHP::read($osmFile, 'osm') and geoPHP::write($geometry, 'osm') methods to load and create OSM files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants