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 shapefiles from a client, one is their entire network (complete with unique IDs) and another a selection I need. However the selection file does not have unique IDs but the entire one does. How would I be able to select the lines that appear in both files from the entire network shapefile?

Thanks, Alan

share|improve this question
up vote 1 down vote accepted

For Mapinfo you should try this methods.

method (Intersects)

Copy this SQL code in some text editor. Replace table names (table1 and table2) with your tables (where first table is a entire network with IDs and second one is a partial) and save it with extension .QRY.

Fields {*}
Tables {table1, table2}
Where {table1.Obj Intersects table2.Obj}
Group {}
Order {}
Into {Selection}

Then, in MapInfo go to menu QUERY/SQL Select... (or press ALT+Q and again press Q) Now you are in SQL Select editor. Click on LOAD TEMPLATE and load QRY file.

Check again with Verify and click OK. You should get all lines from table1 that intersects table2

method (creating a Buffer)

Select all objects from Table2. Then create a buffer around it > Objects/Buffer…

  • enter some small value in “Value” (0.2meters)
  • choose “One buffer for each object”

In next dialog (Data Aggregation) set 'Aggregation Method' all to “Value” then OK.

You have now a small buffer around each object in table2.

Now create like in previous example a QRY file and run it:

Fields {*}
Tables {table1, table2}
Where {table1.Obj Entirely Within table2.Obj}
Group {}
Order {}
Into {selection}

You should get all lines from table1 that intersects table2

share|improve this answer
Thank you, nice Mr Bungle avatar btw – Alan Carr Feb 22 '13 at 13:37
Thanks for the feedback :) If the answer work for you: you can "accepted" the answer (click the grey checkmark at the left side of the answer). – sys49152 Sep 30 '13 at 7:06

In QGIS do: Vector->Spatial Query and set the query to 'Intersects'. This may also select the lines that just touch the ends of your sub-set geometry. In ArcGIS this would be 'Select by Location' but I am not familiar with MapInfo. Using PostGIS through the QGIS interface will give you more control over the select-by-location operation.

The alternative is to do a Spatial Join of your geometry with the attributes on the geometry without (in QGIS do: Vector->Data Management->Join Attributes by location. This will put all the attributes back into the 'selection' shapefile.

...or... (in GIS there is ALWAYS at least half a dozen ways of doing something) if the geometries are identical for the features you want (i.e. the sub-set is not clipped), you could make a 'selection-id' field in each shapefile based on a string concatenated from the x and y coordinates of the central coordinate (which should be safe for a road network - or you could do some combination of the start and end point geometries). Then simply do a table join and discard anything which doesn't match. This last approach will be completely GIS-software independent and would get you round any issues with the free way in which QGIS implements select by intersection.

share|improve this answer
Thanks, I'll give this a try in the morning – Alan Carr Feb 21 '13 at 17:15

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.