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

Support z-coordinate as input for @turf/turf-tin #772

Merged
merged 2 commits into from May 30, 2017
Merged

Conversation

dpmcmlxxvi
Copy link
Collaborator

Addresses #628 for @turf/tin. PR has the following edits:

  • Uses z-coordinate of input points only if input z-property is undefined. So, should be backwards compatible.
  • Updates test fixtures to include z-coordinate.
  • Updated test.js and bench.js syntax to ES6.

Please fill in this template.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Have read How To Contribute.
  • Run npm test at the sub modules where changes have occurred.
  • Run npm run lint to ensure code style at the turf module level.


global.points = JSON.parse(fs.readFileSync(__dirname+'/test/Points.geojson'));
const points = JSON.parse(fs.readFileSync(__dirname+'/test/Points.json'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When refactoring, use the path.join() method to make it friendly for cross platforms (Windows).

const path = require('path');
const points = JSON.parse(fs.readFileSync(path.join(__dirname, 'test', 'Points.json')));

@@ -39,24 +39,42 @@ var featurecollection = helpers.featureCollection;
*/
module.exports = function (points, z) {
//break down points
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to add some simple validation to test the input is correctly a FeatureCollection.

if (points.type !== 'FeatureCollection') throw new Error('points must be a FeatureCollection');

if (z) point.z = p.properties[z];
if (z) {
point.z = p.properties[z];
} else if (p.geometry.coordinates.length === 3) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good

const fs = require('fs');
const path = require('path');
const test = require('tape');
const tin = require('./index.js');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index.js can be dropped.

const tin = require('./');


fs.writeFileSync(path.join(__dirname, 'test', 'Tin.json'), JSON.stringify(tinned));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saving the outputs is very useful to see the final results, also saving the fixtures using .geojson makes it easier to preview the GeoJSON directly in GitHub.

Copy link
Member

@DenisCarriere DenisCarriere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants