New answers tagged

0 votes

Casting geometry to MULTI using GeoPandas?

I've made an extension to GeoSeries, using Pandas api extension, that works similar to ST_Multi in PostGIS. The extension is not really needed for this problem, but it is convenient if you want to add ...
Anton Hammarström's user avatar
2 votes

GeoPandas to pull attributes from polygons based on point coordinates

Depending on what you need exactly, geopandas also supports immediate filtering on the file. If you only need the row(s) for one or some points (the mask can also be a GeoDataFrame with multiple ...
Pieter's user avatar
  • 651
3 votes

GeoPandas to pull attributes from polygons based on point coordinates

Create a point df using gpd.points_from_xy and then spatial join. It is very fast: import geopandas as gpd from sqlalchemy import create_engine as ce con = ce("postgresql://postgres@localhost:...
BERA's user avatar
  • 68.9k
3 votes

Setting the background color when plotting in GeoPandas

One way is to create a box covering the dataframes extent and plot this below your df using zorder: import geopandas as gpd from shapely import box df = gpd.read_file(r"C:\GIS\data\testdata\...
BERA's user avatar
  • 68.9k
5 votes
Accepted

Creating GeoJSON from GeoDataFrame with integer feature ids

It is a bit of a search in the documentation to find it, but you can pass GDAL layer creation options as parameters in to_file. From the geopandas documentation: **kwargs: Keyword args to be ...
Pieter's user avatar
  • 651
0 votes

Split polygon by string length Python

Simplifying the geometries is an easy way of reducing geometry complexity. But if you want to split: You can create a bounding rectangle around each polygon that should be split, move one of the short ...
BERA's user avatar
  • 68.9k
0 votes

Writing GeoDataFrame to GeoJSON without Null values in GeoPandas

If we are ok with creating a GeoJSON with nulls, and then creating another one, then this also works: jq '.features |= map(.properties |= with_entries(select(.value != null)))' w_nulls.geojson > ...
zabop's user avatar
  • 1,544
1 vote

Ways to speed up geopandas overlay when applying it on large datasets

Disclaimer: I am the developer of the Geofileops library. You could try using geofileops. This is a library that aims to efficiently process larger geo files. It will apply multiprocessing under the ...
Pieter's user avatar
  • 651
7 votes
Accepted

Exporting list-type field using GeoPandas

Indeed, I will encounter the same ValueError error after trying your code: ... File "fiona\\ogrext.pyx", line 1409, in fiona.ogrext.WritingSession.writerecs File "fiona\\ogrext....
Taras's user avatar
  • 31.4k
3 votes

Intersection in geopandas takes long time to execute

There are several options that will/should be faster. geopandas.clip geopandas.intersection doesn't use a spatial index to check first if it is useful to calculate the intersection before calculating ...
Pieter's user avatar
  • 651
4 votes
Accepted

Intersection in geopandas takes long time to execute

This: intersections = remaining_parcels.intersection(coverage_df.unary_union) is very slow, because each polygon in remaining_parcels is intersected with a huge dissolved/unioned multipolygon. Try ...
BERA's user avatar
  • 68.9k
1 vote

Splitting a MultiLineString with Shapely Split preserving the original MultiLineString composition

If we decompose the MultiLineString, the result is: for i in multiline: print(i) LINESTRING (0 0, 1 0, 2 0, 3 0, 4 0) # green line LINESTRING (0.5 0, 0.5 -1) # red line LINESTRING (1.5 0, 2 2) ...
gene's user avatar
  • 54.4k
6 votes
Accepted

Control Layer Order/Z-Index of Custom DivIcon() Marker in Folium Map

Solution for your problem are Leaflet map panes (see https://leafletjs.com/reference.html#map-pane), which are DOM elements used to control the ordering of layers on the map. Each map pane has it's ...
TomazicM's user avatar
  • 24.1k
3 votes
Accepted

Interpolating polygon values based on neighbouring polygons in QGIS

You dont specify how you want to interpolate. This buffers the grey polygons and use the surrounding polygons values to calculate the average, with the intersection areas as weights. So a polygon with ...
BERA's user avatar
  • 68.9k
0 votes

How to densify LineString vertices in Shapely/GeoPandas

I'm late to the party, but for future reference, Shapely now has this as a builtin feature called segmentize(). Just pass in a linestring geometry and the maximum segment length that you want to see. ...
AJSmyth's user avatar
  • 383
3 votes

Compute the area of differents buildings for differents regions in GeoPandas

You can use groupby each row, reproject it using .estimate_utm_crs, and measure the area: import geopandas as gpd file = r"/home/bera/Desktop/GIStest/worldwide_squares.gpkg" df = gpd....
BERA's user avatar
  • 68.9k
4 votes
Accepted

Finding "most frequently intersected area"?

import geopandas as gpd from shapely.ops import unary_union, polygonize xcoords = [1,3,2,0] ycoords = [1,2,4,3] df = gpd.GeoDataFrame(geometry=gpd.points_from_xy(x=xcoords, y=ycoords)) df.geometry =...
BERA's user avatar
  • 68.9k
0 votes

python - psycopg2.errors.RaiseException find_srid() - could not find the corresponding SRID

I had this same problem, which was from a bug in geopandas where it only looks at the geometry_columns and not the geography_columns table for the SRID. See: https://github.com/geopandas/geopandas/...
schimmy's user avatar
  • 101
0 votes

Gridworkflow intersection with other spatial objects such as a geodataframe

Your arguments to GridSpec are all wrong. Both tile_size and resolution are measured in CRS units and the units for EPSG:4326 are degrees. So you are asking for tiles that are over 30,000 degrees ...
Paul Haesler's user avatar
0 votes

Error in gpd.join related to 'PyGEOSSTRTreeIndex'

Here is how I solved the problem. (1) I added this module on the top of the script # Geospatial libraries import geopandas as gpd import pygeos gpd.options.use_pygeos = True (2) I restarted the ...
bravopapa's user avatar
  • 439
1 vote

Splitting many polygons by many lines

You can list all intersecting lines, split the polygon with each line, extract their boundaries, union, and polygonize. Then explode the dataframe to create a row for each polygon part: import ...
BERA's user avatar
  • 68.9k
0 votes

GEOSException: IllegalArgumentException: point array must contain 0 or >1 elements

Thank you for this hint about single-point LineStrings. I go through dozens of shapefiles, and some of them have this issue, so I came up with a way to fix them automatically by removing single-point ...
messamat's user avatar
0 votes

Geopandas+linux=pyproj.exceptions.ProjError: x, y, z, and time must be same size

Downgrading Shapely from 2.01 to 1.8.4 worked for me. Please refer to this link for further details https://cleanenergyfutures.insightworks.com/pages/9119.html
ANAND TUKKO's user avatar
1 vote

City Suburbs Polygon using OSMNX

Got it! The edits worked. Changed and added tags in Open Street Maps: type: multipolygon, area: yes, boundary: administrative. With those edits the query managed to succeed. I had to wait a while for ...
Irving Bennett's user avatar

Top 50 recent answers are included