Last active
June 17, 2017 14:55
-
-
Save rowanwins/e23208be1c5b27c1af2abdffab546444 to your computer and use it in GitHub Desktop.
Test turf/boolean modules against shapely
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from shapely.geometry import asShape | |
import fiona | |
import os | |
import sys | |
turf_dir = sys.argv[1] | |
predicate = sys.argv[2] | |
def runTestOnFile(dir, file, turfResult): | |
fc = fiona.open(dir + file, 'r') | |
shape0 = asShape(fc[0]['geometry']) | |
shape1 = asShape(fc[1]['geometry']) | |
shapelyResult = None | |
if predicate == 'contains': | |
shapelyResult = shape0.contains(shape1) | |
if predicate == 'crosses': | |
shapelyResult = shape0.crosses(shape1) | |
if (shapelyResult == turfResult): | |
print 'Matching outputs: ' + file | |
else: | |
print 'ERR: ' + file + ' TurfResult: ' + str(turfResult) + ' ShapelyResult: ' + str(shapelyResult) | |
false_dir = turf_dir + "\\test\\false\\" | |
for file in os.listdir(false_dir): | |
runTestOnFile(false_dir, file, False) | |
true_dir = turf_dir + "\\test\\true\\" | |
for file in os.listdir(true_dir): | |
runTestOnFile(true_dir, file, True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run from the cmd line using something like