{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Populating the interactive namespace from numpy and matplotlib\n" ] } ], "source": [ "%pylab inline\n", "import ogr\n", "import os\n", "import shapely, shapely.wkt\n", "import shapely_tools as st\n", "import osm2dh\n", "import utm_conversion as utm\n", "from gdal_sample_points import gdal_sample_points\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import pdb\n", "import pyproj" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# TODO: multiLinestrings afvangen in filter_features\n", "# TODO: dit verplaatsen naar osm2dh\n", "\n", "def osm2channel(fn, check_fields, layer_index=1, # input \n", " bbox=None, key='waterway', value='drain', # filter\n", " max_snap_dist = 1, # geom changes\n", " depth=2., width=1., proftype=2, dtm_fn=None): # properties\n", " # filter features from OSM\n", " features = osm2dh.filter_features(fn, check_fields, bbox=bbox, key=key, value=value, layer_index=layer_index)\n", " \n", " # list of feature geometries\n", " geoms_edit = [ft['geom'] for ft in features]\n", " # snap and split lines\n", "# geoms_edit, index = st.snap_lines(geoms, max_dist=max_snap_dist, return_index=True)\n", " \n", " # temporary replacement\n", " index = range(len(features))\n", " \n", " objects = []\n", " for i, ift in enumerate(index):\n", " data = features[ift]\n", " data['geom'] = geoms_edit[i]\n", " # set default values\n", " data['proftype'] = proftype\n", " if not('depth' in data):\n", " data['depth'] = depth\n", " if not('width' in data):\n", " data['width'] = width\n", " ## TODO: make try except around this function\n", " # parse osm features and append to list\n", " o = osm2dh.Channel(bbox=bbox, dtm_fn=dtm_fn, **data)\n", " objects.append(o)\n", " return objects\n", "\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# filter culverts, skip invalide fields and create gate objects\n", "dataDir = r'd:\\temp\\CF1.2'\n", "db_fn= os.path.join(dataDir, 'OSM', 'manzese_large-latest_v2.db')\n", "dtm_fn = os.path.join(dataDir, 'DTM', 'manzese_DTM_0_5m_UTM37S_small.tif')\n", "\n", "outDir = r'd:\\temp\\CF1.2\\DFM_data'\n", "pli_fn = os.path.join(outDir, 'channels', r'manzese_channels.pli')\n", "dtm_xyz_fn = os.path.join(outDir, 'channels', r'manzese_channels_dtm_samples.xyz')\n", "prof_xyz_fn = os.path.join(outDir, 'channels', r'manzese_channels_profloc.xyz')\n", "profdef_fn = os.path.join(outDir, 'channels', r'manzese_channels_profdef.txt')\n", "\n", "bnd_fn = os.path.join(outDir, 'boundaries', r'forcing.ext')\n", "domain = shapely.geometry.Polygon([(524400, 9250200), (524400, 9247000), (526700, 9247000), (526700, 9250200)])\n", "\n", "# purge any existing files\n", "if os.path.exists(pli_fn):\n", " os.unlink(pli_fn)\n", "if os.path.exists(dtm_xyz_fn):\n", " os.unlink(dtm_xyz_fn)\n", "if os.path.exists(prof_xyz_fn):\n", " os.unlink(prof_xyz_fn)\n", "if os.path.exists(profdef_fn):\n", " os.unlink(profdef_fn)\n", "\n", "check_fields = {\n", " 'width': float,\n", " 'depth': float\n", "}\n", "\n", "\n", "# objects = osm2channel(db_fn, check_fields, key='waterway', value='drain', depth=5., width=10., proftype=2, layer_index=1, dtm_fn=dtm_fn)\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Adding waterway of type ditch with depth 1.00 and width 1.00\n", "> d:\\svn\\openearthtools\\python\\applications\\hydrotools\\sandbox\\osmmodelbuilding\\osm2dh.py(223)to_bnd_cnds()\n", "-> text_file.write(self.fmt_bnd_cnds(bnd_fn, bnd_cnd))\n", "(Pdb) bnd_fn\n", "'d:\\\\temp\\\\CF1.2\\\\DFM_data\\\\boundaries\\\\channel341763677_1_bnd.pli'\n", "(Pdb) n\n", "> d:\\svn\\openearthtools\\python\\applications\\hydrotools\\sandbox\\osmmodelbuilding\\osm2dh.py(224)to_bnd_cnds()\n", "-> bnd_const_bnd_fn = os.path.join(bnd_path, _bnd_fn.rsplit('.', 1)[0] + '_0001.cmp')\n", "(Pdb) q\n" ] }, { "ename": "BdbQuit", "evalue": "", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mBdbQuit\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 22\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mo\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_xyz\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mprof_xyz_fn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mo\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mprofdef\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mn\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'geometry'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mo\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_id\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mappend\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mTrue\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mo\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mobjects\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mn\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 23\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mo\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_profdef\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mprofdef_fn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mo\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mprofdef\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'properties'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mappend\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mTrue\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mo\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mobjects\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m---> 24\u001b[0;31m \u001b[1;33m[\u001b[0m\u001b[0mo\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_bnd_cnds\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbnd_fn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mo\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbnd_cnds\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mn\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbnd_path\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mos\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbnd_fn\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mappend\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mTrue\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mo\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mobjects\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mn\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mo\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbnd_cnds\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 25\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[0;32md:\\svn\\openearthtools\\python\\applications\\hydrotools\\sandbox\\osmmodelbuilding\\osm2dh.py\u001b[0m in \u001b[0;36mto_bnd_cnds\u001b[0;34m(self, fn, bnd_cnd, bnd_path, append)\u001b[0m\n\u001b[1;32m 222\u001b[0m \u001b[0mpdb\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mset_trace\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 223\u001b[0m \u001b[0mtext_file\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwrite\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfmt_bnd_cnds\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbnd_fn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbnd_cnd\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 224\u001b[0;31m \u001b[0mbnd_const_bnd_fn\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mos\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbnd_path\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0m_bnd_fn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrsplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'.'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m'_0001.cmp'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 225\u001b[0m \u001b[1;31m# also write the accompanying .pli file!\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 226\u001b[0m \u001b[1;31m# TODO: parse .pli file\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[0;32md:\\svn\\openearthtools\\python\\applications\\hydrotools\\sandbox\\osmmodelbuilding\\osm2dh.py\u001b[0m in \u001b[0;36mto_bnd_cnds\u001b[0;34m(self, fn, bnd_cnd, bnd_path, append)\u001b[0m\n\u001b[1;32m 222\u001b[0m \u001b[0mpdb\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mset_trace\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 223\u001b[0m \u001b[0mtext_file\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwrite\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfmt_bnd_cnds\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbnd_fn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbnd_cnd\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 224\u001b[0;31m \u001b[0mbnd_const_bnd_fn\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mos\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbnd_path\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0m_bnd_fn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrsplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'.'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m'_0001.cmp'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 225\u001b[0m \u001b[1;31m# also write the accompanying .pli file!\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 226\u001b[0m \u001b[1;31m# TODO: parse .pli file\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[0;32mC:\\Anaconda2\\lib\\bdb.pyc\u001b[0m in \u001b[0;36mtrace_dispatch\u001b[0;34m(self, frame, event, arg)\u001b[0m\n\u001b[1;32m 47\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[1;31m# None\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 48\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mevent\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m'line'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m---> 49\u001b[0;31m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdispatch_line\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 50\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mevent\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m'call'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 51\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdispatch_call\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0marg\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[0;32mC:\\Anaconda2\\lib\\bdb.pyc\u001b[0m in \u001b[0;36mdispatch_line\u001b[0;34m(self, frame)\u001b[0m\n\u001b[1;32m 66\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstop_here\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbreak_here\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 67\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0muser_line\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m---> 68\u001b[0;31m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mquitting\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mBdbQuit\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 69\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtrace_dispatch\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 70\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[0;31mBdbQuit\u001b[0m: " ] } ], "source": [ "keys = ['waterway', 'waterway', 'waterway', 'waterway']\n", "values = ['ditch', 'stream', 'river', 'drain']\n", "depths = [1., 1., 2., 0.5]\n", "widths = [1., 1., 5., 0.5]\n", "objects = []\n", "for key, value, depth, width in zip(keys, values, depths, widths)[0:1]:\n", " print('Adding {:s} of type {:s} with depth {:.2f} and width {:.2f}'.format(key, value, depth, width))\n", " objects_part = osm2channel(db_fn,\n", " check_fields=check_fields,\n", " bbox=domain,\n", " key=key,\n", " value=value,\n", " depth=depth,\n", " width=width,\n", " proftype=2,\n", " layer_index=1,\n", " dtm_fn=dtm_fn)\n", " objects += objects_part\n", "# write to files\n", "[o.to_pli(pli_fn, o._sname, o.feature, append=True) for o in objects]\n", "[o.to_xyz(dtm_xyz_fn, o._geom, o.dtm_samples, append=True) for o in objects]\n", "[o.to_xyz(prof_xyz_fn, o.profdef[n]['geometry'], [o._id], append=True) for o in objects for n in range(2)]\n", "[o.to_profdef(profdef_fn, o.profdef[0]['properties'], append=True) for o in objects]\n", "[o.to_bnd_cnds(bnd_fn, o.bnd_cnds[n], bnd_path=os.path.split(bnd_fn)[0], append=True) for o in objects for n in range(len(o.bnd_cnds))]\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "o = objects[1]\n", "len(o.bnd_cnds)\n", "print os.path.split(bnd_fn)[0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def fmt_pli_header(name, geom, keys):\n", " pli_header_fmt = \"\"\"{:s}\n", "{:6d}{:6d}\n", "\"\"\".format\n", " return pli_header_fmt(name, len(geom.xy[0]), 2+len(keys))\n", "def fmt_pli(name, feature, keys):\n", " \"\"\"\n", " Args:\n", " name: name of feature to write\n", " feature: feature to write (1st and 2nd field goes to geometry)\n", " keys: keys to write to 3rd, 4th and xth fields\n", "\n", " Returns:\n", "\n", " \"\"\"\n", " pli_row_fmt = str('{:15.3f}{:15.3f}' + '{:15.3f}'*len(keys) + '\\n').format\n", " pli_header = fmt_pli_header(name, feature['geometry'], keys)\n", " pli_rows = ''\n", " for n, (x, y) in enumerate(zip(*feature['geometry'].xy)):\n", " vals = [float(feature['properties'][key]) for key in keys]\n", " pli_rows += pli_row_fmt(x, y, *vals)\n", " return pli_header + pli_rows\n", "\n", "s = fmt_pli('some_geom', objects[1].feature, ['depth', 'id'])\n", "print s" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#\n", "fn_shp = r'd:\\OneDrive\\projects\\1230843_Challenge_Fund\\OSM\\manzese_channels.shp'\n", "fn_bnd_shp = r'd:\\OneDrive\\projects\\1230843_Challenge_Fund\\OSM\\manzese_boundaries.shp'\n", "# write new geometries to shapefile to check\n", "from shapely.geometry import mapping, LineString\n", "import fiona\n", "from fiona import crs\n", "epgs=32737 # UTM37S\n", "\n", "# Define a polygon feature geometry with one attribute\n", "schema = {\n", " 'geometry': 'LineString',\n", " 'properties': {'id': 'int', \n", " 'depth': 'float',\n", " 'width': 'float',\n", " },\n", "}\n", "\n", "schema_bnd = {\n", " 'geometry': 'LineString',\n", " 'properties': {'id': 'int', \n", " 'bnd_type': 'str',\n", " 'bnd_pli_fn': 'str',\n", " },\n", "}\n", "\n", "# Write a new Shapefile\n", "with fiona.open(fn_shp, 'w', 'ESRI Shapefile', schema, crs=crs.from_epsg(epgs)) as c:\n", " ## If there are multiple geometries, put the \"for\" loop here\n", " for o in objects:\n", " c.write({\n", " 'geometry': mapping(o.geom_utm), # write line in utm\n", " 'properties': {'id': int(o.osm_id), \n", " 'depth':float(o.depth), \n", " 'width':float(o.width),\n", "# 'proftype':float(o.proftype),\n", " },\n", " })\n", "# also write a shapefile for the boundary conditions\n", "# Write a new Shapefile\n", "with fiona.open(fn_bnd_shp, 'w', 'ESRI Shapefile', schema_bnd, crs=crs.from_epsg(epgs)) as c:\n", " ## If there are multiple geometries, put the \"for\" loop here\n", " for o in objects:\n", " for bnd_cnd in o.bnd_cnds:\n", " if bnd_cnd['geom'] is not None:\n", " c.write({\n", " 'geometry': mapping(bnd_cnd['geom']), # write boundary polyline in utm\n", " 'properties': {'id': int(o.osm_id), \n", " 'bnd_type':str(bnd_cnd['type']), \n", " 'bnd_pli_fn':str(bnd_cnd['bnd_fn']),\n", " },\n", " })" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print str(bnd_cnd['bnd_fn'])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.11" } }, "nbformat": 4, "nbformat_minor": 0 }