Permalink
Browse files

Added gt property processor

  • Loading branch information...
1 parent 76e4436 commit 6481023e87dcb822b2b648d5abf038c80869a018 @DamonOehlman committed Jul 2, 2012
View
@@ -7,7 +7,10 @@ define('ogc', ['./geofilter', 'formatter', 'underscore'], function(geofilter, fo
var builders = {},
- templates = {};
+ templates = {},
+ propertyTags = {
+ gt: 'PropertyIsGreaterThan'
+ };
function makePropertyTag(args, opts) {
return templates.property(args);
@@ -38,15 +41,28 @@ define('ogc', ['./geofilter', 'formatter', 'underscore'], function(geofilter, fo
// iterate through the rules and generate the output
rules.forEach(function(rule) {
- var builder = builders[(rule || {}).type];
+ var type = (rule || {}).type,
+ builder = builders[type],
+ tagName = propertyTags[type];
// if we have a valid builder, then process
if (typeof builder == 'function') {
// run the builder
output += builder(rule.type, rule.args || {}, opts);
}
+ else if (tagName) {
+ output += '<ogc:' + tagName + '>' + makePropertyTag(rule.args || {}, opts) + '</ogc:' + tagName + '>';
+ }
+ else {
+ throw new Error('Unable to build OGC filter for rule type "' + (rule || {}).type + '"');
+ }
});
+ // if the number of rules is greater than 1, combine in an And clause
+ if (rules.length > 1) {
+ output = '<ogc:And>' + output + '</ogc:And>';
+ }
+
return output;
});
View
@@ -10,7 +10,10 @@ var _ogc_templates = {
var builders = {},
- templates = {};
+ templates = {},
+ propertyTags = {
+ gt: 'PropertyIsGreaterThan'
+ };
function makePropertyTag(args, opts) {
return templates.property(args);
@@ -41,15 +44,28 @@ geofilter.registerConverter('ogc', function(rules, opts) {
// iterate through the rules and generate the output
rules.forEach(function(rule) {
- var builder = builders[(rule || {}).type];
+ var type = (rule || {}).type,
+ builder = builders[type],
+ tagName = propertyTags[type];
// if we have a valid builder, then process
if (typeof builder == 'function') {
// run the builder
output += builder(rule.type, rule.args || {}, opts);
}
+ else if (tagName) {
+ output += '<ogc:' + tagName + '>' + makePropertyTag(rule.args || {}, opts) + '</ogc:' + tagName + '>';
+ }
+ else {
+ throw new Error('Unable to build OGC filter for rule type "' + (rule || {}).type + '"');
+ }
});
+ // if the number of rules is greater than 1, combine in an And clause
+ if (rules.length > 1) {
+ output = '<ogc:And>' + output + '</ogc:And>';
+ }
+
return output;
});
View
@@ -9,7 +9,10 @@
var builders = {},
- templates = {};
+ templates = {},
+ propertyTags = {
+ gt: 'PropertyIsGreaterThan'
+ };
function makePropertyTag(args, opts) {
return templates.property(args);
@@ -40,15 +43,28 @@
// iterate through the rules and generate the output
rules.forEach(function(rule) {
- var builder = builders[(rule || {}).type];
+ var type = (rule || {}).type,
+ builder = builders[type],
+ tagName = propertyTags[type];
// if we have a valid builder, then process
if (typeof builder == 'function') {
// run the builder
output += builder(rule.type, rule.args || {}, opts);
}
+ else if (tagName) {
+ output += '<ogc:' + tagName + '>' + makePropertyTag(rule.args || {}, opts) + '</ogc:' + tagName + '>';
+ }
+ else {
+ throw new Error('Unable to build OGC filter for rule type "' + (rule || {}).type + '"');
+ }
});
+ // if the number of rules is greater than 1, combine in an And clause
+ if (rules.length > 1) {
+ output = '<ogc:And>' + output + '</ogc:And>';
+ }
+
return output;
});
View
@@ -9,7 +9,10 @@
var builders = {},
- templates = {};
+ templates = {},
+ propertyTags = {
+ gt: 'PropertyIsGreaterThan'
+ };
function makePropertyTag(args, opts) {
return templates.property(args);
@@ -40,15 +43,28 @@
// iterate through the rules and generate the output
rules.forEach(function(rule) {
- var builder = builders[(rule || {}).type];
+ var type = (rule || {}).type,
+ builder = builders[type],
+ tagName = propertyTags[type];
// if we have a valid builder, then process
if (typeof builder == 'function') {
// run the builder
output += builder(rule.type, rule.args || {}, opts);
}
+ else if (tagName) {
+ output += '<ogc:' + tagName + '>' + makePropertyTag(rule.args || {}, opts) + '</ogc:' + tagName + '>';
+ }
+ else {
+ throw new Error('Unable to build OGC filter for rule type "' + (rule || {}).type + '"');
+ }
});
+ // if the number of rules is greater than 1, combine in an And clause
+ if (rules.length > 1) {
+ output = '<ogc:And>' + output + '</ogc:And>';
+ }
+
return output;
});
View
@@ -7,7 +7,10 @@ var _ogc_templates = {
var builders = {},
- templates = {};
+ templates = {},
+ propertyTags = {
+ gt: 'PropertyIsGreaterThan'
+ };
function makePropertyTag(args, opts) {
return templates.property(args);
@@ -38,15 +41,28 @@ geofilter.registerConverter('ogc', function(rules, opts) {
// iterate through the rules and generate the output
rules.forEach(function(rule) {
- var builder = builders[(rule || {}).type];
+ var type = (rule || {}).type,
+ builder = builders[type],
+ tagName = propertyTags[type];
// if we have a valid builder, then process
if (typeof builder == 'function') {
// run the builder
output += builder(rule.type, rule.args || {}, opts);
}
+ else if (tagName) {
+ output += '<ogc:' + tagName + '>' + makePropertyTag(rule.args || {}, opts) + '</ogc:' + tagName + '>';
+ }
+ else {
+ throw new Error('Unable to build OGC filter for rule type "' + (rule || {}).type + '"');
+ }
});
+ // if the number of rules is greater than 1, combine in an And clause
+ if (rules.length > 1) {
+ output = '<ogc:And>' + output + '</ogc:And>';
+ }
+
return output;
});
View
@@ -3,7 +3,10 @@
//=collate ogc-templates
var builders = {},
- templates = {};
+ templates = {},
+ propertyTags = {
+ gt: 'PropertyIsGreaterThan'
+ };
function makePropertyTag(args, opts) {
return templates.property(args);
@@ -34,15 +37,28 @@ geofilter.registerConverter('ogc', function(rules, opts) {
// iterate through the rules and generate the output
rules.forEach(function(rule) {
- var builder = builders[(rule || {}).type];
+ var type = (rule || {}).type,
+ builder = builders[type],
+ tagName = propertyTags[type];
// if we have a valid builder, then process
if (typeof builder == 'function') {
// run the builder
output += builder(rule.type, rule.args || {}, opts);
}
+ else if (tagName) {
+ output += '<ogc:' + tagName + '>' + makePropertyTag(rule.args || {}, opts) + '</ogc:' + tagName + '>';
+ }
+ else {
+ throw new Error('Unable to build OGC filter for rule type "' + (rule || {}).type + '"');
+ }
});
+ // if the number of rules is greater than 1, combine in an And clause
+ if (rules.length > 1) {
+ output = '<ogc:And>' + output + '</ogc:And>';
+ }
+
return output;
});
@@ -1,6 +0,0 @@
-<ogc:Filter>
- <ogc:PropertyIsGreaterThan>
- <ogc:PropertyName>DEPTH_M</ogc:PropertyName>
- <ogc:Literal>1000</ogc:Literal>
- </ogc:PropertyIsGreaterThan>
-</ogc:Filter>
@@ -0,0 +1,4 @@
+<ogc:PropertyIsGreaterThan>
+ <ogc:PropertyName>WEIGHT</ogc:PropertyName>
+ <ogc:Literal>20</ogc:Literal>
+</ogc:PropertyIsGreaterThan>
View
@@ -8,4 +8,10 @@ describe('OGC filter converter tests', function() {
converter: 'ogc',
targetFile: 'ogc/likeSand.xml'
}));
+
+ it('should be able to convert a single gt statement', comparator({
+ rules: [mockrules.heavierThan20],
+ converter: 'ogc',
+ targetFile: 'ogc/heavierThan20.xml'
+ }));
});

0 comments on commit 6481023

Please sign in to comment.