| 98 | | def get_db_prep_lookup(self, lookup_type, value): |
|---|
| 99 | | """ |
|---|
| 100 | | Returns field's value prepared for database lookup, accepts WKT and |
|---|
| 101 | | GEOS Geometries for the value. |
|---|
| 102 | | """ |
|---|
| 103 | | if lookup_type in ORACLE_SPATIAL_TERMS: |
|---|
| 104 | | # special case for isnull lookup |
|---|
| 105 | | if lookup_type == 'isnull': return GeoFieldSQL([], []) |
|---|
| 106 | | |
|---|
| 107 | | # Get the geometry with SRID; defaults SRID to that |
|---|
| 108 | | # of the field if it is None |
|---|
| 109 | | geom = self.get_geometry(value) |
|---|
| 110 | | |
|---|
| 111 | | # The adaptor will be used by psycopg2 for quoting the WKT. |
|---|
| 112 | | adapt = OracleSpatialAdaptor(geom) |
|---|
| 113 | | |
|---|
| 114 | | if geom.srid != self._srid: |
|---|
| 115 | | # Adding the necessary string substitutions and parameters |
|---|
| 116 | | # to perform a geometry transformation. |
|---|
| 117 | | where = ['%s(SDO_GEOMETRY(%%s, %s), %%s)' % (TRANSFORM, geom.srid)] |
|---|
| 118 | | params = [adapt, self._srid] |
|---|
| 119 | | else: |
|---|
| 120 | | where = ['SDO_GEOMETRY(%%s, %s)' % geom.srid] |
|---|
| 121 | | params = [adapt] |
|---|
| 122 | | |
|---|
| 123 | | if isinstance(value, tuple): |
|---|
| 124 | | if lookup_type in DISTANCE_FUNCTIONS or lookup_type == 'dwithin': |
|---|
| 125 | | # Getting the distance parameter in the units of the field |
|---|
| 126 | | where += [self.get_distance(value[1])] |
|---|
| 127 | | elif lookup_type == 'relate': |
|---|
| 128 | | # No extra where parameters for SDO_RELATE queries. |
|---|
| 129 | | pass |
|---|
| 130 | | else: |
|---|
| 131 | | where += map(gqn, value[1:]) |
|---|
| 132 | | return GeoFieldSQL(where, params) |
|---|
| 133 | | else: |
|---|
| 134 | | raise TypeError("Field has invalid lookup: %s" % lookup_type) |
|---|
| 135 | | |
|---|
| 136 | | def get_db_prep_save(self, value): |
|---|
| 137 | | "Prepares the value for saving in the database." |
|---|
| 138 | | if not bool(value): |
|---|
| 139 | | # Return an empty string for NULL -- but this doesn't work yet. |
|---|
| 140 | | return '' |
|---|
| 141 | | if isinstance(value, GEOSGeometry): |
|---|
| 142 | | return OracleSpatialAdaptor(value) |
|---|
| 143 | | else: |
|---|
| 144 | | raise TypeError('Geometry Proxy should only return GEOSGeometry objects.') |
|---|
| 145 | | |
|---|