I am a beginner with GIS data, and have been looking for an answer but have not yet found it.

I have a spreadsheet with lat/long points. I also have a shapefile with several numbered polygons over a geographical area. I would like to do the following:

  1. For each row in the spreadsheet (lat/long point) determine which polygon it is within
  2. Update the spreadsheet (or generate a new spreadsheet/shapefile/etc.) with each row having its polygon number in a new column.

I suspect I could possibly use ogr2ogr to do this, or possibly write some Python code to do it, but I really don't even know where to start.

closed as too broad by PolyGeo Mar 10 at 1:35

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    First convert your coordinate pairs to points (some searching on this site will show you how) I've seen a few questions covering this and then search for spatial joining in QGIS, again on this site. I'm not sure about updating an existing spreadsheet without code but it is possible that there is a plugin that could help with that. – Michael Stimson Jul 25 '14 at 4:26

@Michael Miles-Stimson for pointed me in the general vicinity in the comment above. I used QGIS for this.

The solution was to do the following:

  • Load the polygon data into QGIS as a shapefile layer
  • Load the lat/long points into QGIS as a delimited text layer
  • In QGIS perform a layer query to select only the polygon I want (doing polygons one at a time is acceptable in my case)
  • In QGIS use Vector->Research Tools->Select by location
  • Select features in the lat/long layer that intersect features in the polygon layer
  • Then export the lat/long layer by choosing Layer->Save As, and checking the 'Use selected features only' box, then saving as a CSV file

This gives me one CSV file per polygon, which is good enough for what I needed. I have since figured out better ways to do this by importing into PostgreSQL/PostGIS and performing the queries I need.

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