Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
35e649b1
Kaydet (Commit)
35e649b1
authored
Eyl 17, 2016
tarafından
Claude Paroz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Simplified PostGIS index creation
Less special-casing and code more in line with 'normal' index creation.
üst
9715b99f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
55 deletions
+27
-55
schema.py
django/contrib/gis/db/backends/postgis/schema.py
+27
-55
No files found.
django/contrib/gis/db/backends/postgis/schema.py
Dosyayı görüntüle @
35e649b1
...
...
@@ -6,61 +6,33 @@ class PostGISSchemaEditor(DatabaseSchemaEditor):
geom_index_ops_nd
=
'GIST_GEOMETRY_OPS_ND'
rast_index_wrapper
=
'ST_ConvexHull(
%
s)'
sql_add_spatial_index
=
"CREATE INDEX
%(index)
s ON
%(table)
s USING
%(index_type)
s (
%(column)
s
%(ops)
s)"
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
PostGISSchemaEditor
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
geometry_sql
=
[]
def
geo_quote_name
(
self
,
name
):
return
self
.
connection
.
ops
.
geo_quote_name
(
name
)
def
column_sql
(
self
,
model
,
field
,
include_default
=
False
):
from
django.contrib.gis.db.models.fields
import
BaseSpatialField
if
not
isinstance
(
field
,
BaseSpatialField
):
return
super
(
PostGISSchemaEditor
,
self
)
.
column_sql
(
model
,
field
,
include_default
)
column_sql
=
super
(
PostGISSchemaEditor
,
self
)
.
column_sql
(
model
,
field
,
include_default
)
if
field
.
spatial_index
:
# Spatial indexes created the same way for both Geometry and
# Geography columns.
field_column
=
self
.
quote_name
(
field
.
column
)
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.
field_column
=
self
.
rast_index_wrapper
%
field_column
index_ops
=
''
elif
field
.
geography
:
index_ops
=
''
else
:
# Use either "nd" ops which are fast on multidimensional cases
# or just plain gist index for the 2d case.
if
field
.
dim
>
2
:
index_ops
=
self
.
geom_index_ops_nd
else
:
index_ops
=
''
self
.
geometry_sql
.
append
(
self
.
sql_add_spatial_index
%
{
"index"
:
self
.
quote_name
(
'
%
s_
%
s_id'
%
(
model
.
_meta
.
db_table
,
field
.
column
)),
"table"
:
self
.
quote_name
(
model
.
_meta
.
db_table
),
"column"
:
field_column
,
"index_type"
:
self
.
geom_index_type
,
"ops"
:
index_ops
,
}
)
return
column_sql
def
create_model
(
self
,
model
):
super
(
PostGISSchemaEditor
,
self
)
.
create_model
(
model
)
# Create geometry columns
for
sql
in
self
.
geometry_sql
:
self
.
execute
(
sql
)
self
.
geometry_sql
=
[]
def
add_field
(
self
,
model
,
field
):
super
(
PostGISSchemaEditor
,
self
)
.
add_field
(
model
,
field
)
# Create geometry columns
for
sql
in
self
.
geometry_sql
:
self
.
execute
(
sql
)
self
.
geometry_sql
=
[]
def
_field_should_be_indexed
(
self
,
model
,
field
):
if
getattr
(
field
,
'spatial_index'
,
False
):
return
True
return
super
(
PostGISSchemaEditor
,
self
)
.
_field_should_be_indexed
(
model
,
field
)
def
_create_index_sql
(
self
,
model
,
fields
,
suffix
=
""
,
sql
=
None
):
if
len
(
fields
)
!=
1
or
not
hasattr
(
fields
[
0
],
'geodetic'
):
return
super
(
PostGISSchemaEditor
,
self
)
.
_create_index_sql
(
model
,
fields
,
suffix
=
suffix
,
sql
=
sql
)
field
=
fields
[
0
]
field_column
=
self
.
quote_name
(
field
.
column
)
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.
field_column
=
self
.
rast_index_wrapper
%
field_column
elif
field
.
dim
>
2
and
not
field
.
geography
:
# Use "nd" ops which are fast on multidimensional cases
field_column
=
"
%
s
%
s"
%
(
field_column
,
self
.
geom_index_ops_nd
)
return
self
.
sql_create_index
%
{
"name"
:
self
.
quote_name
(
'
%
s_
%
s_id'
%
(
model
.
_meta
.
db_table
,
field
.
column
)),
"table"
:
self
.
quote_name
(
model
.
_meta
.
db_table
),
"using"
:
"USING
%
s"
%
self
.
geom_index_type
,
"columns"
:
field_column
,
"extra"
:
''
,
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment