Toblerity / Fiona

Fiona reads and writes geographic data files
https://fiona.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.15k stars 202 forks source link

Importing shapefile using fiona #290

Closed DanqingZ closed 8 years ago

DanqingZ commented 8 years ago

Hi all,

I am using geopandas to import shapefile, but it seems the problem is due to fiona according to this post

It is strange that, fiona works for some certain shapefiles, but does not work for others. And actually I think are shapefiles I use are well -maintained. For they can all be opened using QGIS.

Below are my scripts and errors I get.

import fiona
with fiona.open('taz.shp') as src:
    for feature in src:
        print feature

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-9-b70513efc12b> in <module>()
      1 import fiona
      2 with fiona.open('taz.shp') as src:
----> 3     for feature in src:
      4         print feature

fiona/ogrext.pyx in fiona.ogrext.Iterator.__next__ (fiona/ogrext.c:17244)()

fiona/ogrext.pyx in fiona.ogrext.FeatureBuilder.build (fiona/ogrext.c:3254)()

IndexError: list index out of range
geowurster commented 8 years ago

@DanqingZ Looks like this might be a GDAL 1.0 vs. 2.0 issue. What version of GDAL and Fiona are you running?

DanqingZ commented 8 years ago

They are listed as below, I am using anaconda and pip~ fiona 1.6.0 np110py27_0 gdal 1.11.0 np19py27_0

geowurster commented 8 years ago

@DanqingZ Could you please paste the results of:

import fiona.ogrext
print(fiona.ogrext.get_gdal_release_name())
DanqingZ commented 8 years ago

@geowurster 2.0.0

geowurster commented 8 years ago

@DanqingZ So you have two versions of GDAL installed and Fiona is using 2.0. @sgillies I think you know more about the conda vs. pip install process than I do.

DanqingZ commented 8 years ago

Oh yes, I used pip install to install both the Fiona and GDAL packages @geowurster @sgillies

sgillies commented 8 years ago

@DanqingZ once you get GDAL 2.0 (which Fiona doesn't yet support, but soon...) off your conda environment's library path, Fiona will import and run just fine.

DanqingZ commented 8 years ago

@sgillies ...That is exactly my problem..How to get the GDAL 2.0 off my conda environment's library path? I type "conda list" in the terminal, and it shows the version of GDAL is 1.11

sgillies commented 8 years ago

@DanqingZ sorry, but that's a conda issue that you'll need to take up with ContinuumIO or the conda community.

patrick-dd commented 8 years ago

@DanqingZ did you figure out a solution? I've exactly the same problem.

NicolasCadieux commented 8 years ago

Hi,

I have not found a way to save the output from Fiona into a list and to read it back with shapely. I figure i need to use gdal and output to WKT. Don't know how to make shapely understand the Fiona dictionary output:(

For now, I just use a different file obj for every time I need to do a loop inside a loop. Same file but different handle I guess... Still hoping to get some help on this. It should be simple. I must be missing a small thing. Cheers.

Nicolas

On Nov 13, 2015 23:12, patrick-dd notifications@github.com wrote: @DanqingZ did you figure out a solution? I've exactly the same problem.


Reply to this email directly or view it on GitHub: https://github.com/Toblerity/Fiona/issues/290#issuecomment-156623997

NicolasCadieux commented 8 years ago

http://gis.stackexchange.com/questions/139905/how-to-call-shapely-coords-on-a-fiona-filtered-list On Nov 13, 2015 23:12, patrick-dd notifications@github.com wrote:@DanqingZ did you figure out a solution? I've exactly the same problem.

—Reply to this email directly or view it on GitHub.

NicolasCadieux commented 8 years ago

Hi,

I don't know what I was doing wrong... but it works..

import fiona from shapely.geometry import shape import time ptList = [] classpolyList =[] with fiona.open("c:/pytemp/fiona/planning_neighborhoods.shp", "r") as classPoly: classpolyList = list(classPoly) with fiona.open("c:/pytemp/fiona/Schools_Private_Pt.shp", "r") as inputLidarPt: x = time.time() print x
ptList = list(inputLidarPt) x = time.time() print x
for polyg in classpolyList: for pts in ptList: if shape(polyg['geometry']).contains(shape(pts['geometry'])): pass else: pass
y = time.time() z = y-x
print z print 'done'

Date: Fri, 13 Nov 2015 20:12:13 -0800 From: notifications@github.com To: Fiona@noreply.github.com Subject: Re: [Fiona] Importing shapefile using fiona (#290)

@DanqingZ did you figure out a solution? I've exactly the same problem.

— Reply to this email directly or view it on GitHub.

grant-humphries commented 8 years ago

@DanqingZ @NicolasCadieux the following commands fixed this issue for me (I had installed gdal and fiona with conda and was at version 2.0.0 and 1.6.0 respectively):

conda install gdal=1.11.2
conda install fiona=1.5.1
linwoodc3 commented 7 years ago

This may not be an issue for others, but when i filtered my geodataframe to exclude null cells in the geometry column, I could successfully write geojson or shapefiles. I ws receiving the same error as the OP before.