Created
May 22, 2018 19:05
-
-
Save loganpowell/d918d3439d06115691700c4f721c30aa to your computer and use it in GitHub Desktop.
TODOS
This file contains hidden or 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 fetch = require("node-fetch"); | |
| var WKT = require("terraformer-wkt-parser"); | |
| var ramda = require("ramda"); | |
| require("dotenv").load(); | |
| var testWKT = WKT.convert({ | |
| type: "Polygon", | |
| coordinates: [ | |
| [[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]], | |
| [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]] | |
| ] | |
| }); | |
| var rawTigerConfig = ({ | |
| geometryType, | |
| spatialRelationship, | |
| geometry, | |
| source, | |
| scope, | |
| vintage, | |
| outFields | |
| }) => { | |
| let string = | |
| "https://cors-anywhere.herokuapp.com/https://tigerweb.geo.census.gov/arcgis/rest/services/" + | |
| source + "/" + // "TIGERweb" | |
| vintage + // "tigerWMS_ACS2016" | |
| "/MapServer/" + scope + // "84" | |
| "/query?geometry=" + geometry + // <- lng,lat | |
| "&geometryType=" + geometryType + | |
| "&inSR=4269&spatialRel=" + spatialRelationship + | |
| "&outFields=" + outFields + // "STATE" | |
| "&returnGeometry=false&f=geojson"; | |
| return string; | |
| }; | |
| var testConfigObj = { | |
| geometry: "-87.0722,31.1052", // <- concat coord array input | |
| source: "TIGERweb", | |
| vintage: "tigerWMS_ACS2016", | |
| outFields: "STATE", | |
| scope: "84" | |
| }; | |
| var geoPointOpts = { | |
| geometryType: "esriGeometryPoint", | |
| spatialRelationship: "esriSpatialRelIntersects" | |
| } | |
| var point2Fips = (customOpts) => { | |
| let opts = R.merge( // <- merge objects to create single obj arg | |
| geoPointOpts, | |
| customOpts | |
| ) | |
| return rawTigerConfig(opts) | |
| } | |
| var simpleFips = point2Fips(testConfigObj) // => "https://cors-anywhere.herokuapp.com/https://tigerweb.geo.census.gov/arcgis/rest/services/TIGERweb/tigerWMS_ACS2016/MapServer/84/query?geometry=-87.0722,31.1052&geometryType=esriGeometryPoint&inSR=4269&spatialRel=esriSpatialRelIntersects&outFields=STATE&returnGeometry=false&f=geojson" | |
| var tigerFetch = configObj => fetch(point2Fips(configObj)); | |
| var jsonify = response => response.json() | |
| var fipsScopeConfig = (scope) => R.pipeP( | |
| tigerFetch, | |
| jsonify, // sync | |
| R.view(R.lensPath(["features", 0, "properties", scope])), | |
| R.tap(console.log) | |
| ) | |
| var getFipsByLngLat = fipsScopeConfig("STATE") | |
| getFipsByLngLat(testConfigObj) // => 01 **Woot** | |
| /* === === === START NOTES === === === | |
| // Examples based on this query | |
| var queryEx = https://tigerweb.geo.census.gov/arcgis/rest/services/TIGERweb/tigerWMS_ACS2016/MapServer/84/query?geometry=-87.0722,31.1052&geometryType=esriGeometryPoint&inSR=4269&spatialRel=esriSpatialRelIntersects&outFields=STATE&returnGeometry=false&f=geojson | |
| // ========== TODO: | |
| 1: Discect Tigerweb taxonomy to configure inputs for all endpoints: | |
| https://tigerweb.geo.census.gov/tigerwebmain/TIGERweb_wms.html | |
| ?: get geo_level fips with an input geometry | |
| var geoFrameOpts = { | |
| geometryType: "esriGeometryEnvelope", | |
| spatialRelationship: "esriSpatialRelContains" | |
| } | |
| // ========== FURTHER STUDIES: | |
| // Piping promises (1) | |
| const program = (...list) => acc => | |
| R.flatten(list).reduce((acc,fn) => acc.then(fn), Promise.resolve(acc)); | |
| // Study in composition (2) | |
| var tree = {a: [ { b: 'hey' } ] }; | |
| var findIn = R.curry((path, obj) => | |
| R.compose( | |
| R.view(R.__, obj), // R.__ takes the composed path | |
| R.apply(R.compose), | |
| R.map( | |
| R.cond([ | |
| [R.is(Number), R.lensIndex], | |
| [R.T, R.lensProp] | |
| ]) | |
| ) | |
| )(path) | |
| ) | |
| findIn(['a', 0, 'b'], tree); // => "hey" | |
| // ========== SOURCES: | |
| (1) https://medium.com/@dtipson/more-functional-javascript-reducing-promises-ramda-js-arrow-functions-again-c1f90e0a79d0 | |
| (2) https://github.com/ramda/ramda/issues/1816 | |
| // === === === END NOTES === === === */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment