瀏覽代碼

Fixed #25951 -- Trimmed default representation of GEOSGeometry

Thanks Sergey Fedoseev for the report.
Claude Paroz 9 年之前
父節點
當前提交
9686c888d6

+ 1 - 1
django/contrib/gis/geos/geometry.py

@@ -408,7 +408,7 @@ class GEOSGeometry(GEOSBase, ListMixin):
     @property
     def wkt(self):
         "Returns the WKT (Well-Known Text) representation of this Geometry."
-        return wkt_w(dim=3 if self.hasz else 2).write(self).decode()
+        return wkt_w(dim=3 if self.hasz else 2, trim=True).write(self).decode()
 
     @property
     def hex(self):

+ 1 - 1
docs/ref/contrib/gis/geoip2.txt

@@ -47,7 +47,7 @@ Here is an example of its usage::
     >>> g.lon_lat('uh.edu')
     (-95.4342, 29.834)
     >>> g.geos('24.124.1.80').wkt
-    'POINT (-97.0000000000000000 38.0000000000000000)'
+    'POINT (-97 38)'
 
 ``GeoIP`` Settings
 ==================

+ 7 - 3
docs/ref/contrib/gis/geos.txt

@@ -69,11 +69,11 @@ All these constructors take the keyword argument ``srid``. For example::
 
     >>> from django.contrib.gis.geos import GEOSGeometry, LineString, Point
     >>> print(GEOSGeometry('POINT (0 0)', srid=4326))
-    SRID=4326;POINT (0.0000000000000000 0.0000000000000000)
+    SRID=4326;POINT (0 0)
     >>> print(LineString((0, 0), (1, 1), srid=4326))
-    SRID=4326;LINESTRING (0.0000000000000000 0.0000000000000000, 1.0000000000000000 1.0000000000000000)
+    SRID=4326;LINESTRING (0 0, 1 1)
     >>> print(Point(0, 0, srid=32140))
-    SRID=32140;POINT (0.0000000000000000 0.0000000000000000)
+    SRID=32140;POINT (0 0)
 
 Finally, there is the :func:`fromfile` factory method which returns a
 :class:`GEOSGeometry` object from a file::
@@ -369,6 +369,10 @@ another object.
 
     Returns the Well-Known Text of the geometry (an OGC standard).
 
+    .. versionchanged:: 1.10
+
+        Non-significant zeros are stripped from the output.
+
 __ https://developers.google.com/kml/documentation/
 
 Spatial Predicate Methods

+ 17 - 9
docs/releases/1.10.txt

@@ -654,14 +654,29 @@ You can check if your database has any of the removed hashers like this::
     # Unsalted MD5 passwords might not have an 'md5$$' prefix:
     User.objects.filter(password__length=32)
 
+:mod:`django.contrib.gis`
+-------------------------
+
+* Support for SpatiaLite < 3.0 and GEOS < 3.3 is dropped.
+
+* The ``add_postgis_srs()`` backwards compatibility alias for
+  ``django.contrib.gis.utils.add_srs_entry()`` is removed.
+
+* On Oracle/GIS, the :class:`~django.contrib.gis.db.models.functions.Area`
+  aggregate function now returns a ``float`` instead of ``decimal.Decimal``.
+  (It's still wrapped in a measure of square meters.)
+
+* The default :class:`~django.contrib.gis.geos.GEOSGeometry` representation (WKT
+  output) is trimmed by default. That is, instead of
+  ``POINT (23.0000000000000000 5.5000000000000000)``, you'll get
+  ``POINT (23 5.5)``.
+
 Miscellaneous
 -------------
 
 * The ``repr()`` of a ``QuerySet`` is wrapped in ``<QuerySet >`` to
   disambiguate it from a plain list when debugging.
 
-* Support for SpatiaLite < 3.0 and GEOS < 3.3 is dropped.
-
 * ``utils.version.get_version()`` returns :pep:`440` compliant release
   candidate versions (e.g. '1.10rc1' instead of '1.10c1').
 
@@ -669,9 +684,6 @@ Miscellaneous
   since pre-1.0. If you use it in your project, you can add it to your
   project's settings. The default value was ``'/accounts/logout/'``.
 
-* The ``add_postgis_srs()`` backwards compatibility alias for
-  ``django.contrib.gis.utils.add_srs_entry()`` is removed.
-
 * Objects with a ``close()`` method such as files and generators passed to
   :class:`~django.http.HttpResponse` are now closed immediately instead of when
   the WSGI server calls ``close()`` on the response.
@@ -698,10 +710,6 @@ Miscellaneous
   argument of the ``render_options()`` method is also removed, making
   ``selected_choices`` the first argument.
 
-* On Oracle/GIS, the :class:`~django.contrib.gis.db.models.functions.Area`
-  aggregate function now returns a ``float`` instead of ``decimal.Decimal``.
-  (It's still wrapped in a measure of square meters.)
-
 * Tests that violate deferrable database constraints will now error when run on
   a database that supports deferrable constraints.
 

File diff suppressed because it is too large
+ 0 - 6
tests/gis_tests/data/geometries.json


+ 1 - 1
tests/gis_tests/geos_tests/test_geos.py

@@ -737,7 +737,7 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
         """Test with a null srid and a srid unknown to GDAL."""
         for srid in [None, 999999]:
             pnt = Point(111200, 220900, srid=srid)
-            self.assertTrue(pnt.ewkt.startswith(("SRID=%s;" % srid if srid else '') + "POINT (111200.0"))
+            self.assertTrue(pnt.ewkt.startswith(("SRID=%s;" % srid if srid else '') + "POINT (111200"))
             self.assertIsInstance(pnt.ogr, gdal.OGRGeometry)
             self.assertIsNone(pnt.srs)
 

Some files were not shown because too many files changed in this diff