Last active
August 29, 2015 14:16
-
-
Save hugoledoux/0798ee79fe76a1b0ed8f to your computer and use it in GitHub Desktop.
are the triangles in a shapefile valid?
This file contains 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
import sys | |
import os | |
import fiona | |
from shapely.geometry import Polygon | |
from shapely.geometry import asShape | |
from shapely.geometry import mapping | |
#-- Global variables | |
INFILE = "Vlak_3D_LOD0/terreinVlak_3D_LOD0.shp" | |
def main(): | |
aretrianglesvalid(INFILE) | |
print "done." | |
def aretrianglesvalid(infile): | |
c = fiona.open(infile, 'r') | |
#-- Find and print the number of geometries | |
print "Number of features:", len(c) | |
#-- store the geometries in a list | |
lsPolys = [] | |
for each in c: | |
lsPolys.append(asShape(each['geometry'])) | |
totaltr = 0 | |
totalinvalid = 0 | |
for mp in lsPolys: | |
totaltr += len(mp) | |
for p in mp: | |
valid = True | |
if len(list(p.exterior.coords)) != 4: | |
print p.wkt | |
valid = False | |
if len(p.interiors) != 0: | |
print p.wkt | |
valid = False | |
if valid == False: | |
totalinvalid += 1 | |
print "total triangles", totaltr | |
print "total invalid", totalinvalid | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment