Changes between Version 5 and Version 6 of FAQVector


Ignore:
Timestamp:
Nov 19, 2007, 12:29:27 PM (16 years ago)
Author:
springmeyer
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FAQVector

    v5 v6  
    55== How can I merge hundreds of shapefiles? ==
    66
    7 Here's a bash script to bulk load a directory of shapefiles that have the same schema to postgis.  It could obviously be made smarter, but it seems to do the trick.
     7Here's a bash script to bulk load a directory of shapefiles that have the same schema to postgis.  It could obviously be made smarter, but it seems to do the trick.
     8
     9
    810{{{
    911#!/bin/bash
     
    2022done
    2123}}}
     24
     25*Note if you get an import error from postgis similiar to "ERROR:  new row for relation "layer1" violates check constraint" you should try substituting "-nlt GEOMETRY" for your GEOMETRY TYPE (in the above example it is POLYGON). This will avoid errors if your shapefile includes both Polygon and Multipolygon geometries, for example. See this thread http://postgis.refractions.net/pipermail/postgis-users/2006-June/012495.html
     26
     27These Unix shell steps illustrate how to batch merge multiple shapefiles into a single shapefile using OGR. This assumes you have downloaded a group of shapefiles in .zip format which are all the same type of data but just need to be combined. This works on a Mac but has not been test on other versions of UNIX:
     28
     29{{{
     30#Make a new directory called "tmp" and a sub directory called "merged"
     31mkdir tmp
     32mkdir tmp/merged
     33
     34#copy all zipped files to the "tmp" directory and then "cd" into it
     35cp *.zip tmp
     36cd tmp
     37
     38#unzip all the .zip archives
     39find . -name "*.zip" -exec unzip '{}' \;
     40
     41#delete all .zip archives
     42rm *.zip
     43
     44#move a single shapefile (and the cooresponded .shx, .dbf, etc files) to the "merged" directory (exchange 'myshape*' for the name of one of your shapefiles keeping the '*' at the end of the name)
     45find . -name 'myshape*' -exec mv '{}' merged \;
     46 
     47#Batch merge all the remaining shapefiles from the tmp dir into the copied file in the merge dir (exchange 'myshape' for the name of the copied shapefile)
     48for i in $(ls *.shp); do ogr2ogr -f 'ESRI Shapefile' -update -append merged $i -nln myshape
     49done
     50
     51}}}
     52
    2253
    2354This Windows cmd shell example merges multiple ''*wetlands*''shapefiles in the current directory to a single {{{merged\wetlands.shp}}} (double % to put in a script, {{{%f}}} --> {{{%%f}}}):