1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

[3.2.x] Corrected outputs and made cosmetic edits in GeoDjango tutorial.

Backport of b5bf026813ca9aff83243f901edd722e0d60c2ea from main
This commit is contained in:
Mariusz Felisiak 2021-09-15 09:15:39 +02:00
parent b51e0a37cf
commit 454ee4d3b8

View File

@ -78,9 +78,9 @@ file. Edit the database connection settings to match your setup::
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis', 'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'geodjango', 'NAME': 'geodjango',
'USER': 'geo', 'USER': 'geo',
}, },
} }
@ -258,7 +258,7 @@ This command should produce the following output:
-- Create model WorldBorder -- Create model WorldBorder
-- --
CREATE TABLE "world_worldborder" ( CREATE TABLE "world_worldborder" (
"id" serial NOT NULL PRIMARY KEY, "id" bigserial NOT NULL PRIMARY KEY,
"name" varchar(50) NOT NULL, "name" varchar(50) NOT NULL,
"area" integer NOT NULL, "area" integer NOT NULL,
"pop2005" integer NOT NULL, "pop2005" integer NOT NULL,
@ -273,7 +273,7 @@ This command should produce the following output:
"mpoly" geometry(MULTIPOLYGON,4326) NOT NULL "mpoly" geometry(MULTIPOLYGON,4326) NOT NULL
) )
; ;
CREATE INDEX "world_worldborder_mpoly_id" ON "world_worldborder" USING GIST ( "mpoly" ); CREATE INDEX "world_worldborder_mpoly_id" ON "world_worldborder" USING GIST ("mpoly");
COMMIT; COMMIT;
If this looks correct, run :djadmin:`migrate` to create this table in the If this looks correct, run :djadmin:`migrate` to create this table in the
@ -367,13 +367,20 @@ system associated with it. If it does, the ``srs`` attribute will return a
>>> srs = lyr.srs >>> srs = lyr.srs
>>> print(srs) >>> print(srs)
GEOGCS["GCS_WGS_1984", GEOGCS["WGS 84",
DATUM["WGS_1984", DATUM["WGS_1984",
SPHEROID["WGS_1984",6378137.0,298.257223563]], SPHEROID["WGS 84",6378137,298.257223563,
PRIMEM["Greenwich",0.0], AUTHORITY["EPSG","7030"]],
UNIT["Degree",0.0174532925199433]] AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AXIS["Latitude",NORTH],
AXIS["Longitude",EAST],
AUTHORITY["EPSG","4326"]]
>>> srs.proj # PROJ representation >>> srs.proj # PROJ representation
'+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ' '+proj=longlat +datum=WGS84 +no_defs'
This shapefile is in the popular WGS84 spatial reference This shapefile is in the popular WGS84 spatial reference
system -- in other words, the data uses longitude, latitude pairs in system -- in other words, the data uses longitude, latitude pairs in
@ -389,7 +396,7 @@ The following code will let you examine the OGR types (e.g. integer or
string) associated with each of the fields: string) associated with each of the fields:
>>> [fld.__name__ for fld in lyr.field_types] >>> [fld.__name__ for fld in lyr.field_types]
['OFTString', 'OFTString', 'OFTString', 'OFTInteger', 'OFTString', 'OFTInteger', 'OFTInteger', 'OFTInteger', 'OFTInteger', 'OFTReal', 'OFTReal'] ['OFTString', 'OFTString', 'OFTString', 'OFTInteger', 'OFTString', 'OFTInteger', 'OFTInteger64', 'OFTInteger', 'OFTInteger', 'OFTReal', 'OFTReal']
You can iterate over each feature in the layer and extract information from both You can iterate over each feature in the layer and extract information from both
the feature's geometry (accessed via the ``geom`` attribute) as well as the the feature's geometry (accessed via the ``geom`` attribute) as well as the
@ -423,11 +430,10 @@ Boundary geometries may be exported as WKT and GeoJSON::
>>> print(geom.json) >>> print(geom.json)
{ "type": "Polygon", "coordinates": [ [ [ 12.415798, 43.957954 ], [ 12.450554, 43.979721 ], ... { "type": "Polygon", "coordinates": [ [ [ 12.415798, 43.957954 ], [ 12.450554, 43.979721 ], ...
``LayerMapping`` ``LayerMapping``
---------------- ----------------
To import the data, use a LayerMapping in a Python script. To import the data, use a ``LayerMapping`` in a Python script.
Create a file called ``load.py`` inside the ``world`` application, Create a file called ``load.py`` inside the ``world`` application,
with the following code:: with the following code::
@ -685,7 +691,6 @@ GeoDjango also offers a set of geographic annotations to compute distances and
several other operations (intersection, difference, etc.). See the several other operations (intersection, difference, etc.). See the
:doc:`functions` documentation. :doc:`functions` documentation.
Putting your data on the map Putting your data on the map
============================ ============================