-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add tests for the new KML validator #71
Comments
Hey @GretaCB thanks for the thoughts! Lots of this came up during our push on Friday with @springmeyer as well. I believe the usage of Mapnik omnivore is where we were hitting the KML drivers - would be interesting to see if there's a light way to use it. Worth noting @BergWerkGIS has a PR open tha introduces GDAlL as well. Let's remove redundant code! |
@GretaCB I agree. That is check in |
@springmeyer Thanks for digging into this. I'm not as deeply familiar with the dependency trees. Does avoiding direct dependency on gdal, preclude/nullify an update allowing patch updates to gdal? |
Pausing here while we consider a different approach to KML validation: #69. |
Below I summarize my thoughts. The current solution in #68 feels not ideal to be. Below I've rehashed the problem and put forth a new solution as a straw dog that I hope @who8mycakes @GretaCB and @mapsam can help tune.
Give the above my sense is that we should revisit #68 and apply a fix that addresses the core problem more directly. I feel like the core problem is that the inefficiency of KML compounds given the way that Change mapbox-upload-validate like: diff --git a/lib/validate.js b/lib/validate.js
index 4e55d55..01c6341 100644
--- a/lib/validate.js
+++ b/lib/validate.js
@@ -9,6 +9,9 @@ var TileJSON = require('tilejson');
var Serialtiles = require('../lib/tilelive-serialtiles');
var Mapbox = require('../lib/tilelive-mapbox');
var invalid = require('./invalid');
+var uploadLimits = require('mapbox-upload-limits');
+var qs = require('querystring');
+var url = require('url');
Vector.registerProtocols(tilelive);
MBTiles.registerProtocols(tilelive);
@@ -36,7 +39,11 @@ module.exports.info = function validateInfo(uri, limits, callback) {
limits = { max_metadata: 60 * 1024 };
}
- tilelive.info(uri, function(err, info) {
+ var opts = url.parse(uri, true);
+ opts.pathname = qs.unescape(opts.pathname);
+ opts.query.layerLimit = uploadLimits.kml.layers;
+
+ tilelive.info(opts, function(err, info) {
if (err) return callback(invalid(err));
if (info.prepare) return callback(invalid('Source cannot contain prepare key'));
Change tilelive-omnivore like: diff --git a/index.js b/index.js
index a0b5c8c..0bf74f5 100644
--- a/index.js
+++ b/index.js
@@ -14,6 +14,7 @@ function Omnivore(uri, callback) {
uri = url.parse(uri, true);
var files = uri.pathname.split(',');
var layerName = uri.query.layerName ? decodeURI(uri.query.layerName) : null;
+ var layerLimit = uri.query.layerLimit ? +decodeURI(uri.query.layerLimit) : null;
var omnivore = this;
var q = queue();
@@ -26,6 +27,9 @@ function Omnivore(uri, callback) {
if (metadata.dstype === 'gdal' && metadata.raster.bands[0].rasterDatatype !== 'Byte') {
return next('Only 8 bit TIFFs are supported');
}
+ if (metadata.layers.length > layerLimit) {
+ return next(metadata.layers.length+ ' layers found. Maximum of ' + layerLimit + ' layers allowed.');
+ }
metadata.filepath = filepath;
next(null, metadata);
}); |
@springmeyer thanks for clearly writing down the root cause here. Super helpful explanation and I like the direction of the solution. Happy to help update tilelive-omnivore if need be. |
Awesome @springmeyer , thanks for this runthrough. Finally able to read it after a crazy week. I like the way you're thinking here: Typically, I aim to genericize/abstract code out as much as possible, but in this case, there's a reason for implementing the opposite. Love the emphasis on Per chat:
Option passed to tilelive-omnivoreEven though this layer limit is mapbox-specific, it is still based on what we've seen Mapnik can handle. So seems relevant to include this option for other devs to use and know about. Object passed to tilelive.infoCorrect me if I'm wrong, but this could potentially be a breaking change in tilelive.js cc @rclark |
Thanks for the review @GretaCB.
I don't think it is breaking:
👍 Correct, that is what I'm proposing I think in the second diff at #71 (comment). |
In the meantime, until we implement @springmeyer's approach to kml validation, tests to cover the kml validation currently in production have been added: #72. A suggested above, the tests cover:
|
Awesome, thanks @who8mycakes . Next actions will be to close this ticket out since it relates to KML tests, and open a new ticket with a plan forward for optimizing mapbox-upload-validate and removing redundant code (per comments above). |
@who8mycakes Awesome job with debugging here, and a successful #FridayDeploy :) Here are some of my thoughts going forward.
Tests
Now that we have a new kml validation script, we'll need tests for the new script.
At bare minimum, some the tests I'm seeing needed would recreate the following error cases:
x layers found. Maximum of y layers allowed.
No duplicate layers allowed.
gdal.open()
Remove redundant code
Also, looks like some of the same logic is within two other places:
We should remove the excess layer-validation logic to avoid future confusion about where exactly this takes place in tileset-unpacker. Let's be kind to our future selves :)
Optimize use of dependencies
Also, curious if
gdal
is needed in order to find layer count. Is it possible to usemapnik-omnivore
since it's already a dependency? This would help avoid adding a pretty substantial dependency (gdal
). Not sure if this was part of your convo with @mapsam last week.cc @mapbox/unpacker
The text was updated successfully, but these errors were encountered: