Questions tagged [fiona]

Fiona is OGR's new, neat, Pythonic API

Filter by
Sorted by
Tagged with
33
votes
10answers
6k views

How to easily shift all features in a vector dataset?

Let's say that I put together a Shapefile and all the features have their vertices shifted by a constant amount. What's the easiest way of shifting all the features (hence the (x,y) position of their ...
31
votes
4answers
17k views

More Efficient Spatial join in Python without QGIS, ArcGIS, PostGIS, etc

I'm attempting to do a spatial join much like the example here: Is there a python option to "join attributes by location"?. However, that approach seems really inefficient / slow. Even ...
18
votes
1answer
2k views

Calculating Focal Statistics for Special Neighborhood?

I'm looking to calculate focal statistics for each cell of a raster, within a neighborhood of a specified criteria. Background - I have three binary rasters, each representing a single vegetation ...
17
votes
1answer
7k views

Finding Nearest Line Segments to Point using shapely?

Background From a known Point, I require to establish the nearest surrounding "visible perimeter" against a table of MultiLineStrings, as shown on the diagram. I've searched this site with a number ...
16
votes
3answers
15k views

Generating GeoJSON with Python

I want to programmatically create a GeoJSON file using polygons from a shapefile but adding attributes from my own application. This is easily done for a shapefile: def create_data_dayer(self,...
14
votes
3answers
10k views

Dissolving polygons based on attributes with Python (shapely, fiona)?

I have been trying to create a function that does basically the same thing that the QGIS "dissolve" function. I thought it would be super easy but well apparently not. So from what I have gathered ...
13
votes
3answers
9k views

Understanding use of spatial indexes with RTree?

I'm having trouble understanding the use of spatial indexes with RTree. Example: I have 300 buffered points, and I need to know each buffer's intersection area with a polygon shapefile. The polygon ...
12
votes
1answer
8k views

GeoPandas to_file() saves GeoDataFrame without coordinate system

I have GeoPandas 0.2.1 py27_0 fiona 1.7.0 np110py27_1 Python 2.7.10 installed in Anaconda 2-4.1.1-Windows-x86 environment. I am able to construct GeoDataFrame by reading input datasets and ...
11
votes
2answers
15k views

Creating Shapely MultiPolygons from shapefile MultiPolygons

I'm reading a shapefile using Fiona: with fiona.open('data/boroughs/boroughs_n.shp') as source: mpolys = [p for p in source] candidate = polys[0]['geometry'] this gives me a dict containing a ...
11
votes
3answers
7k views

How to add support for FileGDB (Esri file gdb API) driver in fiona?

There has been a tons of questions on that but none of them solved my problem. I have a machine with: Windows 7 x64 Python 3.4.3 x64 gdal installed: gdalinfo --version --> GDAL 1.11.4, released ...
10
votes
5answers
8k views

Reading raw data into geopandas

Is it possible to read raw data into a geopandas GeoDataFrame, a la a pandas DataFrame? For example, the following works: import pandas as pd import requests data = requests.get("https://data....
10
votes
1answer
4k views

Drivers of Fiona

What drivers does the python package fiona have? When I check the manual it says [...] and the possible formats are enumerated in the fiona.drivers list. However, when I type in python from fiona ...
10
votes
1answer
4k views

Convert shapefile from projected coordinates using Python

Newbie here struggling with GIS. I am trying to map out wards for the city of Milwuakee using shapefiles found on their county website county website. I am following the thread here with some success. ...
10
votes
6answers
10k views

Fiona ImportError: DLL load failed

I've been using the great Shapely/Fiona combo successfully on Linux, but now i need to create a kind of production environment on windows and theres only one problem. When i try to import fiona, i get ...
9
votes
1answer
9k views

Rasterize a shapefile with Geopandas or fiona - python

I need to rasterize a really simple shapefile a bit like this http://tinyurl.com/odfbanu. Which is just a shapefile coutaining counties in the US.I have seen this previous answer : GDAL RasterizeLayer ...
8
votes
2answers
5k views

Fiona: get each feature extent (bounds)

I was looking in Fiona to get for each feature its extent but I didn't find how. I have try to far to do something like below import fiona with fiona.open('countries/ne_10m_admin_0_countries.shp', '...
8
votes
3answers
4k views

Mapping between OGR and Python data types?

I'm writing a shapefile using OGR in python, creating fields on-the-fly from a python data source. Creation of a new field requires an OGR data type, is there a mapping between OGR and python data ...
8
votes
2answers
5k views

better way to duplicate a layer using ogr in python?

I'm splitting a large shapefile into many smaller ones using ogr. I'd like to just copy all of the field and layer config information from the original. Here's how I'm doing it now: src = ogr.Open('...
8
votes
3answers
3k views

RTree spatial index does not result in faster intersection computation

I have some code that I am using to determine which Shapely Polygon/MultiPolygons intersect with a number of Shapely LineStrings. Through the answers to this question the code has gone from this: ...
8
votes
2answers
11k views

Geopandas Polygon to matplotlib patches Polygon conversion

Unfortunately geopandas plotting is extremely slow and takes a lot of resources, hence I would like to use instead matplotlib for plotting. When I use pure Fiona to open and read the shapefile I ...
8
votes
1answer
9k views

Line vs. Polygon Intersection Coordinates

I am working with Python, Shapely and Fiona... Is there any way where I can give in an input of a line shapefile and a polygon shapefile, and get a result of the intersection points and their ...
8
votes
2answers
1k views

Rasterio does not execute the rasterize function

Rasterio's features.rasterize() function is not working as expected. I have two files: OpenStreetMap shapefile with land usages Raster (.tif) with satellite imagery Goal: Create a raster file from ...
7
votes
2answers
9k views

Intersecting two shapefiles from Python or command line?

I'm new to working with geo data and trying to address a similar question to the one posted as How to calculate the size of a particular area below a buffer in QGIS Using command line and/or shapely/...
7
votes
1answer
4k views

Plot shapefile on top of raster using plot and imshow from matplotlib

I need to plot a shapefile on top of a raster. I would like to use the python package rasterio and some combination of fiona or geopandas to load the shapefile. I found an example in the rasterio ...
6
votes
2answers
17k views

Convert shapely polygon coordinates

I am trying to work with a shapefile using shapely, fiona and python. The original coordinate system is in latitude and longitude that I am trying to convert to state plane system. So I want an ...
6
votes
2answers
3k views

Python: How to export Shapely objects to DXF file

Using shapely package for Python how to export the resulting shapely objects such as buffer to a DXF file?
6
votes
2answers
8k views

How do I write a GeoPandas dataframe into a single file (preferably JSON or GeoPackage)?

I'm new to GIS and having a basic beginner problem. I've got data in the form of a geopackage .gpkg from GADM.org. I can read in and use the data without problem using Geopandas (via built-in Fiona)....
6
votes
1answer
3k views

Adding column to shapefile with Fiona?

I wrote the script to copy a existing shapefile tc_line to a new file tc_pi, and it ran fine: from shapely.geometry import mapping, shape import fiona with fiona.open('tc_line.shp', 'r') as input: ...
6
votes
1answer
611 views

Custom transverse Mercator projection with fiona and shapely

AS a build off from this question I posted over a year ago Buffer miles in decimal degrees with fiona and shapely I am attempting to create 50-mile buffers around each earthquake. I have taken the ...
6
votes
1answer
528 views

Finding out and editing specific rows of attribute table in line shapefile using Python?

I got a line shapefile tc_line with 166 rows (line segments), and the figure below was its atttribute table: Originally, I had to manually select lines (these lines were lines upstream and around ...
6
votes
2answers
2k views

Error getting text attributes from shapefile with python / pyshp

I have a shapefile, containing only points in XY-coordinates and a string attribute for each point. I would like to read the coordinates and the attribute for postprocessing in python, but can't get ...
6
votes
1answer
967 views

Buffer miles in decimal degrees with fiona and shapely

I have a script where I parse geojson earthquake data from around the world and create the point locations of the earthquake incidents. The script works fine. The CRS is 4326 or wgs84/lat long. I am ...
5
votes
5answers
8k views

How to install Fiona to read Shapefile attributes with OSGeo4W?

I´m developing a plugin in Python and I need to read the shapefile attributes, so I found the Fiona API and dbfpy also but I don't understand how to install these packages because I install the QGIS ...
5
votes
2answers
8k views

Count the number of points in a (multi)polygon in shapely?

I'm using Python, Shapely and Fiona to process some shapefiles. Is there an easy way to count the number of points in a polygon/multipolygon in Shapely and Fiona?
5
votes
1answer
11k views

Using Fiona to write a new shapefile from scratch

I am new to Fiona, and trying to wrap my head around reading a csv file and writing out an ESRI shapefile. I have most of it down, but am missing two things; (1) defining the projection/spatial ...
5
votes
1answer
4k views

Reading the names of geodatabase file layers in Python

I'm looking at New York City's Projected Sea Level Rise dataset. This dataset states that it is: Geodatabase of projected sea level rise based on models released by New York City Panel on Climate ...
5
votes
2answers
3k views

Splitting a line shapefile into segments of equal length in python

I want to split a line shapefile into segments of equal length, let say into length of x meters each. There is tool v.split.length as mentioned in this answer: how to split a line into a specific no. ...
5
votes
2answers
2k views

Find common borders of features and get their attributes using fiona and shapely

I would like to find neighboured features in a shapefile using fiona and shapely. As shown in this answer https://gis.stackexchange.com/a/95595/62250 it's easy to get common borders between features. ...
5
votes
2answers
2k views

Reading/writing utf-8 encoded data using Fiona?

So I have a 'cpg' file with my 'in_file' shapefile data (definitely set to 'utf-8'). I was using 'meta' to create the same schema/crs as 'in_file'...though it runs, my text fields are borked on ...
5
votes
1answer
5k views

How to efficiently determine which of thousands of polygons intersect with a linestring [duplicate]

I have a shapefile that contains several thousand Polygons/MultiPolygons and another shapefile that has a variable number of LineStrings. In the example below the blue Polygons are those that ...
5
votes
2answers
992 views

Changing shapefile's field type using fiona?

I need to have a layer time-enabled for Esri application-making. Coming from the source, it has an int type column called year. I need to find a way to automate its conversion to date. I first tried ...
5
votes
2answers
3k views

Geopandas: Write layer back into GeoDataBase

I use geopandas (which uses fiona) to read a GeoDataBase layer (using driver="OpenFileGDB") into a geodataframe for easy manipulation. read_shp = gpd.read_file(GDB_file, layer=layer_choice) That ...
4
votes
1answer
6k views

Iterate through a shapefile

How do i iterate through a shapefile using shapely. This is my code but it keeps outputting the same id. I think that it keeps looking at the same record. fc = fiona.open("file1.shp") print fc.schema ...
4
votes
1answer
2k views

GeoPandas ValueError: A LinearRing must have at least 3 coordinate tuples

I am trying to read a multi-polygon GeoJSON file in GeoPandas, but I am getting the following error: 'ValueError: A LinearRing must have at least 3 coordinate tuples' command used is gpd.read_file(...
4
votes
1answer
3k views

Shapely/ Python looping through a number of polygons

I am trying to loop through a set of polygons in shapely so using python) to determine whether they overlap or not. I do not want to do it manually as later i want to generalise the procedure and do ...
4
votes
1answer
2k views

Select by attributes within the fiona Python module

Is it possible to select polygons from a shapefile based upon their attributes using the Fiona Python module? I can't seem to find anything in the docs, but it seems like a strange thing not to be ...
4
votes
1answer
613 views

Read only geometry from shapefile with python/geopandas

I would like to open a shapefile(shp) without loading the attributes(dbf), as I do not care about attributes and it takes about 25 minutes to load them. I am using Python Geopandas, so any Fiona or ...
4
votes
1answer
5k views

Fiona - Preffered method for defining a schema

I'm fairly new to the world of python and GIS - so this is definitely a beginner question. I am following Tom Macwrights small guide to Shapely and Fiona, and I noticed that even when opening the ...
4
votes
1answer
2k views

What is a convenient way to write OSM data to a .shp file in python

I wish grab OSM data that is within a specified bounding box and matches specific key/value combinations. I then want to write this to a .shp file for further processing using, probably, the QGIS api. ...
4
votes
1answer
4k views

Fiona + Shapely: Loading a set of LineStrings and writing their centroids to a shapefile, including original properties

I am using Fiona to load a set of links. Then I put every record in the rows of a pandas.DataFrame. Then I get the centroid of each LineString using Shapely. Afterwards I copy the schema of the ...