Questions tagged [shapely]

Shapely is an open source Python package for construction and analysis of 2D planar geometric objects common to geographic information systems.

Filter by
Sorted by
Tagged with
3
votes
1answer
126 views

Strange warning/error when working with polygons

Reading a polygon shapefile with geopandas I got a strange error. I found out it is a normally hidden warning about another error, which I saw only because I turned warnings to errors. It also appears ...
0
votes
0answers
9 views

parallel_offset changes number of point in LineString(Shapely)

import matplotlib.pyplot as plt import pandas as pd from shapely.geometry import LineString from shapely.geometry.base import JOIN_STYLE path = [ dict(x=0, y=0), dict(x=1, y=0), dict(x=2, ...
1
vote
1answer
134 views

Making a polygon from list of xy coordinates using Shapely

I am new to Python (moving over from Matlab) and am trying check if a set of points are inside a polygon using Shapely as I am not able to install GeoPandas (tried for over a week now and am tired of ...
2
votes
1answer
920 views

Finding shortest distance from point(s) to number of polygons at varying angles using shapely?

My aim is to calculate the distance a point is from land in Python, trying to replicate the functionality of fetchR. Given an origin and distance, I create shapely LineStrings which radiate out from ...
0
votes
2answers
754 views

GEOSGeom_createLinearRing_r returned a NULL pointer

I want to import cartopy on Python3, but it keeps showing me File "shapely\speedups\_speedups.pyx", line 408, in shapely.speedups._speedups.geos_linearring_from_py ...
0
votes
1answer
49 views

Problem with intersection between two Geopandas Dataframes

I have 2 shape files one "country.shp" (containing the tiles geometry covering the whole country) & other "district.shp"(containing one particular district). Now I want to get the tiles ...
1
vote
1answer
50 views

Checking if geopoint is in shapefile containing world cities

I have approximately 13 million (lat,long) geocoordinates. I also have a shapefile containing 3460 cities. I need to find the City in which this geocoordinate can be found. This is what I am currently ...
1
vote
0answers
42 views

Splitting polygon into equal area polygons using shapely

I would like to split complex geometries into n smallest geometries of the same area in Python. While I can divide simple geometry in the following way: from shapely.geometry import LineString, ...
2
votes
0answers
20 views

Finding the bounds of a single pixel in a raster in Python

I have a satellite image and a group of polygons scattered around the image. The polygons are small and cover a single-pixel most of the time; I'm trying to create a new raster where each pixel value ...
36
votes
5answers
58k views

How to write Shapely geometries to shapefiles?

Can someone demonstrate a simple way to write geometry data-structures from shapely into shapefiles? I am particularly interested in polygons with holes and linestrings. It would also be beneficial to ...
1
vote
1answer
43 views

Dragging a polygon in shapely

If I have a polygon and I translate it in a direction n to a new location, how can I create a new polygon formed by the act of translation? To take a simple example consider the rectangle below with ...
1
vote
2answers
823 views

including SRID in WKBWriter in Shapely doesn't work

I want to encode coordinates of LineString in WKB with the SRID included wkbwriter = shapely.geos.WKBWriter(shapely.geos.lgeos, big_endian=False, include_srid=True) geo = wkbwriter.write_hex(...
2
votes
0answers
24 views

Polygon simplification without intersection in GeoPandas/Shapely

Is there an in-the-can solution for simplifying a boundary that won't intersect the original poly? Something like .convex_hull but with a fillet option possibly? For example, .simplify() produces ...
0
votes
0answers
21 views

Fiona Saving Gives DriverIOError

I have a script that I used before to clip polygons. I modified it a touch to use in another place, but am running into a fiona.errors.DriverIOError. As far as I can tell, all the code is working ...
0
votes
2answers
44 views

How to convert string type to shapely object

I used to have a Pandas data frame with geometry column (I guess you call it as GeoPandas data frame) where all the instances were multiline string with shapely.geometry data type. When I saved it as ...
0
votes
1answer
32 views

GeoPandas: Error plotting after clipping shapefile

I am interested in plotting data on the city of Göteborg (in English Gothenburg, Sweden). I am starting with shapefiles of Sweden and then clipping them to concentrate my study in Göteborg. # ...
1
vote
1answer
909 views

Calculate area of polygons in square meters when CRS is EPSG:25833

I have EPSG:28533 coordinates and would like to calculate its area in square meters and then transform these coordinates to EPSG:3857. I have taken the code from here to calculate the area but it does ...
1
vote
1answer
42 views

Python Shapely crop / clip using 'intersection': cropped line is split at self-intersections

In using 'intersection' to crop / clip a single 'braided' line using a rectangle (actually a grown version of that rectangle using 'buffer'), the internal portion of the line gets split on self-...
1
vote
0answers
52 views

Wrong features when exporting vectorized raster data to a file using GeoPandas after applying a filter and a dissolve operation

I have a raster file with black areas having a value of 0 and white areas having a value of 1, resulting from a visibility analysis: I vectorized this raster after loading it with rasterio: import ...
0
votes
0answers
30 views

Multiple 3D polygons to a single 2D MultiPolygon having individual overlapping features or a single 3D MultiPolygonZ

I narrowed a 3D problem to a GeoDataFrame G containing four Shapely polygons, each is a 3D flat triangle. In 3 dimensions, these polygons all share a common summit and also a common edge, 2-by-2. They ...
0
votes
1answer
300 views

GeoPandas setting geometry for a row with .loc and Multipolygons

Given the following example: def merge_with_largest(input_gdf,poly): # select the polygons bordering polygon close_by_gdf = input_gdf[input_gdf.geometry.intersects(poly)] # selects ...
2
votes
1answer
68 views

Dissolving polygons based on polygon attribute values in Python

I have a shapefile, with multiple features inside. I am trying to dissolve the nearby/adjacent features based on the shapefile particular attribute value (gridcode), but the difference shouldn't be ...
0
votes
1answer
45 views

Convert distance() in shapely to kilometres

I am using the following code: x = POINT(-1.154321, 55.124412) y = POINT(-1.2354352, 56.2345235) distance = x.distance(y) print(distance) I am unsure what distance measurement is being used, but my ...
3
votes
2answers
50 views

Obtain min and max lat,long for all geometries using GeoPandas

I am reading a shapefile of a county and need to extract the min and max coordinates across all geometries. It seems like this is possible with each individual geometries in the shapefile with shapely ...
1
vote
1answer
216 views

Dump multiple geometry columns of a GeoDataFrame to Features in a FeatureCollection (GeoJSON) instead of properties?

I have a GeoDataFrame with some of its attributes that are geometries (only the position is the one which was interpreted as the active geometry when loading the data from PostGIS): import psycopg2 ...
26
votes
3answers
25k views

How to polygonize raster to shapely polygons

I am seeking an open-source python solution to convert raster to polygon (no ArcPy). I did know the GDAL function to convert raster to polygon, and here is the manual: http://pcjericks.github.io/py-...
1
vote
1answer
2k views

Merging multi-polygons gives me error in shapely

I am trying to merge a bunch of either polygons or multipolygons by the merge_multi_polygons function in shapely, I am using my below code inside Spark elems=row['_c0'] ...
18
votes
4answers
17k views

Welding individual line segments into one LineString using Shapely [closed]

I'm using Shapely in python and I'm given a MultiLineString with a bunch of Linestring objects. I can guarantee that all the LineString objects are simple lines with only 2 vertices and that they are ...
2
votes
1answer
820 views

Find nearest polygon (from GeoSeries) to point (from GeoSeries)

I have two GeoSeries, consisting of points and polygons. I want to find the polygon in dataframe B that is closest to each point in dataframe A. The polygons are rooftops from https://github.com/...
1
vote
2answers
877 views

Extract polygon name dataframe if the geo-point is inside polygon?

I have two dataset one with polygon name and polygon and other with location name and latitude and longitude. Data 1 (Geopandas Dataframe) import geopandas as gpd data_poly = gpd.read_file(path + "...
1
vote
1answer
43 views

Delete polygons that have one or more side parts in common [closed]

I am trying to solve a particular case of comparison of polygons to others. I have five polygons distributed as in the figure below. The black polygon is the one with the largest area. There may be ...
1
vote
2answers
52 views

Plot shapely polygon on top of rasterio

I have 2D raster and I'm interested in plotting on top of it polygon. When I print the geometry and its' type I get this: #this is inside a loop that takes each time one row which is one polygon ...
0
votes
1answer
40 views

Float point problems using Shapely using WKT

I am having float point problems using the Shapely library. I realize now, (after reading the instructions) that using pt.wkt will trim the variable therefore, I am changing my code to uses wkt.dumps(...
1
vote
2answers
41 views

Converting list of coordinates and attributes into GeoDataFrame using Geopandas/Shapely

I have a list with two sets of coordinates and two attributes associated with them. The list was populated from my email so the structure can be modified if need be. Current list structure: [(((long1, ...
4
votes
1answer
174 views

Obtaining a transform for Affine transformation (Cartesian to geodetic coordinate system)

I have a Line, defined as 2 points in a Cartesian coordinate system. Shapely allows projecting this line with an affine transformation if a transform is specified. from shapely.geometry import ...
2
votes
1answer
53 views

Python - Shapely to convert 2 columns to WKB

I have 2 columns in a CSV called Longitude and Latitude which are being parsed using my Python AWS Lambda Code. I am using the shapely module with the following code to convert the long/lats into ...
1
vote
1answer
28 views

Efficient way to get the geocoordinates of all the intersections in a city (using GeoPandas / Shapely / Fiona)?

Given a dataset of roads for a city, represented as LineStrings and loaded into GeoPandas, what is an efficient, built-in-way to get the geocoordinates of all the intersections, using GeoPandas or ...
7
votes
3answers
12k views

Plotting Shapely Multipolygon using Matplotlib

I have few polygons or boxes. Ones intersect each other but some are isolated. For example I have free figures: import shapely.geometry as sg import shapely.ops as so import matplotlib.pyplot as plt ...
2
votes
1answer
2k views

Interpolating every X distance along line in shapely

If I have a shapely multiline object that contains many lines whose total length each is 50km (when traced from the origin), and I want to interpolate along the multiline every X meters (let's say ...
2
votes
1answer
2k views

How to create shape in Shapely from an SVG <path> element?

AFAIK, you need to provide a list of coordinates to Shapely in order to create a shape but that's not how SVG <path> element works. Is there a way to create a Shapely shape using an SVG <path&...
23
votes
6answers
22k views

Area in KM from Polygon of coordinates

I have polygons from coordinates in (python shapely) that looks like this POLYGON ((24.8085317 46.8512821, 24.7986952 46.8574619, 24.8088238 46.8664741, 24.8155239 46.8576335, 24.8085317 46.8512821)) ...
1
vote
1answer
15 views

MultiPolygon Filtering in Shapely

I have a large set S: List[Polygon] (Shapely Polygons), and a mask: MultiPolygon. I want to filter out all of the polygons in S that intersect with mask. I can write: S2 = [p for p in S if not mask....
1
vote
1answer
24 views

Transform GeoJSON shape with 2 requirements

We have this shape in GeoJSON: https://gist.github.com/panchicore/0324b0e366211c3d907b1c42f54db9c9 And the expected output is: Outer side (frontiers) sticks to its country frontiers (given the ...
12
votes
2answers
12k views

Geopandas Line Polygon Intersection

I'm trying to find where multiple lines intersect a polygon for two different geodataframes: from shapely.geometry import Polygon, LineString import geopandas as gpd polygon = Polygon([(0, 0), (1, 0)...
1
vote
1answer
343 views

Create LineString from lat/lon coords form CSV. with beginning and ending lat/lon?

I am iterating through a CSV file of tornadoes, and for each row getting the beginning lat, beginning long, ending lat, and ending long. and trying to plot their line geometry on a map. I got the ...
2
votes
1answer
72 views

Validity of LinearRing in shapely

Consider the following code: import numpy as np from shapely.geometry.polygon import LinearRing llpts = np.asarray([[18.5165 , 73.82883333], [18.51678333, 73.8279 ], [18.5156 , ...
6
votes
3answers
1k views

How do I correctly reproject a geodataframe with multiple geometry columns?

In the geopandas documentation it says that A GeoDataFrame may also contain other columns with geometrical (shapely) objects, but only one column can be the active geometry at a time. To change which ...
1
vote
1answer
75 views

Generating MultiPoint column from two Point columns without changing number of rows using shapely

from shapely.geometry import MultiPoint, Point a=Point(1, 1.5) b=Point(2, 1.5) c=MultiPoint([a,b]) I am trying to create a MultiPoint column from two Point columns. Using the example code above, I ...
7
votes
2answers
7k views

Geopandas equivalent to select by location

I have 2 geodataframes: A single multi-part polygon Many points I have read them in with the following: poly=gpd.read_file('C:\\Users\\srcha\\Desktop\\folder\\poly.shp') points=gpd.read_file('c:\\...
1
vote
0answers
66 views

Buffer to linestring in shapely produces extra line

Here is my code: from shapely import wkt line_string = 'LINESTRING(114.337434257064 22.6869985219834,114.3375897 22.6869952,114.3378091 22.6869939,114.3379256 22.6869866,114.338153 22.6869723,114....

1
2 3 4 5
15