A command-line tool for extracting vector basemap data from the Natural Earth dataset:
ne extract --scale 110 --extent -92,28,-88,32ne wraps the GDAL ogr2ogr utility to quickly extract relevant geospatial layers from Natural Earth in shapefile format for a specific geographic extent.
- Extract multiple Natural Earth layers for a specific geographic extent
- Choose from NE’s three detail levels: 1:10m, 1:50m, or 1:110m scale
- Apply buffer around your extent for context, with independent control for east-west and north-south
- Default basemap layer set or custom layer selection
Before installing ne, you need:
- Ruby 3.2 or later
- GDAL with the
ogr2ogrutility installed- macOS:
brew install gdal - Check installation:
ogr2ogr --version
- macOS:
- Natural Earth dataset installed locally
- Default location:
/Users/Shared/Geodata/ne - Can be customized via the
NE_DATA_DIRenvironment variable (see Configuration below)
- Default location:
Clone the repository and install as a local gem:
git clone https://github.com/anandaroop/ne.git
cd ne
bundle install
bundle exec rake install # installs onto your systemBy default, ne expects the Natural Earth dataset to be located at /Users/Shared/Geodata/ne. If your dataset is in a different location, you can configure it using the NE_DATA_DIR environment variable.
One-time usage:
NE_DATA_DIR=/path/to/your/natural-earth ne extract --scale 110 --extent -92,28,-88,32Persistent configuration:
Add to your shell profile (~/.zshrc, ~/.bashrc, etc.):
export NE_DATA_DIR=/path/to/your/natural-earthThen use ne commands normally:
ne extract --scale 110 --extent -92,28,-88,32The configured path will also be recorded in the metadata.json file of each extraction for reproducibility.
View all available Natural Earth layers:
ne listFilter by scale:
ne list --scale 110
ne list -s 50Filter by theme:
ne list --theme physical
ne list -t culturalFilter to only default layers (a handful of basic physical and cultural layers that ne extract will extract by default, unless an a list of layers is explicity specified; see below):
ne list --default
ne list -dCombine filters:
ne list --scale 10 --theme cultural --defaultExtract Natural Earth data for a specific geographic extent:
ne extract --scale 110 --extent -92,28,-88,32-
--scaleor-s: Scale of the data10- 1:10,000,000 (largest scale, greatest detail)50- 1:50,000,000 (intermediate scale, moderate detail)110- 1:110,000,000 (smallest scale, least detail)
-
--extentor-e: Geographic bounding box in the formatxmin,ymin,xmax,ymax- Example:
-95.0,28.0,-87.7,33.8(Gulf Coast region)
- Example:
-
--bufferor-b: Expand the extent by a percentage (default: 20%)- Single value applies to both axes:
--buffer 15(15% buffer on all sides) - Two values for independent control:
--buffer 25,15(25% east-west, 15% north-south) - Specify as decimal (0-1) or percentage (1-100)
- Examples:
--buffer 0.15,--buffer 15,--buffer 25,15
- Single value applies to both axes:
-
--layersor-l: Comma-separated list of layers to extract- Default layers (if omitted):
landlakesrivers_lake_centerlines_scale_rankadmin_0_countriesadmin_0_boundary_lines_disputed_areasadmin_0_boundary_lines_landadmin_1_states_provinces_scale_rankadmin_1_states_provinces_lines
- Use
defaultto include default layers:--layers default - Specify custom layers:
--layers land,lakes,coastline - Combine default + extras:
--layers default,glaciated_areas,populated_places
- Default layers (if omitted):
-
--outputor-o: Output directory (default: current directory)- Absolute path:
--output /path/to/output - Relative path:
--output ../extracts - Home directory:
--output ~/geodata
- Absolute path:
Extract Gulf Coast region at 1:110m scale with default layers and 20% buffer:
ne extract --scale 110 --extent -95,28,-88,32Extract with 15% buffer:
ne extract --scale 110 --extent -92,28,-88,32 --buffer 0.15Extract with independent east-west and north-south buffers:
ne extract --scale 110 --extent -92,28,-88,32 --buffer 25,15Extract specific layers:
ne extract --scale 110 --extent -92,28,-88,32 --layers land,lakes,rivers_lake_centerlines_scale_rank,populated_places_simpleAdd glaciated areas to the default layer set:
ne extract --scale 110 --extent -92,28,-88,32 --layers default,glaciated_areasExtract at 1:10m scale for maximum detail:
ne extract --scale 10 --extent -95,28,-88,32 --buffer 25Extract to a specific directory:
ne extract --scale 110 --extent -92,28,-88,32 --output ~/geodata/extractsDisplay a curated list of example usage commands:
ne examples
ne tldrThis shows common usage patterns with comments explaining each command.
Remove Natural Earth output directories from the current directory:
ne cleanThis command:
- Scans the current directory for Natural Earth extraction folders (matching pattern
ne-{scale}m-{coordinates}…) - Shows a list of directories to be deleted
- Asks for confirmation before deletion
- Reports success or failure for each deletion
Display the current version of the ne tool:
ne versionExtracted data is saved to a directory named based on the scale and extent:
ne-110m--92-28--88-32/
If the directory already exists, a sequence number is automatically appended:
ne-110m--92-28--88-32-1/
ne-110m--92-28--88-32-2/
Each directory contains the extracted layers as shapefiles with their associated files (.shp, .dbf, .shx, .prj).
GDAL is not installed or not in your PATH. Install GDAL using your system's package manager.
The Natural Earth dataset is not installed at the expected location, or the specific layer is not available at the requested scale.
Solutions:
- Verify the dataset exists at
/Users/Shared/Geodata/ne(default location) - If your dataset is elsewhere, set the
NE_DATA_DIRenvironment variable (see Configuration section) - Use
ne list --scale <scale>to see available layers at the specified scale
When using --output, ensure the directory exists before running the extraction. The tool will not create the parent directory, only the extraction subdirectory.
See AGENTS.md for development guidelines and project structure.
bundle exec rake # Run tests and linter
bundle exec rake spec # Run tests only
bundle exec rake lint # Run linter only
bundle exec rake fix # Auto-fix linter issuesMIT