Beispiel #1
0
 def translate(self, x, y, z=0.0, **kwargs):
     """
     Translates the geometry to a new location using the given numeric
     parameters as offsets.
     """
     if connections[self.db].ops.spatialite:
         if z != 0.0:
             raise NotImplementedError(
                 'SpatiaLite does not support 3D translation.')
         s = {
             'procedure_fmt': '%(geo_col)s,%(x)s,%(y)s',
             'procedure_args': {
                 'x': x,
                 'y': y
             },
             'select_field': GeomField(),
         }
     else:
         s = {
             'procedure_fmt': '%(geo_col)s,%(x)s,%(y)s,%(z)s',
             'procedure_args': {
                 'x': x,
                 'y': y,
                 'z': z
             },
             'select_field': GeomField(),
         }
     return self._spatial_attribute('translate', s, **kwargs)
Beispiel #2
0
 def scale(self, x, y, z=0.0, **kwargs):
     """
     Scales the geometry to a new size by multiplying the ordinates
     with the given x,y,z scale factors.
     """
     if connections[self.db].ops.spatialite:
         if z != 0.0:
             raise NotImplementedError(
                 'SpatiaLite does not support 3D scaling.')
         s = {
             'procedure_fmt': '%(geo_col)s,%(x)s,%(y)s',
             'procedure_args': {
                 'x': x,
                 'y': y
             },
             'select_field': GeomField(),
         }
     else:
         s = {
             'procedure_fmt': '%(geo_col)s,%(x)s,%(y)s,%(z)s',
             'procedure_args': {
                 'x': x,
                 'y': y,
                 'z': z
             },
             'select_field': GeomField(),
         }
     return self._spatial_attribute('scale', s, **kwargs)
Beispiel #3
0
    def snap_to_grid(self, *args, **kwargs):
        """
        Snap all points of the input geometry to the grid.  How the
        geometry is snapped to the grid depends on how many arguments
        were given:
          - 1 argument : A single size to snap both the X and Y grids to.
          - 2 arguments: X and Y sizes to snap the grid to.
          - 4 arguments: X, Y sizes and the X, Y origins.
        """
        if False in [isinstance(arg, (float,) + six.integer_types) for arg in args]:
            raise TypeError('Size argument(s) for the grid must be a float or integer values.')

        nargs = len(args)
        if nargs == 1:
            size = args[0]
            procedure_fmt = '%(geo_col)s,%(size)s'
            procedure_args = {'size': size}
        elif nargs == 2:
            xsize, ysize = args
            procedure_fmt = '%(geo_col)s,%(xsize)s,%(ysize)s'
            procedure_args = {'xsize': xsize, 'ysize': ysize}
        elif nargs == 4:
            xsize, ysize, xorigin, yorigin = args
            procedure_fmt = '%(geo_col)s,%(xorigin)s,%(yorigin)s,%(xsize)s,%(ysize)s'
            procedure_args = {'xsize': xsize, 'ysize': ysize,
                              'xorigin': xorigin, 'yorigin': yorigin}
        else:
            raise ValueError('Must provide 1, 2, or 4 arguments to `snap_to_grid`.')

        s = {'procedure_fmt': procedure_fmt,
             'procedure_args': procedure_args,
             'select_field': GeomField(),
             }

        return self._spatial_attribute('snap_to_grid', s, **kwargs)
Beispiel #4
0
 def _geom_attribute(self, func, tolerance=0.05, **kwargs):
     """
     DRY routine for setting up a GeoQuerySet method that attaches a
     Geometry attribute (e.g., `centroid`, `point_on_surface`).
     """
     s = {'select_field': GeomField()}
     if connections[self.db].ops.oracle:
         s['procedure_fmt'] = '%(geo_col)s,%(tolerance)s'
         s['procedure_args'] = {'tolerance': tolerance}
     return self._spatial_attribute(func, s, **kwargs)
Beispiel #5
0
 def reverse_geom(self, **kwargs):
     """
     Reverses the coordinate order of the geometry, and attaches as a
     `reverse` attribute on each element of this GeoQuerySet.
     """
     s = {'select_field': GeomField()}
     kwargs.setdefault('model_att', 'reverse_geom')
     if connections[self.db].ops.oracle:
         s['geo_field_type'] = LineStringField
     return self._spatial_attribute('reverse', s, **kwargs)
Beispiel #6
0
 def translate(self, x, y, z=0.0, **kwargs):
     """
     Translates the geometry to a new location using the given numeric
     parameters as offsets.
     """
     s = {'procedure_fmt' : '%(geo_col)s,%(x)s,%(y)s,%(z)s',
          'procedure_args' : {'x' : x, 'y' : y, 'z' : z},
          'select_field' : GeomField(),
          }
     return self._spatial_attribute('translate', s, **kwargs)
Beispiel #7
0
 def scale(self, x, y, z=0.0, **kwargs):
     """
     Scales the geometry to a new size by multiplying the ordinates
     with the given x,y,z scale factors.
     """
     s = {'procedure_fmt' : '%(geo_col)s,%(x)s,%(y)s,%(z)s',
          'procedure_args' : {'x' : x, 'y' : y, 'z' : z},
          'select_field' : GeomField(),
          }
     return self._spatial_attribute('scale', s, **kwargs)
Beispiel #8
0
 def add_to_query(self, query, alias, col, source, is_summary):
     if hasattr(source, '_geom'):
         # Doing additional setup on the Query object for spatial aggregates.
         aggregate = getattr(query.aggregates_module, self.name)
         
         # Adding a conversion class instance and any selection wrapping
         # SQL (e.g., needed by Oracle).
         if aggregate.conversion_class is GeomField:
             query.extra_select_fields[alias] = GeomField()
             if SpatialBackend.select:
                 query.custom_select[alias] = SpatialBackend.select
  
     super(GeoAggregate, self).add_to_query(query, alias, col, source, is_summary)
 def _geomset_attribute(self, func, geom, tolerance=0.05, **kwargs):
     """
     DRY routine for setting up a GeoQuerySet method that attaches a
     Geometry attribute and takes a Geoemtry parameter.  This is used
     for geometry set-like operations (e.g., intersection, difference,
     union, sym_difference).
     """
     s = {'geom_args' : ('geom',),
          'select_field' : GeomField(),
          'procedure_fmt' : '%(geo_col)s,%(geom)s',
          'procedure_args' : {'geom' : geom},
         }
     if connections[self.db].ops.oracle:
         s['procedure_fmt'] += ',%(tolerance)s'
         s['procedure_args']['tolerance'] = tolerance
     return self._spatial_attribute(func, s, **kwargs)