wavded / ogr2ogr

An ogr2ogr wrapper library
MIT License
214 stars 46 forks source link

CSV support? #67

Closed ferily7 closed 3 years ago

ferily7 commented 3 years ago

I'm trying to send a csv file over to my postgres but I noticed that I get the following error:

Unable to open datasource `fileName.csv' with the following drivers.
  -> `netCDF'
  -> `PDS4'
  -> `VICAR'
  -> `JP2OpenJPEG'
  -> `MBTiles'
  -> `BAG'
  -> `ESRI Shapefile'
  -> `MapInfo File'
  -> `OGR_VRT'
  -> `Memory'
  -> `GML'
  -> `KML'
  -> `GeoJSON'
  -> `GeoJSONSeq'
  -> `ESRIJSON'
  -> `TopoJSON'
  -> `GPKG'
  -> `SQLite'
  -> `PostgreSQL'
  -> `FlatGeobuf'
  -> `PGDUMP'
  -> `OGR_PDS'
  -> `MVT'

Is there no support for csv files?

wavded commented 3 years ago

CSV is supported through OGR_VRT, do you have a sample code snippet on how you are using this in code?

ferily7 commented 3 years ago

Yes, my code looks like this:

let ogr = await ogr2ogr(path)
    .format('PostgreSQL')
    .destination(databaseHost)
    .options(['-nlt', 'PROMOTE_TO_MULTI', '-nln', 'schema.tableName, '-a_srs', 'EPSG:4326', '-oo', 'X_POSSIBLE_NAMES="' + long + '"', '-oo', 'Y_POSSIBLE_NAMES="' + lat + '"', '-overwrite',]).promise();

where path is the path to the CSV file and databaseHost is my database credentials

wavded commented 3 years ago

specifying a destination can sometimes cause issues but, out of curiosity, does this work:

let ogr = await ogr2ogr(fs.createReadStream(path), 'csv')
    .format('PostgreSQL')
    .destination(databaseHost)
    .options(['-nlt', 'PROMOTE_TO_MULTI', '-nln', 'schema.tableName, '-a_srs', 'EPSG:4326', '-oo', 'X_POSSIBLE_NAMES="' + long + '"', '-oo', 'Y_POSSIBLE_NAMES="' + lat + '"', '-overwrite',]).promise();
ferily7 commented 3 years ago

Hmmm still didn't work for me.. I still get the same error about the drivers

ferily7 commented 3 years ago

So @wavded I tried a different file and it seems like the module is successful but it didn't send over the data correctly to my destination... When I look at the table in my postgres, it's empty. Is there something wrong with csv and the destination?

wavded commented 3 years ago

Gosh, I don't have a great way to test this as I don't have a Postgres environment readily available. Usually I try to mimic the command using the ogr2ogr command line tool itself to see. I don't see anything API wise that is amiss with what you've shared.

ferily7 commented 3 years ago

It seems to run the ogr2ogr command successfully but it isn’t writing the data in the csv correctly..

ferily7 commented 3 years ago

The name of the table in my postgres is correct, but when I try to view all the data for that table, all I see is a ogc_fid column with nothing in it

ferily7 commented 3 years ago

I also noticed that the same file writes to my postgres locally but when I try to do it on my lambda function, it doesn't work properly. The data isn't in the table

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 3 years ago

This issue was closed because it has been stalled for 5 days with no activity.