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 Null geometries #866

Merged
merged 16 commits into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions packages/turf-bbox-clip/test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const test = require('tape');
const fs = require('fs');
const test = require('tape');
const path = require('path');
const load = require('load-json-file');
const write = require('write-json-file');
const {point, feature} = require('@turf/helpers');
const turfBBox = require('@turf/bbox');
const featureCollection = require('@turf/helpers').featureCollection;
const point = require('@turf/helpers').point;
const {featureCollection} = require('@turf/helpers');
const bboxClip = require('./');

const directories = {
Expand Down Expand Up @@ -34,8 +34,8 @@ test('turf-bbox-clip', t => {
t.end();
});

test('turf-bbox-clip errors', t => {
t.throws(() => bboxClip(point([5, 10]), [-180, -90, 180, 90]));
test('turf-bbox-clip -- throws', t => {
t.throws(() => bboxClip(point([5, 10]), [-180, -90, 180, 90]), /geometry Point not supported/);
t.end();
});

Expand All @@ -48,3 +48,8 @@ function colorize(feature, color = '#F00', width = 6) {
};
return feature;
}

test('turf-bbox-clip -- null geometries', t => {
t.throws(() => bboxClip(feature(null), [-180, -90, 180, 90]), /No valid coordinates/);
t.end();
});
31 changes: 16 additions & 15 deletions packages/turf-bbox-polygon/test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
var test = require('tape')
var bboxPolygon = require('./')
const test = require('tape');
const bboxPolygon = require('./');

test('bboxPolygon', function(t){
t.plan(2);
test('bboxPolygon', t => {
t.plan(2);

var poly = bboxPolygon([0,0,10,10]);
const poly = bboxPolygon([0, 0, 10, 10]);

t.ok(poly.geometry.coordinates, 'should take a bbox and return the equivalent polygon feature');
t.equal(poly.geometry.type, 'Polygon', 'should be a Polygon geometry type');
t.ok(poly.geometry.coordinates, 'should take a bbox and return the equivalent polygon feature');
t.equal(poly.geometry.type, 'Polygon', 'should be a Polygon geometry type');
});

test('bboxPolygon valid geojson', function (t) {
var poly = bboxPolygon([0,0,10,10]),
coordinates = poly.geometry.coordinates;
t.ok(poly, 'should be valid geojson.');
t.equal(coordinates[0].length, 5);
t.equal(coordinates[0][0][0], coordinates[0][coordinates.length - 1][0]);
t.equal(coordinates[0][0][1], coordinates[0][coordinates.length - 1][1]);
t.end();
test('bboxPolygon valid geojson', t => {
const poly = bboxPolygon([0, 0, 10, 10]);
const coordinates = poly.geometry.coordinates;

t.ok(poly, 'should be valid geojson.');
t.equal(coordinates[0].length, 5);
t.equal(coordinates[0][0][0], coordinates[0][coordinates.length - 1][0]);
t.equal(coordinates[0][0][1], coordinates[0][coordinates.length - 1][1]);
t.end();
});
129 changes: 60 additions & 69 deletions packages/turf-bbox/test.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,63 @@
var test = require('tape');
var fs = require('fs');
var extent = require('./');

// test data
var fc = require('./test/FeatureCollection');
var pt = require('./test/Point');
var line = require('./test/LineString');
var poly = require('./test/Polygon');
var multiLine = require('./test/MultiLineString');
var multiPoly = require('./test/MultiPolygon');

test('extent', function(t){
// FeatureCollection
var fcExtent = extent(fc);

t.ok(fcExtent, 'FeatureCollection');
t.equal(fcExtent[0], 20);
t.equal(fcExtent[1], -10);
t.equal(fcExtent[2], 130);
t.equal(fcExtent[3], 4);

// Point
var ptExtent = extent(pt);
t.ok(ptExtent, 'Point');
t.equal(ptExtent[0], 102);
t.equal(ptExtent[1], 0.5);
t.equal(ptExtent[2], 102);
t.equal(ptExtent[3], 0.5);

// Line
var lineExtent = extent(line);

t.ok(lineExtent, 'Line');
t.equal(lineExtent[0], 102);
t.equal(lineExtent[1], -10);
t.equal(lineExtent[2], 130);
t.equal(lineExtent[3], 4);

// Polygon
var polyExtent = extent(poly);

t.ok(polyExtent, 'Polygon');
t.equal(polyExtent[0], 100);
t.equal(polyExtent[1], 0);
t.equal(polyExtent[2], 101);
t.equal(polyExtent[3], 1);

// MultiLineString
var multiLineExtent = extent(multiLine);

t.ok(multiLineExtent, 'MultiLineString');
t.equal(multiLineExtent[0], 100);
t.equal(multiLineExtent[1], 0);
t.equal(multiLineExtent[2], 103);
t.equal(multiLineExtent[3], 3);

// MultiPolygon
var multiPolyExtent = extent(multiPoly);

t.ok(multiPolyExtent, 'MultiPolygon');
t.equal(multiPolyExtent[0], 100);
t.equal(multiPolyExtent[1], 0);
t.equal(multiPolyExtent[2], 103);
t.equal(multiPolyExtent[3], 3);
const test = require('tape');
const {
point,
lineString,
polygon,
feature,
featureCollection,
multiPolygon,
multiLineString} = require('@turf/helpers');
const bbox = require('./');

// Fixtures
const pt = point([102.0, 0.5]);
const line = lineString([[102.0, -10.0], [103.0, 1.0], [104.0, 0.0], [130.0, 4.0]]);
const poly = polygon([[[101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0], [101.0, 0.0]]]);
const multiLine = multiLineString([
[[100.0, 0.0], [101.0, 1.0]],
[[102.0, 2.0], [103.0, 3.0]]
]);
const multiPoly = multiPolygon([
[[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
[[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]], [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
]);
const fc = featureCollection([pt, line, poly, multiLine, multiPoly]);

test('bbox', t => {
// FeatureCollection
const fcBBox = bbox(fc);
t.deepEqual(fcBBox, [100, -10, 130, 4], 'featureCollection');

// Point
const ptBBox = bbox(pt);
t.deepEqual(ptBBox, [102, 0.5, 102, 0.5], 'point');

// Line
const lineBBox = bbox(line);
t.deepEqual(lineBBox, [102, -10, 130, 4], 'lineString');

// Polygon
const polyExtent = bbox(poly);
t.deepEqual(polyExtent, [100, 0, 101, 1], 'polygon');

// MultiLineString
const multiLineBBox = bbox(multiLine);
t.deepEqual(multiLineBBox, [100, 0, 103, 3], 'multiLineString');

// MultiPolygon
const multiPolyBBox = bbox(multiPoly);
t.deepEqual(multiPolyBBox, [100, 0, 103, 3], 'multiPolygon');


t.end();
});

t.throws(function() {
var multiPolyExtent = extent({});
}, /Unknown Geometry Type/, 'unknown geometry type error');
test('bbox -- throws', t => {
t.throws(() => bbox({}), /Unknown Geometry Type/, 'unknown geometry type error');
t.end();
});

t.end();
test('bbox -- null geometries', t => {
t.deepEqual(bbox(feature(null)), [Infinity, Infinity, -Infinity, -Infinity]);
t.end();
});
39 changes: 0 additions & 39 deletions packages/turf-bbox/test/FeatureCollection.js

This file was deleted.

21 changes: 0 additions & 21 deletions packages/turf-bbox/test/LineString.js

This file was deleted.

25 changes: 0 additions & 25 deletions packages/turf-bbox/test/MultiLineString.js

This file was deleted.

75 changes: 0 additions & 75 deletions packages/turf-bbox/test/MultiPolygon.js

This file was deleted.

10 changes: 0 additions & 10 deletions packages/turf-bbox/test/Point.js

This file was deleted.

Loading