diff --git a/CHANGELOG.md b/CHANGELOG.md index 30d9a0815..a97c7d09d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). * catch omission of `new` keyword for `koop.Files` * Gracefully handle malformed esri geoms in geojson conversion * Revert Windows command line escaping, it was done improperly +* Always tranform datum for NAD83 exports ## [2.8.4] - 2015-09-24 ### Fixed diff --git a/lib/Exporter.js b/lib/Exporter.js index 160a5db01..29fd2e915 100644 --- a/lib/Exporter.js +++ b/lib/Exporter.js @@ -439,7 +439,13 @@ function moveFile (inFile, newFile, callback) { } }) } - +/** + * Fixes incorrect WKT Strings + * + * @param {string} inWkt - The original well-known text for the projection + * @param {integer} wkid - The well-known id for the projection + * @private + */ function fixWkt (inWkt, wkid) { // we have issue projecting this WKID w/o a datum xform // FYI there may be other proj codes needed here @@ -448,19 +454,27 @@ function fixWkt (inWkt, wkid) { case 3078: wkt = '+proj=omerc +lat_0=45.30916666666666 +lonc=-86 +alpha=337.25556 +k=0.9996 +x_0=2546731.496 +y_0=-4354009.816 + ellps=GRS80 +datum=NAD83 +units=m +no_defs' break - case 2927: - wkt = 'PROJCS["NAD83(HARN) / Washington South (ftUS)",GEOGCS["NAD83(HARN)",DATUM["NAD83_High_Accuracy_Regional_Network",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[-0.9956,1.9013,0.5215,0.025915,0.009426,0.011599,-0.00062],AUTHORITY["EPSG","6152"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4152"]],UNIT["US survey foot",0.3048006096012192,AUTHORITY["EPSG","9003"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",47.33333333333334],PARAMETER["standard_parallel_2",45.83333333333334],PARAMETER["latitude_of_origin",45.33333333333334],PARAMETER["central_meridian",-120.5],PARAMETER["false_easting",1640416.667],PARAMETER["false_northing",0],AUTHORITY["EPSG","2927"],AXIS["X",EAST],AXIS["Y",NORTH]]' - break case 28992: wkt = '+title=Amersfoort/Amersfoort +proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.999908 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs +towgs84=565.2369,50.0087,465.658,-0.406857330322398,0.350732676542563,-1.8703473836068,4.0812' break default: wkt = inWkt } + // per Melita Kennedy @esri This is the correct datum transformation to NAD83 for the variant of WGS84 used in recent data. See also: http://www.epsg-registry.org/ + if (wkt.match(/NAD83/)) return wkt.replace('TOWGS84[0,0,0,0,0,0,0]', 'TOWGS84[-0.9956,1.9013,0.5215,0.025915,0.009426,0.011599,-0.00062]') if (wkt.match(/UTM/)) return wkt.replace('TOWGS84[0,0,0,0,0,0,0]', 'TOWGS84[-0.9956,1.9013,0.5215,0.025915,0.009426,0.011599,-0.00062]') return wkt } +/** + * Gets a set of OGR Paramters for an export + + * @param {string} format - the output format + * @param {string} inFile - the geojson or vrt to use as a source + * @param {string} outFile - the file to write + * @param {object} geojson - a geojson object used in the xform + * @param {object} options - potentially contains a fields object + */ function getOgrParams (format, inFile, outFile, geojson, options, callback) { // escape quotes in file names inFile = inFile.replace(/"/g, '"') @@ -496,6 +510,14 @@ function getOgrParams (format, inFile, outFile, geojson, options, callback) { } } +/** + * Add parameters specific to a csv export + * + * @param {array} cmd - an array of OGR command parts to modify + * @param {object} options - may contain fields + * @return {array} + * @private + */ function csvParams (cmd, options) { var hasPointGeom = options.geometryType === 'Point' var fields = options.fields.join('|').toLowerCase().split('|') @@ -507,6 +529,14 @@ function csvParams (cmd, options) { return cmd } +/** + * Add parameters specific to a csv export + * + * @param {string} cmd - an array of OGR command parts to modify + * @param {object} options - may contain a wkid or wkt + * @param {function} callback - calls back back with a modified command array or an error + * @private + */ function shapefileParams (cmd, options, callback) { // make sure geometries are still written even if the first is null cmd.push('-nlt ' + options.geometryType.toUpperCase()) @@ -525,6 +555,11 @@ function shapefileParams (cmd, options, callback) { } } +/** + * Adds final parameters to the OGR function call + * @param {array} cmd - an array of OGR command parts to modify + * @return {string} the final OGR command + */ function finishOgrParams (cmd) { cmd.push('-update') cmd.push('-append') @@ -534,6 +569,12 @@ function finishOgrParams (cmd) { return cmd.join(' ') } +/** + * Gets projection information for a shapefile exprot + * @param {object} options - contains info on spatial reference, wkid and wkt + * @param {function} callback - calls back with an error or wkt + * @private + */ function addProjection (options, callback) { // if there is a passed in WKT just use that if (!options.sr) options.sr = {} diff --git a/test/models/exporter-test.js b/test/models/exporter-test.js index 181c33bca..9d45e38f3 100644 --- a/test/models/exporter-test.js +++ b/test/models/exporter-test.js @@ -226,7 +226,7 @@ describe('exporter Model', function () { exporter.getOgrParams(format, inFile, outFile, geojson, options, function (err, cmd) { should.not.exist(err) - cmd.should.equal('ogr2ogr --config SHAPE_ENCODING UTF-8 -f "ESRI Shapefile" outfile.shp infile.json -nlt POINT -t_srs \'PROJCS["NAD83 / California zone 6 (ftUS)",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4269"]],UNIT["US survey foot",0.3048006096012192,AUTHORITY["EPSG","9003"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",33.88333333333333],PARAMETER["standard_parallel_2",32.78333333333333],PARAMETER["latitude_of_origin",32.16666666666666],PARAMETER["central_meridian",-116.25],PARAMETER["false_easting",6561666.667],PARAMETER["false_northing",1640416.667],AUTHORITY["EPSG","2230"],AXIS["X",EAST],AXIS["Y",NORTH]]\' -fieldmap identity -update -append -skipfailures -lco ENCODING=UTF-8') + cmd.should.equal('ogr2ogr --config SHAPE_ENCODING UTF-8 -f "ESRI Shapefile" outfile.shp infile.json -nlt POINT -t_srs \'PROJCS["NAD83 / California zone 6 (ftUS)",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[-0.9956,1.9013,0.5215,0.025915,0.009426,0.011599,-0.00062],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4269"]],UNIT["US survey foot",0.3048006096012192,AUTHORITY["EPSG","9003"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",33.88333333333333],PARAMETER["standard_parallel_2",32.78333333333333],PARAMETER["latitude_of_origin",32.16666666666666],PARAMETER["central_meridian",-116.25],PARAMETER["false_easting",6561666.667],PARAMETER["false_northing",1640416.667],AUTHORITY["EPSG","2230"],AXIS["X",EAST],AXIS["Y",NORTH]]\' -fieldmap identity -update -append -skipfailures -lco ENCODING=UTF-8') done() }) })