[postgis-users] st_union produces different result from st_memunion

Martin Davis mtnclimb at gmail.com
Thu Jul 9 11:58:53 PDT 2020


Following up on my suggestion that the source data from JtsOp can be read
out of the DB, and the output data copied back into it, here's an example
of how to do this.  For clarity this is shown on multiple lines, but it
needs to be run as a single command line.  Also, as a bonus and to show the
capability of JtsOp, the output of the overlay is polygonized before being
written back to the DB.  (The non-standard syntax for POLYGON EMPTY is to
work around a small bug in JtsOp - going to fix that soon).

psql -qtA -c "SELECT * FROM ov_test_lines;"
| <JTS_HOME>/bin/jtsop.sh -a stdin -b "POLYGON (EMPTY)" -f wkb -explode
OverlayNG.union 100000000
| <JTS_HOME>/bin/jtsop.sh -a stdin -f wkb -explode Polygonize.polygonize
| psql -c "\copy ov_test_poly FROM stdin"

This expects a table "ov_test_poly" to exist with the following definition:

CREATE TABLE public.ov_test_poly (
    geom geometry(Polygon, 4326)
);


On Thu, Jul 9, 2020 at 9:07 AM Martin Davis <mtnclimb at gmail.com> wrote:

> Good that it's working for you too.
>
> Glad you asked about scripting.  I was just going to post about a good
> option for doing this in a scripted way.  This uses the new JTS CLI [1][2].
> (Note you will need to pull the latest overly-sr branch and rebuild, since
> the -explode option is newly added as of yesterday)
>
> Here's a JtsOp command to run OverlayNG on the full dataset from a WKB
> file, saving the result to a file:
>
> <JTS HOME>/bin/jtsop.sh -a dbca_dump_116_35_117_34.wkb -b "POLYGON
> (EMPTY)" -f wkb -explode OverlayNG.union 100000000 > out.wkb
>
> Alternatively the input could be sourced from a psql command-line query
> extracting the WKB from the DB.  That can be piped to the JtsOP command,
> using the option "-a stdin".
>
> And it may be possible to pipe the JtsOp WKB output back into the DB,
> perhaps by wrapping it with a SQL header and footer containing a COPY
> command?
>
> If you get this working it would be nice to see the toolchain.
>
> As for getting this into PostGIS, that is definitely the plan, and is
> being worked on right now.  Hopefully to ship by Q4 2020.
>
> [1] https://github.com/locationtech/jts/blob/master/doc/JTSOp.md
> [2] http://lin-ear-th-inking.blogspot.com/2019/08/a-cli-for-jts.html
>
> On Thu, Jul 9, 2020 at 1:15 AM Jonathan Schultz <jonathan at schultz.la>
> wrote:
>
>> It seems to work OK for me too. I managed to export the result using the
>> 'Save as XML' function, which is a bit painful but does the job. Can you
>> suggest how difficult it would be to script the procedure?
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20200709/3c552ab0/attachment.html>


More information about the postgis-users mailing list