wavded / ogr2ogr

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

More examples of how to write data #93

Closed bertday closed 1 year ago

bertday commented 1 year ago

Hello @wavded and thank you for this awesome project!

I'm trying to get started using this package to read and write geodata. I'm a little confused though looking at the examples how I would recreate a canonical use of ogr2ogr, like:

ogr2ogr -f GeoJSON foo.geojson foo.shp

All of the examples seem to focus on reading data in. I happened to see a more clear-cut read-write example in #92 so I'm using that, but just wanted to suggest as a new user that it may be helpful to have a similar example in the docs!

Thanks again and Happy New Year!

wavded commented 1 year ago

Thanks @rbrtmrtn for the suggestion and encouragement. I agree, a ogr2ogr command to code example would be helpful. In your case it would be:

ogr2ogr -f GeoJSON foo.geojson foo.shp

By default, if possible, GeoJSON is returned, so:

let geojson = await ogr2ogr("./foo.shp")
bertday commented 1 year ago

Thanks for the quick response @wavded!

It's helpful to see that minimal example. I think what I struggle with a bit in Node is writing files out, so if there were a complete (but still minimal) example of reading foo.shp and writing it out as foo.geojson to disk, that would be super helpful.

Or I can try doing a PR once I figure it out 😄

sgibbes commented 1 year ago

Hi @rbrtmrtn, I am just getting started with trying to use this in an AWS Lambda function. I too was confused as to how to write the data, and I agree the documentation could be elaborated on. I was able to get this to work in a local environment (not quite there in the lambda function). If it helps, this is how I got the data to write to a geojson file:

ogr2ogr('/local/file.shp', {destination:'/local/file.json', options: [ '-t_srs', 'EPSG:4326' ]}).exec((err, data) => { if (data && data.details) { console.log(data.details) } if (err) { console.log(err) } })

Within the lambda function, I am stuck on how to install gdal tools. So if you have any tips on that, send them my way! Thanks.

wavded commented 1 year ago

Sorry for the delay on this. Previously we had an examples folder where we put little code snippets of usage for different use cases. Would that make sense to start another one? A lot of them previously were community driven. Suppose we could do a Wiki as well.

github-actions[bot] commented 1 year 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 1 year ago

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