Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZeroDivisonError when calculating certain centroids #767

Closed
stefanborchardt opened this Issue Mar 20, 2016 · 6 comments

Comments

Projects
None yet
5 participants
@stefanborchardt
Copy link

stefanborchardt commented Mar 20, 2016

I can calculate all centroids of a shapefile with shapely 1.5.13, but PySAL 1.11 throws ZeroDivisonErrors. Geos version is 2.0.2, I think. Python 2.7.11/ Anaconda 2.5.0 64bit.

Shapefile problem polygons:
zerodivision_shpfile.zip
Pickle of the pysal (and shapely) polygons that cause trouble:
centroid_divzero.zip
Full data set https://data.sfgov.org/Energy-and-Environment/San-Francisco-Urban-Tree-Canopy/w9tk-3w8c

The error occurred when I used pysal.min_threshold_dist_from_shapefile(). It would be great if such a rather high level function would handle things more gracefully.

@stefanborchardt stefanborchardt changed the title ZDE when calculating certain centroids ZeroDivisonError when calculating certain centroids Mar 20, 2016

@kritinsai

This comment has been minimized.

Copy link

kritinsai commented Mar 20, 2016

@stefanborchardt Could you list the modules you imported when you created the pickle, cause i am not able to load it.

@stefanborchardt

This comment has been minimized.

Copy link
Author

stefanborchardt commented Mar 20, 2016

@kritinsai Sorry. Don't forget to unzip the file first.
import pysal import shapely.geometry as sg import shapely.ops as so import fiona import pickle

@kritinsai

This comment has been minimized.

Copy link

kritinsai commented Mar 21, 2016

@stefanborchardt Is 75461932.639456302 a reasonable value for the minimum_threshold_distance?

@stefanborchardt

This comment has been minimized.

Copy link
Author

stefanborchardt commented Mar 21, 2016

@kritinsai, I have to admit I'm new to spatial analysis. My calculation for the part of data that did not throw an error was 934258.692654. Coordinates are in a state plane with a bounding box of about [5979385,2085840,6024664,2123823]. I would expect a minimum threshold to be lower than the width of 40000 - the number says for which distance all shapes have at least one neighbor, right?
I have made a simplified, merged version of the file for which I have a min threshold of 1315.

@ljwolf ljwolf added the Bug label Apr 1, 2016

@Makosak

This comment has been minimized.

Copy link
Contributor

Makosak commented Apr 1, 2016

I had a similar issue last year; there may be an error with the shapefile you're using. I was using a standard NYC shapefile downloaded from a gov org, and there were digitizing issues that resulted in this error being thrown when I tried to calculate a K-nearest neighbors function that required centroids. The shapefile reports a bounding box that does not contain all the bounding boxes for the individual shapes.

Try validating the geometry; following comments I received back then:
QGIS -> Vector -> Geometry Tools -> Check Geometry Validity

@ljwolf

This comment has been minimized.

Copy link
Member

ljwolf commented Jul 16, 2016

This may be fixed by #768

@ljwolf ljwolf added the Needs Review label Jul 16, 2016

@sjsrey sjsrey closed this Sep 26, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.