{"id":16229385,"url":"https://github.com/brandonxiang/geojson-python-utils","last_synced_at":"2025-08-25T01:07:39.064Z","repository":{"id":57433818,"uuid":"56040603","full_name":"brandonxiang/geojson-python-utils","owner":"brandonxiang","description":"Python helper functions for manipulating GeoJSON","archived":false,"fork":false,"pushed_at":"2016-09-18T15:12:08.000Z","size":304,"stargazers_count":89,"open_issues_count":0,"forks_count":18,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2025-06-26T07:04:41.357Z","etag":null,"topics":["distance","featurecollection","geojson","polygon","python","utils"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brandonxiang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-12T07:23:45.000Z","updated_at":"2024-07-14T00:01:58.000Z","dependencies_parsed_at":"2022-08-28T05:00:46.299Z","dependency_job_id":null,"html_url":"https://github.com/brandonxiang/geojson-python-utils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/brandonxiang/geojson-python-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonxiang%2Fgeojson-python-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonxiang%2Fgeojson-python-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonxiang%2Fgeojson-python-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonxiang%2Fgeojson-python-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brandonxiang","download_url":"https://codeload.github.com/brandonxiang/geojson-python-utils/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandonxiang%2Fgeojson-python-utils/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271989820,"owners_count":24854702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distance","featurecollection","geojson","polygon","python","utils"],"created_at":"2024-10-10T12:58:12.694Z","updated_at":"2025-08-25T01:07:39.042Z","avatar_url":"https://github.com/brandonxiang.png","language":"Python","readme":"# geojson-python-utils\n\n\u003e 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[中文文档](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","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandonxiang%2Fgeojson-python-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrandonxiang%2Fgeojson-python-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandonxiang%2Fgeojson-python-utils/lists"}