Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Looking for V2 documentation? Click here.
ogr2ogr wraps the ogr2ogr
GDAL tool to enable file conversion and re-projection of spatial data in simplified friendly API.
Install GDAL tools (includes the ogr2ogr
command line tool)
Install package:
npm install ogr2ogr
ogr2ogr takes either a path, a stream, or a GeoJSON object. The result of the transformation will depend on the format returned.
// Using CommonJS modules
const ogr2ogr = require('ogr2ogr').default
// Using ECMAScript modules or Typescript
import ogr2ogr from 'ogr2ogr'
// Promise API
(async() {
// Convert path to GeoJSON.
let {data} = await ogr2ogr('/path/to/spatial/file')
console.log(data)
// Convert GeoJSON object to ESRI Shapefile stream.
let {stream} = await ogr2ogr(data, {format: 'ESRI Shapefile'})
// Convert ESRI Shapefile stream to KML text.
let {text} = await ogr2ogr(stream, {format: 'KML'})
console.log(text)
})()
// Callback API
ogr2ogr('/path/to/spatial/file').exec((err, {data}) => {
console.log(data)
})
ogr2ogr has varying support for format input and output. Consult the particular driver you are interested in for more details. It is highly recommend to run the latest version of GDAL to get the best support. This project attempts to cast the widest net for support. Here are some notables:
Drivers | Output | Notes |
---|---|---|
GeoJSON | data | Default format returned when none specified |
CSV, GeoRSS, GML, GMT, GPX, JML, KML, MapML, PDF, VDV | text | Drivers supporting /vsidout/ return text |
Other | stream | All other drivers return a file stream |
The input
may be one of:
string
). This includes file paths and network paths including HTTP endpoints.ReadableStream
.The following options
are available (none required):
format
- Output format (default: GeoJSON
)timeout
- Timeout, in milliseconds, before command forcibly terminated (default: 0
)maxBuffer
- Max output size in bytes for stdout/stderr (default: 1024 * 1024 * 50
)options
- Custom ogr2ogr arguments and driver options (e.g. ['--config', 'SHAPE_RESTORE_SHX', 'TRUE']
)env
- Custom environmental variables (e.g. {ATTRIBUTES_SKIP: 'YES'}
)destination
- Select another output than the output object (e.g. useful for writing to databases).command
- Command to run (default: ogr2ogr
)The output
object has the following properties:
cmd
- The ogr2ogr
command executed (useful for debugging).text
- Text output from drivers that support /vsistdout/
(see formats above)data
- Parsed GeoJSON output (used when format
is GeoJSON
)stream
- A ReadableStream
of the output. Used for drivers that do not support /vsistdout/
.
ESRI Shapefile
), this will be a zip stream containing all the data.extname
- The file extension of the data returned.details
- Any text printed to STDERR
. This includes any warnings reported by ogr2ogr when it ran.The callback API supports the same options as above but in a NodeJS style callback format.
Retrieve the version of ogr2ogr
that will be called by default by this library (same as calling ogr2ogr --version
from command line).
const version = await ogr2ogr.version()
console.log(version)
// GDAL X.X.X, released XXXX/XX/XX
Running ogr2ogr
in a Docker container:
ogr2ogr("/home/.../path/to/spatial/file", {
command: "docker run -v /home/:/home --rm osgeo/gdal ogr2ogr",
})
Converting an isolated .shp
file:
ogr2ogr("/path/to/file.shp", {
options: ["--config", "SHAPE_RESTORE_SHX", "TRUE"],
})
Getting more debug information by using the CPL_DEBUG
option. Debug info added to details
on the output
object.
ogr2ogr("/path/to/file.shp", {
options: ["--config", "CPL_DEBUG", "TRUE"],
})
Parsing custom geometry fields in a CSV. Use CSV driver options, like:
ogr2ogr("/path/to/file.csv", {
options: ["-oo", "GEOM_POSSIBLE_NAMES=the_geom"],
})
Re-project geometry:
ogr2ogr("/path/to/file.shp", {
options: ["-t_srs", "EPSG:4326"],
})
FAQs
ogr2ogr wrapper w/ multiple format support
We found that ogr2ogr demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.