Coder Social home page Coder Social logo

andre-geldenhuis / dem-to-stl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ideashakerlab/dem-to-stl

0.0 2.0 0.0 129 KB

Python scripts for converting the CDED flavour of DEM (Digital Elevation Model) files to 2D Bitmaps and 3D STL files.

License: MIT License

Python 100.00%

dem-to-stl's Introduction

DEM to STL

This repository contains Python scripts for converting the CDED flavour of DEM (Digital Elevation Model) files to 2D Bitmaps and 3D STL files. CDED stands for Canadian Digital Elevation Model, and is generally used to describe topographical surveys of various regions within Canada. Example: CDED Model of the Greater Toronto Area

STL files are commonly used for 3D printing. The resulting STL files from this script should be fully 3D-printable.

Basic Usage

These scripts were written and tested in Python 2.7.

Reading the DEM Metadata:

python dump_dem_metadata.py sourcefile.dem

Converting the DEM to a Bitmap:

python dem_to_bmp.py sourcefile.dem destinationfile.bmp [-c] [-q INT]
  • The -c flag will output blue-green instead of greyscale.
  • The -q represents "quality". 1 will match the source resolution, while higher numbers will reduce the resolution.

Converting the DEM to an STL:

python dem_to_stl.py sourcefile.dem destinationfile.stl [-q INT]
  • The -q represents "quality". 1 will match the source resolution, while higher numbers will reduce the resolution.

Advanced Usage

The module cdedtools.demparser currently offers two functions:

from cdedtools import demparser

with open('filename.dem', 'r') as f:
  # read_metadata(f) will parse the headers of a DEM file
  # and return a dictionary of metadata entries. Integers
  # that represent string values in the CDED spec will be
  # translated to a readable string where appropriate, 
  # eg. uomGround: 1 -> uomGround: "Meters".
  # See cdedtools.translationtables to view all translations.
  metadata = demparser.read_metadata(f)
  
  # read_data(f) will parse the elevation data from a DEM
  # file and return a two-dimensional array of integers.
  # Typically, -32767 is considered a void value, while all
  # other values are distances above (+) or below (-) sea level.
  elevations = demparser.read_data(f)

The module stltools.stlgenerator offers a single function:

from stltools import stlgenerator

heightmap = [
  [10, 10, 10], # y
  [10, 40, 10], # y
  [10, 10, 10]  # y
  # x,  x,  x
]

# Given a two-dimensional array of integers, this function
# will write a binary STL to the specified destination
# file. Under most circumstances, the model should be solid
# and manifold; ready for 3D printing. The heightmap is applied
# to the top facets only, while the bottom and sides will be flat.
# The distance between each point on the x and y axis will be 1mm.
# the elevation values will be interpreted in millimeters with 
# values less than 1 being rounded up to 1mm.
stlgenerator.generate_from_heightmap_array(heightmap, 'destination.stl')

dem-to-stl's People

Contributors

andre-geldenhuis avatar pmcmonagle avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.