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

[NOT READY] Add initial support for FileGDB format #73

Closed
wants to merge 1 commit into from
Closed
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
43 changes: 40 additions & 3 deletions lib/datasource-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ function getProjection(file, filetype, callback) {
if (err) return callback(err);
return callback(null, proj);
});
//else kml and gpx
} else if(filetype === '.gdb') {
projectionViaOGR(file, function(err, proj) {
if (err) return callback(err);
return callback(null, proj);
});
//else kml, gpx, geojson, and csv we assume is WGS84 (aka +init=epsg:4326 or +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs)
}
else return callback(null, '+init=epsg:4326');
}
Expand Down Expand Up @@ -438,6 +443,37 @@ function projectionFromRaster(filepath, callback) {

callback(null, info);
}

/**
* Obtains projection from any ogr vector format by using node-gdal lib
* @param file (filepath)
* @returns result.proj4
*/
function projectionViaOGR(filepath, callback) {

var ds;
try { ds = gdal.open(filepath); }
catch(err) {
return callback(invalid('could not open the file ' + filepath));
}

if (!ds || !ds.layers || ds.layers.count() < 1) {
return callback(invalid('file has no valid layers: ' + filepath));
}
// FIXME: https://github.com/mapbox/mapnik-omnivore/issues/72
if (ds.layers.count() > 1) {
return callback(invalid('No support yet for multilayer files inside ' + filepath));
} else {
try {
var proj4 = srs.parse(ds.layers.get(0).srs.toWKT()).proj4;
if (proj4) return callback(null,proj4);
} catch(err) {
console.error(err.stack);
}
}
return callback(invalid('could not read spatial reference information for ' + filepath));
}

/**
* Iterates through source's bands and obtains band properties
* @param ds (Datasource)
Expand Down Expand Up @@ -565,7 +601,7 @@ function getDatasourceProperties(file, filetype, callback) {
}

// Get layers for kml or topojson
else if (filetype === '.kml' || filetype === '.topojson') {
else if (filetype === '.kml' || filetype === '.topojson' || filetype === '.gdb') {
// Get KML layer names from the OGR error message...for now
getLayers(options, function(err, layers) {
if (err) return callback(err);
Expand Down Expand Up @@ -657,5 +693,6 @@ module.exports = {
getMinMaxZoomGDAL: getMinMaxZoomGDAL,
getProjection: getProjection,
projectionFromRaster: projectionFromRaster,
projectionFromShape: projectionFromShape
projectionFromShape: projectionFromShape,
projectionViaOGR: projectionViaOGR
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"tape": "3.0.x",
"coveralls": "~2.11.1",
"istanbul": "~0.3.0",
"mapnik-test-data": "http://mapbox-npm.s3.amazonaws.com/package/mapnik-test-data-2.0.3-fece0a9c546074a1479e9eae2333184029bb2279.tgz"
"mapnik-test-data": "https://github.com/mapbox/mapnik-test-data/tarball/moar"
},
"scripts": {
"test": "tape test/*.js",
Expand Down
18 changes: 18 additions & 0 deletions test/datasource-processor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var expectedMetadata_1week_earthquake = JSON.parse(fs.readFileSync(path.resolve(
var expectedMetadata_sample_tif = JSON.parse(fs.readFileSync(path.resolve('test/fixtures/metadata_sample_tif.json')));
var expectedMetadata_sample_vrt = JSON.parse(fs.readFileSync(path.resolve('test/fixtures/metadata_sample_vrt.json')));
var expectedMetadata_topo = JSON.parse(fs.readFileSync(path.resolve('test/fixtures/metadata_topo.json')));
var expectedMetadata_filegdb = JSON.parse(fs.readFileSync(path.resolve('test/fixtures/metadata_filegdb.json')));

var UPDATE = process.env.UPDATE;

Expand Down Expand Up @@ -201,6 +202,23 @@ var UPDATE = process.env.UPDATE;
/**
* Testing datasourceProcessor.init
*/
tape('[FILEGDB] Setup', function(assert) {
var gdbFile = testData + '/data/filegdb/multipoint.gdb';
var filesize = 428328; // N/A since it is a directory!
var type = '.gdb';
//Overwrites metadata json file if output does not match
datasourceProcessor.init(gdbFile, filesize, type, function(err, metadata) {
if (err) {
assert.ifError(err, 'should not error');
return assert.end();
}
if (UPDATE) fs.writeFileSync(path.resolve('test/fixtures/metadata_filegdb.json'), JSON.stringify(metadata, null, 2));
assert.deepEqual(metadata, expectedMetadata_filegdb);

assert.end();
});
});

tape('[SHAPE] Setup', function(assert) {
var shpFile = testData + '/data/shp/world_merc/world_merc.shp';
var filesize = 428328;
Expand Down
33 changes: 33 additions & 0 deletions test/fixtures/metadata_filegdb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"filesize": 428328,
"projection": "+proj=utm +zone=18 +datum=WGS84 +units=m +no_defs",
"filename": "multipoint",
"center": [
-75.16024141355962,
39.95769202781635
],
"extent": [
-75.16026089315217,
39.9576802349116,
-75.16022193396708,
39.9577038207211
],
"json": {
"vector_layers": [
{
"id": "multipoint",
"description": "",
"minzoom": 0,
"maxzoom": 22,
"fields": {}
}
]
},
"minzoom": 0,
"maxzoom": 22,
"layers": [
"multipoint"
],
"dstype": "ogr",
"filetype": ".gdb"
}