question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Propose new module (save & read)

See original GitHub issue

I seem to constantly have to write the following functions to read & save GeoJSON files (.geojson).

var truncate = require('@turf/truncate')
function read (filename) {
  return JSON.parse(fs.readFileSync(filename, 'utf8'))
}

function save (filename, features) {
  fs.writeFileSync(filename, JSON.stringify(truncate(features), null, 2))
}

An easy solution was to change the GeoJSON filename extension to (.json), but there’s many times where the data comes in as (.geojson) and I need to write this helper function.

Solution

Create a FILE SYSTEM group of functions @turf/file-system (I dunno… just throwing that out there).

For start it would have both read & save functions.

var read = require('@turf/file-system').read
var save = require('@turf/file-system').save

For people who only need fs to read & write GeoJSON this would replace require('fs') for GeoJSON purposes.

var fs =require('@turf/file-system')
fs.save('example.geojson', featureCollection)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
tmcwcommented, Jan 31, 2017

👍 This sounds useful, I guess the big question is whether save should, by default, use truncate to limit coords.

0reactions
DenisCarrierecommented, Feb 1, 2017

I just used load-json-file & write-json-file in the test.js for @turf/truncate without any issues, those libraries are very easy to use and solves read & write issue I had.

https://github.com/Turfjs/turf/blob/master/packages/turf-truncate/test.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

csv — CSV File Reading and Writing — Python 3.11.1 ...
The csv module implements classes to read and write tabular data in CSV format. ... The Python Enhancement Proposal which proposed this addition...
Read more >
Module Composition | Terraform - HashiCorp Developer
Module composition allows infrastructure to be described from modular building blocks.
Read more >
Chapter 8. Writing a custom SELinux policy
8.3. Creating a local SELinux policy module · Open a new .cil file with a text editor, for example: Copy · Insert the...
Read more >
Module proposal form with guidance notes When drafting a ...
When drafting a new module, use the module proposal form which includes guidance notes. Modules are drafted on the New module proposal form...
Read more >
Create custom functions in Excel - Microsoft Support
Creating a simple custom function · Press Alt+F11 to open the Visual Basic Editor (on the Mac, press FN+ALT+F11), and then click Insert...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found