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
0
votes
0answers
4 views

Creating Swath View from Point data using Python?

My situation Input: point data from planting file Feature Attribute: [('DeletionFlag', 'C', 1, 0), ['Field', 'C', 254, 0], ['Dataset', 'C', 254, 0], ['Product', 'C', 254, 0], ['Obj__Id', 'N', 15,...
0
votes
0answers
13 views

Errors importing shapely.geometry into QGIS 3.6

I got error messages when executing 2nd statement below in python console of QGIS 3.6 (and QGIS 3.8) import shapely from shapely.geometry import Polygon If I execute the 2nd statement again, there ...
2
votes
1answer
61 views

Creating equally spaced coordinates on California state map created with basemap?

I have created a California state map with basemap Python library and this shapefile. Code is below from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt fig, ax = plt.subplots(...
2
votes
1answer
62 views

Populating layer field with dict.values() in PyQGIS 3?

I've coded the script below in PyQGIS 3 to get the azimuth of starting or ending points for a line layer that touches a border. It works fine, but I want to populate the azimuth field layer with the ...
1
vote
1answer
18 views

Splitting or decomposing LineString into original single lines or segments using shapely?

I am trying to split a LineString into single segments: from shaply import LineString,MultiPoint from shapely.ops import split xp = [-2,1,2,2.5,4,1,-1,2,4,5,6] yp = [-2,1,1,0,1,2,2,3,4,4,4] ...
1
vote
1answer
48 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 ...
2
votes
1answer
57 views

Why is a projection conversion off by factor of SQRT(2)?

I am attempting to draw a 3 km ring around downtown Minneapolis. Let downtown be defined as Government Plaza (-93.2661, 44.9765). I am using this ring to calculate census tracts within a distance of a ...
7
votes
2answers
213 views

Getting geometries of hurricane's 'cone of uncertainty' using shapely?

I'm trying to plot hurricane forecast maps using python. I have several forecast positions derived from official advisories, and interpolate them into a smoothed curve, then draw a polygon of 'cone of ...
3
votes
1answer
69 views

Getting Unique Intersections of Multiple Polygons Efficiently in Python

I would like to get a list of all polygons that are intersections of other polygons. However, that list of intersections cannot self-overlap. For example, if I have a triple Venn diagram, I would ...
1
vote
1answer
49 views

Error: Input [<shapely.geometry.point.Point>, <shapely.geometry.point.Point>] is the wrong shape for a LineString

I'm trying to create a linestring out of a dataframe of latitudes and longitudes. geometry = [Point(xy) for xy in zip(linkdf.lon, linkdf.lat)] linkgdf = GeoDataFrame(linkdf, geometry=geometry) ...
0
votes
1answer
51 views

Buffering geometry with points in WGS84 using shapely?

I have a polygon in python shapely that I would like to buffer with a 100 foot buffer. If the polygon is stored as a series of WGS84 lon/lat points how would I go about calculating the distance of ...
1
vote
0answers
53 views

Geopandas simplify results in gaps between polygons

The goal is to simplify the geometries of a shapefile containing multipolygons. However, when I use Shapely's simplify in geopandas, the result contains gaps between the polygons. I was hoping that ...
1
vote
1answer
36 views

MULTIPOINT Text to list of POINT objects

I need to convert a MULTIPOINT string to a list of POINT objects. For example, suppose I have a query with ST_AsText() producing an output that is captured in my_points: >>>print(my_points) ...
1
vote
1answer
31 views

Determining whether the geometry field in a SQLite table has z coordinates using Python

In the Shapely package, there is a function that allows you to determine whether coordinates include a Z value. It is object.has_z. Is there a way that a similar command can be carried on the ...
1
vote
0answers
21 views

Transforming TM75(29903) squares to ETRS89(3035)?

A bit of a long winded explanation here so please bear with me. I have received grid square data in ETRS89(3035) which I need to cross reference with out own grid squares which are in TM75(29903). ...
0
votes
1answer
56 views

geopandas: “LineStrings must have at least 2 coordinate tuples” when reading gpx files

I am trying to use geopandas to read in some gpx files (generated from a Garmin vista HCX). For many gpx files, given this code: >>> import geopandas as gpd >>> data = gpd....
0
votes
1answer
53 views

Testing intersection between shapely object and geopandas GeoSeries?

This is a Python question, involving geopandas and the libraries it calls, primarily pandas and shapely. tl;dr: I am trying to run a test using if foo.intersects(bar): and am repeatedly getting one ...
2
votes
1answer
31 views

Normalized interpolation doesn't work for WGS84

I am trying to interpolate linestring on WGS84 coordinate system by factor 0.5. LineString length is 427 meters (measured by different tools), so I expect to get line with length=213.5 meters. But I ...
1
vote
1answer
38 views

GeoPandas does not identify points inside polygon

I am trying to intersect some points with a polygon in GeoPandas. First I create a Point GeoDataFrame from a text file. import geopandas as gp import numpy as np import pandas as pd from shapely....
0
votes
1answer
50 views

Extending (buffering) set of polygons into empty space only using Shapely?

I have a set of polygons of which I would like to extend the boundaries a bit into empty space, using Shapely. They are not allowed to overlap each other at all. For example creating buffers and then ...
1
vote
1answer
146 views

Removing self-intersection from invalid polygon using shapely?

This geometry is invalid: POLYGON ((234107.4999285005 581107.0000356995, 234250.1399285011 581055.220035702, 234347.470028501 581007.8300357014, 234427.899928499 580959.1000357009, 234483.1350285001 ...
0
votes
2answers
63 views

How to create a weighted square lattice as well as a weighted network graph

I am planning to create a weighted square lattice for different sizes, and then label each edge with its associated weight. It's similar to this thread "How to load a weighed shapefile in networkX" ...
0
votes
2answers
36 views

Using dictionary of file names and DD coordinates to create points in shapefile using shapely?

I'm working on a Python script that strips the GPS info from images and uses that info to create a shapefile from that info. Right now I have all the file names as keys to tuples of decimal degrees ...
0
votes
0answers
26 views

Coordinate System shows up incorrect after converting a shapely object to a shapefile [duplicate]

I am trying to convert a simple point object created using shapely to a shapefile using fiona as instructed in this post. I pretty much followed line by line except that I changed the crs as I need it ...
2
votes
0answers
92 views

Intersecting shapefile/GeoDataFrame using Geopandas, shapely etc?

I'm currently transferring from ESRI to open source GIS by recreating basic ArcGIS tasks in Python, mainly using Geopandas since I have some experience with Pandas. Now I'm trying to intersect a ...
0
votes
0answers
24 views

Getting zip code from string geom using shapely?

I have a list of geoms each in string form. I can convert them either to our or python shapely geom but does any have a function to find a zipcode from that geom? I was unable to find one. I can use ...
0
votes
2answers
357 views

Converting list of polygons to multipolygon using shapely?

I have a list of polygons where each polygon is a wkt form as follows: list_polygons = ['POLYGON ((-88.131229288 41.900200029,-88.12973798 41.900104202,-88.129785999 41.894907769,-88.131352409 41....
4
votes
1answer
96 views

Making Shapely box larger using GeoPandas?

I'm creating a box that covers the the area of a GeoPandas GeoDataFrame, so that I can use it as an inverted map to later cover up unwanted spill-over data. import geopandas as gpd import geoplot as ...
1
vote
1answer
32 views

How to reverse the MultiLineString command to a list of arrays

Let's you have a list of coordinates that you can convert to a line string: coords = [((0.0, 0.0), (0.0, 20.0)), ((20.0, 0.0), (20.0, 20.0)), ((1.0569687968009744, 14.934839039628798), (5....
2
votes
0answers
51 views

Dissolve Line Strings to one string - “No Shapely geometry can be created from null value”

I have a layer with 7000 LineStrings, all represent bus routes: It seems that all the bus routes are contiguous, but I'm not sure of it. I'm trying to use python shapely to dissolve all those ...
3
votes
1answer
79 views

Using libraries other than PyQGIS to develop plugin for QGIS?

I develop a plugin for QGIS. Before to integreted it in the QGIS I developped it with GIS library (Fiona, shapely, geopandas, ...) and it work well. Now I try to build it with plugin_builder of QGIS. ...
2
votes
1answer
29 views

I have the following multilinestring, and I am looking for finding the intersection between each pair

I have a pair of lines, which I like to find the intersect of each of one them with each other. I know for two lines I can do the following: from shapely.geometry import LineString line1 = ...
1
vote
0answers
28 views

Cut line at intersection using Shapely

I'm trying to cut a line at the intersection, if a line crosses another line within a single multilinestring then and the end of the line is below a maximum distance threshold then it swaps the end of ...
1
vote
2answers
222 views

How to extract biggest Polygon from MultiPolygon in GeoPandas?

Given a Shapely MultiPolygon, how can I extract the biggest Polygon? For example, given a MultiPolygon as follows: from shapely.geometry import Polygon, MultiPolygon multipolygon = MultiPolygon([...
1
vote
1answer
108 views

Quickly find all polygons that overlap with two or more polygons in Shapely

I have a set of Polygons (in Shapely) that I wish to find all intersections that are comprised of overlaps of two or more polygons. I have been working based off the code found in this answer. I have ...
1
vote
1answer
87 views

Intersection function returns multiple coordinates

I am trying to find intersection vertices of two polygons defined below PG = Polygon([(0.0,0.0), (0.0,4.0), (2.0, 0.0)]) QG = shapely.affinity.rotate(PG, 10.0, origin="centroid") print(PG....
0
votes
1answer
53 views

Clip shapefile based on another shapefile [closed]

I have two shapefiles with me, one big and one small. I want to clip part of big shapefile where the small shapefile is located. I tried QGIS vector intersect by geometry, but that is returning me ...
0
votes
1answer
60 views

Find intersection vertices of two polygons

I have defined two polygons and I can find whether they intersect or not. I need to find the intersection vertices if they intersect or not ? How can I do that ? p1 = Polygon([(0,0), (1,1), (1,0)]) ...
0
votes
0answers
35 views

ST_Polygonize/Shapely cannot polygonize when overlapping with shared node/point

I'm trying to use both polygonize_full (Shapely, python) and ST_Polygonize (postgis) to get all polygons from a set of line strings. There is one case where it fails: when there is an "overlapping ...
0
votes
0answers
206 views

Smoothing shapefiles using Python

The purple is the original polygon to be smoothed and I would like to smooth the polygons as the red line using Python. I tried simplify but looks like I need a buffer and simplify the buffer. But I ...
1
vote
0answers
56 views

How to segment polygon in to line segment?

I want to segment a Polygon or PolyLine in segment of line and remove some segments. I have an polygon that i convert in polyline by the code below and it work well: from shapely.geometry import ...
0
votes
0answers
49 views

Writing only one of the input vector fields to output vector using Fiona/ Python?

I'm working on a function to perform operations on folders of vector files. These files might have differing attribute fields but there will be a common field between them. I'm using fiona in python ...
0
votes
1answer
322 views

Python geopandas dataframe of polygons — determine nearest neighbor polygon?

I am trying to figure out how to dynamically create expanded regions of interest based on polygon geometries in geopandas until some threshold is satisfied (essentially custom regions across the ...
0
votes
0answers
23 views

How can I group the geodataframe on the basis of the column

I have a geodataframe that has a ununique column(text) and polygon geometry for each row. How can I group the gdf on the basis of the column? gathering and converting polygons to multipolygon I think ...
1
vote
1answer
198 views

Delaunay triangulation algorithm in shapely producing erratic result

I would like to triangulate the following polygon: The wkt for the geometry is given as follows: POLYGON ((3 0, 2 0, 2 0.75, 2.5 0.75, 2.5 0.6, 2.25 0.6, 2.25 0.2, 3 0.2, 3 0)) I ran this code to ...
1
vote
0answers
337 views

Calculating distance between point and MultiPolygon Geoseries object in Python [closed]

I want to calculate the distance of a point from the Multiploygon geoseries object created using cascaded_union function of GeoPandas. Following is my code: import numpy as np import pandas as pd ...
1
vote
0answers
26 views

Check point in line segment not accurate in Shapely

I use Shapely and I've run into an issue where I can find the intersection of two lines. However once I have the intersection point, I don't seem to be able and cross-reference that it belongs in both ...
0
votes
0answers
29 views

Would like to randomly sample points from within a polygon using Python [duplicate]

I would like to achieve something similar to the ArcGIS Create Random Points tool using geopandas, shapely, or rasterio. I aim to have a polygon with some holes in it (removed by subtracting buffered ...
0
votes
1answer
155 views

Dissolving polygons to single part features with Python (shapely and fiona)?

I used the code from Dissolving polygons based on multiple attributes with Python (shapely and fiona)? to dissolve a shapefile using shapely and fiona. However the output creates multi-part geometries....
0
votes
0answers
64 views

Issue with GeoPandas method 'contains' for two GeoDataFrames

I want to verify that a GeoDataFrame called mask2 COMPLETELY CONTAINS all the linestrings in another GeoDataFrame called transect_file2. In the image is clearly visible that transect number 16 (TR_ID=...