Skip to content

Instantly share code, notes, and snippets.

@crofty
Last active September 7, 2023 20:26
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crofty/ebe1bf5c738b13f0ad0fe6eeda280eb9 to your computer and use it in GitHub Desktop.
Save crofty/ebe1bf5c738b13f0ad0fe6eeda280eb9 to your computer and use it in GitHub Desktop.
node_modules
gdalwmscache
<GDAL_WMS>
<Service name="TMS">
<ServerUrl>https://s3.amazonaws.com/elevation-tiles-prod/geotiff/${z}/${x}/${y}.tif</ServerUrl>
</Service>
<DataWindow>
<UpperLeftX>-20037508.34</UpperLeftX>
<UpperLeftY>20037508.34</UpperLeftY>
<LowerRightX>20037508.34</LowerRightX>
<LowerRightY>-20037508.34</LowerRightY>
<TileLevel>14</TileLevel>
<TileCountX>1</TileCountX>
<TileCountY>1</TileCountY>
<YOrigin>top</YOrigin>
</DataWindow>
<Projection>EPSG:3857</Projection>
<BlockSizeX>512</BlockSizeX>
<BlockSizeY>512</BlockSizeY>
<BandsCount>1</BandsCount>
<DataType>Int16</DataType>
<ZeroBlockHttpCodes>403,404</ZeroBlockHttpCodes>
<DataValues>
<NoData>-32768</NoData>
</DataValues>
<Cache/>
</GDAL_WMS>
{
"name": "svg-contours",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@mapbox/geo-viewport": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/@mapbox/geo-viewport/-/geo-viewport-0.2.2.tgz",
"integrity": "sha1-kyBsBEI4whpg/KfpBkyM5j6AJ7Q=",
"requires": {
"@mapbox/sphericalmercator": "1.0.5"
}
},
"@mapbox/sphericalmercator": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/@mapbox/sphericalmercator/-/sphericalmercator-1.0.5.tgz",
"integrity": "sha1-cCN7l3QJXtHP286nqP0fyCsmkfI="
},
"commander": {
"version": "2.14.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.14.1.tgz",
"integrity": "sha512-+YR16o3rK53SmWHU3rEM3tPAh2rwb1yPcQX5irVn7mb0gXbwuCCrnkbV5+PBfETdfg1vui07nM6PCG1zndcjQw=="
},
"d3-array": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/d3-array/-/d3-array-1.2.1.tgz",
"integrity": "sha512-CyINJQ0SOUHojDdFDH4JEM0552vCR1utGyLHegJHyYH0JyCpSeTPxi4OBqHMA2jJZq4NH782LtaJWBImqI/HBw=="
},
"d3-geo": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/d3-geo/-/d3-geo-1.9.1.tgz",
"integrity": "sha512-l9wL/cEQkyZQYXw3xbmLsH3eQ5ij+icNfo4r0GrLa5rOCZR/e/3am45IQ0FvQ5uMsv+77zBRunLc9ufTWSQYFA==",
"requires": {
"d3-array": "1.2.1"
}
},
"d3-geo-projection": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/d3-geo-projection/-/d3-geo-projection-2.3.2.tgz",
"integrity": "sha512-fbIDeSs1n0Y3IxqjtljeHUong4YEK2YS7jR/YKQCoWYBRJLEcieSq1lciCB9+HuNIdJtD7xVRyXFiZGIqu3ydA==",
"requires": {
"commander": "2.14.1",
"d3-array": "1.2.1",
"d3-geo": "1.9.1"
}
},
"topojson-client": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/topojson-client/-/topojson-client-3.0.0.tgz",
"integrity": "sha1-H5kpOnfvQqRI0DKoGqmCtz82DS8=",
"requires": {
"commander": "2.14.1"
}
}
}
}
{
"name": "svg-contours",
"version": "1.0.0",
"description": "",
"main": "bounds.js",
"dependencies": {
"@mapbox/geo-viewport": "^0.2.2",
"d3-geo-projection": "^2.3.2",
"topojson-client": "^3.0.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
require 'json'
def run_command(command)
puts command
system(command) or raise Error
end
lat, lng = "53.868377, -2.300712".split(', ')
zoom = 12 # Controls the area plotted
scale = 1 # Finer grained control over area plotted
width = 1000
height = width * 0.707
js = <<-JS
var geoViewport = require('@mapbox/geo-viewport');
const bounds = geoViewport.
bounds([#{lng}, #{lat}], #{zoom}, [#{width*scale},#{height*scale}])
console.log(JSON.stringify(bounds));
JS
node_output = %x[node -e "#{js}"].chomp
p node_output
left,bottom,right,top = JSON.parse(node_output)
run_command <<-SH
rm -f pendle.tif
docker run -v $(pwd):/gdal -w /gdal geographica/gdal2 \
gdal_translate \
-of GTiff \
-projwin #{left} #{top} #{right} #{bottom} \
-projwin_srs EPSG:4326 \
-outsize #{width*5} 0 \
elevation.xml pendle.tif
SH
run_command <<-SH
rm -f pendle-4326.tif
docker run -v $(pwd):/gdal -w /gdal geographica/gdal2 \
gdalwarp \
-s_srs EPSG:3857 \
-t_srs EPSG:4326 \
pendle.tif pendle-4326.tif
SH
run_command <<-SH
rm -f contour.geojson
docker run -v $(pwd):/gdal -w /gdal geographica/gdal2 \
gdal_contour \
-a elev pendle-4326.tif \
-f GeoJSON \
-i 10.0 \
contour.geojson
SH
run_command <<-SH
rm -f contours-simplified.geojson
cat contour.geojson | \
geoproject 'd3.geoMercator().fitSize([#{width}, #{height}], d)' | \
geo2topo contours=- | \
toposimplify -p 1 -f | \
topoquantize 1e5 | \
topo2geo contours=contours-simplified.geojson
SH
run_command <<-SH
rm -f pendle.svg
geo2svg -w #{width} -h #{height} < contours-simplified.geojson > pendle.svg
SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment