# Tag Info

### Filter by bounding box in GeoPandas

You can use the cx method on a geodataframe to select rows within a bounding box. For your example frames: xmin, ymin, xmax, ymax = df_sussex.total_bounds sac_sussex = df_sac.cx[xmin:xmax, ymin:ymax] ...
• 914
Accepted

### Removing small holes from the polygon

You can use the following example script. The script removes all holes from a polygon whose area is smaller than eps. from shapely import wkt from shapely.geometry import Polygon # sample polygon ...
• 77.3k
Accepted

### Difference between geometry() and \$geometry in QGIS

Right next to the list of functions your screenshot is of, should be the currently selected function's documentation. For me, with QGIS 2.18.12 those read: \$geometry Returns the geometry of the ...
• 11k

### Creating square buffers around points using shapely?

Here is how you can create square buffers using geopandas. Note that geometric operations in geopandas are performed by shapely. import geopandas as gpd from shapely.geometry import Point import ...
• 51.7k
Accepted

### Reading geopackage geometries in Python

You can use the gdal/ogr, fiona (built on gdal/ogr) or geopandas (built on fiona) python libraries. Below is a fiona example: import fiona # No need to pass "layer='etc'" if there's only one layer ...
• 67.4k
Accepted

### Difference between QgsPoint, QgsPointXY and QgsGeometry.fromPointXY() in PyQGIS

QgsPoint is a point class which supports Z (3D) and M values. (What are Z and M?) x, y, z, m = 10, 10, 20, 5 QgsPoint(x, y) # 2D # <QgsPoint: Point (10 10)> QgsPoint(x, y, z) # 3D # <...
• 77.3k

### Filling holes in polygons using QGIS

I faced the same problem as yours with this shapefile, having many gaps between polygons. In order to solve the problem, You could use a slight modification of tshiffle's method: First, perform the ...
• 831
Accepted

### Centroid coordinates for odd-shaped polygons

I think the standard QGIS polygon centroid tools calculate the centre of mass in order to determine the polygon's centroid. So this could lie outside the polygon itself (nothing to do with projection)....
• 76.1k
Accepted

### Calculate distance from a Point within a Polygon to its edge

Compare the point to the polygon's exterior ring: poly.exterior.distance(point)
• 9,066

### Visualising WKT geometry string in QGIS

No Plugin required In QGIS deploy a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer.... In the Query window simply paste the following expression: SELECT ...
• 33.5k
Accepted

### Drawing ellipse with shapely

Answer First, define a circle of radius 1. Then define an ellipse along x and y axis. Rotate the ellipse. Finally, actually draw the ellipse. Code from matplotlib import pyplot from shapely.geometry....
• 10.5k

### Difference between geometry() and \$geometry in QGIS

\$geometry returns the geometry of the current feature as in: geom_to_wkt(\$geometry) geometry() returns the geometry of a specific feature as in geom_to_wkt(geometry(get_feature('my_layer', '...
• 1,870
Accepted

### TypeError: Input geometry column must contain valid geometry objects

I tested the following and works fine: from shapely import wkt import pandas as pd df = pd.DataFrame( {'name': ['testname', 'testname'], 'geom': ['MULTIPOLYGON (((21.78 40.36, ... 21.77 40....
• 567
Accepted

### Deleting small holes in polygons specifying the size with PostGIS

This is one of those processes which are simple in an iterative language, but trickier in set-oriented SQL. But the ST_DumpX set-returning functions in PostGIS and the array handling in Postgres make ...
• 5,173

### Identify polygon containing point with R sf package

What you are looking can be done using sf::st_intersects() as commented. I provide a full working example using USA states. library(magrittr) library(ggplot2) library(sf) tt <- read_sf(path, "...
• 3,146

### Reading geopackage geometries in Python

Geopandas is extremely useful and easy to use for this kind of thing: http://geopandas.org/ You can load vector data with attributes (e.g. from geopackages, shapefiles, etc.) into ?(geo)pandas ...
• 236
Accepted

### Difference between bounding box, envelope, extent, bounds?

I think you'll find there is a bit of overlap with these definitions. They're all very similar, in my opinion. However, ESRI has a glossary of GIS terms, so I just looked them up. The definitions are ...
• 21.9k
Accepted

### QGIS: "Invalid geometry" even after using validity checker and v.clean

I ran the Check validity from the dropdown Used the default settings The result was an Invalid Output I then copied and pasted the co-ordinated into the QGIS project window screen (Centre bottom) ...
• 3,632

### Creating centroid inside of polygon

If you want a point that is for sure inside the polygon use representative point: Returns a cheaply computed point that is guaranteed to be within the geometric object. import geopandas as gpd ...
• 75.3k

### Visualising WKT geometry string in QGIS

In QGIS >=3.18.3 we can copy one or multiple WKT strings into clipboard and paste them using Edit > Paste Feature As > Temporary Scratch Layer... into map canvas. CRS needs to be adjusted ...
• 5,903

### Multipoint vs point PostGIS

The easiest way to extract a point from a single-point MULTIPOINT is ST_GeometryN: SELECT ST_AsText(ST_GeometryN('MULTIPOINT ((1 1))', 1)); --POINT(1 1) This avoids potential problems in ...
• 13.2k

### Transforming single QgsGeometry object from one CRS to another using PyQGIS

Old Question, but duckduckgo brings you here for "pyqgis transform single geometry" Just like Riccardo Pointed out, the accepted answer does not work for scripts in QGIS 3, the situation is explained ...
• 902
Accepted

### Correcting the geometry of overlapping polygons in the same layer in QGIS

First make sure your Buildings have a unique "id" (which does not contain a | character, you will see why below). You can add it for example via field calculator by adding a new field with ...
• 35k

### PostGIS, closest point to another point

This is referred to as (spatial) (K)NN search; the most performant approach is a LATERAL sub-query in conjunction with the index driven <-> operator: SELECT a.id, b.id, -- a.geom / ...
• 30.5k
Accepted

### Copy geometry data as HEXEWKB from csv to table in PostGIS

When you see an error like: st_setsrid(unknown, integer) it doesn't mean the ST_SetSRID does not exist, it means that there is a problem with the argument type unknown. So, you can fix this by ...
• 13.7k
Accepted

### How to fix "Hole lies outside shell"

indeed, in PostGIS ST_IsValidReason returns Hole lies outside shell[681306.938491638 5312528.24474655] ST_MakeValid changes it to a MULTIPOLYGON: MULTIPOLYGON(((681306.938491638 5312528.24474655,...
• 2,097

### Detecting branched polygon shape?

You could have a look at the following method : skeletonize your polygons and rather work on line type features related to your original polygon with a unique source polygon ID. I guess there's some ...
• 7,858
Accepted

### How to fix 'GeoSeries' object has no attribute '_geom'

When you are at the following line of your script: print((row.geometry).within(buddies_buf.geometry)) then row.geometry is a single shapely Point (row is a Series representing a single row, so row....
• 3,933
Accepted

### Filtering layers by geometry type using PyQGIS

You can simply use the isSpatial() method of the QgsVectorLayer class, to filter geometry and geometryless layers. Additionally, you should not use numbers to do such comparisons. Recommendations ...
• 36.7k