Created
May 4, 2012 14:21
-
-
Save tschaub/2595076 to your computer and use it in GitHub Desktop.
quick implementation of polygon splitting process
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
// Execute method for js:split process expects polygon and line geometries as input | |
run: function(inputs) { | |
var merger = new LineMerger(); | |
merger.add(inputs.poly._geometry); | |
merger.add(inputs.line._geometry); | |
var collection = merger.getMergedLineStrings(); | |
var union = new UnaryUnionOp(collection).union(); | |
var polygonizer = new Polygonizer(); | |
polygonizer.add(union); | |
var parts = polygonizer.getPolygons(); | |
var candidate, intersection, polys = []; | |
for (var i=0, ii=parts.size(); i<ii; ++i) { | |
candidate = geom.Geometry.from_(parts.get(i)); | |
// TODO: ask MD if inputs.poly.overlaps(candidate) is expected to work here | |
try { | |
intersection = candidate.intersection(inputs.poly); | |
// TODO: unhack this | |
if (intersection.area / candidate.area > 0.01) { | |
polys.push(candidate); | |
} | |
} catch (err) { | |
// pass | |
} | |
} | |
return {result: new geom.MultiPolygon(polys)}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment