I have a shapefile with 1475 records, and I want to generate a shapefile for each record.
What can I do to generate them avoiding selecting and exporting each record to do that?
I have a shapefile with 1475 records, and I want to generate a shapefile for each record.
What can I do to generate them avoiding selecting and exporting each record to do that?
Let's assume you have access to Excel and this is a one-off and you don't want to (or are unwilling to) write a program.
Open the .dbf file in excel - yes, it's an Excel type just don't save it. What you want is just the FID field, but that's not there is it! You will notice that the records are arranged sequentially and consecutively (1-n with no breaks). Start a new worksheet and close the dbf, insert a series for the number of records (1-1475).
Insert a column before the series in the worksheet and copy this into it:
ogr2ogr -where FID=
Which is the OGR2OGR command. In this example I'm using a query filter which can adapt to any unique attribute or group of features. The other option is -fid .
in the column after the FID put your output shapefile and use your imagination for the output shape file, in this example I have used ="d:\OutPath\Out" & B1 & ".shp". The input shape file goes last.

fill the table by selecting the cells A, C & D for all the rows and use Ctrl + D to fill down. The fomula will change each output file:

Now save as CSV, ignore the warnings, open with Notepad and you will get:
ogr2ogr -where FID=,1,d:\OutPath\Out1.shp,d:\some_path\InShape.shp
ogr2ogr -where FID=,2,d:\OutPath\Out2.shp,d:\some_path\InShape.shp
ogr2ogr -where FID=,3,d:\OutPath\Out3.shp,d:\some_path\InShape.shp
ogr2ogr -where FID=,4,d:\OutPath\Out4.shp,d:\some_path\InShape.shp
ogr2ogr -where FID=,5,d:\OutPath\Out5.shp,d:\some_path\InShape.shp
ogr2ogr -where FID=,6,d:\OutPath\Out6.shp,d:\some_path\InShape.shp
ogr2ogr -where FID=,7,d:\OutPath\Out7.shp,d:\some_path\InShape.shp
ogr2ogr -where FID=,8,d:\OutPath\Out8.shp,d:\some_path\InShape.shp
ogr2ogr -where FID=,9,d:\OutPath\Out9.shp,d:\some_path\InShape.shp
Do a find & replace FID=, with FID=, then , with space and you will get this:
ogr2ogr -where FID=1 d:\OutPath\Out1.shp d:\some_path\InShape.shp
ogr2ogr -where FID=2 d:\OutPath\Out2.shp d:\some_path\InShape.shp
ogr2ogr -where FID=3 d:\OutPath\Out3.shp d:\some_path\InShape.shp
ogr2ogr -where FID=4 d:\OutPath\Out4.shp d:\some_path\InShape.shp
ogr2ogr -where FID=5 d:\OutPath\Out5.shp d:\some_path\InShape.shp
ogr2ogr -where FID=6 d:\OutPath\Out6.shp d:\some_path\InShape.shp
ogr2ogr -where FID=7 d:\OutPath\Out7.shp d:\some_path\InShape.shp
ogr2ogr -where FID=8 d:\OutPath\Out8.shp d:\some_path\InShape.shp
ogr2ogr -where FID=9 d:\OutPath\Out9.shp d:\some_path\InShape.shp
Which is batch commands! Save the file with the extension .bat and then double click to run.
The other way of exporting using -FID looks like this:
ogr2ogr -FID 1 d:\OutPath\Out1.shp d:\some_path\InShape.shp
ogr2ogr -FID 2 d:\OutPath\Out2.shp d:\some_path\InShape.shp
ogr2ogr -FID 3 d:\OutPath\Out3.shp d:\some_path\InShape.shp
ogr2ogr -FID 4 d:\OutPath\Out4.shp d:\some_path\InShape.shp
ogr2ogr -FID 5 d:\OutPath\Out5.shp d:\some_path\InShape.shp
ogr2ogr -FID 6 d:\OutPath\Out6.shp d:\some_path\InShape.shp
ogr2ogr -FID 7 d:\OutPath\Out7.shp d:\some_path\InShape.shp
ogr2ogr -FID 8 d:\OutPath\Out8.shp d:\some_path\InShape.shp
ogr2ogr -FID 9 d:\OutPath\Out9.shp d:\some_path\InShape.shp
traps Paths with spaces must be enclosed in "", so D:\project data\FromShape.shp becomes "d:\project data\FromShape.shp".
OGR2OGR comes with QGIS but you might need to do some changes to get it to work. If the computer can't find the program insert the line set path=C:\Program Files\QGIS Dufour\bin;%path% in the top of the batch file... obviously substitute your own path to QGIS\bin folder, this one is for Dufour.
The name of the shapefile is Consolidado de Archivos Geográficos de Rutas -Shape - (12/04/14) – Ariel May 26 '14 at 21:48