0

I am trying to map which county a set of coordinates I have are in. I want the code to go through each coordinate, check which county it is in, and then print the corresponding county. However, currently when ran the cursor in idle just flashes and nothing appears to happen. Any help with where my code might be going wrong would be greatly appreciated. I'm not sure if the code is correctly checking the counties or whether it can get the the names of the counties from the shapefile?

import pysal as ps
from ast import literal_eval

COUNTIES = '/Users/JoshuaHawley/Desktop/counties/English Ceremonial Counties.shp'
shps = ps.open(COUNTIES)

counties = shps.read()

f = open('/Users/JoshuaHawley/sundayCoordinates.txt').read()
seq = literal_eval(f.replace("\n", ","))

coordinates = seq[0:]
for line in coordinates:
    points = coordinates[:2]

NotFound = True

while NotFound == True:
    if coordinates in counties:
        NotFound = False
        name_of_county = counties.getNamePolygon()
        print(name_of_county)
JTH
  • 445
  • 1
  • 5
  • 8
  • This code is not correct. counties is a list of polygons, and does not support contains (i.e. coordinates in counties). You need to create a locator first, assuming counties are polygons you would use a PolygonLocator (https://pysal.readthedocs.org/en/latest/library/cg/locators.html#pysal.cg.locators.PolygonLocator) – Charles Dec 08 '15 at 20:20
  • getNamePolygon is also not a real function, you'll need to create your own logic to lookup a polygon's name in the DBF based on the polygon's offset in the shapefile. – Charles Dec 08 '15 at 20:21

0 Answers0