{ "metadata": { "name": "", "signature": "sha256:ba1607d3481ad10b36292d4d6aa243f2bafea730e04533cf19e114b20bd82f0b" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "The WGS extent of image in JSON format has a crossing" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import json, webbrowser" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 9 }, { "cell_type": "code", "collapsed": false, "input": [ "from osgeo import gdal, gdal_array" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 10 }, { "cell_type": "code", "collapsed": false, "input": [ "ds = gdal.Open(\"/vsicurl/http://landsat-pds.s3.amazonaws.com/L8/225/071/LC82250712015212LGN00/LC82250712015212LGN00_B4.TIF\")" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 11 }, { "cell_type": "code", "collapsed": false, "input": [ "jsInfo = gdal.Info(ds, format='json')" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 12 }, { "cell_type": "code", "collapsed": false, "input": [ "ds = None" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 13 }, { "cell_type": "code", "collapsed": false, "input": [ "jsExtent = jsInfo['wgs84Extent']" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 14 }, { "cell_type": "code", "collapsed": false, "input": [ "js_to_geojson_io = {\n", " \"type\": \"FeatureCollection\",\n", " \"features\": [\n", " {\n", " \"type\": \"Feature\",\n", " \"properties\": {},\n", " \"geometry\": jsExtent\n", " }\n", " ]\n", "}" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 28 }, { "cell_type": "code", "collapsed": false, "input": [ "v_json = json.dumps(js_to_geojson_io)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 29 }, { "cell_type": "code", "collapsed": false, "input": [ "print v_json" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "{\"type\": \"FeatureCollection\", \"features\": [{\"geometry\": {\"type\": \"Polygon\", \"coordinates\": [[[-55.1980338, -14.8524218], [-55.1789556, -16.9806545], [-53.0479293, -14.8254994], [-53.0061936, -16.9496626], [-55.1980338, -14.8524218]]]}, \"type\": \"Feature\", \"properties\": {}}]}\n" ] } ], "prompt_number": 30 }, { "cell_type": "code", "collapsed": false, "input": [ "url = \"http://geojson.io/#data=data:application/json,{0}\".format( v_json )" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 18 }, { "cell_type": "code", "collapsed": false, "input": [ "webbrowser.open( url ) # Open geojson.io" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 17, "text": [ "True" ] } ], "prompt_number": 17 } ], "metadata": {} } ] }