def polygonQuery(connection, sql): """This takes an SQL query, runs it, and creates polygons out of it. This function is still being fleshed out, and needs to filter out the necessary information for dealing with MultiPolygons, and the interior and exterior rings of Polygons.""" data = db.runopen(connection, sql) geom = [] for rowTuple in data: ewkt = rowTuple[0] cleaned_ewkt = db.removeSRID(ewkt) multiPolygon = shapely.wkt.loads(cleaned_ewkt) try: for polygon in multiPolygon: geom.append(polygon.exterior.coords) except: return 'error reading polygons in multipolygons' return geom
def queryToPolygonsWithAttr(connection, sql, attrNames): """This function takes an open database connection (a psycopg2 object, refer to psycopg2 docs and the db module for more info), an sql statement, and a list of attribute names, and uses these three things to construct a set of polygons with attributes in Maya. the return value is a list of the names of the created polygons.""" data = db.runopen(connection, sql) items = [] for rowTuple in data: ewkt = rowTuple[0] attData = rowTuple[1:] attDict = dict(zip(attrNames, attData)) cleaned_ewkt = db.removeSRID(ewkt) multiPolygon = shapely.wkt.loads(cleaned_ewkt) try: for polygon in multiPolygon: itemTuple = (polygon.exterior.coords, attDict) items.append(itemTuple) except: return 'error reading polygons in multipolygons' return makePolygonsWithAttr(items)
def queryToMesh(connection, sql): """This function takes an open database connection (a psycopg2 object, refer to psycopg2 docs and the db module for more info), an sql statement and uses these things to construct a mesh in Maya. The return value is the name of the created mesh.""" data = db.runopen(connection, sql) points = [] twoDpoints = [] Zs = [] for rowTuple in data: ewkt = rowTuple[0] cleaned_ewkt = db.removeSRID(ewkt) p = shapely.wkt.loads(cleaned_ewkt) point = (p.x, p.y, p.z) xy = (p.x,p.y) points.append(point) twoDpoints.append(xy) Zs.append(p.z) # build a structure from delaunay triangulation triStructure = triforce.triangulate(twoDpoints) # now I need to turn the points and structure into a mesh return makeMesh(points, triStructure)
def queryToMesh(connection, sql): """This function takes an open database connection (a psycopg2 object, refer to psycopg2 docs and the db module for more info), an sql statement and uses these things to construct a mesh in Maya. The return value is the name of the created mesh.""" data = db.runopen(connection, sql) points = [] twoDpoints = [] Zs = [] for rowTuple in data: ewkt = rowTuple[0] cleaned_ewkt = db.removeSRID(ewkt) p = shapely.wkt.loads(cleaned_ewkt) point = (p.x, p.y, p.z) xy = (p.x, p.y) points.append(point) twoDpoints.append(xy) Zs.append(p.z) # build a structure from delaunay triangulation triStructure = triforce.triangulate(twoDpoints) # now I need to turn the points and structure into a mesh return makeMesh(points, triStructure)