first prototype for openscad rendering
This commit is contained in:
parent
69daf8a60f
commit
1524fc2340
2 changed files with 24 additions and 0 deletions
17
src/c3nav/mapdata/management/commands/renderscad.py
Normal file
17
src/c3nav/mapdata/management/commands/renderscad.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import os
|
||||||
|
from django.conf import settings
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
from c3nav.mapdata.utils.scad import polygon_scad
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'render the map to openscad'
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
from c3nav.mapdata.models import AltitudeArea
|
||||||
|
filename = os.path.join(settings.RENDER_ROOT, 'all.scad')
|
||||||
|
with open(filename, 'w') as f:
|
||||||
|
for area in AltitudeArea.objects.all():
|
||||||
|
f.write('translate([0, 0, %.2f]) ' % area.altitude)
|
||||||
|
f.write(polygon_scad(area.geometry)+';\n')
|
7
src/c3nav/mapdata/utils/scad.py
Normal file
7
src/c3nav/mapdata/utils/scad.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
from shapely.geometry import mapping
|
||||||
|
|
||||||
|
|
||||||
|
def polygon_scad(polygon):
|
||||||
|
return 'polygon(points='+json.dumps(mapping(polygon)['coordinates'][0], separators=(',', ':'))+')'
|
Loading…
Add table
Add a link
Reference in a new issue