2

I am working on a research project. I have two tables, one of a polygon that represents a severe weather risk area, one that represents the US. I want to merge them into one output polygon. I am stuck with the syntax of how to do this.

spc is the table of the risk area, simple_us is the us. I want to output the union of these two table into the geometry column of a new table called spc_clip.

My current command is:

INSERT INTO spc_clip (geom) VALUES (ST_Union(a.geom, b.geom)), spc as a, simple_us as b;

As it sits now I get a syntax error at spc when I run the command.

Any ideas on how to proceed?

Next I want to export the geometry of the union to a JSON. I am not sure how to do this. I cannot test this line until I get the above union done.

SELECT row_to_json(t) FROM (SELECT name,geom FROM spc_clip) t;

NOTE: name is already in the table and works fine. I am just struggling with the join and the json export.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Matt
  • 21
  • 1
  • See http://gis.stackexchange.com/questions/53883/postgis-union-between-two-tables-preserving-attributes – Mapperz Mar 27 '14 at 16:32
  • Your initial problem is of syntax. You have the geom referenced with the destination table. In the values section, however, you are listing 3 different columns. The references to the spc as a, and simple_us as b should be in a subquery to the `ST_Union command. This is in addition to the information that @Mapperz provided. – Get Spatial Mar 27 '14 at 17:11

1 Answers1

1

Try this instead your INSERT:

INSERT INTO spc_clip (geom)
  SELECT (ST_Union(a.geom, b.geom))
  FROM spc as a, simple_us as b;
Sorin Călinică
  • 5,118
  • 1
  • 17
  • 23