[postgis-users] Fast access to PostGIS from c/c++

Boehm, Andreas boehm at rif.fuedo.de
Tue Dec 12 05:02:30 PST 2006


Hi Markus,

sorry to be slow in replying. I got distracted by other issues
yesterday. 

> Why does the Tablewriter not work? Can you give us the code 
> example, and the error message? We've used COPY to fill lots 
> of geometry tables over here.

Here is my code to insert points with tablewriter:

void InsertPointsTableWriter(connection &c)
{
  work *t = new work(c, "insert_points");
  tablewriter *w = new tablewriter(*t, POINTS_TABLE);
  vector<string> myData;
  myData.resize(2);
  srand(42); 
  double x, y;
  for (int i = 0; i < POINT_COUNT;)
  {
    x = ((double) rand() + ((double) rand() / RAND_MAX)) 
      / (RAND_MAX + 1) * X_MAX;
    y = ((double) rand() + ((double) rand() / RAND_MAX)) 
      / (RAND_MAX + 1) * Y_MAX;

    myData[0] = to_string(i);
    myData[1] = "GeometryFromText('POINT(" + to_string(x) + " " 
      + to_string(y) + ")', -1)";
    w->insert(myData);

    // every 10000 points complete writing, start a new transaction
    if (++i % 10000 == 0)
    {
      w->complete();
      delete w;
      t->commit();
      delete t;
      t = new work(c, "insert_points");
      w = new tablewriter(*t, POINTS_TABLE);
      cerr << ".";
    }
  }

  // Complete writing
  w->complete();
  delete w;
  t->commit();
  delete t;
  cerr << "#";
}

The error message is:
SQL error: ERROR:  parse error - invalid geometry
CONTEXT:  COPY points, line 1, column geom:
"GeometryFromText('POINT(122.072 
9172.53)', -1)"
Query was: '[END COPY]'

Running "INSERT INTO points VALUES (1, GeometryFromText('POINT(122.072 
9172.53)', -1));" in pgAdmin was sucsessful.

Regards,
Andi



More information about the postgis-users mailing list