Skip to content

Commit

Permalink
Merge pull request #134 from pelias/rename_polygon_field_shape
Browse files Browse the repository at this point in the history
rename 'polygon' field to 'shape' to match pelias/schema
  • Loading branch information
orangejulius authored Sep 10, 2020
2 parents 9c8379d + 27b21bd commit 1a5ae33
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
10 changes: 5 additions & 5 deletions Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Document.prototype.toESDocument = function() {
popularity: this.popularity,
population: this.population,
addendum: {},
polygon: this.shape
shape: this.shape
};

// add encoded addendum namespaces
Expand Down Expand Up @@ -136,8 +136,8 @@ Document.prototype.toESDocument = function() {
if( !Object.keys( doc.addendum || {} ).length ){
delete doc.addendum;
}
if( !Object.keys( doc.polygon || {} ).length ){
delete doc.polygon;
if( !Object.keys( doc.shape || {} ).length ){
delete doc.shape;
}

return {
Expand Down Expand Up @@ -576,7 +576,7 @@ Document.prototype.getCentroid = function(){
};

// shape
Document.prototype.setPolygon = function( value ){
Document.prototype.setShape = function( value ){

validate.type('object', value);
validate.truthy(value);
Expand All @@ -585,7 +585,7 @@ Document.prototype.setPolygon = function( value ){
return this;
};

Document.prototype.getPolygon = function(){
Document.prototype.getShape = function(){
return this.shape;
};

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var poi = new Document( 'geoname', 'venue', 1003 )
.setAddendum('wikipedia', { slug: 'HackneyCityFarm' })
.setAddendum('geonames', { foreignkey: 1 })
.setCentroid({ lon: 0.5, lat: 50.1 })
.setPolygon( geojsonObject /* any valid geojson object */ )
.setShape( geojsonObject /* any valid geojson object */ )
.setBoundingBox( bboxObject /* see tests for bbox syntax */ );

console.log( poi );
Expand Down
2 changes: 1 addition & 1 deletion test/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ for( var x=0; x<iterations; x++ ){
.setPopulation(10)
.setPopularity(3)
.setCentroid({ lon: 0.5, lat: 50.1 })
.setPolygon(fixtures.new_zealand)
.setShape(fixtures.new_zealand)
.setBoundingBox(fixtures.new_zealand_bbox)
.toESDocument();
}
Expand Down
22 changes: 11 additions & 11 deletions test/document/polygon.js → test/document/shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@ var Document = require('../../Document');

module.exports.tests = {};

module.exports.tests.getPolygon = function(test) {
test('getPolygon', function(t) {
module.exports.tests.getShape = function(test) {
test('getShape', function(t) {
var doc = new Document('mysource','mylayer','myid');
doc.shape = { 'foo': 'bar' };
t.deepEqual(doc.getPolygon(), doc.shape, 'getter works');
t.deepEqual(doc.getShape(), doc.shape, 'getter works');
t.end();
});
};

module.exports.tests.setPolygon = function(test) {
test('setPolygon', function(t) {
module.exports.tests.setShape = function(test) {
test('setShape', function(t) {
var doc = new Document('mysource','mylayer','myid');
t.equal(doc.shape, undefined, 'polygon undefined');
t.equal(doc.setPolygon({ 'foo': 'bar' }), doc, 'chainable');
t.equal(doc.setShape({ 'foo': 'bar' }), doc, 'chainable');
t.deepEqual(doc.shape, { 'foo': 'bar' }, 'polygon set');
t.end();
});
test('setPolygon - validate', function(t) {
test('setShape - validate', function(t) {
var doc = new Document('mysource','mylayer','myid');
t.throws( doc.setPolygon.bind(doc,undefined), null, 'invalid type' );
t.throws( doc.setPolygon.bind(doc,''), null, 'invalid type' );
t.throws( doc.setPolygon.bind(doc,1), null, 'invalid type' );
t.throws( doc.setPolygon.bind(doc,[]), null, 'invalid type' );
t.throws( doc.setShape.bind(doc,undefined), null, 'invalid type' );
t.throws( doc.setShape.bind(doc,''), null, 'invalid type' );
t.throws( doc.setShape.bind(doc,1), null, 'invalid type' );
t.throws( doc.setShape.bind(doc,[]), null, 'invalid type' );
t.end();
});
};
Expand Down
8 changes: 4 additions & 4 deletions test/document/toESDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports.tests.toESDocument = function(test) {
});
doc.setPopulation(123);
doc.setPopularity(456);
doc.setPolygon({ key: 'value' });
doc.setShape({ key: 'value' });
doc.addCategory('category 1');
doc.addCategory('category 2');
doc.setAddendum('wikipedia', { slug: 'HackneyCityFarm' });
Expand Down Expand Up @@ -72,7 +72,7 @@ module.exports.tests.toESDocument = function(test) {
bounding_box: '{"min_lat":12.121212,"max_lat":13.131313,"min_lon":21.212121,"max_lon":31.313131}',
population: 123,
popularity: 456,
polygon: {
shape: {
key: 'value'
},
category: [
Expand Down Expand Up @@ -135,7 +135,7 @@ module.exports.tests.toESDocument = function(test) {
t.false(esDoc.data.hasOwnProperty('center_point'), 'should not include center');
t.false(esDoc.data.hasOwnProperty('population'), ' should not include population');
t.false(esDoc.data.hasOwnProperty('popularity'), ' should not include popularity');
t.false(esDoc.data.hasOwnProperty('polygon'), ' should not include polygon');
t.false(esDoc.data.hasOwnProperty('shape'), ' should not include shape');
t.end();

});
Expand Down Expand Up @@ -192,7 +192,7 @@ module.exports.tests.toESDocument = function(test) {
t.false(esDoc.data.hasOwnProperty('center_point'), 'should not include center');
t.false(esDoc.data.hasOwnProperty('population'), ' should not include population');
t.false(esDoc.data.hasOwnProperty('popularity'), ' should not include popularity');
t.false(esDoc.data.hasOwnProperty('polygon'), ' should not include polygon');
t.false(esDoc.data.hasOwnProperty('shape'), ' should not include shape');
t.end();

});
Expand Down
2 changes: 1 addition & 1 deletion test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var tests = [
require('./document/addendum.js'),
require('./document/address.js'),
require('./document/parent.js'),
require('./document/polygon.js'),
require('./document/shape.js'),
require('./document/category.js'),
require('./document/boundingbox.js'),
require('./document/source.js'),
Expand Down
2 changes: 1 addition & 1 deletion test/serialize/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports.tests.complete = function(test) {
.setAddendum('wikipedia', { slug: 'HackneyCityFarm' })
.setAddendum('geonames', { foreignkey: 1 })
.setCentroid({ lon: 0.5, lat: 50.1 })
.setPolygon(fixtures.new_zealand)
.setShape(fixtures.new_zealand)
.setBoundingBox(fixtures.new_zealand_bbox);

var s = serializeDeserialize( doc );
Expand Down

0 comments on commit 1a5ae33

Please sign in to comment.