Created
August 1, 2013 00:32
-
-
Save rclark/6127516 to your computer and use it in GitHub Desktop.
Trying to mine data from FEMA National Flood Hazard Layer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require("fs"), | |
_ = require("underscore"), | |
request = require("request"), | |
baseUrl = "https://hazards.fema.gov/gis/nfhl/rest/services/public/NFHL/MapServer/28", | |
outEsri = JSON.stringify({"displayFieldName":"DFIRM_ID","fieldAliases":{"FLD_ZONE":"FLD_ZONE","ZONE_SUBTY":"ZONE_SUBTY"},"fields":[{"name":"FLD_ZONE","type":"esriFieldTypeString","alias":"FLD_ZONE","length":17},{"name":"ZONE_SUBTY","type":"esriFieldTypeString","alias":"ZONE_SUBTY","length":57}]}), | |
outFile = fs.createWriteStream("fema-get-all-esri.json"); | |
outFile.write(outEsri + ",features:["); | |
request(baseUrl + "?f=json", function (err, response, information) { | |
if (err) {throw err; return;} | |
var info = JSON.parse(information), | |
wanted = _.filter(info.drawingInfo.renderer.uniqueValueInfos, function (symbol) { | |
return symbol.label === "1% Annual Chance Flood Hazard" || symbol.label === "0.2% Annual Chance Flood Hazard"; | |
}), | |
params = _.map(wanted, function (symbol) { | |
var parts = symbol.value.split(", "), | |
fld = parts[0] === "<Null>" ? "+is+Null" : "%3D'" + parts[0] + "'"; | |
sub = parts[1] === "<Null>" ? "+is+Null" : "%3D'" + parts[1] + "'"; | |
return "&where=FLD_ZONE" + fld + "+and+ZONE_SUBTY" + sub; | |
}), | |
queryUrl = baseUrl + "/query?f=json&geometryType=esriGeometryEnvelope&geometry=-114.97192382812499,31.302021690136105,-108.77014160156249,37.13842453422676&inSR=4326&spatialRel=esriSpatialRelIntersects&returnGeometry=true&outFields=FLD_ZONE,ZONE_SUBTY&outSr=4326"; | |
params.forEach(function (where) { | |
request(queryUrl + where, function (err, response, data) { | |
if (err) {throw err; return;} | |
var esriJson = JSON.parse(data); | |
if (esriJson.exceededTransferLimit) { | |
console.log("\n" + where + " exceeded transfer limit"); | |
} else { | |
esriJson.features.forEach(function (feature) { | |
outFile.write(JSON.stringify(feature) + ","); | |
}) | |
} | |
}); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment