user3712093
user3712093

Reputation: 11

Cartopy system-wide location for natural earth shapefiles

Is there any location I can configure and put natural earth shapefiles that all users can use? My air-gapped system can't reach out to the internet to download files, so I need to point cartopy at a local store of shapefiles and configure it to look there instead of trying to reach out if it can't find them in ~/.local/share/cartopy/shapefiles/ file structure. Even the simplest tests of my install fail for this reason. I've found a few references on how to place shapefiles within that structure, so I could mimic that somewhere else. I suppose it would also be possible to symlink each user's .local/share/cartopy/shapefiles directories to a central location, but that seems like a kludge. Is there a better way that I'm missing?

EDIT: (hope this is the stackoverflow way--I am the original submitter)

OK. I'm back on this. I downloaded the ne_110m_yada_yada shapefiles unzipped them and put them in my .local/share/cartopy/shapefile/natural_earth/cultural|physical) as I found them on a connected laptop when I ran this test program:

import cartopy
import matplotlib.pyplot as plt


def main():

    ax = plt.axes(projection=cartopy.crs.PlateCarree())
    ax.add_feature(cartopy.feature.LAND)
    ax.add_feature(cartopy.feature.OCEAN)
    ax.add_feature(cartopy.feature.COASTLINE)
    ax.add_feature(cartopy.feature.BORDERS, linestyle=':')
    ax.add_feature(cartopy.feature.LAKES, alpha=0.5)
    ax.add_feature(cartopy.feature.RIVERS)
    ax.set_extent([-20, 60, -40, 40])

plt.show()


if __name__ == '__main__':
    main()

That worked as expected. I hid the files in my .local cache and had my sysadmin hack the cartopy.config to point to the in /data/cartopy/ where I hoped it would find /data/cartopy/shapefiles/natural_earth/cultural|physical where the zipped data ultimately resided. Is it expecting zipped files there or is that only if it tries to go out and download them? Cartopy did not find the zip files there and tried to go to the internet. What are the rules for putting data in pre_existing_data_dir? Will cartopy find the zip files if placed in /data/cartopy/ and do the right thing. Or do I need the shapefile/natural_earth subdirectories? I'd like to just point it only as far as /data/cartopy and have it find any shapefile or raster data I have parked in that hierarchy, whatever the source. Natural Earth is merely the test case. I'm not ruling out that my sysadmin messed up, but he is extremely competent and I may have misled him.

The links and documentation provided in the initial answer were helpful, but not helpful enough for cartopy-challenged me.

Upvotes: 1

Views: 2179

Answers (1)

pelson
pelson

Reputation: 21839

Duplicate of Location of stored offline data for cartopy

In summary, a read-only cache of data can be configured with pre_existing_data_dir in cartopy.config. For a writeable cache (that cartopy can extend) data_dir is the config item. Cartopy will check the pre_existing_data_dir cache before checking the data_dir when determining whether or not it needs to fetch the resource on your behalf.

HTH


References:

Take a look at http://scitools.org.uk/cartopy/docs/latest/cartopy.html#cartopy.config for how to configure cartopy.

You may also be interested in similar questions at:

Upvotes: 0

Related Questions