Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A computer made me// TODO: Make this a configuration option
- var knex = require("knex")({
- client: "pg",
- connection: {
- host: "localhost",
- user: "postgres",
- password: "",
- database: "geodb"
- },
- pool: { min: 0, max: 7 }
- });
- const argv = require("yargs").argv;
- const uuidv4 = require("uuid/v4");
- const prompts = require("prompts");
- const fs = require("fs");
- const fsPromises = fs.promises;
- const dropstream = require("dropbox-stream");
- const shapefile = require("shapefile");
- const util = require("util");
- const exec = util.promisify(require("child_process").exec);
- const path = require("path");
- const turf = require("turf");
- const dropboxAccessToken = process.env.DROPBOX_ACCESS_TOKEN;
- const silent = argv.silent;
- const fieldMaps = {};
- const relationMaps = {};
- let downloadFilesAgain = false;
- const writeToFile = (contents) => {
- fs.appendFileSync(`migrate_logs.txt`, contents);
- }
- // This function will do an update on insertion conflict
- // It uses the unique() method of knex to determine what
- // keys there are to avoid on update. Meaning that key
- // groupins on rows must be mutually unique as a set ?
- // Not sure that the above means aside from a,b and a,c
- // were a b and c are unique would cost unintended results
- // as a,b would be updated by a,c but retain a,b keys
- function insertOrUpdate(knex, tableName, data, fields, uniques) {
- const exclusions = Object.keys(data)
- .filter(c => uniques.indexOf(c) < 0)
- .map(c => knex.raw("?? = EXCLUDED.??", [c, c]).toString())
- .join(",\n");
- const insertString = knex(tableName)
- .insert(data)
- .toString();
- let conflictString = "";
- // If we have uniques && we have non uniques ... yes, this can happen :D
- const nonUniques = fields.filter(f => uniques.indexOf(f) < 0).length;
- if (nonUniques) {
- conflictString = knex
- .raw(
- ` ON CONFLICT (??) DO UPDATE SET ${exclusions} RETURNING *;`,
- uniques.join(", ")
- )
- .toString();
- } else {
- conflictString = knex.raw(` ON CONFLICT DO NOTHING;`).toString();
- }
- const query = (insertString + conflictString).replace(/\?/g, "\\?");
- return knex.raw(query);
- }
- // This is the main function where seeds the database. Its not the
- // most apt naming. 'silent' is a last minute addition that
- // automatically downloads data and seeds using all shapefiles.
- const runMigrationWith = async (
- zipfile,
- insertTableName,
- migration,
- statecode
- ) => {
- if (
- !silent &&
- (await prompts({
- type: "toggle",
- name: "value",
- message: `Process ${insertTableName} for ${zipfile}`,
- initial: false,
- active: "yes",
- inactive: "no"
- })).value === false
- ) {
- return;
- }
- const dropboxPath = zipfile.replace(/data/, "");
- const folderPath = /(.*(?:\/|\\)).*/.exec(zipfile)[1];
- const filename = /.*(?:\/|\\)(.*)/.exec(zipfile)[1];
- // Download source files again
- if (downloadFilesAgain) {
- await fsPromises.mkdir(folderPath, { recursive: true });
- console.log(`Downloading ${filename}`);
- await new Promise(function(resolve, reject) {
- dropstream
- .createDropboxDownloadStream({
- token: dropboxAccessToken,
- path: dropboxPath
- })
- .on("error", err => {
- console.log(err);
- reject(err);
- })
- .on("metadata", metadata => (meta = metadata))
- .pipe(fs.createWriteStream(zipfile))
- .on("finish", () => {
- console.log("Done!");
- resolve(true);
- });
- });
- console.log(`Decompressing ${filename}`);
- //require('child_process').execSync(`cd ${folderPath} && unzip -o ${filename}`, (err, stdout, stderr) => {
- // Drop errors
- //});
- console.log("Done!");
- }
- const insertion = {};
- let zipEntries = null;
- await new Promise((resolve, reject) => {
- exec(`cd ${folderPath} && unzip -l ${filename}`, (err, stdout, stderr) => {
- resolve(stdout);
- });
- })
- .then(data => (zipEntries = data))
- .catch(err => console.error(err));
- console.log("got zipEntries", zipEntries);
- const shpRegex = /([^\s]+\.shp)$/gm;
- let shpFiles = [];
- // Go through all the files in the zip
- let match;
- while ((match = shpRegex.exec(zipEntries))) {
- const zipEntry = match[1];
- if (!zipEntry.startsWith("__MAC")) {
- // Do not want these __MAC things
- shpFiles.push(zipEntry);
- }
- }
- // Sort to ensure order
- shpFiles = shpFiles.sort();
- for (let iZipEntry = 0; iZipEntry < shpFiles.length; iZipEntry++) {
- const zipEntry = shpFiles[iZipEntry];
- const safeEntryName = zipEntry.replace(/(\.|\/|\\)/g, "_");
- // Ask to seed. Useful incase we are just seeding bits and pieces
- if (
- silent ||
- (await prompts({
- type: "toggle",
- name: "value",
- message: `Seed ${insertTableName} with ${zipEntry}`,
- initial: false,
- active: "yes",
- inactive: "no"
- })).value === true
- ) {
- console.log(`Processing ${zipEntry}`);
- writeToFile(`Processing ZIPENTRY: ${zipEntry}\n`);
- console.log('opening source');
- writeToFile('opening source\n');
- writeToFile(`Opening FolderPath and ZipEntry: ${folderPath} ${zipEntry}\n`);
- const source = await shapefile.open(path.join(folderPath, zipEntry));
- console.log('processing source');
- writeToFile(`Processing Source: ${source}\n`);
- const fieldMapping = fieldMaps[safeEntryName];
- const relationMapping = relationMaps[safeEntryName];
- if (!fieldMapping) continue; // We did not map this, so skip it :D
- let result = await source.read(); // reads each feature in the shapefile
- console.log('init source read');
- writeToFile(`init source read\n`);
- do {
- try {
- let validInsertion = true;
- for (let fieldName in fieldMapping) {
- console.log(`FN: ${fieldName}`);
- writeToFile(`FN: ${fieldName}\n`);
- // Special case, geometry
- if (fieldName === "geom") {
- const geojson = JSON.stringify(result.value.geometry);
- /*
- // The insertion will be deemed invalid if there is unsupported geometry
- if (/(line|point|collection)/gi.test(geojson)) {
- validInsertion = false;
- } else
- */
- {
- insertion[fieldName] = knex.raw(
- `ST_SetSRID(ST_MakeValid(ST_GeomFromGeoJSON('${geojson}')), 4326)`
- );
- }
- }
- // Special case, uuid
- else if (fieldName === "uuid") {
- insertion[fieldName] = uuidv4();
- }
- // Special case shape_area
- else if (fieldName === "shape_area") {
- if (fieldMapping[fieldName] === "") {
- insertion[fieldName] = turf.area(result.value.geometry);
- }
- }
- // Special case, county if not directly specified
- else if (fieldName === "county") {
- if (fieldMapping[fieldName] === "") {
- const maria = /\/Parcels_(.*)_Co/.exec(zipEntry); // naming convention 1
- const loveland = /\w{2}_(.*)\./.exec(zipEntry); // naming convention 2
- if (maria && maria.length > 1) {
- insertion[fieldName] = maria[1].toLowerCase();
- } else if (loveland && loveland.length > 1) {
- insertion[fieldName] = loveland[1].toLowerCase();
- }
- } else {
- insertion[fieldName] = result.value.properties[
- fieldMapping[fieldName]
- ].toLowerCase();
- }
- }
- // Special case, state if not directly specified
- else if (fieldName === "state" && fieldMapping[fieldName] === "") {
- insertion[fieldName] = statecode.toUpperCase();
- }
- // Special case, any field that is also denoted by "referecnes"
- else if (
- migration.references &&
- fieldName in migration.references
- ) {
- // This is a refernec e so we need to go the extra mile
- const refTable = /(.*)\./.exec(
- migration.references[fieldName]
- )[1];
- const ref = /.*\.(.*)/.exec(migration.references[fieldName])[1];
- const condition = {};
- condition[relationMapping[fieldName]] =
- result.value.properties[fieldMapping[fieldName]];
- // Try to find an existing match
- let r = await knex(refTable)
- .select(ref)
- .where(condition);
- // If there is not linking element, we insert one that satisfies our conditions
- if (!r.length) {
- // console.log("inserting");
- let q = await knex(refTable).insert(condition);
- // console.log(q);
- r = await knex(refTable)
- .select(ref)
- .where(condition);
- }
- insertion[fieldName] = r[0][ref];
- }
- // Otherwise we map if none is provided
- else if (
- fieldMapping[fieldName] !== "" &&
- fieldMapping[fieldName] !== "NONE" &&
- result.value.properties // for when the dbf exceeds the max size of 2.15GB and we literally run out of data ... :(
- ) {
- insertion[fieldName] =
- result.value.properties[fieldMapping[fieldName]];
- }
- // Unit conversion
- if (fieldMapping[fieldName].toLowerCase().indexOf("acre") >= 0) {
- insertion[fieldName] = 4046.86 * insertion[fieldName];
- } else if (
- fieldMapping[fieldName].toLowerCase().indexOf("sqft") >= 0
- ) {
- insertion[fieldName] = 0.092903 * insertion[fieldName];
- }
- }
- let cache = [];
- // console.log(JSON.stringify(insertion, function(key, value) {
- // if (typeof value === 'object' && value !== null) {
- // if (cache.indexOf(value) !== -1) {
- // // Duplicate reference found
- // try {
- // // If this value does not reference a parent it can be deduped
- // return JSON.parse(JSON.stringify(value));
- // } catch (error) {
- // // discard key if value cannot be deduped
- // return;
- // }
- // }
- // // Store value in our collection
- // cache.push(value);
- // }
- // return value;
- // }));
- // console.log(insertion.pid);
- if (validInsertion) {
- console.log('start valid insertion');
- writeToFile('start valid insertion\n');
- // If we have uniques && we have non uniques ... yes, this can happen :D
- if (migration.uniques) {
- console.log('insert or update');
- await insertOrUpdate(
- knex,
- insertTableName,
- insertion,
- migration.fields,
- migration.uniques
- );
- } else {
- console.log('normal insert');
- writeToFile('normal insert\n');
- await knex(insertTableName).insert(insertion);
- }
- console.log('valid insertion');
- writeToFile('valid insertion\n');
- }
- } catch (e) {
- console.log("Error inserting: " + insertion.oid);
- console.log(e.message);
- } finally {
- console.log(`Processing ${zipEntry}`);
- writeToFile(`Processing ${zipEntry}\n`);
- result = await source.read();
- console.log('finally result source read');
- writeToFile('finally result source read\n');
- }
- } while (!result.done);
- }
- }
- };
- (async function() {
- downloadFilesAgain =
- silent ||
- (await prompts({
- type: "toggle",
- name: "value",
- message: `Fetch new data from dropbox?`,
- initial: false,
- active: "yes",
- inactive: "no"
- })).value;
- if ((await knex.schema.hasTable("parcels")) == false) {
- await knex.schema.createTable("parcels", function(table) {
- table.increments("id");
- table
- .uuid("uuid")
- .index()
- .unique()
- .notNullable();
- table.integer("oid").index();
- table.text("pid");
- table.text("county");
- table.decimal("assessed_area", 14, 2);
- table.decimal("shape_area", 14, 2);
- table.text("state").index();
- table.specificType("geom", "geometry").index(null, "GIST");
- table.jsonb("cache");
- table.datetime("deleted_at");
- table.timestamps(true, true);
- });
- }
- fieldMaps["Parcels_Fl_fl_duval_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_duval_shp"] = {};
- fieldMaps["Parcels_Fl_fl_hardee_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_hardee_shp"] = {};
- fieldMaps["Parcels_Fl_fl_gadsden_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_gadsden_shp"] = {};
- fieldMaps["Parcels_Fl_fl_lafayette_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_lafayette_shp"] = {};
- fieldMaps["Parcels_Fl_fl_calhoun_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_calhoun_shp"] = {};
- fieldMaps["Parcels_Fl_fl_miami-dade_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_miami-dade_shp"] = {};
- fieldMaps["Parcels_Fl_fl_orange_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_orange_shp"] = {};
- fieldMaps["Parcels_Fl_fl_volusia_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_volusia_shp"] = {};
- fieldMaps["Parcels_Fl_fl_brevard_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_brevard_shp"] = {};
- fieldMaps["Parcels_Fl_fl_bradford_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_bradford_shp"] = {};
- fieldMaps["Parcels_Fl_fl_santa-rosa_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_santa-rosa_shp"] = {};
- fieldMaps["Parcels_Fl_fl_franklin_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_franklin_shp"] = {};
- fieldMaps["Parcels_Fl_fl_sarasota_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_sarasota_shp"] = {};
- fieldMaps["Parcels_Fl_fl_gilchrist_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_gilchrist_shp"] = {};
- fieldMaps["Parcels_Fl_fl_manatee_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_manatee_shp"] = {};
- fieldMaps["Parcels_Fl_fl_jackson_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_jackson_shp"] = {};
- fieldMaps["Parcels_Fl_fl_liberty_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_liberty_shp"] = {};
- fieldMaps["Parcels_Fl_fl_bay_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_bay_shp"] = {};
- fieldMaps["Parcels_Fl_fl_holmes_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_holmes_shp"] = {};
- fieldMaps["Parcels_Fl_fl_washington_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_washington_shp"] = {};
- fieldMaps["Parcels_Fl_fl_hillsborough_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_hillsborough_shp"] = {};
- fieldMaps["Parcels_Fl_fl_hernando_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_hernando_shp"] = {};
- fieldMaps["Parcels_Fl_fl_levy_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_levy_shp"] = {};
- fieldMaps["Parcels_Fl_fl_martin_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_martin_shp"] = {};
- fieldMaps["Parcels_Fl_fl_sumter_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_sumter_shp"] = {};
- fieldMaps["Parcels_Fl_fl_citrus_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_citrus_shp"] = {};
- fieldMaps["Parcels_Fl_fl_clay_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_clay_shp"] = {};
- fieldMaps["Parcels_Fl_fl_columbia_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_columbia_shp"] = {};
- fieldMaps["Parcels_Fl_fl_seminole_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_seminole_shp"] = {};
- fieldMaps["Parcels_Fl_fl_alachua_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_alachua_shp"] = {};
- fieldMaps["Parcels_Fl_fl_walton_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_walton_shp"] = {};
- fieldMaps["Parcels_Fl_fl_jefferson_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_jefferson_shp"] = {};
- fieldMaps["Parcels_Fl_fl_st-johns_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_st-johns_shp"] = {};
- fieldMaps["Parcels_Fl_fl_leon_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_leon_shp"] = {};
- fieldMaps["Parcels_Fl_fl_pasco_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_pasco_shp"] = {};
- fieldMaps["Parcels_Fl_fl_okaloosa_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_okaloosa_shp"] = {};
- fieldMaps["Parcels_Fl_fl_wakulla_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_wakulla_shp"] = {};
- fieldMaps["Parcels_Fl_fl_union_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_union_shp"] = {};
- fieldMaps["Parcels_Fl_fl_charlotte_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_charlotte_shp"] = {};
- fieldMaps["Parcels_Fl_fl_suwannee_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_suwannee_shp"] = {};
- fieldMaps["Parcels_Fl_fl_hendry_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_hendry_shp"] = {};
- fieldMaps["Parcels_Fl_fl_indian-river_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_indian-river_shp"] = {};
- fieldMaps["Parcels_Fl_fl_nassau_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_nassau_shp"] = {};
- fieldMaps["Parcels_Fl_fl_putnam_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_putnam_shp"] = {};
- fieldMaps["Parcels_Fl_fl_broward_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_broward_shp"] = {};
- fieldMaps["Parcels_Fl_fl_dixie_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_dixie_shp"] = {};
- fieldMaps["Parcels_Fl_fl_taylor_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_taylor_shp"] = {};
- fieldMaps["Parcels_Fl_fl_osceola_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_osceola_shp"] = {};
- fieldMaps["Parcels_Fl_fl_pinellas_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_pinellas_shp"] = {};
- fieldMaps["Parcels_Fl_fl_flagler_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_flagler_shp"] = {};
- fieldMaps["Parcels_Fl_fl_monroe_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_monroe_shp"] = {};
- fieldMaps["Parcels_Fl_fl_palm_beach_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_palm_beach_shp"] = {};
- fieldMaps["Parcels_Fl_fl_glades_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_glades_shp"] = {};
- fieldMaps["Parcels_Fl_fl_baker_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_baker_shp"] = {};
- fieldMaps["Parcels_Fl_fl_highlands_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_highlands_shp"] = {};
- fieldMaps["Parcels_Fl_fl_marion_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_marion_shp"] = {};
- fieldMaps["Parcels_Fl_fl_lee_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_lee_shp"] = {};
- fieldMaps["Parcels_Fl_fl_escambia_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_escambia_shp"] = {};
- fieldMaps["Parcels_Fl_fl_okeechobee_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_okeechobee_shp"] = {};
- fieldMaps["Parcels_Fl_fl_desoto_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_desoto_shp"] = {};
- fieldMaps["Parcels_Fl_fl_lake_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_lake_shp"] = {};
- fieldMaps["Parcels_Fl_fl_collier_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_collier_shp"] = {};
- fieldMaps["Parcels_Fl_fl_polk_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_polk_shp"] = {};
- fieldMaps["Parcels_Fl_fl_madison_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_madison_shp"] = {};
- fieldMaps["Parcels_Fl_fl_hamilton_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_hamilton_shp"] = {};
- fieldMaps["Parcels_Fl_fl_palm-beach_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_palm-beach_shp"] = {};
- fieldMaps["Parcels_Fl_fl_st-lucie_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_st-lucie_shp"] = {};
- fieldMaps["Parcels_Fl_fl_gulf_shp"] = {
- uuid: "",
- oid: "geoid",
- pid: "parcelnumb",
- county: "county",
- assessed_area: "",
- shape_area: "",
- state: "sourceagen",
- geom: ""
- };
- relationMaps["Parcels_Fl_fl_gulf_shp"] = {};
- await runMigrationWith(
- "data/GIS/gis_processed_data/wc_florida/WC_FL_V0.1/Parcels_Fl.zip",
- "parcels",
- {
- table: "parcels",
- func:
- " await knex.schema.createTable('parcels', function (table) { table.increments('id'); table.uuid('uuid').index().unique().notNullable(); table.integer('oid').index(); table.text('pid'); table.text('county'); table.decimal('assessed_area', 14, 2); table.decimal('shape_area', 14, 2); table.text('state').index(); table.specificType('geom', 'geometry').index(null, 'GIST'); table.jsonb('cache'); table.datetime('deleted_at'); table.timestamps(true, true); });",
- fields: [
- "uuid",
- "oid",
- "pid",
- "county",
- "assessed_area",
- "shape_area",
- "state",
- "geom"
- ],
- references: {},
- uniques: ["uuid"]
- },
- "FL"
- );
- if ((await knex.schema.hasTable("fl_forests")) == false) {
- await knex.schema.createTable("fl_forests", function(table) {
- table.increments("id");
- table
- .uuid("uuid")
- .index()
- .unique()
- .notNullable();
- table.integer("oid").index();
- table.integer("value").notNullable();
- table.specificType("geom", "geometry").index(null, "GIST");
- table.datetime("deleted_at");
- table.timestamps(true, true);
- });
- }
- fieldMaps["Forest_FL_Forest_FL_shp"] = {
- uuid: "",
- oid: "OBJECTID",
- value: "SITE",
- geom: ""
- };
- relationMaps["Forest_FL_Forest_FL_shp"] = {};
- await runMigrationWith(
- "data/GIS/GIS_Processed_Data/WC_Florida/WC_FL_V0.1/Forest_FL.zip",
- "fl_forests",
- {
- table: "fl_forests",
- func:
- " await knex.schema.createTable('fl_forests', function (table) { table.increments('id'); table.uuid('uuid').index().unique().notNullable(); table.integer('oid').index(); table.integer('value').notNullable(); table.specificType('geom', 'geometry').index(null, 'GIST'); table.datetime('deleted_at'); table.timestamps(true, true); });",
- fields: ["uuid", "oid", "value", "geom"],
- references: {},
- uniques: ["uuid"]
- },
- "FL"
- );
- if ((await knex.schema.hasTable("fl_hurricane_severity")) == false) {
- await knex.schema.createTable("fl_hurricane_severity", function(table) {
- table.increments("id");
- table
- .uuid("uuid")
- .index()
- .unique()
- .notNullable();
- table.integer("oid").index();
- table.specificType("geom", "geometry").index(null, "GIST");
- table.text("slope");
- table.datetime("deleted_at");
- table.timestamps(true, true);
- });
- }
- fieldMaps["Hurricane_Severity_FL_Hurricane_Severity_FL_shp"] = {
- uuid: "",
- oid: "",
- geom: "",
- slope: ""
- };
- relationMaps["Hurricane_Severity_FL_Hurricane_Severity_FL_shp"] = {};
- await runMigrationWith(
- "data/GIS/GIS_Processed_Data/WC_Florida/WC_FL_V0.1/Hurricane_Severity_FL.zip",
- "fl_hurricane_severity",
- {
- table: "fl_hurricane_severity",
- func:
- " await knex.schema.createTable('fl_hurricane_severity', function (table) { table.increments('id'); table.uuid('uuid').index().unique().notNullable(); table.integer('oid').index(); table.specificType('geom', 'geometry').index(null, 'GIST'); table.text('slope'); table.datetime('deleted_at'); table.timestamps(true, true); });",
- fields: ["uuid", "oid", "geom", "slope"],
- references: {},
- uniques: ["uuid"]
- },
- "FL"
- );
- if ((await knex.schema.hasTable("fl_ffs_priority")) == false) {
- await knex.schema.createTable("fl_ffs_priority", function(table) {
- table.increments("id");
- table
- .uuid("uuid")
- .index()
- .unique()
- .notNullable();
- table.integer("oid").index();
- table.specificType("geom", "geometry").index(null, "GIST");
- table.text("priority");
- table.datetime("deleted_at");
- table.timestamps(true, true);
- });
- }
- fieldMaps["Priority_2015_FFS_FL_Priority_2015_FFS_FL_shp"] = {
- uuid: "",
- oid: "Id",
- geom: "",
- priority: ""
- };
- relationMaps["Priority_2015_FFS_FL_Priority_2015_FFS_FL_shp"] = {};
- await runMigrationWith(
- "data/GIS/GIS_Processed_Data/WC_Florida/WC_FL_V0.1/Priority_2015_FFS_FL.zip",
- "fl_ffs_priority",
- {
- table: "fl_ffs_priority",
- func:
- " await knex.schema.createTable('fl_ffs_priority', function (table) { table.increments('id'); table.uuid('uuid').index().unique().notNullable(); table.integer('oid').index(); table.specificType('geom', 'geometry').index(null, 'GIST'); table.text('priority'); table.datetime('deleted_at'); table.timestamps(true, true); });",
- fields: ["uuid", "oid", "geom", "priority"],
- references: {},
- uniques: ["uuid"]
- },
- "FL"
- );
- if ((await knex.schema.hasTable("fl_longleaf")) == false) {
- await knex.schema.createTable("fl_longleaf", function(table) {
- table.increments("id");
- table
- .uuid("uuid")
- .index()
- .unique()
- .notNullable();
- table.integer("oid").index();
- table.specificType("geom", "geometry").index(null, "GIST");
- table.text("priority");
- table.datetime("deleted_at");
- table.timestamps(true, true);
- });
- }
- fieldMaps["Longleaf_Prioirty_FL_llp_priorityareas_all_Simplified_shp"] = {
- uuid: "",
- oid: "",
- geom: "",
- priority: ""
- };
- relationMaps[
- "Longleaf_Prioirty_FL_llp_priorityareas_all_Simplified_shp"
- ] = {};
- fieldMaps["Longleaf_Prioirty_FL_llp_priorityareas_High_shp"] = {
- uuid: "",
- oid: "",
- geom: "",
- priority: ""
- };
- relationMaps["Longleaf_Prioirty_FL_llp_priorityareas_High_shp"] = {};
- await runMigrationWith(
- "data/GIS/GIS_Processed_Data/WC_Florida/WC_FL_V0.1/Longleaf_Prioirty_FL.zip",
- "fl_longleaf",
- {
- table: "fl_longleaf",
- func:
- " await knex.schema.createTable('fl_longleaf', function (table) { table.increments('id'); table.uuid('uuid').index().unique().notNullable(); table.integer('oid').index(); table.specificType('geom', 'geometry').index(null, 'GIST'); table.text('priority'); table.datetime('deleted_at'); table.timestamps(true, true); });",
- fields: ["uuid", "oid", "geom", "priority"],
- references: {},
- uniques: ["uuid"]
- },
- "FL"
- );
- if ((await knex.schema.hasTable("fl_strategic_habitats")) == false) {
- await knex.schema.createTable("fl_strategic_habitats", function(table) {
- table.increments("id");
- table
- .uuid("uuid")
- .index()
- .unique()
- .notNullable();
- table.integer("oid").index();
- table.specificType("geom", "geometry").index(null, "GIST");
- table.text("habitat");
- table.datetime("deleted_at");
- table.timestamps(true, true);
- });
- }
- fieldMaps["Strategic_Habitat_FL_Strategic_Habitat_FL_shp"] = {
- uuid: "",
- oid: "OBJECTID",
- geom: "",
- habitat: ""
- };
- relationMaps["Strategic_Habitat_FL_Strategic_Habitat_FL_shp"] = {};
- await runMigrationWith(
- "data/GIS/GIS_Processed_Data/WC_Florida/WC_FL_V0.1/Strategic_Habitat_FL.zip",
- "fl_strategic_habitats",
- {
- table: "fl_strategic_habitats",
- func:
- " await knex.schema.createTable('fl_strategic_habitats', function (table) { table.increments('id'); table.uuid('uuid').index().unique().notNullable(); table.integer('oid').index(); table.specificType('geom', 'geometry').index(null, 'GIST'); table.text('habitat'); table.datetime('deleted_at'); table.timestamps(true, true); });",
- fields: ["uuid", "oid", "geom", "habitat"],
- references: {},
- uniques: ["uuid"]
- },
- "FL"
- );
- if ((await knex.schema.hasTable("fl_mills")) == false) {
- await knex.schema.createTable("fl_mills", function(table) {
- table.increments("id");
- table
- .uuid("uuid")
- .index()
- .unique()
- .notNullable();
- table.integer("oid").index();
- table.specificType("geom", "geometry").index(null, "GIST");
- table.text("mill");
- table.datetime("deleted_at");
- table.timestamps(true, true);
- });
- }
- fieldMaps["Mills_FL_Mills_FL_shp"] = {
- uuid: "",
- oid: "",
- geom: "",
- mill: "NAME"
- };
- relationMaps["Mills_FL_Mills_FL_shp"] = {};
- await runMigrationWith(
- "data/GIS/GIS_Processed_Data/WC_Florida/WC_FL_V0.1/Mills_FL.zip",
- "fl_mills",
- {
- table: "fl_mills",
- func:
- " await knex.schema.createTable('fl_mills', function (table) { table.increments('id'); table.uuid('uuid').index().unique().notNullable(); table.integer('oid').index(); table.specificType('geom', 'geometry').index(null, 'GIST'); table.text('mill'); table.datetime('deleted_at'); table.timestamps(true, true); });",
- fields: ["uuid", "oid", "geom", "mill"],
- references: {},
- uniques: ["uuid"]
- },
- "FL"
- );
- if ((await knex.schema.hasTable("fl_invasive")) == false) {
- await knex.schema.createTable("fl_invasive", function(table) {
- table.increments("id");
- table
- .uuid("uuid")
- .index()
- .unique()
- .notNullable();
- table.integer("oid").index();
- table.specificType("geom", "geometry").index(null, "GIST");
- table.text("species");
- table.datetime("deleted_at");
- table.timestamps(true, true);
- });
- }
- fieldMaps["Invasive_FL_Invasive_FL_shp"] = {
- uuid: "",
- oid: "OBJECTID",
- geom: "",
- species: "SCINAME"
- };
- relationMaps["Invasive_FL_Invasive_FL_shp"] = {};
- fieldMaps["Invasive_FL_Invasive_1mile_FL_shp"] = {
- uuid: "",
- oid: "OBJECTID",
- geom: "",
- species: "SCINAME"
- };
- relationMaps["Invasive_FL_Invasive_1mile_FL_shp"] = {};
- await runMigrationWith(
- "data/GIS/GIS_Processed_Data/WC_Florida/WC_FL_V0.1/Invasive_FL.zip",
- "fl_invasive",
- {
- table: "fl_invasive",
- func:
- " await knex.schema.createTable('fl_invasive', function (table) { table.increments('id'); table.uuid('uuid').index().unique().notNullable(); table.integer('oid').index(); table.specificType('geom', 'geometry').index(null, 'GIST'); table.text('species'); table.datetime('deleted_at'); table.timestamps(true, true); });",
- fields: ["uuid", "oid", "geom", "species"],
- references: {},
- uniques: ["uuid"]
- },
- "FL"
- );
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement