Created
November 28, 2019 06:23
-
-
Save IReese/6ee8a08b252e96e45179ab2a6571ea6d to your computer and use it in GitHub Desktop.
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
const csvWriter = require('csv-write-stream') | |
const shapefile = require("shapefile"); | |
const cover = require('@mapbox/tile-cover'); | |
const fs = require('fs'); | |
async function main() { | |
const shp = await shapefile.read('~/nz-imagery-surveys_wgs.shp'); | |
//console.log(shp) | |
var limits = { | |
min_zoom: 12, | |
max_zoom: 13 | |
}; | |
const newShp = shp.features.find(feats => feats.properties.name == 'Gisborne 0.1m Urban Aerial Photos (2017-2018)') | |
var tilesOut = cover.geojson(newShp.geometry, limits) //compare gizzy polygons to wgs poly options | |
//console.log(tilesOut) | |
tilesOut.features.forEach(function(wgsBbox){ | |
var name = newShp.properties.name | |
var ulx = wgsBbox.geometry.coordinates[0][0][0] | |
var uly = wgsBbox.geometry.coordinates[0][0][1] | |
var lrx = wgsBbox.geometry.coordinates[0][2][0] | |
var lry = wgsBbox.geometry.coordinates[0][2][1] | |
console.log(newShp.properties.name) | |
console.log(ulx) | |
console.log(uly) | |
console.log(lrx) | |
console.log(lry) | |
if (!fs.existsSync('out.csv')){ | |
writer = csvWriter({sendHeaders: false}) | |
writer.pipe(fs.createWriteStream('out.csv')) | |
writer.write({filename: name, ulX: ulx, ulY: uly, lrX: lrx, lrY: lry}) | |
} | |
else{ | |
writer = csvWriter({sendHeaders: false}) | |
writer.pipe(fs.createWriteStream('out.csv',{flags: 'a'})) | |
writer.write({filename: name, ulX: ulx, ulY: uly, lrX: lrx, lrY: lry}) | |
} | |
writer.end() | |
}) | |
} | |
main().catch(e => console.error(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment