featureservice
Advanced tools
Comparing version 1.5.13 to 1.6.0
@@ -5,2 +5,6 @@ # Change Log | ||
## [1.6.0] - 2018-06-19 | ||
### Added | ||
* Check for an option `outSR` and if provided use it to transform data; if no outSR option default to `outSR=4326` | ||
## [1.5.13] - 2018-01-31 | ||
@@ -241,2 +245,3 @@ ### Fixed | ||
[1.6.0]: https://github.com/koopjs/featureservice/compare/v1.5.13...v1.6.0 | ||
[1.5.13]: https://github.com/koopjs/featureservice/compare/v1.5.12...v1.5.13 | ||
@@ -243,0 +248,0 @@ [1.5.12]: https://github.com/koopjs/featureservice/compare/v1.5.11...v1.5.12 |
21
index.js
@@ -27,2 +27,3 @@ var queue = require('async').queue | ||
this.layer = this.options.layer || service.layer || 0 | ||
this.outSR = this.options.outSR || 4326 | ||
@@ -75,3 +76,3 @@ this.logger = this.options.logger | ||
*/ | ||
// TODO combine this with _requestFeatures | ||
// TODO combine this with _requestFeatures | ||
FeatureService.prototype.request = function (url, callback) { | ||
@@ -329,3 +330,3 @@ var json | ||
if (err) return callback(err) | ||
if (meta.count < meta.layer.maxRecordCount && meta.count < this.options.size) return callback(null, singlePage(this.server, this.layer)) | ||
if (meta.count < meta.layer.maxRecordCount && meta.count < this.options.size) return callback(null, singlePage(this.server, this.layer, this.outSR)) | ||
this.concurrency = this.options.concurrency || Utils.setConcurrency(this.hosted, meta.layer.geometryType) | ||
@@ -369,4 +370,10 @@ this.maxConcurrency = this.concurrency | ||
function singlePage (server, layer) { | ||
return [{req: [server, '/', layer, '/query?where=1=1&returnGeometry=true&returnZ=true&outFields=*&outSR=4326&f=json'].join('')}] | ||
/** | ||
* Handle feature server request where total number of features can be acquired in a single page | ||
* @param {*} server | ||
* @param {*} layer | ||
* @param {integer} outSR - wkid of output spatial reference | ||
*/ | ||
function singlePage (server, layer, outSR = 4326) { | ||
return [{req: [server, '/', layer, '/query?where=1=1&returnGeometry=true&returnZ=true&outFields=*&outSR=' + outSR + '&f=json'].join('')}] | ||
} | ||
@@ -420,3 +427,3 @@ | ||
resultOffset = i * size | ||
var pageUrl = url + '/' + this.layer + '/query?outSR=4326&f=json&outFields=*&where=1=1' | ||
var pageUrl = url + '/' + this.layer + '/query?outSR=' + this.outSR + '&f=json&outFields=*&where=1=1' | ||
if (pages === 1) return [{req: pageUrl + '&geometry=&returnGeometry=true&returnZ=true&geometryPrecision='}] | ||
@@ -450,3 +457,3 @@ pageUrl += '&resultOffset=' + resultOffset | ||
var where = [oidField, ' >= ', pageMin, ' AND ', oidField, '<=', pageMax].join('') | ||
var pageUrl = this.server + '/' + (this.layer) + '/query?outSR=4326&where=' + where + '&f=json&outFields=*' | ||
var pageUrl = this.server + '/' + (this.layer) + '/query?outSR=' + this.outSR + '&where=' + where + '&f=json&outFields=*' | ||
pageUrl += '&geometry=&returnGeometry=true&returnZ=true&geometryPrecision=10' | ||
@@ -489,3 +496,3 @@ reqs.push({req: pageUrl}) | ||
where = [objId, '>=', pageMin, '+AND+', objId, '<=', pageMax].join('') | ||
pageUrl = url + '/' + (this.layer || 0) + '/query?outSR=4326&where=' + where + '&f=json&outFields=*' | ||
pageUrl = url + '/' + (this.layer || 0) + '/query?outSR=' + this.outSR + '&where=' + where + '&f=json&outFields=*' | ||
pageUrl += '&geometry=&returnGeometry=true&returnZ=true&geometryPrecision=' | ||
@@ -492,0 +499,0 @@ reqs.push({req: pageUrl}) |
{ | ||
"name": "featureservice", | ||
"description": "Get all features from an Esri Feature Service", | ||
"version": "1.5.13", | ||
"version": "1.6.0", | ||
"author": "Chris Helm", | ||
@@ -9,3 +9,5 @@ "bugs": { | ||
}, | ||
"contributors": ["Daniel Fenton"], | ||
"contributors": [ | ||
"Daniel Fenton" | ||
], | ||
"dependencies": { | ||
@@ -24,4 +26,4 @@ "async": "^2.1.5", | ||
"standard": "^10.0.0", | ||
"tap-spec": "^4.0.2", | ||
"tape": "^4.0.1", | ||
"tap-spec": "^4.1.2", | ||
"tape": "^4.9.1", | ||
"zlib-browserify": "0.0.3" | ||
@@ -28,0 +30,0 @@ }, |
@@ -71,3 +71,3 @@ var sinon = require('sinon') | ||
test('build offset pages', function (t) { | ||
test('build range pages', function (t) { | ||
var pages | ||
@@ -84,2 +84,13 @@ var stats = {min: 0, max: 2000} | ||
test('build range pages with output spatial reference 4629', function (t) { | ||
var pages | ||
var stats = {min: 0, max: 2000} | ||
var service = new FeatureService('http://koop.dc.esri.com/socrata/seattle/2tje-83f6/FeatureServer/1', {objectIdField: 'OBJECTID', outSR: 4629}) | ||
pages = service._rangePages(stats, stats.max / 2, true) | ||
t.equal(pages[0].req, 'http://koop.dc.esri.com/socrata/seattle/2tje-83f6/FeatureServer/1/query?outSR=4629&where=OBJECTID>=0+AND+OBJECTID<=999&f=json&outFields=*&geometry=&returnGeometry=true&returnZ=true&geometryPrecision=') | ||
t.equal(pages[1].req, 'http://koop.dc.esri.com/socrata/seattle/2tje-83f6/FeatureServer/1/query?outSR=4629&where=OBJECTID>=1000+AND+OBJECTID<=2000&f=json&outFields=*&geometry=&returnGeometry=true&returnZ=true&geometryPrecision=') | ||
t.equal(pages.length, 2) | ||
t.end() | ||
}) | ||
test('build id based pages', function (t) { | ||
@@ -96,2 +107,14 @@ var ids = [0, 1, 2, 3, 4, 5] | ||
test('build id based pages with output spatial reference 4629', function (t) { | ||
var ids = [0, 1, 2, 3, 4, 5] | ||
var maxCount = 2 | ||
var service = new FeatureService('http://koop.dc.esri.com/socrata/seattle/2tje-83f6/FeatureServer/1', {objectIdField: 'OBJECTID', outSR: 4629}) | ||
var pages = service._idPages(ids, maxCount, true) | ||
t.equal(pages.length, 3) | ||
t.equal(pages[0].req, 'http://koop.dc.esri.com/socrata/seattle/2tje-83f6/FeatureServer/1/query?outSR=4629&where=OBJECTID >= 0 AND OBJECTID<=1&f=json&outFields=*&geometry=&returnGeometry=true&returnZ=true&geometryPrecision=10') | ||
t.equal(pages[1].req, 'http://koop.dc.esri.com/socrata/seattle/2tje-83f6/FeatureServer/1/query?outSR=4629&where=OBJECTID >= 2 AND OBJECTID<=3&f=json&outFields=*&geometry=&returnGeometry=true&returnZ=true&geometryPrecision=10') | ||
t.equal(pages[2].req, 'http://koop.dc.esri.com/socrata/seattle/2tje-83f6/FeatureServer/1/query?outSR=4629&where=OBJECTID >= 4 AND OBJECTID<=5&f=json&outFields=*&geometry=&returnGeometry=true&returnZ=true&geometryPrecision=10') | ||
t.end() | ||
}) | ||
test('build result offset pages', function (t) { | ||
@@ -103,3 +126,12 @@ var maxCount = 100 | ||
t.equal(pages.length, 4) | ||
t.end() | ||
}) | ||
test('build result offset pages with output spatial reference 4629', function (t) { | ||
var maxCount = 100 | ||
var service = new FeatureService('http://koop.dc.esri.com/socrata/seattle/2tje-83f6/FeatureServer/1', {objectIdField: 'OBJECTID', outSR: 4629}) | ||
var pages = service._offsetPages(4, maxCount, true) | ||
t.equal(pages[0].req, 'http://koop.dc.esri.com/socrata/seattle/2tje-83f6/FeatureServer/1/query?outSR=4629&f=json&outFields=*&where=1=1&resultOffset=0&resultRecordCount=100&geometry=&returnGeometry=true&returnZ=true&geometryPrecision=') | ||
t.equal(pages[1].req, 'http://koop.dc.esri.com/socrata/seattle/2tje-83f6/FeatureServer/1/query?outSR=4629&f=json&outFields=*&where=1=1&resultOffset=100&resultRecordCount=100&geometry=&returnGeometry=true&returnZ=true&geometryPrecision=') | ||
t.equal(pages.length, 4) | ||
t.end() | ||
@@ -572,3 +604,2 @@ }) | ||
service._requestFeatures(task, function (err) { | ||
t.equal(err.code, 504) | ||
t.equal(err.url, 'http://www.foobar.com/FeatureServer/0/query?where=1=1') | ||
@@ -575,0 +606,0 @@ t.end() |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
593562
1143
1