Advertisement
Guest User

Untitled

a guest
Aug 4th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. 'use strict';
  2.  
  3. //this script extracts source/destination values from .JSON (dataOut.json)
  4.  
  5. let obj = require('./dataOut.json');
  6. var fs = require('fs');
  7.  
  8. const source = [];
  9. const destination = [];
  10. // block is each section of the array
  11. obj.forEach(block => {
  12. //json variables
  13. const source_address = block.source_address;
  14. const source_lat = block.source_lat;
  15. const source_lng = block.source_lng;
  16. const scan_type = block.scan_type;
  17. module.exports = { scan_type: block.scan_type };
  18. //source contains the new object
  19. source.push({
  20. id: source_lat + source_lng,
  21. "source-lat": source_lat,
  22. "source-lng": source_lng,
  23. "source_address": source_address,
  24. x: {
  25. valueOf: function () {
  26. var latlng = [
  27. source_lat,
  28. source_lng
  29. ];
  30. var xy = map.FUNCTION_FOR_CONVERTING_LAT_LNG_TO_X_Y(latlng);
  31. return xy[0];
  32. }
  33. },
  34. y: {
  35. valueOf: function () {
  36. var latlng = [
  37. source_lat,
  38. source_lng
  39. ];
  40. var xy = map.FUNCTION_FOR_CONVERTING_LAT_LNG_TO_X_Y(latlng);
  41. return xy[1];
  42. }
  43. }
  44. });
  45. });
  46.  
  47. obj.forEach(block => {
  48. //dest variables
  49. const dest_address = block.dest_address;
  50. const dest_lat = block.dest_lat;
  51. const dest_lng = block.dest_lng;
  52. const scan_type = block.scan_type;
  53. destination.push({
  54. id: dest_lat + dest_lng,
  55. "destination-lat": dest_lat,
  56. "destination-lng": dest_lng,
  57. "destination_address": dest_address,
  58. x: {
  59. valueOf: function () {
  60. var latlng = [
  61. dest_lat,
  62. dest_lng
  63. ];
  64. var xy = map.FUNCTION_FOR_CONVERTING_LAT_LNG_TO_X_Y(latlng);
  65. return xy[0];
  66. }
  67. },
  68. y: {
  69. valueOf: function () {
  70. var latlng = [
  71. dest_lat,
  72. dest_lng
  73. ];
  74. var xy = map.FUNCTION_FOR_CONVERTING_LAT_LNG_TO_X_Y(latlng);
  75. return xy[1];
  76. }
  77. }
  78. });
  79. });
  80. //write out and stringify
  81. fs.writeFile('./parentSource.json', JSON.stringify(source, null, 2), 'utf-8');
  82. fs.writeFile('./parentDestination.json', JSON.stringify(destination, null, 2), 'utf-8');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement