Skip to content

Commit 1c160f8

Browse files
authored
Merge branch 'master' into boolfix
2 parents c8684db + 5fe92dd commit 1c160f8

File tree

5 files changed

+31
-32
lines changed

5 files changed

+31
-32
lines changed

tifeatures/dbmodel.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,24 +131,28 @@ async def get_table_index(
131131
query = """
132132
WITH t AS (
133133
SELECT
134-
schemaname,
135-
tablename,
136-
format('%I.%I', schemaname, tablename) as id,
137-
format('%I.%I', schemaname, tablename)::regclass as t_oid,
138-
obj_description(format('%I.%I', schemaname, tablename)::regclass, 'pg_class') as description,
134+
nspname as schemaname,
135+
relname as tablename,
136+
format('%I.%I', nspname, relname) as id,
137+
c.oid as t_oid,
138+
obj_description(c.oid, 'pg_class') as description,
139139
(
140140
SELECT
141141
attname
142142
FROM
143+
pg_attribute a
144+
LEFT JOIN
143145
pg_index i
144-
JOIN pg_attribute a ON
146+
ON (
145147
a.attrelid = i.indrelid
146148
AND a.attnum = ANY(i.indkey)
149+
)
147150
WHERE
148-
i.indrelid = format('%I.%I', schemaname, tablename)::regclass
149-
AND
150-
(i.indisunique OR i.indisprimary)
151-
ORDER BY i.indisprimary
151+
a.attrelid = c.oid
152+
ORDER BY
153+
i.indisprimary DESC NULLS LAST,
154+
i.indisunique DESC NULLS LAST,
155+
attname ~* E'id$' DESC NULLS LAST
152156
LIMIT 1
153157
) as pk,
154158
(
@@ -164,7 +168,7 @@ async def get_table_index(
164168
pg_attribute
165169
WHERE
166170
attnum>0
167-
AND attrelid=format('%I.%I', schemaname, tablename)::regclass
171+
AND attrelid=c.oid
168172
) as columns,
169173
(
170174
SELECT
@@ -210,16 +214,18 @@ async def get_table_index(
210214
FROM geography_columns
211215
) as geo
212216
WHERE
213-
f_table_schema = schemaname
214-
AND f_table_name = tablename
217+
f_table_schema = n.nspname
218+
AND f_table_name = c.relname
215219
) as geometry_columns
216220
FROM
217-
pg_tables
221+
pg_class c
222+
JOIN pg_namespace n ON (c.relnamespace=n.oid)
218223
WHERE
219-
schemaname NOT IN ('pg_catalog', 'information_schema')
220-
AND tablename NOT IN ('spatial_ref_sys','geometry_columns')
221-
AND (:schemas::text[] IS NULL OR schemaname = ANY (:schemas))
222-
AND (:tables::text[] IS NULL OR tablename = ANY (:tables))
224+
relkind in ('r','v', 'm', 'f', 'p')
225+
AND n.nspname NOT IN ('pg_catalog', 'information_schema')
226+
AND c.relname NOT IN ('spatial_ref_sys','geometry_columns')
227+
AND (:schemas::text[] IS NULL OR n.nspname = ANY (:schemas))
228+
AND (:tables::text[] IS NULL OR c.relname = ANY (:tables))
223229
224230
)
225231
SELECT

tifeatures/filter/filters.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ def attribute(name: str, fields: List[str]):
279279
elif name.lower() == "false":
280280
return False
281281
else:
282-
print(name, fields)
283282
raise TypeError(f"Field {name} not in table.")
284283

285284

tifeatures/layer.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,26 +131,21 @@ def _geom(
131131
return pg_funcs.cast(None, "json")
132132

133133
g = logic.V(geometry_column.name)
134+
g = pg_funcs.cast(g, "geometry")
135+
136+
if geometry_column.srid == 4326:
137+
g = logic.Func("ST_Transform", g, pg_funcs.cast(4326, "int"))
134138

135139
if bbox_only:
136140
g = logic.Func("ST_Envelope", g)
137-
138141
elif simplify:
139142
g = logic.Func(
140143
"ST_SnapToGrid",
141144
logic.Func("ST_Simplify", g, simplify),
142145
simplify,
143146
)
144147

145-
if geometry_column.srid == 4326:
146-
g = logic.Func("ST_AsGeoJson", g)
147-
148-
else:
149-
g = logic.Func(
150-
"ST_Transform",
151-
logic.Func("ST_AsGeoJson", g),
152-
4326,
153-
)
148+
g = logic.Func("ST_AsGeoJson", g)
154149

155150
return g
156151

@@ -398,7 +393,6 @@ async def query(
398393
),
399394
geom_columns=[g.name for g in self.geometry_columns],
400395
)
401-
402396
async with pool.acquire() as conn:
403397
items = await conn.fetchval(q, *p)
404398

tifeatures/templates/item.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ <h2>Properties</h2>
3131
</div>
3232

3333
<script>
34-
var geojson = {{ response|safe }};
34+
var geojson = {{ response|tojson }};
3535
var map = L.map('map').setView([0, 0], 1);
3636
map.addLayer(new L.TileLayer(
3737
'https://tile.openstreetmap.org/{z}/{x}/{y}.png', {

tifeatures/templates/items.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ <h1>Collection Items: {{ response.title or response.id }}</h1>
8080
//
8181
// mapping
8282
//
83-
var geojson = {{ response|safe }};
83+
var geojson = {{ response|tojson }};
8484
var map = L.map('map').setView([0, 0], 1);
8585
map.addLayer(new L.TileLayer(
8686
'https://tile.openstreetmap.org/{z}/{x}/{y}.png', {

0 commit comments

Comments
 (0)