| 1 |
var fs = require("fs"), |
| 2 |
vows = require("vows"), |
| 3 |
assert = require("assert"); |
| 4 |
|
| 5 |
var shapefile = require("../"); |
| 6 |
|
| 7 |
var suite = vows.describe("shapefile"); |
| 8 |
|
| 9 |
suite.addBatch({ |
| 10 |
"An empty shapefile": testConversion("empty"), |
| 11 |
"A shapefile with boolean properties": testConversion("boolean-property"), |
| 12 |
"A shapefile with numeric properties": testConversion("number-property"), |
| 13 |
"A shapefile with string properties": testConversion("string-property"), |
| 14 |
"A shapefile with mixed properties": testConversion("mixed-properties"), |
| 15 |
"A shapefile with date properties": testConversion("date-property"), |
| 16 |
"A shapefile with UTF-8 property names": testConversion("utf8-property", {encoding: "utf-8"}), |
| 17 |
"A shapefile with ISO-8859-1 property names": testConversion("latin1-property"), |
| 18 |
"A shapefile of points": testConversion("points"), |
| 19 |
"A shapefile of multipoints": testConversion("multipoints"), |
| 20 |
"A shapefile of polylines": testConversion("polylines"), |
| 21 |
"A shapefile of polygons": testConversion("polygons"), |
| 22 |
"A shapefile of null features": testConversion("null"), |
| 23 |
"ignoring properties": testConversion("ignore-properties", {"ignore-properties": true}) |
| 24 |
}); |
| 25 |
|
| 26 |
function fixActualProperties(feature) { |
| 27 |
for (var key in feature.properties) { |
| 28 |
if (feature.properties[key] == null) { |
| 29 |
delete feature.properties[key]; |
| 30 |
} |
| 31 |
} |
| 32 |
delete feature.properties.FID; // ogr2ogr built-in? |
| 33 |
} |
| 34 |
|
| 35 |
function fixExpectedProperties(feature) { |
| 36 |
var d = feature.properties.date; |
| 37 |
if (d) feature.properties.date = new Date(+d.substring(0, 4), d.substring(4, 6) - 1, +d.substring(6, 8)); |
| 38 |
} |
| 39 |
|
| 40 |
function testConversion(name, options) { |
| 41 |
return { |
| 42 |
topic: readCollection(name, options), |
| 43 |
"has the expected features": function(actual) { |
| 44 |
var expected = JSON.parse(fs.readFileSync("./test/" + name + ".json", "utf-8")); |
| 45 |
actual.features.forEach(fixActualProperties); |
| 46 |
expected.features.forEach(fixExpectedProperties); |
| 47 |
assert.deepEqual(actual, expected); |
| 48 |
} |
| 49 |
}; |
| 50 |
} |
| 51 |
|
| 52 |
function readCollection(name, options) { |
| 53 |
return function() { |
| 54 |
shapefile.read("./test/" + name + ".shp", options, this.callback); |
| 55 |
}; |
| 56 |
} |
| 57 |
|
| 58 |
suite.export(module); |