[Qgis-user] Write Coordinates to Attribute Table

Ron Bentley rtbentley at gmail.com
Sun Aug 24 14:50:25 PDT 2008


>>> I'm looking for a way to write X/Y coordinates for a point shapefile
>>> back into two columns (X/Y) in the shapefile's attribute table.  Can
>>> QGIS do this?  If so, how?  If not, is there another open source tool
>>> that can perform this operation?  Ideally, the less steps required the
>>> better, as this is something that will need to be repeated multiple
>>> times--thus a script would be ideal!

If you're going to be doing this a lot, this is definitely a job for 
Postgresql/PostGIS.  The attached shell script illustrates how that 
might be done.  It adds two columns, X and Y, to the SHP file database.

It assumes you have Postgresq1/PostGIS installed, that you can add and 
drop tables in the database you name, and that psql, shp2pgsql, and 
pgsql2shp are all in the path.

There are basically five steps in the script:

   1.  Import the SHP file into a temporary PostGIS table.
   2.  Add the X and Y columns.
   3.  Populate the X and Y columns with xy coordinates from the_geom.
   4.  Export the PostGIS table to a SHP file.
   5.  Drop the temporary PostGIS table.

Ron Bentley
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: addXYtoSHP
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20080824/28e4f159/attachment.ksh>


More information about the Qgis-user mailing list