diff --git a/django/contrib/gis/geos/geometry.py b/django/contrib/gis/geos/geometry.py index 744d89275f..99e680e492 100644 --- a/django/contrib/gis/geos/geometry.py +++ b/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): diff --git a/docs/ref/contrib/gis/geoip2.txt b/docs/ref/contrib/gis/geoip2.txt index cbcba9fac9..0f9a51f69a 100644 --- a/docs/ref/contrib/gis/geoip2.txt +++ b/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 ================== diff --git a/docs/ref/contrib/gis/geos.txt b/docs/ref/contrib/gis/geos.txt index 5397fd7a52..11c1a8dcd3 100644 --- a/docs/ref/contrib/gis/geos.txt +++ b/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 diff --git a/docs/releases/1.10.txt b/docs/releases/1.10.txt index 37f7f65b80..aed1ab7c83 100644 --- a/docs/releases/1.10.txt +++ b/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 ```` 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. diff --git a/tests/gis_tests/data/geometries.json b/tests/gis_tests/data/geometries.json index c2b9e4f27e..b33f87b010 100644 --- a/tests/gis_tests/data/geometries.json +++ b/tests/gis_tests/data/geometries.json @@ -19,14 +19,14 @@ {"wkt": "", "bad": true, "hex": false} ], "wkt_out": [ - {"wkt": "POINT (110 130)", "ewkt": "POINT (110.0000000000000000 130.0000000000000000)", "kml": "110.0,130.0,0", "gml": "110,130"}, - {"wkt": "POINT (110 130 85)", "ewkt": "POINT Z (110.0000000000000000 130.0000000000000000 85.0000000000000000)", "kml": "110.0,130.0,85.0", "gml": "110,130,85"}, - {"wkt": "LINESTRING (40 40,50 130,130 130)", "ewkt": "LINESTRING (40.0000000000000000 40.0000000000000000, 50.0000000000000000 130.0000000000000000, 130.0000000000000000 130.0000000000000000)", "kml": "40.0,40.0,0 50.0,130.0,0 130.0,130.0,0", "gml": "40,40 50,130 130,130"}, - {"wkt": "POLYGON ((150 150,410 150,280 20,20 20,150 150),(170 120,330 120,260 50,100 50,170 120))", "ewkt": "POLYGON ((150.0000000000000000 150.0000000000000000, 410.0000000000000000 150.0000000000000000, 280.0000000000000000 20.0000000000000000, 20.0000000000000000 20.0000000000000000, 150.0000000000000000 150.0000000000000000), (170.0000000000000000 120.0000000000000000, 330.0000000000000000 120.0000000000000000, 260.0000000000000000 50.0000000000000000, 100.0000000000000000 50.0000000000000000, 170.0000000000000000 120.0000000000000000))", "kml": "150.0,150.0,0 410.0,150.0,0 280.0,20.0,0 20.0,20.0,0 150.0,150.0,0170.0,120.0,0 330.0,120.0,0 260.0,50.0,0 100.0,50.0,0 170.0,120.0,0", "gml": "150,150 410,150 280,20 20,20 150,150170,120 330,120 260,50 100,50 170,120"}, - {"wkt": "MULTIPOINT (10 80,110 170,110 120)", "ewkt": "MULTIPOINT (10.0000000000000000 80.0000000000000000, 110.0000000000000000 170.0000000000000000, 110.0000000000000000 120.0000000000000000)", "kml": "10.0,80.0,0110.0,170.0,0110.0,120.0,0", "gml": "10,80110,170110,120"}, - {"wkt": "MULTILINESTRING ((110 100,40 30,180 30),(170 30,110 90,50 30))", "ewkt": "MULTILINESTRING ((110.0000000000000000 100.0000000000000000, 40.0000000000000000 30.0000000000000000, 180.0000000000000000 30.0000000000000000), (170.0000000000000000 30.0000000000000000, 110.0000000000000000 90.0000000000000000, 50.0000000000000000 30.0000000000000000))", "kml": "110.0,100.0,0 40.0,30.0,0 180.0,30.0,0170.0,30.0,0 110.0,90.0,0 50.0,30.0,0", "gml": "110,100 40,30 180,30170,30 110,90 50,30"}, - {"wkt": "MULTIPOLYGON (((110 110,70 200,150 200,110 110),(110 110,100 180,120 180,110 110)),((110 110,150 20,70 20,110 110),(110 110,120 40,100 40,110 110)))", "ewkt": "MULTIPOLYGON (((110.0000000000000000 110.0000000000000000, 70.0000000000000000 200.0000000000000000, 150.0000000000000000 200.0000000000000000, 110.0000000000000000 110.0000000000000000), (110.0000000000000000 110.0000000000000000, 100.0000000000000000 180.0000000000000000, 120.0000000000000000 180.0000000000000000, 110.0000000000000000 110.0000000000000000)), ((110.0000000000000000 110.0000000000000000, 150.0000000000000000 20.0000000000000000, 70.0000000000000000 20.0000000000000000, 110.0000000000000000 110.0000000000000000), (110.0000000000000000 110.0000000000000000, 120.0000000000000000 40.0000000000000000, 100.0000000000000000 40.0000000000000000, 110.0000000000000000 110.0000000000000000)))", "kml": "110.0,110.0,0 70.0,200.0,0 150.0,200.0,0 110.0,110.0,0110.0,110.0,0 100.0,180.0,0 120.0,180.0,0 110.0,110.0,0110.0,110.0,0 150.0,20.0,0 70.0,20.0,0 110.0,110.0,0110.0,110.0,0 120.0,40.0,0 100.0,40.0,0 110.0,110.0,0", "gml": "110,110 70,200 150,200 110,110110,110 100,180 120,180 110,110110,110 150,20 70,20 110,110110,110 120,40 100,40 110,110"}, - {"wkt": "GEOMETRYCOLLECTION (POINT (110 260),LINESTRING (110 0,110 60))", "ewkt": "GEOMETRYCOLLECTION (POINT (110.0000000000000000 260.0000000000000000), LINESTRING (110.0000000000000000 0.0000000000000000, 110.0000000000000000 60.0000000000000000))", "kml": "110.0,260.0,0110.0,0.0,0 110.0,60.0,0", "gml": "110,260110,0 110,60"} + {"wkt": "POINT (110 130)", "ewkt": "POINT (110 130)", "kml": "110.0,130.0,0", "gml": "110,130"}, + {"wkt": "POINT (110 130 85)", "ewkt": "POINT Z (110 130 85)", "kml": "110.0,130.0,85.0", "gml": "110,130,85"}, + {"wkt": "LINESTRING (40 40,50 130,130 130)", "ewkt": "LINESTRING (40 40, 50 130, 130 130)", "kml": "40.0,40.0,0 50.0,130.0,0 130.0,130.0,0", "gml": "40,40 50,130 130,130"}, + {"wkt": "POLYGON ((150 150,410 150,280 20,20 20,150 150),(170 120,330 120,260 50,100 50,170 120))", "ewkt": "POLYGON ((150 150, 410 150, 280 20, 20 20, 150 150), (170 120, 330 120, 260 50, 100 50, 170 120))", "kml": "150.0,150.0,0 410.0,150.0,0 280.0,20.0,0 20.0,20.0,0 150.0,150.0,0170.0,120.0,0 330.0,120.0,0 260.0,50.0,0 100.0,50.0,0 170.0,120.0,0", "gml": "150,150 410,150 280,20 20,20 150,150170,120 330,120 260,50 100,50 170,120"}, + {"wkt": "MULTIPOINT (10 80,110 170,110 120)", "ewkt": "MULTIPOINT (10 80, 110 170, 110 120)", "kml": "10.0,80.0,0110.0,170.0,0110.0,120.0,0", "gml": "10,80110,170110,120"}, + {"wkt": "MULTILINESTRING ((110 100,40 30,180 30),(170 30,110 90,50 30))", "ewkt": "MULTILINESTRING ((110 100, 40 30, 180 30), (170 30, 110 90, 50 30))", "kml": "110.0,100.0,0 40.0,30.0,0 180.0,30.0,0170.0,30.0,0 110.0,90.0,0 50.0,30.0,0", "gml": "110,100 40,30 180,30170,30 110,90 50,30"}, + {"wkt": "MULTIPOLYGON (((110 110,70 200,150 200,110 110),(110 110,100 180,120 180,110 110)),((110 110,150 20,70 20,110 110),(110 110,120 40,100 40,110 110)))", "ewkt": "MULTIPOLYGON (((110 110, 70 200, 150 200, 110 110), (110 110, 100 180, 120 180, 110 110)), ((110 110, 150 20, 70 20, 110 110), (110 110, 120 40, 100 40, 110 110)))", "kml": "110.0,110.0,0 70.0,200.0,0 150.0,200.0,0 110.0,110.0,0110.0,110.0,0 100.0,180.0,0 120.0,180.0,0 110.0,110.0,0110.0,110.0,0 150.0,20.0,0 70.0,20.0,0 110.0,110.0,0110.0,110.0,0 120.0,40.0,0 100.0,40.0,0 110.0,110.0,0", "gml": "110,110 70,200 150,200 110,110110,110 100,180 120,180 110,110110,110 150,20 70,20 110,110110,110 120,40 100,40 110,110"}, + {"wkt": "GEOMETRYCOLLECTION (POINT (110 260),LINESTRING (110 0,110 60))", "ewkt": "GEOMETRYCOLLECTION (POINT (110 260), LINESTRING (110 0, 110 60))", "kml": "110.0,260.0,0110.0,0.0,0 110.0,60.0,0", "gml": "110,260110,0 110,60"} ], "hex_wkt": [ {"wkt": "POINT(0 1)", "hex": "01010000000000000000000000000000000000F03F"}, diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py index ef03736f9e..6c32835237 100644 --- a/tests/gis_tests/geos_tests/test_geos.py +++ b/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)