{ "info": { "author": "brandonxiang", "author_email": "1542453460@qq.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python" ], "description": "# geojson-python-utils\n\n> JavaScript Version: [geojson-js-utils](https://github.com/maxogden/geojson-js-utils)\n\nThis project is inspired by [geojson-js-utils](https://github.com/maxogden/geojson-js-utils). Geojson becomes more popular than before. These algorithms also are what I want to learn about, which may give you some inspiration.\n\n## Chinese Doc\n\n[\u4e2d\u6587\u6587\u6863](README_CN.md)\n\n## Usage\n\nCopy `geojson_utils.py` into your working directory, and import the modules into your py file.\n\n```\nfrom geojson_utils import linestrings_intersect\n```\n\nor install\n\n```\npip install geojson_utils\n```\n\n## Example\n\n### Linestrings Intersection\n\nTo valid whether linestrings from geojson are intersected with each other.\n\n```\nfrom geojson_utils import linestrings_intersect\n\ndiagonal_up_str = '{ \"type\": \"LineString\",\"coordinates\": [[0, 0], [10, 10]]}'\ndiagonal_down_str = '{ \"type\": \"LineString\",\"coordinates\": [[10, 0], [0, 10]]}'\nfar_away_str = '{ \"type\": \"LineString\",\"coordinates\": [[100, 100], [110, 110]]}'\ndiagonal_up = json.loads(diagonal_up_str)\ndiagonal_down = json.loads(diagonal_down_str)\nfar_away = json.loads(far_away_str)\n\nprint linestrings_intersect(diagonal_up, diagonal_down)\n#[{'type': 'Point', 'coordinates': [0, 0]}]\nprint linestrings_intersect(diagonal_up, far_away)\n#[]\n```\n\n### Point in Polygon\nTo valid whether the point is located in a polygon\n\n```\nfrom geojson_utils import point_in_polygon\n\nin_str = '{\"type\": \"Point\", \"coordinates\": [5, 5]}'\nout_str = '{\"type\": \"Point\", \"coordinates\": [15, 15]}'\nbox_str = '{\"type\": \"Polygon\",\"coordinates\": [[ [0, 0], [10, 0], [10, 10], [0, 10] ]]}'\nin_box = json.loads(in_str)\nout_box = json.loads(out_str)\nbox = json.loads(box_str)\n\nprint point_in_polygon(in_box, box)\n#True\npoint_in_polygon(out_box, box)\n#False\n```\n\n\n### Point in Multipolygon\nTo valid whether the point is located in a mulitpolygon (donut polygon is not supported)\n\n```\nfrom geojson_utils import point_in_multipolygon\n\npoint_str = '{\"type\": \"Point\", \"coordinates\": [0.5, 0.5]}'\nsingle_point_str = '{\"type\": \"Point\", \"coordinates\": [-1, -1]}'\nmultipoly_str = '{\"type\":\"MultiPolygon\",\"coordinates\":[[[[0,0],[0,10],[10,10],[10,0],[0,0]]],[[[10,10],[10,20],[20,20],[20,10],[10,10]]]]}'\npoint = json.loads(point_str)\nsingle_point = json.loads(single_point_str)\nmultipoly = json.loads(multipoly_str)\n\nprint point_in_multipolygon(point, multipoly)\n#True\nprint point_in_multipolygon(single_point, multipoly)\n#False\n```\n\n\n### Draw Circle\nTo get a circle shape polygon based on centerPoint and radius\n\n```\nfrom geojson_utils import draw_circle\n\npt_center = json.loads('{\"type\": \"Point\", \"coordinates\": [0, 0]}')\n\nprint len(draw_circle(10, pt_center)['coordinates'][0])\n#15\nprint len(draw_circle(10, pt_center, 50)['coordinates'][0])\n#50\n```\n\n\n### Rectangle Centroid\nTo get the centroid of the rectangle\n\n```\nfrom geojson_utils import centroid\n\nbox_str = '{\"type\": \"Polygon\",\"coordinates\": [[[0, 0],[10, 0],[10, 10],[0, 10]]]}'\nbox = json.loads(box_str)\ncentroid = rectangle_centroid(box)\n\nprint centroid['coordinates']\n#[5, 5]\n```\n \n\n\n### Distance between Two Points\nTo calculate the distance between two point on the sphere like google map (reference http://www.movable-type.co.uk/scripts/latlong.html)\n\n```\nfrom geojson_utils import point_distance\n\nfairyland_str = '{\"type\": \"Point\", \"coordinates\": [-122.260000705719, 37.80919060818706]}'\nnavalbase_str = '{\"type\": \"Point\", \"coordinates\": [-122.32083320617676, 37.78774223089045]}'\nfairyland = json.loads(fairyland_str)\nnavalbase = json.loads(navalbase_str)\n\nprint math.floor(point_distance(fairyland, navalbase))\n# 5852\n```\n\n\n\n### Geometry within Radius\nTo valid whether point or linestring or polygon is inside a radius around a center\n\n```\nfrom geojson_utils import geometry_within_radius\n\ncenter_point_str = '{\"type\": \"Point\", \"coordinates\": [-122.260000705719, 37.80919060818706]}'\ncheck_point_str = '{\"type\": \"Point\", \"coordinates\": [-122.32083320617676, 37.78774223089045]}'\ncenter_point = json.loads(center_point_str)\ncheck_point = json.loads(check_point_str)\n\nprint geometry_within_radius(check_point, center_point, 5853)\n#True\n```\n\n\n### Area\nTo calculate the area of polygon\n\n```\nfrom geojson_utils import area\n \nbox_str = '{\"type\": \"Polygon\",\"coordinates\": [[ [0, 0], [10, 0], [10, 10], [0, 10] ]]}'\nbox = json.loads(box_str)\nprint area(box)\n#100\n```\n\n\n### Centroid\nTo get the centroid of polygon\nadapted from http://paulbourke.net/geometry/polyarea/javascript.txt\n\n```\nfrom geojson_utils import centroid\nbox_str = '{\"type\": \"Polygon\",\"coordinates\": [[ [0, 0], [10, 0], [10, 10], [0, 10] ]]}'\nbox = json.loads(box_str)\n\nprint centroid(box)\n#{\"type\": \"Point\", \"coordinates\": [5, 5]})\n```\n\n\n### Destination point\nTo calculate a destination Point base on a base point and a distance\n\n```\nfrom geojson_utils import destination_point\n\nstartpoint_str = '{\"type\": \"Point\", \"coordinates\": [-122.260000705719, 37.80919060818706]}'\nstartpoint = json.loads(startpoint_str)\n\nprint destination_point(startpoint, 180, 2000)\n#{'type': 'Point', 'coordinates': [-122.26000070571902, 19.822758489812447]}\n```\n\n### Merge Featurecollection geojson \n\nTo merge features into one featurecollection\n\n```\nfrom geojson_utils import merge_featurecollection\nwith open('tests/first.json','r') as fp:\n first = json.load(fp)\nwith open('tests/second.json','r') as fp:\n second = json.load(fp)\nwith open('tests/result.json','r') as fp:\n result = json.load(fp)\nmerge_featurecollection(first,second)\n```\n\n### Simplify other point\n\nSimplify the point featurecollection of poi with another point features accoording by distance.\n\nAttention: point featurecollection only\n\n## Conversion between wgs84, gcj02, bd09\n\nConversion between wgs84, gcj02 and bd09\n\nParameter One: geojson geometry\n\nParameter Two: \n\n- **wgs2gcj** coordinates conversion from wgs84 to gcj02 \n- **gcj2wgs** coordinates conversion from gcj02 to wgs84 \n- **wgs2bd** coordinates conversion from wgs84 to bd09 \n- **bd2wgs** coordinates conversion from bd09 to wgs84 \n- **gcj2bd** coordinates conversion from gcj02 to bd09 \n- **bd2gcj** coordinates conversion from bd09 to gcj02 \n\n\n```\nfrom geojson_utils import convertor\nwith open('tests/province_wgs.geojson', encoding='utf-8') as fp:\n geojson = json.load(fp)\n features = geojson['features']\n for feature in features:\n origin = feature['geometry']['coordinates'][0][0][0]\n result = convertor(feature['geometry'])\n```\n\n\n## TODO\n\n[TODO](TODO,md)\n\n## Development \n\nOn the develop branch\n\n## License\n\n[MIT](LICENSE)\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/brandonxiang/geojson-python-utils", "keywords": "python geojson util calculation", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "geojson_utils", "package_url": "https://pypi.org/project/geojson_utils/", "platform": "", "project_url": "https://pypi.org/project/geojson_utils/", "project_urls": { "Homepage": "https://github.com/brandonxiang/geojson-python-utils" }, "release_url": "https://pypi.org/project/geojson_utils/0.0.2/", "requires_dist": null, "requires_python": "", "summary": "Python helper functions for manipulating GeoJSON", "version": "0.0.2" }, "last_serial": 2679512, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "7375e47d4f94809d93437a205be5746f", "sha256": "8564e9eeb1438bd698075bf30aeea6da5210540c02d79821809637705b19990d" }, "downloads": -1, "filename": "geojson_utils-0.0.1.tar.gz", "has_sig": false, "md5_digest": "7375e47d4f94809d93437a205be5746f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11213, "upload_time": "2016-08-23T13:57:42", "url": "https://files.pythonhosted.org/packages/f2/dc/e3e47d47bcc042e27199b5715ea3c472706f313f6ba70a56d2181f399dcd/geojson_utils-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "81e35e3a7f0001bff7760eceaa1209cf", "sha256": "9d8d4f2078c0c372456ac785964a5c81b3f04e0f562c0ffaf7582e8426042bc1" }, "downloads": -1, "filename": "geojson_utils-0.0.2.tar.gz", "has_sig": false, "md5_digest": "81e35e3a7f0001bff7760eceaa1209cf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11590, "upload_time": "2017-03-03T03:09:22", "url": "https://files.pythonhosted.org/packages/87/d4/b230d55ce24da526fc5f2cf191c3d06dd60e72355452e95d7393c643b0f9/geojson_utils-0.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "81e35e3a7f0001bff7760eceaa1209cf", "sha256": "9d8d4f2078c0c372456ac785964a5c81b3f04e0f562c0ffaf7582e8426042bc1" }, "downloads": -1, "filename": "geojson_utils-0.0.2.tar.gz", "has_sig": false, "md5_digest": "81e35e3a7f0001bff7760eceaa1209cf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11590, "upload_time": "2017-03-03T03:09:22", "url": "https://files.pythonhosted.org/packages/87/d4/b230d55ce24da526fc5f2cf191c3d06dd60e72355452e95d7393c643b0f9/geojson_utils-0.0.2.tar.gz" } ] }