Ticket #9745: snaptogrid_corrected.diff

File snaptogrid_corrected.diff, 3.0 KB (added by jbronn, 6 years ago)

SVN diff of user-provided patch

  • django/contrib/gis/db/models/manager.py

     
    6363    def scale(self, *args, **kwargs):
    6464        return self.get_query_set().scale(*args, **kwargs)
    6565
     66    def snaptogrid(self, *args, **kwargs):
     67        return self.get_query_set().snaptogrid(*args, **kwargs)
     68
    6669    def svg(self, *args, **kwargs):
    6770        return self.get_query_set().svg(*args, **kwargs)
    6871
  • django/contrib/gis/db/models/query.py

     
    217217             }
    218218        return self._spatial_attribute('scale', s, **kwargs)
    219219
     220    def snaptogrid(self, size=0.01, **kwargs):
     221        """
     222        Snap all points of the input geometry to the grid defined by
     223        cell size.
     224        """
     225        if SpatialBackend.version[0]<1:
     226            raise "Postgis version doesn't support SnapToGrid"
     227        if not isinstance(size, (float, int)):
     228            raise TypeError('Size of the grid must be float or int.')       
     229 
     230        field_name = kwargs.get('field_name', None)
     231        tmp, geo_field = self._spatial_setup('snaptogrid', field_name=field_name)
     232        field_col = self._geocol_select(geo_field, field_name)
     233        geo_col = self.query.custom_select.get(geo_field, field_col)
     234        custom_sel = '%s(%s, %s)' % (SpatialBackend.snaptogrid, geo_col, size)
     235        self.query.custom_select[geo_field] = custom_sel
     236        return self._clone()
     237
    220238    def svg(self, **kwargs):
    221239        """
    222240        Returns SVG representation of the geographic field in a `svg`
  • django/contrib/gis/db/backend/postgis/__init__.py

     
    3030                                    point_on_surface=POINT_ON_SURFACE,
    3131                                    scale=SCALE,
    3232                                    select=GEOM_SELECT,
     33                                    snaptogrid=SNAP_TO_GRID,
    3334                                    svg=ASSVG,
    3435                                    sym_difference=SYM_DIFFERENCE,
    3536                                    transform=TRANSFORM,
  • django/contrib/gis/db/backend/postgis/query.py

     
    6060    PERIMETER = get_func('Perimeter')
    6161    POINT_ON_SURFACE = get_func('PointOnSurface')
    6262    SCALE = get_func('Scale')
     63    SNAP_TO_GRID = get_func('SnapToGrid')
    6364    SYM_DIFFERENCE = get_func('SymDifference')
    6465    TRANSFORM = get_func('Transform')
    6566    TRANSLATE = get_func('Translate')
Back to Top