{ "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\n", "from shapely.geometry import LineString" ] }, { "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 osm2culvert(fn, check_fields, layer_index=1, # input \n", "# bbox=None, key='tunnel', value='culvert', # filter\n", "# depth=2., width=1., 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", "# objects = []\n", "# for data in features:\n", "# geom = data['geom']\n", "# if type(geom) is LineString:\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.Culvert(dtm_fn=dtm_fn, **data)\n", "# objects.append(o)\n", "# else:\n", "# print(data['id'])\n", "# return objects\n", "\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "d:\\temp\\CF1.2\\DFM_data\\structures\n" ] } ], "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, r'manzese_culverts.pliz')\n", "struct_fn = os.path.join(outDir, r'structures.ini')\n", "struct_pli_dir = os.path.join(outDir, 'structures')\n", "print(struct_pli_dir)\n", "\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", "\n", "check_fields = {\n", " 'width': float,\n", " 'depth': float\n", "}" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Adding culverts with depth 1.00 and width 1.00\n" ] } ], "source": [ "depth = 1.\n", "width = 1.\n", "objects = []\n", "\n", "print('Adding culverts with depth {:.2f} and width {:.2f}'.format(depth, width))\n", "objects = osm2dh.osm2culvert(db_fn,check_fields, layer_index=1, # input \n", " bbox=domain, depth=depth, width=width, dtm_fn=dtm_fn, bbox_buffer=-10)\n", "\n", "# write to files\n", "a = [o.to_pli(pli_fn) for o in objects]\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [], "source": [ "b = [o.gate.to_struct(struct_fn, struct_pli_dir) for o in objects]" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'geometry': ,\n", " 'properties': {'crest_level': 26.347750416981221, 'id': 'gate337378600'}}\n" ] } ], "source": [ "from pprint import pprint\n", "pprint(objects[1].gate.feature)\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "float\n" ] } ], "source": [ "a = 34.\n", "if isinstance(a, numpy.generic):\n", " b = numpy.asscalar(a)\n", "else:\n", " b = a\n", "print type(b).__name__" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python [Root]", "language": "python", "name": "Python [Root]" }, "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.12" } }, "nbformat": 4, "nbformat_minor": 0 }