shapely

Shapely intersection: parallel planes

浪尽此生 提交于 2019-12-14 01:22:33
问题 I'm working on determining relationships (boundary/interior intersections) between two 3D objects (triangular faces) and stumbled on Shapely, which I am interested in using instead of implementing my own point/segment/ray/triangle intersection functions. However, I'm running into the following problem: >>> from shapely.geometry import Polygon >>> poly = Polygon([(0,1,1),(1,-1,1),(-1,-1,1)]) >>> poly2 = Polygon([(0,1,0),(1,-1,0),(-1,-1,0)]) >>> poly.intersects(poly2) True >>> poly.equals(poly2

Using Geopandas, how do I select all points not within a polygon?

耗尽温柔 提交于 2019-12-13 14:08:02
问题 I have a DataFrame containing Chicago addresses which I've geocoded into latitude and longitude values, and then into Point objects (making the DataFrame a GeoDataFrame). A small fraction have been incorrectly geocoded with LatLong values outside of Chicago. I have a shapefile for Chicago's boundary (GeoDataFrame), I want to select all rows where the Points are outside of Chicago's boundary polygon. It would be easy to select all points within the polygon (via geopandas sjoin function), but I

How to calculate geodesic distance along a path (lat/lon points) at once?

孤街浪徒 提交于 2019-12-13 03:22:45
问题 Using Python 3.7 with Jupyter Notebook on a Win10 x64. I have a list of lat-long tuples representing a path and I want to calculate the total length along that path in meters. I would like to avoid calculating each segment distance and then adding them all together as I have to do this for 7 million paths. So time efficiency is key. Adding all segments after computing individual distances takes 7ms per path. I want to make it at least 1ms fast. Edit: I need to calculate distances using the

Shapely intersections vs shapely relationships - inexact?

半世苍凉 提交于 2019-12-12 17:50:21
问题 I wonder if I am thinking the wrong way or if this is a bug: I have a linestring and a polygon, I create the intersection points of the line and the polygon's boundary These intersection points should intersect (at least touch) the polygon's boundary, right? from shapely import geometry,wkt line = geometry.LineString([(13.51039642756912, 52.598912814414675), (13.525173800277184, 52.60620240344557)]) poly = geometry.Polygon ([(13.52072838433517, 52.61735554606274), (13.52233276805985, 52

Removing duplicate geometries in Shapely

若如初见. 提交于 2019-12-12 16:26:31
问题 I have a list of Shapely polygons. From that list I want to extract only unique polygons removing the duplicates. How to do it in a faster way? (My list contains thousands of polygons) from shapely.geometry import Polygon lists = [[(1,1),(2,2),(3,3),(4,4)], [(6,6),(7,7),(8,8),(9,9)], [(1,1),(2,2),(3,3),(4,4)]] polys = [Polygon(item) for item in lists] ##This is given condition for poly in polys: test = [p.intersects(poly) for p in polys] ##Return true or false print test [True, False, True]

Plotting disconnected entities with shapely descartes and matplotlib

风格不统一 提交于 2019-12-12 14:26:42
问题 I need to plot a list of disconnected circles which I have created for other purposes in shapely. I was trying to do exactly as the example in http://toblerity.org/shapely/manual.html#cascading-unions shows (see code) but that works only if the circles overlap and the overall thing is connected (which is not in my case). As you can see by replacing the line polygons = [Point(i, 0).buffer(0.7) for i in range(5)] with polygons = [Point(i, 0).buffer(0.7) for i in (0,4)] that breaks with and

Create LineString for unique values in Pandas DataFrame

微笑、不失礼 提交于 2019-12-12 05:29:46
问题 I have a pandas dataframe I would like to iterate over. For instance a simplified version of my dataframe can be: abc begin end ID Lat Long def1 001 123 CAT 13.167 52.411 def2 002 129 DOG 13.685 52.532 def3 003 145 MOOSE 13.698 52.131 def1 004 355 CAT 13.220 52.064 def2 005 361 CAT 13.304 52.121 def3 006 399 DOG 12.020 52.277 def1 007 411 MOOSE 13.699 52.549 def2 008 470 MOOSE 11.011 52.723 I would like to iterate over each unique ID and create a (shapely)LineString from the matching Lat /

Find longest “straight” path between Point and Polygon

百般思念 提交于 2019-12-12 04:56:48
问题 Is it possible to find the longest straight distance between a Point (latitude and longitude) and a Polygon in Shapely ? I read it's possible to find the closest path, but i'm not sure about the longest. 回答1: Try the Hausdorff distance, which is returned by the g1.hausdorff_distance(g2) fuction: from shapely.geometry import Polygon, Point poly = Polygon([(-1, -1), (-2, 2), (4, 4), (4, -1), (-1, -1)]) p = Point(0, 0) poly.hausdorff_distance(p) # 5.656854249492381 Keep in mind, Shapely only

Importing a PostGIS geometry type into Python as a geometry type from Shapely?

落爺英雄遲暮 提交于 2019-12-12 04:36:32
问题 So I have a situation where I have a ton of Linestrings of a broken up route, where I need to Union them together using Shapely's LineMerge or Union OR PostGIS ST_Union. My idea right now is to use Shapely to import the Linestrings as Geometry types. Union them or merge them using Shapely, and then export back to a results table in the database. However, the geometry type in the PostGIS database is just a bunch of gibberish. Like... 01020000020e61000.... How can I translate this from the

Creating a dataframe of Shapely polygons gives “ValueError: A LinearRing must have at least 3 coordinate tuples”

守給你的承諾、 提交于 2019-12-11 05:48:30
问题 I want to create a heatmap of say, provincial population of China and I found this guide to a similar problem here. I have no problem going through the example code though I have to admit that I don't thoroughly understand them all. However when I was trying to mimic the example by using the shapefile of China, the code ran ok till the following df_map = pd.DataFrame({ 'poly': [Polygon(xy) for xy in m.china], 'ward_name': [ward['NAME'] for ward in m.china_info]}) It generates an error that