Created
June 7, 2016 02:24
-
-
Save kiichi/23538a4d083675fbfa6c5d2b80bc8a1d to your computer and use it in GitHub Desktop.
Intersections between different objects using shapely and pyproj. Could be wrapped in geopandas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Intersections between different objects | |
| # This demo shows intersects function between | |
| # Polygons (Box and Circle) | |
| # Note that applying buffer in (m) after projection happened | |
| # | |
| # 1) Reproject WGS84 to Web Mercator which uses m in UnicodeTranslateError | |
| # 2) Call intersects | |
| from shapely.geometry import Point,Polygon | |
| import pyproj | |
| def proj_to_plane(lat, lon): | |
| srcp = pyproj.Proj(init='epsg:4326') # WGS84: Lat Lng | |
| destp = pyproj.Proj(init='epsg:3857') # Web Mercator which uses m | |
| return pyproj.transform(srcp, destp, lon, lat) | |
| poly = Polygon([ | |
| proj_to_plane(40,-90), | |
| proj_to_plane(40,-79), | |
| proj_to_plane(49,-79), | |
| proj_to_plane(49,-90), | |
| proj_to_plane(40,-90) | |
| ]) | |
| (rprojx,rprojy) = proj_to_plane(44,-88) | |
| pt = Point(rprojx,rprojy) | |
| circle = pt.buffer(300*1000) # 300km circle | |
| result = poly.intersects(circle) | |
| print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Another intersection example between a box and circle(s) look like this: https://twitter.com/objectgraph/status/740006995399446528