2

I have

  1. a placename point table in postgis with 'district' column.

  2. a districts polygon shapefile with district name in 'Name' column. See the image below.

I would like to update the 'district' columns(in placename psql table) with the corresponding district name from the shapefile polygons in which each placename point feature reside.

How can I do this in QGIS? Or Is there any other way? enter image description here

1 Answer 1

5

Postgis way : (import polygon shape to postgis using shp2psql )

UPDATE points SET district = poly.district FROM poly WHERE ST_Within(points.geom, poly.geom)

see ST_Within

and i cant remember easy QGIS way , but its possible

6
  • Can we update multiple columns in single update query? like, "province" also..
    – mapsir
    Commented Mar 21, 2014 at 11:49
  • See postgresql.org/docs/9.2/static/sql-update.html UPDATE points SET (district, province) = (poly.district, poly.province) FROM poly WHERE ST_Within(points.geom, poly.geom) That may work , didn't test. But it should be possible. Commented Mar 21, 2014 at 13:48
  • Should I use any EPSG codes? If, yes, how? Point geom is in 900913. And poly geom does not show any.
    – mapsir
    Commented Mar 24, 2014 at 6:08
  • both need to be in same system (ST_SetSrid(geom, srid) can be used to set srid and ST_Transform(geom,srid ) can be used to transform to different projection Commented Mar 24, 2014 at 7:40
  • should I add this along with the update query?
    – mapsir
    Commented Mar 24, 2014 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.