I'm working on a model to predict whether craigslist apartment listings are over or under market value. I'm a complete novice with GIS.

I have the lat and long as well as what neighborhood the author says the apartment is in. But seeing how some neighborhoods are nicer or better known than others, the apartment's actual address is often in other neighborhoods.

enter image description here

The picture is an example of apartments listed under the neighborhood SOMA but many are outside the neighborhood borders.

Is there any way in Python to group lat and longs by neighborhood?

  • There always is, but the implementation all depends on the underlying data. Do you have any data (or just this screenshot, or perhaps an online map), and if so, what format is your data in? EDIT: ok, you have the data, I missed that! In what format? Feb 3, 2015 at 19:48
  • The data is in a csv. Here's a link to the google fusion table. Does this help? google.com/fusiontables/… Feb 3, 2015 at 19:55
  • 1
    OK, so you have the exact coordinates of apartments and a neighborhood that the apartment is said to be in (but not necessarily is), and you want to check what neighborhood it really is in? That is the question the way I understand it, is that correct? If so, does this have to accomplished using Python? Feb 3, 2015 at 20:01
  • 1
    That is a valid dataset for sure. I just downloaded and opened it in QGIS, and then I added your csv as well. I cannot post pictures in this comment, but here is a link to my screenshot: i60.tinypic.com/2hxlevt.png Feb 3, 2015 at 20:32
  • 1
    I think the question you're asking is "does this point fall within this polygon" - check this out, gis.stackexchange.com/questions/84114/… it uses opensource Python packages. It might be a start for you.
    – KHibma
    Feb 3, 2015 at 21:46

3 Answers 3


This tutorial from Boundless has some excellent examples of how to work through similar problems in the borough/neighborhood hierarchy in NYC. It doesn't take long to work through the tutorials and you'll feel a lot more at ease with PostGIS in no time.


Please NOTE

I know this is not a complete answer (yet!), but since I would like to post some screenshots, it is much easier to insert them here than link to upload pages that might get rid of the images at some point.

I am hoping to edit this post as I can figure out the solution with David. Anyone else, please feel free to suggest a wokflow or an alternate solution. I would be happy to add the screenshots in my posting!

You might also want to read the many comments below the question to get a clearer idea of what needs to be solved.

First of all, load your neighborhoods shapefile in QGIS. To do that click the following menu:

enter image description here

This will let you navigate to your file. Make sure you filter for shapefiles, so it is easier to find.

enter image description here

You will now see the file under Layers (top left corner). It is important that you save it anew and give it the correct coordinate system. As you want it to work with your lat/lon values, you would be using WGS84.

Right-click your dataset and go to Save As, and make sure to choose WGS84:

enter image description here

That saves your file with the right coordinate system. Now, you will add the file to QGIS. You can get rid of the original one (right-click: Remove).

Now you would want to add your CSV:

enter image description here

If you downloaded the file from your Google table, like I did, then you do not have to do much here. Just browse to the file and leave everything as is. Click OK, and make sure to enter WGS84 again.

Now your points will be shown ontop of your neighborhoods. To see the tabular data you can right-click either of the files and open their attribute tables:

enter image description here

You will quickly notice that the names of the neighborhoods do not always coincide, which might make the analysis a little more complicated, as we might have to edit the table(s).

Again, I will do my best to edit this post as we go along. I will think of a workflow and try to post it this weekend! If anyone else has suggestions, please enter them as comments, or add a new answer, and briefly note that it is adding to what has been discussed here.

  • this is great. how do i get the shapefile neighborhoods into the csv file data, so that each row/data point has the correct neighborhood? Feb 9, 2015 at 6:17

First yo'll have to get hold of your neighborhoods, as a non-usaian I have no idea if these are publicly available in any form, but what you want is polygons describing your neighborhoods. Preferably as geographic coordinates (lat/lon) in GeoJSON format, but if you get them in some other projection or format: don't worry, use gdal/ogr to massage them into shape (not shapefile).

Saying "In Python", i guess you want an open source solution, go install shapely (available through pip)

Then look up the Shapely docs to figure out how to find what is inside a polygon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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