1

I have a shapefile with Canadian postal codes, but am only looking to load a small subset of the data. I can load the entire data file and use SQL or Django queries to prune the data, but the load process takes about 2 hours on the slower machines I'm using.

As the data I'm actually after is about 10% of the dataset, this isn't a very efficient process.

I'm following the instructions in the Geodjango tutorial, specifically the following code:

from django.contrib.gis.utils import LayerMapping
from geoapp.models import TestGeo
mapping = {'name' : 'str', # The 'name' model field maps to the 'str' layer field.
               'poly' : 'POLYGON', # For geometry fields use OGC name.
               } # The mapping is a dictionary
lm = LayerMapping(TestGeo, 'test_poly.shp', mapping)
lm.save(verbose=True) # Save the layermap, imports the data.

Is there a way to only only import data with a particular name, as in the example above?

I'm limited to the Linux / OS X command line, so wouldn't be able to utilize any GUI tools.

3

If your data to filter is not too complex, use the OGDL/GDAL filtering to reduce your original shapefile before loading anything (QGIS can do the same if you prefer GUI)

ogr2ogr yoursubsetshp.shp youroriginalshp.shp -sql 'SELECT * FROM youroriginalshp WHERE YOUR_COLUMN=VALUE'

You can find some SQL query for OGR/GDAL at the official doc http://www.gdal.org/ogr/ogr_sql.html and http://www.gdal.org/ogr/ogr_sql_sqlite.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.