{ "cells": [ { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "from urllib2 import urlopen\n", "import ogr" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import urllib2\n", "urllib2.url" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "http://overpass.osm.rambler.ru/cgi/xapi_meta?*[bbox=11.5,48.1,11.51,48.11]\n" ] } ], "source": [ "url = r'http://overpass.osm.rambler.ru/cgi/xapi_meta?*[bbox=11.5,48.1,11.51,48.11]'\n", "fn = 'test.osm'\n", "print(url)\n", "response = urlopen(url)\n", "with open(fn, 'w') as f:\n", " f.write(response.read())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "that works nicely, let's see if we can get these data read in and if the fields are left as is without ogr modifications to a \"other_tags\" attribute" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0: points\n", "1: lines\n" ] } ], "source": [ "db_fn = 'test.osm'\n", "ds = ogr.Open(db_fn)\n", "for i in range(ds.GetLayerCount())[0:2]:\n", " print(str(i) + ': ' + str(ds.GetLayerByIndex(i).GetName()))\n", " \n", " # create fields using OGR\n", " src_lyr = ds.GetLayerByIndex(i)\n", " f = src_lyr.GetFeature(1)\n", " if f:\n", " for i in range(f.GetFieldCount()):\n", " fd = f.GetFieldDefnRef(i)\n", " print(\"--> {:s}: {:s}\".format(fd.GetName(), fd.GetTypeName()))\n", "\n", "ds.Destroy()" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'src_lyr' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0msrc_lyr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mGetFeature\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mNameError\u001b[0m: name 'src_lyr' is not defined" ] } ], "source": [ "src_lyr.GetFeature(1)" ] }, { "cell_type": "code", "metadata": {}, "outputs": [], "source": [ "" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python [conda root]", "language": "python", "name": "conda-root-py" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2.0 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.12" } }, "nbformat": 4, "nbformat_minor": 1 }