Skip to content

Needs better explanation / Read.me #92

@csimpi

Description

@csimpi

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;
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions