Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
ZeroDivisonError when calculating certain centroids #767
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:
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.
referenced this issue
Mar 20, 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 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: