{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import xml.etree.ElementTree as ET\n", "\n", "filename = '../raw/Kustfundament_Barro_2011/Kustfundament_def_versie_Barro_1juni2011.shp'\n", "destination = '../cached/kustfundament.kml'\n", "formatted = '../processed/kustfundament.kml'" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "INFO: Open of `../raw/Kustfundament_Barro_2011/Kustfundament_def_versie_Barro_1juni2011.shp'\r\n", " using driver `ESRI Shapefile' successful.\r\n", "\r\n", "Layer name: Kustfundament_def_versie_Barro_1juni2011\r\n", "Metadata:\r\n", " DBF_DATE_LAST_UPDATE=2011-06-15\r\n", "Geometry: Polygon\r\n", "Feature Count: 1\r\n", "Extent: (-122.440156, 376135.439226) - (244113.074501, 629945.679293)\r\n", "Layer SRS WKT:\r\n", "PROJCS[\"RD_New\",\r\n", " GEOGCS[\"GCS_Amersfoort\",\r\n", " DATUM[\"Amersfoort\",\r\n", " SPHEROID[\"Bessel_1841\",6377397.155,299.1528128]],\r\n", " PRIMEM[\"Greenwich\",0.0],\r\n", " UNIT[\"Degree\",0.0174532925199433]],\r\n", " PROJECTION[\"Oblique_Stereographic\"],\r\n", " PARAMETER[\"False_Easting\",155000.0],\r\n", " PARAMETER[\"False_Northing\",463000.0],\r\n", " PARAMETER[\"Central_Meridian\",5.38763888888889],\r\n", " PARAMETER[\"Scale_Factor\",0.9999079],\r\n", " PARAMETER[\"Latitude_Of_Origin\",52.15616055555555],\r\n", " UNIT[\"Meter\",1.0]]\r\n", "Id: Integer (6.0)\r\n" ] } ], "source": [ "# print some details about the file\n", "!ogrinfo -so $filename Kustfundament_def_versie_Barro_1juni2011" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# convert to KML\n", "!ogr2ogr -f KML $destination $filename " ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# create new style with some transparency\n", "style = \"\"\"\n", "\n", "\"\"\"\n", "\n" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ff0000ff0\n", "\t\n" ] } ], "source": [ "# lookup old style\n", "tree = ET.parse(destination)\n", "root = tree.getroot()\n", "placemark = root.find('.//{http://www.opengis.net/kml/2.2}Placemark')\n", "style_el = placemark.find('{http://www.opengis.net/kml/2.2}Style')\n", "# current style, will be replaced\n", "ET.dump(style_el)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "# replace the style element with our style\n", "new_style_el = ET.fromstring(style)\n", "# remove old style\n", "placemark.remove(style_el)\n", "# insert new\n", "placemark.insert(0, new_style_el)\n", "# save file\n", "tree.write(formatted)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "hide_input": false, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.3" } }, "nbformat": 4, "nbformat_minor": 2 }