Skip to main content

New answers tagged

1 vote
Accepted

Geopandas slow after vectorization

I had a look, and I can confirm the extreme slowness. It seems that the NDVI image was 20cm resolution, leading in this case to most of the 390 polygons having at least 1.000 coordinates, with the ...
Pieter's user avatar
  • 3,224
0 votes
Accepted

Cannot load a geodataframe (from a shapefile) into PostgreSQL (as table) via SQLAlchemy

As suggested by @Vince , I have created a new database with a new user ( owner of the database ), reinstalled postgis, recreated the schema data, configured the django app for it, run makemigrations, ...
Tms91's user avatar
  • 185
2 votes
Accepted

Extracting value from raster file using UTM coordinates in python

That is a really poor way to do it. While it should work (though I haven't checked your actual transform calculations and I'm assuming your coordinates are actually in the same CRS as your raster), ...
user2856's user avatar
  • 67.3k
0 votes
Accepted

Dissolve lines that intersect after attending some dataframe (atributte table) conditions

After a long time, I resumed this project and found a solution. # Marge segments based on tabular info ('id' and 'dt') gdf = gpd.GeoDataFrame() for id in gdf_sof.id.unique(): unique_id = gdf_sof.loc[...
Marlon's user avatar
  • 21
1 vote

Filtering records in GeoPackage file by numeric/text fields using GeoPandas/Fiona

You can pass a SQL statement to geopandas.read_file. Something like this: import geopandas as gpd sql = f""" SELECT * FROM "test" WHERE fieldX = 'klmno' ""&...
Pieter's user avatar
  • 3,224
0 votes

Reading GeoPackage file bigger than RAM size with GeoPandas?

The fastest way to read chuncked from a large geopackage is (as far as I know) to filter on the FID using a SQL statement, as this is the primary key. You can execute SQL statements using geopandas....
Pieter's user avatar
  • 3,224
0 votes

Convert the geometry column of a GeoDataFrame with mixed geometry types to a unique multi-type

geofileops has a (private) function harmonize_geometrytypes that provides this functionality. If this would be useful I can move the function to pygeoops, a library with more of these lower level ...
Pieter's user avatar
  • 3,224
0 votes

Viewing what is inside the GeoPackage with Python

Hence GeoPackage is the SQLite container for Geospatial Information, it is possible to investigate metadata tables using the sqlite3 Python Package. Relevant metadata tables are: gpkg_contents, ...
Taras's user avatar
  • 33.3k
1 vote

Generalize/Denoise Multipolygons

Possibly not exactly the same question, but I think the answer could help you out anyway: reclassify_neighbours.
Pieter's user avatar
  • 3,224
2 votes
Accepted

Python: Split Polygons where they overlap one another

You can use unary_union, polygonize, and drop_duplicates or groupby (not sure what you want to do): import geopandas as gpd from shapely.ops import unary_union, polygonize #Create a df with three ...
Bera's user avatar
  • 74.9k
2 votes
Accepted

Buffer without overlaps in Python

Starting from your code, I think voronoi polygons can simply replace the use of Tesselation from momepy because you are using points as input. Since the recently released geopandas 1.0 direct support ...
Pieter's user avatar
  • 3,224
0 votes

Buffer without overlaps in Python

Sounds like you want to be using a Euclidian allocation approach. Your question is about using python and avoiding GDAL. My solution which is neither of your two constraints is simply 1 tool in ArcGIS ...
Hornbydd's user avatar
  • 43.9k
1 vote
Accepted

Opening gkpg in GeoPandas throws: UnsupportedGeometryTypeError: 12

GeoPandas's read_file tries to normalize incoming geometries with https://github.com/Toblerity/Fiona/blob/839989b5a45aee632cab2cddd7bc0da5d101bf2b/fiona/_geometry.pyx#L64 And that fails because your ...
bugmenot123's user avatar
  • 10.9k
0 votes
Accepted

AttributeError: 'GeoSeries' object has no attribute 'is_valid_reason' in GeoPandas

Your code works fine on my Python 3.11 with GeoPandas 1.0.0 and shapely 2.0.4. You will need to update your GeoPandas. Because you are using the 0.14.4 version. The method is_valid_reason() was ...
Taras's user avatar
  • 33.3k
1 vote
Accepted

Sample raster (Landsat) using points (preferably using Python or maybe GEE Code editor)

You can simplify the value extraction by using rasterstats: import geopandas as gpd from rasterstats import zonal_stats df = gpd.read_file(r"/home/bera/Desktop/gistest/pointgrid.shp") ...
Bera's user avatar
  • 74.9k
0 votes

How to write two geopandas dataframes as layers of a .gpkg file in memory in python?

I haven't looked into doing this "properly" in any detail (i.e. using something like io.BytesIO(), see this issue), but here is a dirty workaround that uses gdal and its virtual ("VSI*&...
user2856's user avatar
  • 67.3k
0 votes

Fiona throws no dataset found when attempting to read a KMZ file

Aware that this is an old question now but thought it might be useful for others who are looking into this topic more recently to know that you don't need to extract the files. You can load the ...
Will Blair's user avatar
0 votes

Accessing a shapefile with GoogleEarthEngine-API : Invalid GeoJSON geometry

I am trying to clip Landsat image with shapefile in Google Earth Engine API. I used the previous answers and solved the Invalid GeoJSON geometry problem, but finally the clipped image is not displayed ...
hossein's user avatar
0 votes

Viewing what is inside the GeoPackage with Python

You can list layers with fiona.listlayers, read a sample of rows into a DataFrame, print column names and types, and geometry type: import fiona import geopandas as gpd gpkg = r"/home/bera/...
Bera's user avatar
  • 74.9k
0 votes

Displaying polygon on top of DEM with GeoPandas and Rasterio

Try rasterio.plot show: Rasterio also provides rasterio.plot.show() to perform common tasks such as displaying multi-band images as RGB and labeling the axes with proper geo-referenced extents. from ...
Bera's user avatar
  • 74.9k
0 votes

Rounding coordinates to five decimals in GeoPandas

You can change the data type in your GDF schema. The fiona documentation describes that you can specify a data type in the schema with its length for most data types, and you can also specify the ...
Ilya's user avatar
  • 13
4 votes

Clip data in GeoPandas to keep everything not in polygons

You may use the overlay function to do this by using the difference option. Example: from shapely.geometry import Point, Polygon import geopandas poly = geopandas.GeoSeries([Polygon([(0,0), (2,0), (2,...
jslatane's user avatar
  • 207
2 votes
Accepted

Clip data in GeoPandas to keep everything not in polygons

Using geopandas, the typical way to determine spatial relations efficiently (= using a spatial index) is by using sjoin. You are looking for the predicate=disjoint relation though, which is not ...
Pieter's user avatar
  • 3,224
0 votes

Removing one to many links when performing spatial join in GeoPandas

om_henners answer is great, however it assumes that there is a unique column with only non-null entries to groupby. I ended up extending it for the case where such a column does not exist or has null ...
Phonolog's user avatar
  • 123
0 votes

Getting more precision with GeoPandas?

You can change the data type in your GDF schema. The fiona documentation describes that you can specify a data type in the schema with its length for most data types, and you can also specify the ...
Ilya's user avatar
  • 13
0 votes
Accepted

How to round or limit the number of decimals in geodataframe

I found a solution to my question, everything turned out to be quite simple. GeoPandas uses a schema from Fiona, and all that was needed according to the documentation was to fill in schema['...
Ilya's user avatar
  • 13
4 votes
Accepted

Linking all possible polygons to point within a distance

You can buffer the polygons (or the points) and then spatial join. It should be very fast. import geopandas as gpd pointdf = gpd.read_file(r"C:\GIS\data\Bakgrundskartor\Topografi_250\data\...
Bera's user avatar
  • 74.9k

Top 50 recent answers are included