Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- //this script extracts source/destination values from .JSON (dataOut.json)
- let obj = require('./dataOut.json');
- var fs = require('fs');
- const source = [];
- const destination = [];
- // block is each section of the array
- obj.forEach(block => {
- //json variables
- const source_address = block.source_address;
- const source_lat = block.source_lat;
- const source_lng = block.source_lng;
- const scan_type = block.scan_type;
- module.exports = { scan_type: block.scan_type };
- //source contains the new object
- source.push({
- id: source_lat + source_lng,
- "source-lat": source_lat,
- "source-lng": source_lng,
- "source_address": source_address,
- x: {
- valueOf: function () {
- var latlng = [
- source_lat,
- source_lng
- ];
- var xy = map.FUNCTION_FOR_CONVERTING_LAT_LNG_TO_X_Y(latlng);
- return xy[0];
- }
- },
- y: {
- valueOf: function () {
- var latlng = [
- source_lat,
- source_lng
- ];
- var xy = map.FUNCTION_FOR_CONVERTING_LAT_LNG_TO_X_Y(latlng);
- return xy[1];
- }
- }
- });
- });
- obj.forEach(block => {
- //dest variables
- const dest_address = block.dest_address;
- const dest_lat = block.dest_lat;
- const dest_lng = block.dest_lng;
- const scan_type = block.scan_type;
- destination.push({
- id: dest_lat + dest_lng,
- "destination-lat": dest_lat,
- "destination-lng": dest_lng,
- "destination_address": dest_address,
- x: {
- valueOf: function () {
- var latlng = [
- dest_lat,
- dest_lng
- ];
- var xy = map.FUNCTION_FOR_CONVERTING_LAT_LNG_TO_X_Y(latlng);
- return xy[0];
- }
- },
- y: {
- valueOf: function () {
- var latlng = [
- dest_lat,
- dest_lng
- ];
- var xy = map.FUNCTION_FOR_CONVERTING_LAT_LNG_TO_X_Y(latlng);
- return xy[1];
- }
- }
- });
- });
- //write out and stringify
- fs.writeFile('./parentSource.json', JSON.stringify(source, null, 2), 'utf-8');
- fs.writeFile('./parentDestination.json', JSON.stringify(destination, null, 2), 'utf-8');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement