def _spatial_(self, s, climatemodel):
        col = self.dataset.variables[self.col][:]
        row = self.dataset.variables[self.row][:]
        col_bnds = self.dataset.variables[self.col_bnds][:]
        row_bnds = self.dataset.variables[self.row_bnds][:]
        geoms = []
        total = len(col) * len(row)
        ctr = 0
        for ii in xrange(len(col)):
            for jj in xrange(len(row)):
                if ctr % 2000 == 0:
                    print('  {0} of {1}'.format(ctr, total))
                ctr += 1
                obj = db.IndexSpatial()
                obj.row = ii
                obj.col = jj
                #                obj.dataset = dataset
                pt = Point(col[ii], row[jj])
                obj.centroid = WKTSpatialElement(str(pt))
                poly = Polygon(
                    ((col_bnds[ii, 0], row_bnds[jj, 0]), (col_bnds[ii, 0],
                                                          row_bnds[jj, 1]),
                     (col_bnds[ii, 1], row_bnds[jj, 1]), (col_bnds[ii, 1],
                                                          row_bnds[jj, 0])))
                obj.geom = WKTSpatialElement(str(poly))
                geoms.append(obj)
#                s.add(obj)
        climatemodel.indexspatial = geoms
        print('  committing...')
        s.commit()
Beispiel #2
0
def parse_clause(clause, compiler):
    """This method is used to translate a clause element (geometries, functions, ..).
    According to the type of the clause, a conversion to the database geometry type is added or
    the column clause (column name) or the cascaded clause element is returned.
        
    """
    from geoalchemy.base import SpatialElement, WKTSpatialElement, WKBSpatialElement, DBSpatialElement, GeometryBase
    
    if hasattr(clause, '__clause_element__'):
        # for example a column name
        return clause.__clause_element__()
    elif isinstance(clause, ClauseElement):
        # for cascaded clause elements, like other functions
        return clause
    elif isinstance(clause, SpatialElement):
        if isinstance(clause, (WKTSpatialElement, WKBSpatialElement)):
            return clause
        if isinstance(clause, DBSpatialElement):
            return literal(clause.desc, GeometryBase)    
        return clause.desc
    elif isinstance(clause, basestring) and WKT_REGEX.match(clause):
        return WKTSpatialElement(clause)
    
    # for raw parameters    
    return literal(clause)
Beispiel #3
0
    def deserialize(self):
        """Turns the user input into a GeoAlchemy geometry, which
        can be stored in the database.
        """
        form_value = self.params.getone(self.name)

        if form_value is not None and form_value.strip() != '':
            return WKTSpatialElement(form_value,
                                     srid=self.__get_options().get(
                                         'map_srid', self.field.type.srid))

        return None
Beispiel #4
0
 def process_result(self, value, type):
     if type.wkt_internal:
         return PGPersistentSpatialElement(
             WKTSpatialElement(value, type.srid))
     return PGPersistentSpatialElement(WKBSpatialElement(value, type.srid))