How to use the geoalchemy2.WKBElement function in GeoAlchemy2

To help you get started, we’ve selected a few GeoAlchemy2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gltn / stdm / data / View on Github external
def qgsgeometry_from_wkbelement(wkb_element):
    Convert a geoalchemy object in str or WKBElement format to the a
    QgsGeometry object.
    :return: QGIS Geometry object.
    if isinstance(wkb_element, WKBElement):
        db_session = STDMDb.instance().session
        geom_wkt = db_session.scalar(wkb_element.ST_AsText())

    elif isinstance(wkb_element, str):
        split_geom = wkb_element.split(";")

        if len(split_geom) < 2:
            return None

        geom_wkt = split_geom[1]

    return QgsGeometry.fromWkt(geom_wkt)
github gltn / stdm / navigation / View on Github external
        #Update the style of the property on each overlay operation
        #Set label object
        label_js_object = "null"
        if hasattr(sp_unit, labelfield):
            lbl_val = getattr(sp_unit, labelfield)
            label_js_object = "{'%s':'%s'}" % (labelfield, str(lbl_val))
        #Reproject to web mercator
        geom = getattr(sp_unit, geometry_col)
        sp_unit_wkb = self.dbSession.scalar(geom.ST_Transform(900913))

        web_geom = WKBElement(sp_unit_wkb)
        sp_unit_geo_json = self.dbSession.scalar(web_geom.ST_AsGeoJSON())
        overlay_js = "drawSpatialUnit('%s',%s);" % (sp_unit_geo_json, label_js_object)
        zoom_level = self._setJS(overlay_js)
        #Raise map zoom changed event
github geoadmin / 3d-forge / forge / lib / View on Github external
def toSubQuery(x):
            return session.query(, model.interpolateHeightOnPlane(pts[x])).filter(
                and_(model.bboxIntersects(createBBox(pts[x], 0.01)), model.pointIntersects(pts[x]))).subquery('p%s' % x)
        subqueries = [toSubQuery(i) for i in range(0, len(pts))]

        # Get the height of the corner points as postgis cannot properly clip
        # a polygon
        cornerPts = {}
        step = 2
        j = step
        query = session.query(*subqueries)
        for q in query:
            for i in range(0, len(q), step):
                sub = q[i:j]
                j += step
                cornerPts[sub[0]] = list(to_shape(WKBElement(sub[1])).coords)

        # Clip using the bounds
        clippedGeometry = model.bboxClippedGeom(bounds)
        query = session.query(

        terrainTopo = TerrainTopology(lightning=True)
        for q in query:
            coords = list(to_shape(q.clip).exterior.coords)
            if in cornerPts:
                pt = cornerPts[][0]
                for i in range(0, len(coords)):
                    c = coords[i]
                    if c[0] == pt[0] and c[1] == pt[1]:
github nextgis / nextgiscrowd / ngcrowd / View on Github external
def as_json_dict(self, **init):
        d = dict()
        for c in self.__table__.columns:
            v = getattr(self,
            if isinstance(v, datetime.datetime):
                v = v.isoformat()
            if isinstance(v, WKBElement):
                v = {}
            d[] = v

        for k, v in init.items():
            d[k] = v

        return d
github gltn / stdm / navigation / View on Github external
#Set the name of the field to use for labeling        
        #Update the style of the property on each overlay operation
        #Set label object
        labelJSObject = "null"
        if hasattr(property,labelfield):
            propVal = getattr(property,labelfield)
            labelJSObject = "{'%s':'%s'}"%(labelfield,str(propVal))
        #Reproject to web mercator
        prop_wkb = self.dbSession.scalar(property.geom_polygon.ST_Transform(900913))  
        web_geom = WKBElement(prop_wkb)
        prop_geo_json = self.dbSession.scalar(web_geom.ST_AsGeoJSON())
        overlayJS = "drawProperty('%s',%s);"%(prop_geo_json,labelJSObject)                
        zoomLevel = self._setJS(overlayJS)
        #Raise map zoom changed event