[Xastir] Splitting shapefiles with ogr2ogr

Tom Russo russo at bogodyn.org
Tue Jan 4 13:15:32 EST 2005


A few weeks ago there was talk here about how to split up shapefiles by
feature type (i.e. take tiger files and split out only major roads into
a separate shapefile, etc.).  At that time I produced two utterly trivial
hacks using shapelib that could do some very simple splitting and put them up
on my "shape_web" site.  Some folks have used them to create smaller shapefiles
with fewer features to improve render speed.

I have since looked at ogr2ogr and realized that it can do this operation with 
far more power.

  ogr2ogr -f "ESRI Shapefile" -where 'CFCC like "A1%"' output_directory input_tiger_shape.shp

will create a shapefile and DBF file containing only those shapes in the input
shapefile whose CFCC field matches A1% (in SQL % takes the place of *).  In 
this case, it'd give all primary limited access roads.

An SQL-like WHERE clause of some complexity could be used, but I haven't 
explored what subset of SQL's capability is implemented by OGR.  A clause
like "CFCC=A12 OR CFCC=A22" to select only primary roads in tunnels would work,
for example.  One could also select out only roads, only water features, only
legal boundaries, etc.  

Hope this helps someone.  

-- 
Tom Russo    KM5VY     SAR502  DM64ux         http://www.swcp.com/~russo/
Tijeras, NM  QRPL#1592 K2#398  SOC#236 AHTB#1 http://www.qsl.net/~km5vy/
 "When life gives you lemons, find someone with a paper cut."



More information about the Xastir mailing list