Skip to content

convert a shapefile to a raster heightmap based on attributes

Notifications You must be signed in to change notification settings

miketahani/shp2img

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 

Repository files navigation

sf building footprints data

Description

An ultra-hacky one-off to generate multi-channel heightmaps from shapefiles using 1-3 numeric attributes. Useful for creating heightmaps for GL shaders. Mostly a way for me to learn how to use PIL and read shapefiles.

Currently only works with WGS84-projected shapefiles that contain polygons.

Requirements

Requires pyshp (pip install pyshp) and Pillow (pip install Pillow).

Usage

Usage: shp2img.py -f filename --rgb=attr1,attr2,attr3 [options]

Options:
  -h, --help            show this help message and exit
  --rgb=CHANNELS        one attribute per channel (r,g,b -> attr1,attr2,attr3)
  -f FILENAME, --filename=FILENAME
                        shapefile to convert (omit extension)
  -o OUTFILE, --out=OUTFILE
                        outfile name (defaults to stdout)
  -s SIZE, --size=SIZE  max output dimension. width/height will scale
                        proportionally. (defaults to 2048)
  -e EXT, --extension=EXT
                        output file type (defaults to PNG)
  -c, --show_columns    show attributes and exit

Channels Usage:
  you must define a shapefile attribute for each r,g,b color channel.
  leave placeholders for unused channels.

  ex: --rgb=attr1,attr2,attr3 (all three channels)
      --rgb=attr1,, (red)
      --rgb=,attr2, (green)
      --rgb=,,attr3 (blue)

TODO

  • use a projection instead of just relying on a mercator 1:1 grid
  • support more shapes than polygons

About

convert a shapefile to a raster heightmap based on attributes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages