Exemplo n.º 1
0
def buffer(input_args):
    
    #Casting to float
    lat = float(input_args["lat"])
    lon = float(input_args["lon"])
    range = float(input_args["range"])
    
    
    p = Point(lon,lat)

    buffer = p.buffer(1.0)
    feature = Feature(buffer, properties={'buffer_extent': '1'})
    json_response = dumps(feature, indent=2)
    resp = make_response(json_response, 200)
    
    resp.mimetype = "application/vnd.geo+json" # So that browser knows what is the content type
    
    return resp
Exemplo n.º 2
0
def createJSON(date):
    features = []
    for i in range(len(df)):
        confirmed_cases = int(df.iloc[i,
                                      df.columns.get_loc("Confirmed_cases_" +
                                                         date)])
        if confirmed_cases > 0:
            feature = Feature(
                Point(df.iloc[i, df.columns.get_loc("Long")],
                      df.iloc[i, df.columns.get_loc("Lat")]),
                properties={
                    'Combined_Key':
                    df.iloc[i, df.columns.get_loc("Combined_Key")].strip(),
                    'Confirmed_cases':
                    int(df.iloc[i,
                                df.columns.get_loc("Confirmed_cases_" +
                                                   date)]),
                    'Deaths':
                    int(df.iloc[i, df.columns.get_loc("Deaths_" + date)])
                })
            features.append(feature)

    return features
Exemplo n.º 3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Necessary pip install: shapely and shapely_geojson
#sudo pip install shapely shapely_geojson
#sudo pip install git+https://github.com/alekzvik/shapely-geojson

from shapely.geometry.point import Point
from shapely_geojson import dumps, Feature
p = Point(-8.2918, 41.4425)  # (lon,lat) 41.4425° N, 8.2918° W

buffer = p.buffer(1.0)
feature = Feature(buffer, properties={'buffer_extent': '1'})
f1 = open("./data/guimaraes_buffer.geojson", "w")
f1.write(dumps(feature, indent=2))
Exemplo n.º 4
0
 def get_geojson_feature(self, properties={}):
     feature = Feature(self.shape, properties=properties)
     return json.loads(dumps(feature))
 def test_is_iterable(self):
     features = [Feature(Point(0, 0)), Feature(Point(0, 1))]
     collection = FeatureCollection(features)
     for collection_item, feature in zip(collection, features):
         assert collection_item == feature
 def test_equality(self):
     features = [Feature(Point(0, 0)), Feature(Point(0, 1))]
     one = FeatureCollection(features)
     another = FeatureCollection(features)
     assert one == another
 def test_invalid_geometry(self):
     with pytest.raises(ValueError):
         Feature([0, 1])
 def test_equality(self):
     one = Feature(Point(1, 1))
     another = Feature(Point(1, 1))
     assert one == another
 def test_default_properties(self):
     feature = Feature(Point())
     assert feature.properties == {}
 def test_invalid_properties(self):
     with pytest.raises(ValueError):
         Feature(Point(), properties=[])
Exemplo n.º 11
0
def to_json(line):
    feature = Feature(LineString(line))
    return feature
Exemplo n.º 12
0
def main(argv):
    pc2points_nogeo = {}
    with closing(io.open('bagadres-full.csv')) as io_file:
        rows_read = 0
        old_nr = 0
        last_point = None
        for row in csv.reader(io_file, delimiter=';'):
            rows_read += 1
            if rows_read == 1:
                continue
            # if rows_read % 100 == 0:
            #     print(rows_read)
            if rows_read % 10000 == 0:
                break
            if row[1] == old_nr:
                continue
            old_nr = row[1]
            p = shapely.geometry.Point(float(row[-2]), float(row[-1]))
            if p == last_point:
                continue
            last_point = p
            pc = row[4]
            try:
                pc2points_nogeo[pc].append(p)
            except Exception as e:
                pc2points_nogeo[pc] = [p]
                #    p.coords[:] + p.coords[:] + p.coords[:])

    pc2points = {p: shapely.geometry.MultiPoint(q) for p, q in pc2points_nogeo.items()}
    output = []
    v_input = []
    for p, poly in pc2points.items():
         for p in poly.geoms:
            v_input += p.coords

    world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
    area = world[world.name == 'Netherlands']

    area = area.to_crs(epsg=3395)    # convert to World Mercator CRS
    area_shape = area.iloc[0].geometry   # get the Polygon
    # Recoger todas las lineas y armarlas en poligonos.
    vor = Voronoi(v_input)
    lines = [shapely.geometry.LineString(vor.vertices[line]) for line in vor.ridge_vertices]
    last_pc = ""
    last_polys = []
    polys_found = 0
    polys = 0
    result_polys = []
    pc_polys = {}
    for poly in shapely.ops.polygonize(lines):
        polys += 1
        pc = ""
        old_polys_found = polys_found
        for p2, poly2 in pc2points.items():
            for p in poly2.geoms:
                if poly.contains(p):
                    pc = p2
                    polys_found += 1
                    try:
                        pc_polys[pc].append(poly)
                    except LookupError as e:
                        pc_polys[pc] = [poly]
                    break
        if old_polys_found == polys_found:
            result_polys.append(Feature(poly, {'postcode': None}))

    for pc, polys in pc_polys.items():
        result_polys.append(
            Feature(shapely.ops.unary_union(polys), {'postcode': pc}))

    print(dumps(FeatureCollection(result_polys), indent=2))
    return 0
Exemplo n.º 13
0
def save_shapely(shape, fname, uid="", alg='polylidar'):
    feature = Feature(shape, properties={'uid': uid, 'alg': alg})
    with open(fname, "w") as f:
        dump(feature, f, indent=2)