def test_geometries_iterator(self): points = [Point(0, 0), Point(0, 1)] features = list(map(Feature, points)) collection = FeatureCollection(features) geometry_point_pairs = zip(collection.geometries_iterator(), points) for geometry, point in geometry_point_pairs: assert geometry == point
def get_geometries(pc, class_labels, **kwargs): classes = pc[:, 3] unique_classes = np.unique(classes) geometries = [] for class_id in unique_classes: building = pc[classes == class_id] print(building.shape) class_label = class_labels[int(class_id)] geometries.extend(get_planes(building, class_id, class_label, **kwargs)) return FeatureCollection(geometries)
def getGeoJSON(covid_date_inc): print(f"covid_date_inc: {covid_date_inc}") features = createJSON(getDate(covid_date_inc)) # json_docs = [json.dumps(feature) for feature in features] # resp = jsonify(data=json_docs) # return resp feature_collection = FeatureCollection(features) json_str = dumps(feature_collection, separators=(',', ':')) # The below returns a GeoJSON string that an online GeoJSON validator validated # When axios is used, instead of d3.json(), in the client the console displays # an array of features return json_str
def get_geometries(pc, class_labels, polylidar_kwargs, config_pp, **kwargs): classes = pc[:, 3] xyz = pc[:, :3] unique_classes = np.unique(classes) geometries = [] pl = polylidar.Polylidar3D(**polylidar_kwargs) for class_id in unique_classes: building = np.copy(xyz[classes == class_id]) logging.info("Building class size: %s", building.shape) # import ipdb; ipdb.set_trace() class_label = class_labels[int(class_id)] geometries.extend(get_planes(pl, building, class_id, class_label, config_pp, **kwargs)) logging.info("Extracted %r geometries", len(geometries)) return FeatureCollection(geometries)
def geojson_from_mask(mask, thresh, transform, mode, x_offset=0, y_offset=0, open_kernel=3, close_kernel=3, pixel_tolerence=0): features = [] polys = geometries_from_mask(mask, thresh, transform, mode, x_offset, y_offset, open_kernel, close_kernel, pixel_tolerence) features = [Feature(p) for p in polys] feature_collection = FeatureCollection(features) return dumps(feature_collection, indent=2)
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_features(self): with pytest.raises(ValueError): FeatureCollection([[1, 2]])
def test_geometry_conversion(self): points = [Point(0, 0), Point(0, 1)] features = list(map(Feature, points)) collection = FeatureCollection(points) for collection_item, feature in zip(collection, features): assert collection_item == 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 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
def getGeoJSON(covid_date_inc): features = createJSON(getDate(covid_date_inc)) feature_collection = FeatureCollection(features) json_str = dumps(feature_collection, separators=(',', ':')) return json_str
parser.add_argument('--outputpath', required=True, dest="outputpath", help='The path to the output json file') args = parser.parse_args() data = pd.read_csv(args.inputpath, sep='\t', header=0, encoding='utf8') grouped = data[['Winery', 'lat', 'lon']].groupby(['Winery', 'lat', 'lon']).size().reset_index(name='count') features = list() for i in grouped.itertuples(): nextwinery = Winery(i[1], float(i[2]), float(i[3]), i[4]) nextfeature = create_feature(nextwinery) features.append(nextfeature) feature_collection = FeatureCollection(features) json = dumps(feature_collection, indent=2, ensure_ascii=False) with codecs.open(args.outputpath, 'w', encoding="utf-8") as outfile: outfile.write(json)
if valid != 'Valid Geometry': print('ERREUR:', nom, valid) exit() if Polygon(poly).area > 0.01 and nom not in ['CSG KOUROU 1']: print('ERREUR:', nom, 'emprise trop importante') exit() return (Feature(Polygon(poly), {'nom': nom})) pts = [] nom = None features = [] for ligne in txt: ligne = ligne[:-1] match = re.match(check, ligne) if match: pts.append(match.group(1, 2, 3, 4, 6, 7, 8, 9, 11, 13)) else: if nom: features.append(pts2feature(pts, nom)) nom = None if ligne != '': nom = ligne pts = [] if nom: features.append(pts2feature(pts, nom)) print(dumps(FeatureCollection(features)))