[postgis-users] a couple of procedural questions for populating tables programmatically

Mr. Puneet Kishor punk.kish at gmail.com
Tue Mar 8 06:07:54 PST 2011


I have a couple of procedural questions. I am populating my table with point and cell geometries programmatically. First question: When I INSERT values other than the geometry in rows and then UPDATE the geometry in a second process, everything works --

   $sth = $dbh->prepare(qq{INSERT INTO base.cells (x, y) VALUES (?, ?)});

   for (@a) {
       $sth->execute($a[0], $a[b]);
   }

   $sth = $dbh->prepare(qq{
       UPDATE base.new_cells 
       SET 
           the_point = GeomFromText('POINT(' || x || ' ' || y || ')', 2163),
           the_cell  = GeomFromText(
               'POLYGON((' || 
               (x - $csmid) || ' ' || (y - $csmid) || ',' || 
               (x + $csmid) || ' ' || (y - $csmid) || ',' || 
               (x + $csmid) || ' ' || (y + $csmid) || ',' || 
               (x - $csmid) || ' ' || (y + $csmid) || ',' || 
               (x - $csmid) || ' ' || (y - $csmid) ||  '))', 
               2163
           )
   });
   $sth->execute;

However, if I try to do the above in one attempt like so --

   $sth = $dbh->prepare(qq{INSERT INTO base.cells (x, y, the_point, the_cell) VALUES (?, ?, ?, ?)});

   for (@a) {
       $sth->execute(
           $a[0], 
           $a[b], 
           GeomFromText('POINT(' || $a[0] || ' ' || $a[y] || ')', 2163),
           GeomFromText(
               'POLYGON((' || 
               (x - $csmid) || ' ' || (y - $csmid) || ',' || 
               (x + $csmid) || ' ' || (y - $csmid) || ',' || 
               (x + $csmid) || ' ' || (y + $csmid) || ',' || 
               (x - $csmid) || ' ' || (y + $csmid) || ',' || 
               (x - $csmid) || ' ' || (y - $csmid) ||  '))', 
               2163
           )
       );
   }

I get an error saying the method GeomFromText doesn't exist. Would like to understand the reason behind this.

Second question: I am doing the following to set the SRID (besides specifying it in the UPDATE step above).

   INSERT INTO geometry_columns (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, type)
   VALUES ('', 'base', 'cells', 'the_point', 2, 2163, 'POINT');
   INSERT INTO geometry_columns (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, type)
   VALUES ('', 'base', 'cells', 'the_cell', 2, 2163, 'POLYGON');

Is the above correct and sufficient?

Puneet.


More information about the postgis-users mailing list