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

Needs better explanation / Read.me #92

Open
csimpi opened this issue Dec 8, 2020 · 1 comment
Open

Needs better explanation / Read.me #92

csimpi opened this issue Dec 8, 2020 · 1 comment

Comments

@csimpi
Copy link

csimpi commented Dec 8, 2020

Hi, thank you for this awesome tool, it was extremely helpful parsing huge GeoJSON data.
However, the explanation of the really important part is totally missing. It was difficult to find out what's going on. When I went to your blog post the same happened, when I was looking for how to implement the listener the blog post just say: It's pretty straightforward. It is but not for somebody who gets here the first time :)

Here's my code snippet using the GeoJSON Listener for another users who needs a better example:

<?php

  ini_set('max_execution_time', 0);
  ini_set('memory_limit', -1);

  $tmp_file_name = 'geojson.json';

  $stream = fopen('/tmp/'.$tmp_file_name, 'r');

  $listener = new \JsonStreamingParser\Listener\GeoJsonListener(function($json){
      if(!empty($json)){
          //var_dump($json['properties']);
          ////////////////// Do WHATEVER YOU WANT WITH THE FEATURE //////////////////

          //Storing in db
          $data = [
              'title'     => !empty($json['properties']['shapeName']) ? $json['properties']['shapeName'] :$json['properties']['shapeISO'],
              'iso'     => $json['properties']['shapeISO'],
              'gb_id'     => $json['properties']['shapeID'],
              'country_iso'     => $json['properties']['shapeGroup'],
              'admin_level'     => str_replace('ADM', '', $json['properties']['shapeType']),
          ];

          $json['properties'] = $data;

          $data['geometry'] = json_encode($json);

          try{
               //Mock DB insert
              DB::table('geoboundaries')->insert($data);
          }catch (\Exception $exception){
              dd(substr($exception->getMessage(), 0, 300));
          }



      }

  });
  try {
      $parser = new \JsonStreamingParser\Parser($stream, $listener);
      $parser->parse();

      fclose($stream);
      return true;
  } catch (Exception $e) {
      fclose($stream);
      throw $e;
  }

@soyuka
Copy link

soyuka commented Jan 22, 2021

Take a look at the resources you should be able to handle everything from those:

It's not easy but you'll find a workaround. good luck !

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