{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"5a186b18-89a2-e3b0-1954-2e052a74e0db"},"outputs":[],"source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nfrom shapely import wkt, geometry\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nlbl = pd.read_csv('../input/train_wkt_v4.csv')\n\nsquare = geometry.Polygon([(0.01, -0.01), (0.01, -0.02), (0.02, -0.02), (0.02, -0.01)])\nbroken = []\nfor i, row in lbl.iterrows():\n    poly = wkt.loads(row[2])\n    try:\n        poly.intersection(square)\n    except:\n        broken.append((i, poly))\n\nbroken"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"afdba692-d54f-5038-34d3-551ef791d09c"},"outputs":[],"source":"all(p.is_valid for p in broken[0][1])"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"b966d8e7-1fd2-bc90-bbcd-bee7aecb3c4d"},"outputs":[],"source":"fixed = geometry.MultiPolygon([p for p in broken[0][1] if p.is_valid])\n\nfixed.intersection(square)"}],"metadata":{"_change_revision":0,"_is_fork":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.6.0"}},"nbformat":4,"nbformat_minor":0}