Subject: [Json] (Geo)JSON text sequences in Python

From: Sean Gillies <[email-masked]>
Date: Tue, 23 Sep 2014 12:06:27 -0600

I'm developing Python software for working with the GeoJSON (as seen on
GitHub: https://help.github.com/articles/mapping-geojson-files-on-github)
and GeoJSON text sequences seem like a nice solution to some of the
problems of dealing with many MB feature collection objects that result
from the conversion of traditional spatial data formats. I'm finding no
problems with handling RS separated text sequences.

Below is the generator of Python objects parsed from a text sequence I'm
using in https://github.com/Toblerity/Fiona.

    if first_line.startswith(u'\x1e'):
        def feature_gen():
            buffer = first_line.strip(u'\x1e')
            for line in stdin:
                if line.startswith(u'\x1e'):
                    if buffer:
                        yield json.loads(buffer)
                    buffer = line.strip(u'\x1e')
                else:
                    buffer += line
            else:
                yield json.loads(buffer)

Making text sequences with printf to test my command line programs is not a
problem at all:

    result = subprocess.check_output(
        "printf '\x1e%s\n\x1e%s' | fio collect" % (
            json.dumps(feature, indent=2), json.dumps(feature, indent=2)),
        shell=True)

Thanks for the hard work, everybody. JSON Text Sequence is definitely
useful for spatial data interchange and processing.

-- 
Sean Gillies