optimisation INSERT geo
This commit is contained in:
parent
071005528f
commit
ee082a91de
1 changed files with 3 additions and 4 deletions
|
@ -112,10 +112,9 @@ class EventsResource(BaseEvent):
|
||||||
class EventResource(BaseEvent):
|
class EventResource(BaseEvent):
|
||||||
def maybe_insert_geometry(self, geometry, cur):
|
def maybe_insert_geometry(self, geometry, cur):
|
||||||
# insert into geo table if not existing
|
# insert into geo table if not existing
|
||||||
cur.execute("""INSERT INTO geo (hash, geom, geom_center)
|
cur.execute("""INSERT INTO geo
|
||||||
SELECT *, st_centroid(geom) FROM
|
SELECT geom, md5(st_asewkt(geom)) as hash, st_centroid(geom) as geom_center FROM
|
||||||
(SELECT md5(ewkt) as hash, st_setsrid(st_geomfromewkt(ewkt),4326) as geom FROM
|
(SELECT st_setsrid(st_geomfromgeojson( %s ),4326) as geom) as g
|
||||||
(SELECT st_asewkt(st_geomfromgeojson( %s )) as ewkt) as g) as i
|
|
||||||
WHERE ST_IsValid(geom)
|
WHERE ST_IsValid(geom)
|
||||||
ON CONFLICT DO NOTHING RETURNING hash;""",
|
ON CONFLICT DO NOTHING RETURNING hash;""",
|
||||||
(geometry,))
|
(geometry,))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue