TNOCS / minify-geojson

Minifies (compresses) a GeoJSON file, i.e. by removing properties or using fewer decimals for coordinates.
MIT License
26 stars 3 forks source link

Does not work with specific input file #23

Closed rolandstarke closed 5 years ago

rolandstarke commented 5 years ago

Hey,

I am new to geojson so i hope its not an obvious mistake.

Downloading the file: https://github.com/isellsoap/deutschlandGeoJSON/blob/master/2_bundeslaender/4_niedrig.geojson

and running

minify-geojson  -c 5 .\4_niedrig.geojson

gives the following error and no output file is generated.

SyntaxError: Unexpected token , in JSON at position 0
    at JSON.parse (<anonymous>)
    at OgrJsonStream._transform (node_modules\minify-geojson\node_modules\ogr-json-stream\index.js:57:25)
    at OgrJsonStream.Transform._read (node_modules\minify-geojson\node_modules\readable-stream\lib\_stream_transform.js:184:10)
    at OgrJsonStream.Transform._write (node_modules\minify-geojson\node_modules\readable-stream\lib\_stream_transform.js:172:83)
    at doWrite (node_modules\minify-geojson\node_modules\readable-stream\lib\_stream_writable.js:428:64)
    at writeOrBuffer (node_modules\minify-geojson\node_modules\readable-stream\lib\_stream_writable.js:417:5)
    at OgrJsonStream.Writable.write (node_modules\minify-geojson\node_modules\readable-stream\lib\_stream_writable.js:334:11)
    at ReadStream.ondata (_stream_readable.js:713:22)
    at ReadStream.emit (events.js:200:13)
    at addChunk (_stream_readable.js:294:12)
erikvullings commented 5 years ago

Since you're new to geojson, are you sure you're dealing with an actual geojson file? The error you received suggests a formatting error in the file, perhaps because it's not a geojson. Could you paste a part of the file as a snippet, or try to open it in https://geojson.io...

Sorry, I've answered you to quickly. I'll try to have a look at your file today...

On Mon, 22 Jul 2019, 14:11 Roland Starke, notifications@github.com wrote:

Hey,

I am new to geojson so i hope its not an obvious mistake.

Downloading the file: https://github.com/isellsoap/deutschlandGeoJSON/blob/master/2_bundeslaender/4_niedrig.geojson

and running

minify-geojson -c 5 .\4_niedrig.geojson

gives the following error and no output file is generated.

SyntaxError: Unexpected token , in JSON at position 0 at JSON.parse () at OgrJsonStream._transform (node_modules\minify-geojson\node_modules\ogr-json-stream\index.js:57:25) at OgrJsonStream.Transform._read (node_modules\minify-geojson\node_modules\readable-stream\lib_stream_transform.js:184:10) at OgrJsonStream.Transform._write (node_modules\minify-geojson\node_modules\readable-stream\lib_stream_transform.js:172:83) at doWrite (node_modules\minify-geojson\node_modules\readable-stream\lib_stream_writable.js:428:64) at writeOrBuffer (node_modules\minify-geojson\node_modules\readable-stream\lib_stream_writable.js:417:5) at OgrJsonStream.Writable.write (node_modules\minify-geojson\node_modules\readable-stream\lib_stream_writable.js:334:11) at ReadStream.ondata (_stream_readable.js:713:22) at ReadStream.emit (events.js:200:13) at addChunk (_stream_readable.js:294:12)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/TNOCS/minify-geojson/issues/23?email_source=notifications&email_token=AAX6YO7BXLMBBWQOVRM2POTQAWWY7A5CNFSM4IFYOY5KYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HAUHALA, or mute the thread https://github.com/notifications/unsubscribe-auth/AAX6YO2Q35SNVF2GSA5MF73QAWWY7ANCNFSM4IFYOY5A .

rolandstarke commented 5 years ago

OK, thanks, (the file is fine on geojson.io).

Here is the file I am using now (which gives the error):

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "id": 0,
            "properties": {
                "ID_0": 86,
                "ISO": "DEU",
                "NAME_0": "Germany",
                "ID_1": 1,
                "NAME_1": "Baden-Württemberg",
                "NL_NAME_1": null,
                "VARNAME_1": null,
                "TYPE_1": "Land",
                "ENGTYPE_1": "State"
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [

                        [
                            [
                                8.708373069763297,
                                47.715557098388672
                            ],
                            [
                                8.722451210022371,
                                47.696529388427791
                            ],
                            [
                                8.661308288574162,
                                47.695213317871264
                            ],
                            [
                                8.708373069763297,
                                47.715557098388672
                            ]
                        ]

                ]
            }
        }
    ]
}

OS: windows, line endings of the file: LF

node --version
#v12.4.0
npm show minify-geojson version
#1.2.6
erikvullings commented 5 years ago

@rolandstarke Thanks for noting the issue. I've resolved it for now (and tested that it works on node v10.16 for both your files - the file with one feature, and the 4_niedrig version), but am not completely happy with the solution. When the streaming mode fails (which will always fail for files with only one feature), I use the regular mode, reading the whole input geojson into memory. Have to delve deeper into the issue... For now, you can just grab the latest patch-release version from npm (v1.2.7)

erikvullings commented 5 years ago

@rolandstarke I've just replaced the offending library (ogr-json-schema) with JSONstream, and now it works as it should again, in full streaming mode. Released as v1.3.0.