def query():
    '''
    Expects query variables:
        float : p1x (longitute)
        float : p1y (latitude)
        float : p2x (longitute)
        float : p2y (latitude)
    '''
    p1x = float(request.args.get("p1x"))
    p1y = float(request.args.get("p1y"))
    p2x = float(request.args.get("p2x"))
    p2y = float(request.args.get("p2y"))

    result = find_zips([p1x, p1y], [p2x, p2y], polys)

    # get a dictionary of zipcode -> exterior shape of matching zipcodes
    matches = {k: v for k, v in polys.iteritems() if k in result}
    asCoords = {}

    for k, v in matches.iteritems():
        asCoords[k] = []
        for shape in v:
            asCoords[k].append(list(shape.exterior.coords))

    return json.dumps(asCoords)
def query():
    """
    Expects query variables:
        float : p1x (longitute)
        float : p1y (latitude)
        float : p2x (longitute)
        float : p2y (latitude)
    """
    p1x = float(request.args.get("p1x"))
    p1y = float(request.args.get("p1y"))
    p2x = float(request.args.get("p2x"))
    p2y = float(request.args.get("p2y"))

    result = find_zips([p1x, p1y], [p2x, p2y], polys)

    # get a dictionary of zipcode -> exterior shape of matching zipcodes
    matches = {k: v for k, v in polys.iteritems() if k in result}
    asCoords = {}

    for k, v in matches.iteritems():
        asCoords[k] = []
        for shape in v:
            asCoords[k].append(list(shape.exterior.coords))

    return json.dumps(asCoords)
    def test_first_few(self):
        zips, polys = read_shp(zcta_file, limit=15)
        first = polys[polys.keys()[0]][0]
        sx = first.centroid.x
        sy = first.centroid.y

        last = polys[polys.keys()[-1]][0]
        ex = last.centroid.x
        ey = last.centroid.y

        result = find_zips([sx, sy], [ex, ey], polys)
        assert len(result) >= 2, "Should intersect at least the two zip codes whose centroids we're using"

        import ipdb; ipdb.set_trace()
Beispiel #4
0
    def test_first_few(self):
        zips, polys = read_shp(zcta_file, limit=15)
        first = polys[polys.keys()[0]][0]
        sx = first.centroid.x
        sy = first.centroid.y

        last = polys[polys.keys()[-1]][0]
        ex = last.centroid.x
        ey = last.centroid.y

        result = find_zips([sx, sy], [ex, ey], polys)
        assert len(
            result
        ) >= 2, "Should intersect at least the two zip codes whose centroids we're using"

        import ipdb
        ipdb.set_trace()
    def test_line_inside_concave_1_intersect(self):
        result = find_zips([1, 2], [2, 2], self.ZIPS)

        assert len(result) == 1, "Should have 1 intersections"
        assert '1' in result, "Should intersect with area 1"
    def test_line_along_edge_3(self):
        result = find_zips([5, 5], [7, 3], self.ZIPS)

        assert len(result) == 1, "Should have 1 intersections"
        assert '3' in result, "Should intersect with area 3"
    def test_line_inside_concave_no_intersect(self):
        result = find_zips([1, 2], [1.1, 2], self.ZIPS)

        assert len(result) == 0, "Should have 0 intersections"
    def test_intersect_3_inside_only(self):
        result = find_zips([5, 3], [5, 2], self.ZIPS)

        assert len(result) == 1, "Should have 1 intersections"
        assert '3' in result, "Should intersect with area 3"
    def test_intersect_3_outside_start(self):
        result = find_zips([10, 5], [5, 2], self.ZIPS)

        assert len(result) == 1, "Should have 1 intersections"
        assert '3' in result, "Should intersect with area 3"
 def test_no_intersect(self):
     result = find_zips([0, 10], [10, 10], self.ZIPS)
     assert len(result) == 0, "Should not have any intersections"
    def test_intersect_3_1_inside_start(self):
        result = find_zips([5, 3], [0, 0], self.ZIPS)

        assert len(result) == 2, "Should have 2 intersections"
        assert '3' in result, "Should intersect with area 3"
        assert '1' in result, "Should intersect with area 1"
Beispiel #12
0
    def test_line_inside_concave_1_intersect(self):
        result = find_zips([1, 2], [2, 2], self.ZIPS)

        assert len(result) == 1, "Should have 1 intersections"
        assert '1' in result, "Should intersect with area 1"
Beispiel #13
0
 def test_no_intersect(self):
     result = find_zips([0, 10], [10, 10], self.ZIPS)
     assert len(result) == 0, "Should not have any intersections"
Beispiel #14
0
    def test_line_inside_concave_no_intersect(self):
        result = find_zips([1, 2], [1.1, 2], self.ZIPS)

        assert len(result) == 0, "Should have 0 intersections"
Beispiel #15
0
    def test_line_along_edge_3(self):
        result = find_zips([5, 5], [7, 3], self.ZIPS)

        assert len(result) == 1, "Should have 1 intersections"
        assert '3' in result, "Should intersect with area 3"
Beispiel #16
0
    def test_intersect_3_outside_start(self):
        result = find_zips([10, 5], [5, 2], self.ZIPS)

        assert len(result) == 1, "Should have 1 intersections"
        assert '3' in result, "Should intersect with area 3"
Beispiel #17
0
    def test_intersect_3_inside_only(self):
        result = find_zips([5, 3], [5, 2], self.ZIPS)

        assert len(result) == 1, "Should have 1 intersections"
        assert '3' in result, "Should intersect with area 3"
Beispiel #18
0
    def test_intersect_3_1_inside_start(self):
        result = find_zips([5, 3], [0, 0], self.ZIPS)

        assert len(result) == 2, "Should have 2 intersections"
        assert '3' in result, "Should intersect with area 3"
        assert '1' in result, "Should intersect with area 1"