{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import os\n", "import numpy as np\n", "\n", "# set path to osm scripts dir\n", "os.chdir(r\"d:\\repos\\hydrotools\\sandbox\\osmmodelbuilding\")\n", "\n", "# path to save file\n", "osm_fn = r\"d:\\temp\\SanJuan\\OSM\\SanJuan_bbox.db\"\n", "# path to read bbox\n", "fn_bbox = r\"d:\\temp\\SanJuan\\bbox\"\n", "# get basename without extension\n", "fileid = \".\".join(os.path.basename(osm_fn).split(\".\")[:-1])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "use http://boundingbox.klokantech.com csv format for bounding box." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(-66.052055499999994, 18.4417425)\n" ] } ], "source": [ "# read bbox. \n", "bbox_latlon = np.loadtxt(fn_bbox, delimiter=\",\")\n", "xmin, ymin, xmax, ymax = bbox_latlon\n", "print(np.mean([xmin,xmax]), np.mean([ymin,ymax]))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from osm2dh import download_overpass\n", "\n", "# remove exisiting file with same name\n", "if os.path.exists(osm_fn):\n", " os.unlink(osm_fn)\n", "\n", "# download data to tmp file and then rename\n", "download_overpass('{:s}.tmp'.format(osm_fn), bbox_latlon)\n", "os.rename('{:s}.tmp'.format(osm_fn), osm_fn)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "use gdal_auth.py to get token, see http://www.gdal.org/drv_gft.html" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "GFT_REFRESH_TOKEN = \"1/iiaJbsxbMqqKb_ZPcASNBThEjpnDZUMp06-VVG9QVoA\" #os.environ['GFT_REFRESH_TOKEN']" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "save d:\\temp\\SanJuan\\OSM\\SanJuan_bbox.db layer 1 to SanJuan_bbox_lines in GDrive\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "save d:\\temp\\SanJuan\\OSM\\SanJuan_bbox.db layer 3 to SanJuan_bbox_multipolygons in GDrive\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Self-intersection at or near point -66.069046700000001 18.447367199999999\n", "Self-intersection at or near point -66.067505999999995 18.449123499999999\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Ring Self-intersection at or near point -66.0549398 18.449698399999999\n", "Self-intersection at or near point -66.054438303058816 18.450487079765598\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Self-intersection at or near point -66.055503900000005 18.450248899999998\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Self-intersection at or near point -66.054659257556764 18.442598693267719\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n", "Inserted 250 features ...\n" ] } ], "source": [ "from osm2dh import convert2ft\n", "import ogr\n", "# gdal.SetConfigOption('CPL_DEBUG', 'OFF')\n", "\n", "append = False\n", "fix_geometry = True\n", "simplify_geometry = False\n", "\n", "check_fields_list = [\n", " {'layer': int,\n", " 'depth': float,\n", " 'width': float},\n", " {'building_levels': int,\n", " 'height': float,\n", " 'building': str}]\n", " \n", "\n", "for i, check_fields in zip([1,3], check_fields_list): # lines and multipolygons\n", " # open ogr to read name of layer\n", " ds=ogr.Open(osm_fn)\n", " name = ds.GetLayerByIndex(i).GetName()\n", " ds.Destroy()\n", " output_table = '{}_{}'.format(fileid, name)\n", " print(\"save {} layer {:d} to {} in GDrive\".format(osm_fn, i, output_table))\n", " \n", " # convert to ft\n", " convert2ft(osm_fn, output_table, GFT_REFRESH_TOKEN,\n", " append=append, fix_geometry=fix_geometry, simplify_geometry=simplify_geometry, \n", " layer=i, check_fields=check_fields) " ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python [conda root]", "language": "python", "name": "conda-root-py" }, "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 }