[Tile-serving] [openstreetmap/osm2pgsql] Use PostGIS to make sure geometries are valid (#790)
Sarah Hoffmann
notifications at github.com
Sun Oct 1 21:26:08 UTC 2017
lonvia commented on this pull request.
> @@ -218,7 +218,32 @@ void table_t::stop()
fprintf(stderr, "Sorting data and creating indexes for %s\n", name.c_str());
- pgsql_exec_simple(sql_conn, PGRES_COMMAND_OK, (fmt("CREATE TABLE %1%_tmp %2% AS SELECT * FROM %1% ORDER BY ST_GeoHash(ST_Transform(ST_Envelope(way),4326),10) COLLATE \"C\"") % name % (table_space ? "TABLESPACE " + table_space.get() : "")).str());
+ if (srid == "4326") {
+ /* libosmium assures validity of geoometries in 4326, so the WHERE can be skipped.
typo: geoometries
> @@ -235,6 +260,30 @@ void table_t::stop()
fprintf(stderr, "Creating osm_id index on %s\n", name.c_str());
pgsql_exec_simple(sql_conn, PGRES_COMMAND_OK, (fmt("CREATE INDEX %1%_pkey ON %1% USING BTREE (osm_id) %2%") % name %
(table_space_index ? "TABLESPACE " + table_space_index.get() : "")).str());
+ if (srid != "4326") {
+ pgsql_exec_simple(
+ sql_conn, PGRES_COMMAND_OK,
+ (fmt("CREATE OR REPLACE FUNCTION %1%_valid()\n"
I would choose a longer name here, so that it is less likely to clash with any names chosen by the user.
> + " IF ST_IsValid(NEW.way) THEN \n"
+ " RETURN NEW;\n"
+ " END IF;\n"
+ " RETURN NULL;\n"
+ "END;"
+ "$$ LANGUAGE plpgsql;") %
+ name)
+ .str());
+
+ pgsql_exec_simple(
+ sql_conn, PGRES_COMMAND_OK,
+ (fmt("CREATE TRIGGER %1%_valid BEFORE INSERT OR UPDATE\n"
+ " ON %1%\n"
+ " FOR EACH ROW EXECUTE PROCEDURE %1%_valid();") %
+ name)
+ .str());
What about removing the trigger again?
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/osm2pgsql/pull/790#pullrequestreview-66347362
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/tile-serving/attachments/20171001/417ec6ef/attachment.html>
More information about the Tile-serving
mailing list