Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


I have two shape files that I want merge (overlay/intersect) having in the destination the attributes of the two sources file.

ogr2ogr file_merged.shp tl_2010_us_uac10_conus_albersUA.shp
ogr2ogr -update -append file_merged.shp tabblock2010_10_pophu.shp -nln file_merged

In this way I obtain the polygons of the two shapes, but I lose the attributes of the tabblock2010_10_pophu.shp.

My final aim is then make an sql statement where I can retrieve polygon in common in the both shapes.

Any suggestions??

Thanks in advance

share|improve this question
sql query? You're using some kind of a database? You can easly do that kind of spatial queries using postgis – nickves Sep 29 '12 at 0:21
Thanks menjaraz, i will test it. Actually i think should be possible with ogr2ogr by using sql statement. I tried several combination but not i did not succeed. Let's see if somebody else reply. Ciao Giuseppe – user10600 Sep 29 '12 at 20:38

Using GDAL >= 1.10.0 and its OGR Virtual Format, we can write a VRT file named, for example, merge.vrt (see Example: Union layer (GDAL >= 1.10.0)):

    <OGRVRTUnionLayer name="unionLayer">
        <OGRVRTLayer name="source1">
        <OGRVRTLayer name="source2">

and simply execute in order to simply preserve the attributes of both SHPs:

ogr2ogr merge.shp merge.vrt

Instead, if you want also exclude duplicate geometries from the result:

ogr2ogr merge_distinct.shp merge.vrt -dialect sqlite -sql "SELECT DISTINCT geometry, * FROM merge"
share|improve this answer
+1 because this is ultra cool, but will it allow the OP to do the intersection/conflation stuff they mention? ::bows:: – elrobis Oct 17 '13 at 18:04
@elrobis I have updated the answer, because you make me notice that the second question was unanswered. Thank you. – afalciano Oct 18 '13 at 8:52
Hi, great answer, just an update for the final ogr2ogr statement. instead of "* FROM merge" for your example you want "* FROM unionLayer", since it was defined as unionLayer in your vrt. Also for those unfamiliar with vrt's in ogr your name="source1" will have to be the same as the name of your shapefile, so: <OGRVRTLayer name="myshapefile"> <SrcDataSource>myshapefile.shp</SrcDataSource> – Vesanto Jun 25 '14 at 10:41

I wrote some downloadable code for that. A simple python program to combine shapefiles in many ways:

By default performs the dbf schemes union and it adds an attribute filled with the source shapefile name, so you can recognize records.

This is the commandline for your needs:

python -o file_merged.shp tl_2010_us_uac10_conus_albersUA.shp tabblock2010_10_pophu.shp

(you have to run it in a python environment with available ogr/gdal packages. I wrote some note about this above the code)

share|improve this answer
Looks like the post has moved here:… – Matt Hampel Oct 13 '14 at 14:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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