{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"17817005-b40e-36df-ca28-a2620de9fd7d"},"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\nfrom shapely import 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\nfor i, r in lbl.iterrows():\n    polys = wkt.loads(r[2])\n    for j, poly in enumerate(polys):\n        if not poly.is_valid:\n            break\n\ni, j, polys, poly"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"d007544c-30f5-0c55-a237-0f837ada6e59"},"outputs":[],"source":"newpoly = geometry.MultiPolygon([p for p in polys if p.is_valid])\n\nlen(newpoly), len(polys), len([p for p in polys if p.is_valid])"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"847284f1-030c-9624-6896-e53c48d965f3"},"outputs":[],"source":"polys.intersection(geometry.Polygon([(-1,-1), (-1, 1), (1, 1), (1, -1)]))"}],"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}