Skip to content

Instantly share code, notes, and snippets.

@rowanwins
Last active June 17, 2017 14:55
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rowanwins/e23208be1c5b27c1af2abdffab546444 to your computer and use it in GitHub Desktop.
Test turf/boolean modules against shapely
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)
@rowanwins
Copy link
Author

rowanwins commented Jun 17, 2017

Run from the cmd line using something like

 python turf-shapely.py C:\code\turf\packages\turf-boolean-contains contains

@DenisCarriere
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment