diff options
| author | django-bot <ops@djangoproject.com> | 2025-07-22 20:41:41 -0700 |
|---|---|---|
| committer | nessita <124304+nessita@users.noreply.github.com> | 2025-07-23 20:17:55 -0300 |
| commit | 69a93a88edb56ba47f624dac7a21aacc47ea474f (patch) | |
| tree | f57507a4435d032493cae40e06ecb254790b67b2 /django/contrib/gis | |
| parent | 55b0cc21310b76ce4018dd793ba50556eaf0af06 (diff) | |
Refs #36500 -- Rewrapped long docstrings and block comments via a script.
Rewrapped long docstrings and block comments to 79 characters + newline
using script from https://github.com/medmunds/autofix-w505.
Diffstat (limited to 'django/contrib/gis')
31 files changed, 194 insertions, 138 deletions
diff --git a/django/contrib/gis/db/backends/base/features.py b/django/contrib/gis/db/backends/base/features.py index 22c90a1714..d1e2211bdc 100644 --- a/django/contrib/gis/db/backends/base/features.py +++ b/django/contrib/gis/db/backends/base/features.py @@ -8,10 +8,12 @@ from .operations import BaseSpatialOperations class BaseSpatialFeatures: gis_enabled = True - # Does the database contain a SpatialRefSys model to store SRID information? + # Does the database contain a SpatialRefSys model to store SRID + # information? has_spatialrefsys_table = True - # Does the backend support the django.contrib.gis.utils.add_srs_entry() utility? + # Does the backend support the django.contrib.gis.utils.add_srs_entry() + # utility? supports_add_srs_entry = True # Does the backend introspect GeometryField to its subtypes? supports_geometry_field_introspection = True diff --git a/django/contrib/gis/db/backends/base/operations.py b/django/contrib/gis/db/backends/base/operations.py index 5c09aaa8bc..b3bf4383ad 100644 --- a/django/contrib/gis/db/backends/base/operations.py +++ b/django/contrib/gis/db/backends/base/operations.py @@ -28,8 +28,8 @@ class BaseSpatialOperations: geom_func_prefix = "" - # Mapping between Django function names and backend names, when names do not - # match; used in spatial_function_name(). + # Mapping between Django function names and backend names, when names do + # not match; used in spatial_function_name(). function_names = {} # Set of known unsupported functions of the backend @@ -79,8 +79,8 @@ class BaseSpatialOperations: # Constructors from_text = False - # Default conversion functions for aggregates; will be overridden if implemented - # for the spatial backend. + # Default conversion functions for aggregates; will be overridden if + # implemented for the spatial backend. def convert_extent(self, box, srid): raise NotImplementedError( "Aggregate extent not implemented for this spatial backend." diff --git a/django/contrib/gis/db/backends/mysql/features.py b/django/contrib/gis/db/backends/mysql/features.py index cd99420374..4e46ba40f3 100644 --- a/django/contrib/gis/db/backends/mysql/features.py +++ b/django/contrib/gis/db/backends/mysql/features.py @@ -17,5 +17,6 @@ class DatabaseFeatures(BaseSpatialFeatures, MySQLDatabaseFeatures): @cached_property def supports_geometry_field_unique_index(self): - # Not supported in MySQL since https://dev.mysql.com/worklog/task/?id=11808 + # Not supported in MySQL since + # https://dev.mysql.com/worklog/task/?id=11808 return self.connection.mysql_is_mariadb diff --git a/django/contrib/gis/db/backends/mysql/introspection.py b/django/contrib/gis/db/backends/mysql/introspection.py index 4d6aea78a2..65e7549efc 100644 --- a/django/contrib/gis/db/backends/mysql/introspection.py +++ b/django/contrib/gis/db/backends/mysql/introspection.py @@ -19,9 +19,9 @@ class MySQLIntrospection(DatabaseIntrospection): # column. for column, typ, null, key, default, extra in cursor.fetchall(): if column == description.name: - # Using OGRGeomType to convert from OGC name to Django field. - # MySQL does not support 3D or SRIDs, so the field params - # are empty. + # Using OGRGeomType to convert from OGC name to Django + # field. MySQL does not support 3D or SRIDs, so the field + # params are empty. field_type = OGRGeomType(typ).django field_params = {} break diff --git a/django/contrib/gis/db/backends/oracle/introspection.py b/django/contrib/gis/db/backends/oracle/introspection.py index 8e1a5e7a8c..baaf658b43 100644 --- a/django/contrib/gis/db/backends/oracle/introspection.py +++ b/django/contrib/gis/db/backends/oracle/introspection.py @@ -17,7 +17,8 @@ class OracleIntrospection(DatabaseIntrospection): def get_geometry_type(self, table_name, description): with self.connection.cursor() as cursor: - # Querying USER_SDO_GEOM_METADATA to get the SRID and dimension information. + # Querying USER_SDO_GEOM_METADATA to get the SRID and dimension + # information. try: cursor.execute( 'SELECT "DIMINFO", "SRID" FROM "USER_SDO_GEOM_METADATA" ' @@ -31,8 +32,8 @@ class OracleIntrospection(DatabaseIntrospection): 'corresponding to "%s"."%s"' % (table_name, description.name) ) from exc - # TODO: Research way to find a more specific geometry field type for - # the column's contents. + # TODO: Research way to find a more specific geometry field type + # for the column's contents. field_type = "GeometryField" # Getting the field parameters. diff --git a/django/contrib/gis/db/backends/oracle/operations.py b/django/contrib/gis/db/backends/oracle/operations.py index 77cb8e034c..467fc530b3 100644 --- a/django/contrib/gis/db/backends/oracle/operations.py +++ b/django/contrib/gis/db/backends/oracle/operations.py @@ -227,8 +227,8 @@ class OracleOperations(BaseSpatialOperations, DatabaseOperations): return OracleSpatialRefSys def modify_insert_params(self, placeholder, params): - """Drop out insert parameters for NULL placeholder. Needed for Oracle Spatial - backend due to #10888. + """Drop out insert parameters for NULL placeholder. Needed for Oracle + Spatial backend due to #10888. """ if placeholder == "NULL": return [] diff --git a/django/contrib/gis/db/backends/postgis/introspection.py b/django/contrib/gis/db/backends/postgis/introspection.py index 7c96c2cb04..e3b9957838 100644 --- a/django/contrib/gis/db/backends/postgis/introspection.py +++ b/django/contrib/gis/db/backends/postgis/introspection.py @@ -61,7 +61,8 @@ class PostGISIntrospection(DatabaseIntrospection): # OGRGeomType does not require GDAL and makes it easy to convert # from OGC geom type name to Django field. field_type = OGRGeomType(field_type).django - # Getting any GeometryField keyword arguments that are not the default. + # Getting any GeometryField keyword arguments that are not the + # default. field_params = {} if self.postgis_oid_lookup.get(description.type_code) == "geography": field_params["geography"] = True diff --git a/django/contrib/gis/db/backends/postgis/operations.py b/django/contrib/gis/db/backends/postgis/operations.py index 303e039958..df3cc7c7ee 100644 --- a/django/contrib/gis/db/backends/postgis/operations.py +++ b/django/contrib/gis/db/backends/postgis/operations.py @@ -328,7 +328,8 @@ class PostGISOperations(BaseSpatialOperations, DatabaseOperations): def _get_postgis_func(self, func): """ - Helper routine for calling PostGIS functions and returning their result. + Helper routine for calling PostGIS functions and returning their + result. """ # Close out the connection. See #9437. with self.connection.temporary_connection() as cursor: @@ -340,7 +341,9 @@ class PostGISOperations(BaseSpatialOperations, DatabaseOperations): return self._get_postgis_func("postgis_geos_version") def postgis_lib_version(self): - "Return the version number of the PostGIS library used with PostgreSQL." + """ + Return the version number of the PostGIS library used with PostgreSQL. + """ return self._get_postgis_func("postgis_lib_version") def postgis_proj_version(self): diff --git a/django/contrib/gis/db/backends/postgis/schema.py b/django/contrib/gis/db/backends/postgis/schema.py index c74b574c4c..aef62198cb 100644 --- a/django/contrib/gis/db/backends/postgis/schema.py +++ b/django/contrib/gis/db/backends/postgis/schema.py @@ -100,8 +100,9 @@ class PostGISSchemaEditor(DatabaseSchemaEditor): opclasses = None fields = [field] if field.geom_type == "RASTER": - # For raster fields, wrap index creation SQL statement with ST_ConvexHull. - # Indexes on raster columns are based on the convex hull of the raster. + # For raster fields, wrap index creation SQL statement with + # ST_ConvexHull. Indexes on raster columns are based on the convex + # hull of the raster. expressions = Func(Col(None, field), template=self.rast_index_template) fields = None elif field.dim > 2 and not field.geography: diff --git a/django/contrib/gis/db/backends/spatialite/introspection.py b/django/contrib/gis/db/backends/spatialite/introspection.py index 8d0003fd53..f2f5146586 100644 --- a/django/contrib/gis/db/backends/spatialite/introspection.py +++ b/django/contrib/gis/db/backends/spatialite/introspection.py @@ -52,7 +52,8 @@ class SpatiaLiteIntrospection(DatabaseIntrospection): ogr_type = ogr_type % 1000 + OGRGeomType.wkb25bit field_type = OGRGeomType(ogr_type).django - # Getting any GeometryField keyword arguments that are not the default. + # Getting any GeometryField keyword arguments that are not the + # default. dim = row[0] srid = row[1] field_params = {} diff --git a/django/contrib/gis/db/backends/spatialite/operations.py b/django/contrib/gis/db/backends/spatialite/operations.py index 3509001426..e9321ee2a3 100644 --- a/django/contrib/gis/db/backends/spatialite/operations.py +++ b/django/contrib/gis/db/backends/spatialite/operations.py @@ -48,9 +48,11 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations): "relate": SpatialiteNullCheckOperator(func="Relate"), "coveredby": SpatialiteNullCheckOperator(func="CoveredBy"), "covers": SpatialiteNullCheckOperator(func="Covers"), - # Returns true if B's bounding box completely contains A's bounding box. + # Returns true if B's bounding box completely contains A's bounding + # box. "contained": SpatialOperator(func="MbrWithin"), - # Returns true if A's bounding box completely contains B's bounding box. + # Returns true if A's bounding box completely contains B's bounding + # box. "bbcontains": SpatialOperator(func="MbrContains"), # Returns true if A's bounding box overlaps B's bounding box. "bboverlaps": SpatialOperator(func="MbrOverlaps"), diff --git a/django/contrib/gis/db/backends/spatialite/schema.py b/django/contrib/gis/db/backends/spatialite/schema.py index fb2c5690de..69b8da2501 100644 --- a/django/contrib/gis/db/backends/spatialite/schema.py +++ b/django/contrib/gis/db/backends/spatialite/schema.py @@ -91,7 +91,8 @@ class SpatialiteSchemaEditor(DatabaseSchemaEditor): def delete_model(self, model, **kwargs): from django.contrib.gis.db.models import GeometryField - # Drop spatial metadata (dropping the table does not automatically remove them) + # Drop spatial metadata (dropping the table does not automatically + # remove them) for field in model._meta.local_fields: if isinstance(field, GeometryField): self.remove_geometry_metadata(model, field) @@ -126,9 +127,9 @@ class SpatialiteSchemaEditor(DatabaseSchemaEditor): # NOTE: If the field is a geometry field, the table is just recreated, # the parent's remove_field can't be used cause it will skip the - # recreation if the field does not have a database type. Geometry fields - # do not have a db type cause they are added and removed via stored - # procedures. + # recreation if the field does not have a database type. Geometry + # fields do not have a db type cause they are added and removed via + # stored procedures. if isinstance(field, GeometryField): self._remake_table(model, delete_field=field) else: diff --git a/django/contrib/gis/db/backends/utils.py b/django/contrib/gis/db/backends/utils.py index ffb7420019..4e2035d577 100644 --- a/django/contrib/gis/db/backends/utils.py +++ b/django/contrib/gis/db/backends/utils.py @@ -6,7 +6,8 @@ backends. class SpatialOperator: """ - Class encapsulating the behavior specific to a GIS operation (used by lookups). + Class encapsulating the behavior specific to a GIS operation (used by + lookups). """ sql_template = None diff --git a/django/contrib/gis/db/models/fields.py b/django/contrib/gis/db/models/fields.py index 4542e19040..d1c1a5937e 100644 --- a/django/contrib/gis/db/models/fields.py +++ b/django/contrib/gis/db/models/fields.py @@ -81,8 +81,8 @@ class BaseSpatialField(Field): def __init__(self, verbose_name=None, srid=4326, spatial_index=True, **kwargs): """ - The initialization function for base spatial fields. Takes the following - as keyword arguments: + The initialization function for base spatial fields. Takes the + following as keyword arguments: srid: The spatial reference system identifier, an OGC standard. @@ -195,7 +195,8 @@ class BaseSpatialField(Field): if isinstance(obj, GEOSGeometry): pass else: - # Check if input is a candidate for conversion to raster or geometry. + # Check if input is a candidate for conversion to raster or + # geometry. is_candidate = isinstance(obj, (bytes, str)) or hasattr( obj, "__geo_interface__" ) @@ -395,7 +396,8 @@ class RasterField(BaseSpatialField): geography = False def _check_connection(self, connection): - # Make sure raster fields are used only on backends with raster support. + # Make sure raster fields are used only on backends with raster + # support. if ( not connection.features.gis_enabled or not connection.features.supports_raster diff --git a/django/contrib/gis/db/models/functions.py b/django/contrib/gis/db/models/functions.py index cafcd32e3b..9e94d0f77a 100644 --- a/django/contrib/gis/db/models/functions.py +++ b/django/contrib/gis/db/models/functions.py @@ -121,8 +121,8 @@ class GeomOutputGeoFunc(GeoFunc): class SQLiteDecimalToFloatMixin: """ - By default, Decimal values are converted to str by the SQLite backend, which - is not acceptable by the GIS functions expecting numeric values. + By default, Decimal values are converted to str by the SQLite backend, + which is not acceptable by the GIS functions expecting numeric values. """ def as_sqlite(self, compiler, connection, **extra_context): @@ -483,7 +483,8 @@ class Length(DistanceResultMixin, OracleToleranceMixin, GeoFunc): if self.source_is_geography(): clone.source_expressions.append(Value(self.spheroid)) elif self.geo_field.geodetic(connection): - # Geometry fields with geodetic (lon/lat) coordinates need length_spheroid + # Geometry fields with geodetic (lon/lat) coordinates need + # length_spheroid function = connection.ops.spatial_function_name("LengthSpheroid") clone.source_expressions.append(Value(self.geo_field.spheroid(connection))) else: diff --git a/django/contrib/gis/db/models/lookups.py b/django/contrib/gis/db/models/lookups.py index 49e6c8b606..3d30ffed5c 100644 --- a/django/contrib/gis/db/models/lookups.py +++ b/django/contrib/gis/db/models/lookups.py @@ -70,9 +70,9 @@ class GISLookup(Lookup): return placeholder % rhs, rhs_params def get_rhs_op(self, connection, rhs): - # Unlike BuiltinLookup, the GIS get_rhs_op() implementation should return - # an object (SpatialOperator) with an as_sql() method to allow for more - # complex computations (where the lhs part can be mixed in). + # Unlike BuiltinLookup, the GIS get_rhs_op() implementation should + # return an object (SpatialOperator) with an as_sql() method to allow + # for more complex computations (where the lhs part can be mixed in). return connection.ops.gis_operators[self.lookup_name] def as_sql(self, compiler, connection): @@ -98,8 +98,8 @@ class GISLookup(Lookup): @BaseSpatialField.register_lookup class OverlapsLeftLookup(GISLookup): """ - The overlaps_left operator returns true if A's bounding box overlaps or is to the - left of B's bounding box. + The overlaps_left operator returns true if A's bounding box overlaps or is + to the left of B's bounding box. """ lookup_name = "overlaps_left" @@ -108,8 +108,8 @@ class OverlapsLeftLookup(GISLookup): @BaseSpatialField.register_lookup class OverlapsRightLookup(GISLookup): """ - The 'overlaps_right' operator returns true if A's bounding box overlaps or is to the - right of B's bounding box. + The 'overlaps_right' operator returns true if A's bounding box overlaps or + is to the right of B's bounding box. """ lookup_name = "overlaps_right" @@ -118,8 +118,8 @@ class OverlapsRightLookup(GISLookup): @BaseSpatialField.register_lookup class OverlapsBelowLookup(GISLookup): """ - The 'overlaps_below' operator returns true if A's bounding box overlaps or is below - B's bounding box. + The 'overlaps_below' operator returns true if A's bounding box overlaps or + is below B's bounding box. """ lookup_name = "overlaps_below" @@ -128,8 +128,8 @@ class OverlapsBelowLookup(GISLookup): @BaseSpatialField.register_lookup class OverlapsAboveLookup(GISLookup): """ - The 'overlaps_above' operator returns true if A's bounding box overlaps or is above - B's bounding box. + The 'overlaps_above' operator returns true if A's bounding box overlaps or + is above B's bounding box. """ lookup_name = "overlaps_above" @@ -138,8 +138,8 @@ class OverlapsAboveLookup(GISLookup): @BaseSpatialField.register_lookup class LeftLookup(GISLookup): """ - The 'left' operator returns true if A's bounding box is strictly to the left - of B's bounding box. + The 'left' operator returns true if A's bounding box is strictly to the + left of B's bounding box. """ lookup_name = "left" @@ -148,8 +148,8 @@ class LeftLookup(GISLookup): @BaseSpatialField.register_lookup class RightLookup(GISLookup): """ - The 'right' operator returns true if A's bounding box is strictly to the right - of B's bounding box. + The 'right' operator returns true if A's bounding box is strictly to the + right of B's bounding box. """ lookup_name = "right" @@ -158,8 +158,8 @@ class RightLookup(GISLookup): @BaseSpatialField.register_lookup class StrictlyBelowLookup(GISLookup): """ - The 'strictly_below' operator returns true if A's bounding box is strictly below B's - bounding box. + The 'strictly_below' operator returns true if A's bounding box is strictly + below B's bounding box. """ lookup_name = "strictly_below" @@ -168,8 +168,8 @@ class StrictlyBelowLookup(GISLookup): @BaseSpatialField.register_lookup class StrictlyAboveLookup(GISLookup): """ - The 'strictly_above' operator returns true if A's bounding box is strictly above B's - bounding box. + The 'strictly_above' operator returns true if A's bounding box is strictly + above B's bounding box. """ lookup_name = "strictly_above" @@ -192,8 +192,8 @@ BaseSpatialField.register_lookup(SameAsLookup, "exact") @BaseSpatialField.register_lookup class BBContainsLookup(GISLookup): """ - The 'bbcontains' operator returns true if A's bounding box completely contains - by B's bounding box. + The 'bbcontains' operator returns true if A's bounding box completely + contains by B's bounding box. """ lookup_name = "bbcontains" @@ -212,8 +212,8 @@ class BBOverlapsLookup(GISLookup): @BaseSpatialField.register_lookup class ContainedLookup(GISLookup): """ - The 'contained' operator returns true if A's bounding box is completely contained - by B's bounding box. + The 'contained' operator returns true if A's bounding box is completely + contained by B's bounding box. """ lookup_name = "contained" diff --git a/django/contrib/gis/gdal/envelope.py b/django/contrib/gis/gdal/envelope.py index 8293aa499d..f33f9b4df6 100644 --- a/django/contrib/gis/gdal/envelope.py +++ b/django/contrib/gis/gdal/envelope.py @@ -39,8 +39,8 @@ class Envelope: def __init__(self, *args): """ - The initialization function may take an OGREnvelope structure, 4-element - tuple or list, or 4 individual arguments. + The initialization function may take an OGREnvelope structure, + 4-element tuple or list, or 4 individual arguments. """ if len(args) == 1: diff --git a/django/contrib/gis/gdal/geometries.py b/django/contrib/gis/gdal/geometries.py index f0e56a3e01..6301cd7146 100644 --- a/django/contrib/gis/gdal/geometries.py +++ b/django/contrib/gis/gdal/geometries.py @@ -30,7 +30,8 @@ Example: >>> print(mpnt.proj) +proj=longlat +ellps=clrk66 +datum=NAD27 +no_defs >>> print(mpnt) - MULTIPOINT (-89.99993037860248 29.99979788655764,-89.99993037860248 29.99979788655764) + MULTIPOINT (-89.99993037860248 29.99979788655764,-89.99993037860248 + 29.99979788655764) The OGRGeomType class is to make it easy to specify an OGR geometry type: >>> from django.contrib.gis.gdal import OGRGeomType @@ -248,7 +249,10 @@ class OGRGeometry(GDALBase): @property def area(self): - "Return the area for a LinearRing, Polygon, or MultiPolygon; 0 otherwise." + """ + Return the area for a LinearRing, Polygon, or MultiPolygon; 0 + otherwise. + """ return capi.get_area(self.ptr) @property @@ -411,7 +415,8 @@ class OGRGeometry(GDALBase): else: byteorder = 0 # wkbXDR sz = self.wkb_size - # Creating the unsigned character buffer, and passing it in by reference. + # Creating the unsigned character buffer, and passing it in by + # reference. buf = (c_ubyte * sz)() # For backward compatibility, export old-style 99-402 extended # dimension types when geometry does not have an M dimension. @@ -483,8 +488,8 @@ class OGRGeometry(GDALBase): # #### Topology Methods #### def _topology(self, func, other): - """A generalized function for topology operations, takes a GDAL function and - the other geometry to perform the operation on.""" + """A generalized function for topology operations, takes a GDAL + function and the other geometry to perform the operation on.""" if not isinstance(other, OGRGeometry): raise TypeError( "Must use another OGRGeometry object for topology operations!" diff --git a/django/contrib/gis/gdal/raster/band.py b/django/contrib/gis/gdal/raster/band.py index c3ec960643..34ce39633e 100644 --- a/django/contrib/gis/gdal/raster/band.py +++ b/django/contrib/gis/gdal/raster/band.py @@ -71,8 +71,8 @@ class GDALBand(GDALRasterBase): If approximate=True, the statistics may be computed based on overviews or a subset of image tiles. - If refresh=True, the statistics will be computed from the data directly, - and the cache will be updated where applicable. + If refresh=True, the statistics will be computed from the data + directly, and the cache will be updated where applicable. For empty bands (where all pixel values are nodata), all statistics values are returned as None. diff --git a/django/contrib/gis/gdal/raster/source.py b/django/contrib/gis/gdal/raster/source.py index b33eb11c0f..93c5900970 100644 --- a/django/contrib/gis/gdal/raster/source.py +++ b/django/contrib/gis/gdal/raster/source.py @@ -204,7 +204,8 @@ class GDALRaster(GDALRasterBase): if "skew" in ds_input: self.skew.x, self.skew.y = ds_input["skew"] elif isinstance(ds_input, c_void_p): - # Instantiate the object using an existing pointer to a gdal raster. + # Instantiate the object using an existing pointer to a gdal + # raster. self._ptr = ds_input else: raise GDALException( @@ -410,11 +411,12 @@ class GDALRaster(GDALRasterBase): name of the source raster will be used and appended with _copy. + source_driver_name. - In addition, the resampling algorithm can be specified with the "resampling" - input parameter. The default is NearestNeighbor. For a list of all options - consult the GDAL_RESAMPLE_ALGORITHMS constant. + In addition, the resampling algorithm can be specified with the + "resampling" input parameter. The default is NearestNeighbor. For a + list of all options consult the GDAL_RESAMPLE_ALGORITHMS constant. """ - # Get the parameters defining the geotransform, srid, and size of the raster + # Get the parameters defining the geotransform, srid, and size of the + # raster ds_input.setdefault("width", self.width) ds_input.setdefault("height", self.height) ds_input.setdefault("srid", self.srs.srid) diff --git a/django/contrib/gis/gdal/srs.py b/django/contrib/gis/gdal/srs.py index bb3176c383..cd77a1bf6c 100644 --- a/django/contrib/gis/gdal/srs.py +++ b/django/contrib/gis/gdal/srs.py @@ -44,9 +44,9 @@ class AxisOrder(IntEnum): class SpatialReference(GDALBase): """ - A wrapper for the OGRSpatialReference object. According to the GDAL web site, - the SpatialReference object "provide[s] services to represent coordinate - systems (projections and datums) and to transform between them." + A wrapper for the OGRSpatialReference object. According to the GDAL web + site, the SpatialReference object "provide[s] services to represent + coordinate systems (projections and datums) and to transform between them." """ destructor = capi.release_srs @@ -150,8 +150,8 @@ class SpatialReference(GDALBase): # #### SpatialReference Methods #### def attr_value(self, target, index=0): """ - The attribute value for the given target node (e.g. 'PROJCS'). The index - keyword specifies an index of the child node to return. + The attribute value for the given target node (e.g. 'PROJCS'). The + index keyword specifies an index of the child node to return. """ if not isinstance(target, str) or not isinstance(index, int): raise TypeError @@ -288,7 +288,9 @@ class SpatialReference(GDALBase): @property def local(self): - "Return True if this SpatialReference is local (root node is LOCAL_CS)." + """ + Return True if this SpatialReference is local (root node is LOCAL_CS). + """ return bool(capi.islocal(self.ptr)) @property diff --git a/django/contrib/gis/geos/collections.py b/django/contrib/gis/geos/collections.py index 41a647f234..8659b660b6 100644 --- a/django/contrib/gis/geos/collections.py +++ b/django/contrib/gis/geos/collections.py @@ -27,8 +27,8 @@ class GeometryCollection(GEOSGeometry): else: init_geoms = args - # Ensuring that only the permitted geometries are allowed in this collection - # this is moved to list mixin super class + # Ensuring that only the permitted geometries are allowed in this + # collection this is moved to list mixin super class self._check_allowed(init_geoms) # Creating the geometry pointer array. @@ -61,14 +61,19 @@ class GeometryCollection(GEOSGeometry): return capi.get_geomn(self.ptr, index) def _get_single_external(self, index): - "Return the Geometry from this Collection at the given index (0-based)." + """ + Return the Geometry from this Collection at the given index (0-based). + """ # Checking the index and returning the corresponding GEOS geometry. return GEOSGeometry( capi.geom_clone(self._get_single_internal(index)), srid=self.srid ) def _set_list(self, length, items): - "Create a new collection, and destroy the contents of the previous pointer." + """ + Create a new collection, and destroy the contents of the previous + pointer. + """ prev_ptr = self.ptr srid = self.srid self.ptr = self._create_collection(length, items) diff --git a/django/contrib/gis/geos/coordseq.py b/django/contrib/gis/geos/coordseq.py index a9ec4d2bf0..e54f3f2714 100644 --- a/django/contrib/gis/geos/coordseq.py +++ b/django/contrib/gis/geos/coordseq.py @@ -180,7 +180,8 @@ class GEOSCoordSeq(GEOSBase): @property def kml(self): "Return the KML representation for the coordinates." - # Getting the substitution string depending on whether the coordinates have + # Getting the substitution string depending on whether the coordinates + # have # a Z dimension. if self.hasz: substr = "%s,%s,%s " diff --git a/django/contrib/gis/geos/geometry.py b/django/contrib/gis/geos/geometry.py index cfc2d695ea..48658c4218 100644 --- a/django/contrib/gis/geos/geometry.py +++ b/django/contrib/gis/geos/geometry.py @@ -76,9 +76,10 @@ class GEOSGeometryBase(GEOSBase): def __deepcopy__(self, memodict): """ - The `deepcopy` routine is used by the `Node` class of django.utils.tree; - thus, the protocol routine needs to be implemented to return correct - copies (clones) of these GEOS objects, which use C pointers. + The `deepcopy` routine is used by the `Node` class of + django.utils.tree; thus, the protocol routine needs to be implemented + to return correct copies (clones) of these GEOS objects, which use C + pointers. """ return self.clone() @@ -343,7 +344,8 @@ class GEOSGeometryBase(GEOSBase): def overlaps(self, other): """ Return true if the DE-9IM intersection matrix for the two Geometries - is T*T***T** (for two points or two surfaces) 1*T***T** (for two curves). + is T*T***T** (for two points or two surfaces) 1*T***T** (for two + curves). """ return capi.geos_overlaps(self.ptr, other.ptr) @@ -542,9 +544,9 @@ class GEOSGeometryBase(GEOSBase): """ Return a geometry that represents all points whose distance from this Geometry is less than or equal to distance. Calculations are in the - Spatial Reference System of this Geometry. The optional third parameter sets - the number of segment used to approximate a quarter circle (defaults to 8). - (Text from PostGIS documentation at ch. 6.1.3) + Spatial Reference System of this Geometry. The optional third parameter + sets the number of segment used to approximate a quarter circle + (defaults to 8). (Text from PostGIS documentation at ch. 6.1.3) """ return self._topology(capi.geos_buffer(self.ptr, width, quadsegs)) @@ -567,9 +569,9 @@ class GEOSGeometryBase(GEOSBase): @property def centroid(self): """ - The centroid is equal to the centroid of the set of component Geometries - of highest dimension (since the lower-dimension geometries contribute zero - "weight" to the centroid). + The centroid is equal to the centroid of the set of component + Geometries of highest dimension (since the lower-dimension geometries + contribute zero "weight" to the centroid). """ return self._topology(capi.geos_centroid(self.ptr)) @@ -594,7 +596,10 @@ class GEOSGeometryBase(GEOSBase): return self._topology(capi.geos_envelope(self.ptr)) def intersection(self, other): - "Return a Geometry representing the points shared by this Geometry and other." + """ + Return a Geometry representing the points shared by this Geometry and + other. + """ return self._topology(capi.geos_intersection(self.ptr, other.ptr)) @property @@ -603,7 +608,9 @@ class GEOSGeometryBase(GEOSBase): return self._topology(capi.geos_pointonsurface(self.ptr)) def relate(self, other): - "Return the DE-9IM intersection matrix for this Geometry and the other." + """ + Return the DE-9IM intersection matrix for this Geometry and the other. + """ return capi.geos_relate(self.ptr, other.ptr).decode() def simplify(self, tolerance=0.0, preserve_topology=False): @@ -636,7 +643,10 @@ class GEOSGeometryBase(GEOSBase): return self._topology(capi.geos_unary_union(self.ptr)) def union(self, other): - "Return a Geometry representing all the points in this Geometry and other." + """ + Return a Geometry representing all the points in this Geometry and + other. + """ return self._topology(capi.geos_union(self.ptr, other.ptr)) # #### Other Routines #### diff --git a/django/contrib/gis/geos/libgeos.py b/django/contrib/gis/geos/libgeos.py index 501c28c6d3..99a4f2f94e 100644 --- a/django/contrib/gis/geos/libgeos.py +++ b/django/contrib/gis/geos/libgeos.py @@ -57,7 +57,8 @@ def load_geos(): ) # Getting the GEOS C library. The C interface (CDLL) is used for # both *NIX and Windows. - # See the GEOS C API source code for more details on the library function calls: + # See the GEOS C API source code for more details on the library function + # calls: # https://libgeos.org/doxygen/geos__c_8h_source.html _lgeos = CDLL(lib_path) # Here we set up the prototypes for the initGEOS_r and finishGEOS_r diff --git a/django/contrib/gis/geos/point.py b/django/contrib/gis/geos/point.py index a1a0a33e00..90f0793e16 100644 --- a/django/contrib/gis/geos/point.py +++ b/django/contrib/gis/geos/point.py @@ -26,7 +26,8 @@ class Point(GEOSGeometry): # Here a tuple or list was passed in under the `x` parameter. coords = x elif isinstance(x, (float, int)) and isinstance(y, (float, int)): - # Here X, Y, and (optionally) Z were passed in individually, as parameters. + # Here X, Y, and (optionally) Z were passed in individually, as + # parameters. if isinstance(z, (float, int)): coords = [x, y, z] else: diff --git a/django/contrib/gis/geos/polygon.py b/django/contrib/gis/geos/polygon.py index 554447c73f..c6b96607a9 100644 --- a/django/contrib/gis/geos/polygon.py +++ b/django/contrib/gis/geos/polygon.py @@ -69,8 +69,8 @@ class Polygon(GEOSGeometry): # ### These routines are needed for list-like operation w/ListMixin ### def _create_polygon(self, length, items): # Instantiate LinearRing objects if necessary, but don't clone them yet - # _construct_ring will throw a TypeError if a parameter isn't a valid ring - # If we cloned the pointers here, we wouldn't be able to clean up + # _construct_ring will throw a TypeError if a parameter isn't a valid + # ring If we cloned the pointers here, we wouldn't be able to clean up # in case of error. if not length: return capi.create_empty_polygon() diff --git a/django/contrib/gis/geos/prototypes/errcheck.py b/django/contrib/gis/geos/prototypes/errcheck.py index 5ee43999fa..044bf8bc5c 100644 --- a/django/contrib/gis/geos/prototypes/errcheck.py +++ b/django/contrib/gis/geos/prototypes/errcheck.py @@ -19,7 +19,9 @@ def last_arg_byref(args): def check_dbl(result, func, cargs): - "Check the status code and returns the double value passed in by reference." + """ + Check the status code and returns the double value passed in by reference. + """ # Checking the status code if result != 1: return None diff --git a/django/contrib/gis/measure.py b/django/contrib/gis/measure.py index 707c061a29..71dc130ac4 100644 --- a/django/contrib/gis/measure.py +++ b/django/contrib/gis/measure.py @@ -1,8 +1,8 @@ # Copyright (c) 2007, Robert Coup <robert.coup@onetrackmind.co.nz> # All rights reserved. # -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. @@ -11,20 +11,21 @@ # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # -# 3. Neither the name of Distance nor the names of its contributors may be used -# to endorse or promote products derived from this software without +# 3. Neither the name of Distance nor the names of its contributors may be +# used to endorse or promote products derived from this software without # specific prior written permission. # -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. # """ Distance and Area objects to allow for sensible and convenient calculation diff --git a/django/contrib/gis/utils/layermapping.py b/django/contrib/gis/utils/layermapping.py index e2bf30200e..a4cd04dc05 100644 --- a/django/contrib/gis/utils/layermapping.py +++ b/django/contrib/gis/utils/layermapping.py @@ -107,10 +107,10 @@ class LayerMapping: using=None, ): """ - A LayerMapping object is initialized using the given Model (not an instance), - a DataSource (or string path to an OGR-supported data file), and a mapping - dictionary. See the module level docstring for more details and keyword - argument usage. + A LayerMapping object is initialized using the given Model (not an + instance), a DataSource (or string path to an OGR-supported data file), + and a mapping dictionary. See the module level docstring for more + details and keyword argument usage. """ # Getting the DataSource and the associated Layer. if isinstance(data, (str, Path)): @@ -227,7 +227,8 @@ class LayerMapping: 'Given mapping field "%s" not in given Model fields.' % field_name ) - # Getting the string name for the Django field class (e.g., 'PointField'). + # Getting the string name for the Django field class (e.g., + # 'PointField'). fld_name = model_field.__class__.__name__ if isinstance(model_field, GeometryField): @@ -262,9 +263,9 @@ class LayerMapping: % (fld_name, "(dim=3)" if coord_dim == 3 else "", ltype) ) - # Setting the `geom_field` attribute w/the name of the model field - # that is a Geometry. Also setting the coordinate dimension - # attribute. + # Setting the `geom_field` attribute w/the name of the model + # field that is a Geometry. Also setting the coordinate + # dimension attribute. self.geom_field = field_name self.coord_dim = coord_dim fields_val = model_field @@ -424,7 +425,8 @@ class LayerMapping: digits = dtup[1] d_idx = dtup[2] # index where the decimal is - # Maximum amount of precision, or digits to the left of the decimal. + # Maximum amount of precision, or digits to the left of the + # decimal. max_prec = model_field.max_digits - model_field.decimal_places # Getting the digits to the left of the decimal place for the @@ -446,7 +448,8 @@ class LayerMapping: elif isinstance(ogr_field, (OFTReal, OFTString)) and isinstance( model_field, models.IntegerField ): - # Attempt to convert any OFTReal and OFTString value to an OFTInteger. + # Attempt to convert any OFTReal and OFTString value to an + # OFTInteger. try: val = int(ogr_field.value) except ValueError: @@ -533,7 +536,10 @@ class LayerMapping: ) from exc def geometry_field(self): - "Return the GeometryField instance associated with the geographic column." + """ + Return the GeometryField instance associated with the geographic + column. + """ # Use `get_field()` on the model's options so that we # get the correct field instance if there's model inheritance. opts = self.model._meta @@ -542,7 +548,8 @@ class LayerMapping: def make_multi(self, geom_type, model_field): """ Given the OGRGeomType for a geometry and its associated GeometryField, - determine whether the geometry should be turned into a GeometryCollection. + determine whether the geometry should be turned into a + GeometryCollection. """ return ( geom_type.num in self.MULTI_TYPES @@ -583,12 +590,13 @@ class LayerMapping: When this keyword is set, status information will be printed giving the number of features processed and successfully saved. By default, progress information will pe printed every 1000 features processed, - however, this default may be overridden by setting this keyword with an - integer for the desired interval. + however, this default may be overridden by setting this keyword with + an integer for the desired interval. stream: Status information will be written to this file handle. Defaults to - using `sys.stdout`, but any object with a `write` method is supported. + using `sys.stdout`, but any object with a `write` method is + supported. silent: By default, non-fatal error notifications are printed to stdout, but @@ -631,8 +639,8 @@ class LayerMapping: # Constructing the model using the keyword args is_update = False if self.unique: - # If we want unique models on a particular field, handle the - # geometry appropriately. + # If we want unique models on a particular field, + # handle the geometry appropriately. try: # Getting the keyword arguments and retrieving # the unique model. @@ -688,8 +696,8 @@ class LayerMapping: "Processed %d features, saved %d ...\n" % (num_feat, num_saved) ) - # Only used for status output purposes -- incremental saving uses the - # values returned here. + # Only used for status output purposes -- incremental saving uses + # the values returned here. return num_saved, num_feat if self.transaction_decorator is not None: @@ -708,8 +716,8 @@ class LayerMapping: n_i = len(indices) for i, end in enumerate(indices): - # Constructing the slice to use for this step; the last slice is - # special (e.g, [100:] instead of [90:100]). + # Constructing the slice to use for this step; the last slice + # is special (e.g, [100:] instead of [90:100]). if i + 1 == n_i: step_slice = slice(beg, None) else: diff --git a/django/contrib/gis/utils/ogrinspect.py b/django/contrib/gis/utils/ogrinspect.py index 63353690d9..96f58c9ff1 100644 --- a/django/contrib/gis/utils/ogrinspect.py +++ b/django/contrib/gis/utils/ogrinspect.py @@ -141,8 +141,9 @@ def _ogrinspect( null=False, ): """ - Helper routine for `ogrinspect` that generates GeoDjango models corresponding - to the given data source. See the `ogrinspect` docstring for more details. + Helper routine for `ogrinspect` that generates GeoDjango models + corresponding to the given data source. See the `ogrinspect` docstring for + more details. """ # Getting the DataSource if isinstance(data_source, str): |
