Exemple #1
0
 def tile_rowids(self,x,y,z):
     geocols = self.geo_columns()
     tblinfo = Entity(objid=str(self.objid))
     geocolid = geocols[0]['objid']
     geocolname = geocols[0]['name']
     features = []
     corners = tilecalc.tileBB(int(x),int(y),int(z))
     
     if tblinfo['parent_objid'].startswith('tbl'):
         tbl = self.api.get_entity('Table')(joininfo['parent_objid'])
         tblinfo['parent_objid'] = tbl['parent_objid']
     
     dbid = tblinfo['parent_objid']
     tblid = tblinfo['objid']
     
     stmt = syntax.select_geography_rowids(
         dbid,
         tblid,
         geocolid,
         corners,
         z
     )
             
     r = controllers['dql'].execute(stmt)
     
     return [x[0] for x in r]
Exemple #2
0
    def tile_rowids(self, x, y, z):
        geocols = self.geo_columns()
        tblinfo = Entity(objid=str(self.objid))
        geocolid = geocols[0]['objid']
        geocolname = geocols[0]['name']
        features = []
        corners = tilecalc.tileBB(int(x), int(y), int(z))

        if tblinfo['parent_objid'].startswith('tbl'):
            tbl = self.api.get_entity('Table')(joininfo['parent_objid'])
            tblinfo['parent_objid'] = tbl['parent_objid']

        dbid = tblinfo['parent_objid']
        tblid = tblinfo['objid']

        stmt = syntax.select_geography_rowids(dbid, tblid, geocolid, corners,
                                              z)

        r = controllers['dql'].execute(stmt)

        return [x[0] for x in r]
Exemple #3
0
    def tile(self,x,y,z,magnitude=None):
        tblinfo = self.api.get_byid(self.objid)
        
        simple = False
        layerid = None
        if tblinfo['dobj'] is not None and 'tilescheme' in tblinfo['dobj']:            
            layerid = tblinfo['objid']
            tblinfo = self.api.get_byid(tblinfo['dobj']['tilescheme'][z])
            simple = True
        
        tcols = tblinfo.columns()
        geotypes = ['Polygon','MultiPolygon','Point','MultiPoint','Line','MultiLine']
        geocols = [j for j in tcols if j['datatype'] in geotypes]
        if len(geocols) == 0:
            return
        
        if magnitude is None:
            if 'magnitude' in [j['name'] for j in tcols]:
                magnitude = 'magnitude'
        
        geocolid = geocols[0]['objid']
        geocolname = geocols[0]['name']
        geocoltype = geocols[0]['datatype']
        features = []
        if z > 2:
            corners = tilecalc.tileBB(int(x),int(y),int(z))
        else:
            corners = None
            
        if magnitude is not None:
            cols = dict((j['name'],j) for j in tcols)
            cols.update(
                dict((j['objid'],j) for j in tcols)
            )
            try:
                magnitude = cols[magnitude]['objid']
            except KeyError:
                raise errors.DataError
            
        
        if not tblinfo['parent_objid'].startswith('dbi'):
            tbl = self.api.get_byid(tblinfo['parent_objid'])
            try:
                tblinfo['parent_objid'] = tbl['parent_objid']
            except TypeError:
                tblinfo = tblinfo.row_dict
                tblinfo['parent_objid'] = tbl['parent_objid']
        
        dbid = tblinfo['parent_objid']
        tblid = tblinfo['objid']
        
        #if geocoltype == 'Polygon' or geocoltype == 'MultiPolygon':
            #stmt = syntax.select_geography_poly(
                #dbid,
                #tblid,
                #geocolid,
                #geocolname,
                #corners,
                #z=z,
                #magnitude=magnitude
            #)
        #else:
        stmt = syntax.select_geography(
            dbid,
            tblid,
            geocolid,
            geocolname,
            corners,
            z=z,
            magnitude=magnitude,
            simple=simple
        )

        r = controllers['dql'].execute(stmt)
        
        for row in r:
            features.append({
                'type':'Feature',
                'geometry':json.loads(row[1]),
                'properties':{
                    'rowid':row[0],
                    'objid':tblid,
                    'layerid':layerid,
                    'magnitude':row[2] if len(row) > 2 else None
                }
            })
        
        return {
            'type':'FeatureCollection',
            'features':features
        }
Exemple #4
0
    def tile(self, x, y, z, magnitude=None):
        tblinfo = self.api.get_byid(self.objid)

        simple = False
        layerid = None
        if tblinfo['dobj'] is not None and 'tilescheme' in tblinfo['dobj']:
            layerid = tblinfo['objid']
            tblinfo = self.api.get_byid(tblinfo['dobj']['tilescheme'][z])
            simple = True

        tcols = tblinfo.columns()
        geotypes = [
            'Polygon', 'MultiPolygon', 'Point', 'MultiPoint', 'Line',
            'MultiLine'
        ]
        geocols = [j for j in tcols if j['datatype'] in geotypes]
        if len(geocols) == 0:
            return

        if magnitude is None:
            if 'magnitude' in [j['name'] for j in tcols]:
                magnitude = 'magnitude'

        geocolid = geocols[0]['objid']
        geocolname = geocols[0]['name']
        geocoltype = geocols[0]['datatype']
        features = []
        if z > 2:
            corners = tilecalc.tileBB(int(x), int(y), int(z))
        else:
            corners = None

        if magnitude is not None:
            cols = dict((j['name'], j) for j in tcols)
            cols.update(dict((j['objid'], j) for j in tcols))
            try:
                magnitude = cols[magnitude]['objid']
            except KeyError:
                raise errors.DataError

        if not tblinfo['parent_objid'].startswith('dbi'):
            tbl = self.api.get_byid(tblinfo['parent_objid'])
            try:
                tblinfo['parent_objid'] = tbl['parent_objid']
            except TypeError:
                tblinfo = tblinfo.row_dict
                tblinfo['parent_objid'] = tbl['parent_objid']

        dbid = tblinfo['parent_objid']
        tblid = tblinfo['objid']

        #if geocoltype == 'Polygon' or geocoltype == 'MultiPolygon':
        #stmt = syntax.select_geography_poly(
        #dbid,
        #tblid,
        #geocolid,
        #geocolname,
        #corners,
        #z=z,
        #magnitude=magnitude
        #)
        #else:
        stmt = syntax.select_geography(dbid,
                                       tblid,
                                       geocolid,
                                       geocolname,
                                       corners,
                                       z=z,
                                       magnitude=magnitude,
                                       simple=simple)

        r = controllers['dql'].execute(stmt)

        for row in r:
            features.append({
                'type': 'Feature',
                'geometry': json.loads(row[1]),
                'properties': {
                    'rowid': row[0],
                    'objid': tblid,
                    'layerid': layerid,
                    'magnitude': row[2] if len(row) > 2 else None
                }
            })

        return {'type': 'FeatureCollection', 'features': features}