0

I'm looking for a way to persist my GeoJSON object to a table in PostGIS, I've installed the ogr2ogr JavaScript library to achieve this; on this case this what I got so far:

async function saveBuildFile(geojson) {
  let data = await ogr2ogr(geojson, { format: "PostgreSQL" });
  client.connect();
  const query = SQL`Some query to persist the geojson on a table`;
  await client.query(query);
  client.end();
  console.log("Success");
}

I mean what should be the query to persist the data on PostGIS?

UPDATE: According to the ogr2ogr library docs it is possible add some parameters on the options method parameter; anyways I'm have some issues tryng to get this working:

async function saveBuildFile(geojson) {
  await ogre2ogr(geojson, {
    format: "PostgreSQL",
    options: [
      "PG:'dbname=mydb host=127.0.0.1 port=5432 user=postgres password=admin1'",
      "-nln map_table_001",
    ],
  });
4
  • You'd need a service that provides this capability for a specific solution. It would be a huge security risk if any web client could start writing arbitrary rows (or worse start executing arbitrary commands).
    – Vince
    Nov 2 at 1:38
  • I would suggest you look at the WFS protocol
    – Ian Turton
    Nov 2 at 8:37
  • Is your code called on the server (nodejs) or on the client? If it's on the client you should use a service. If it's on the backend a plain INSERT should work. In your example, how does the data statement look like? Be aware that your table in your database needs to have all the columns and that the database is PostGIS enabled.
    – bloigge
    Nov 3 at 15:09
  • Is on a node js server
    – IBot
    Nov 3 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.