示例#1
0
                                nparts,
                                tpwgts=tpweights,
                                ubvec=None,
                                recursive=recursive,
                                **metis_options)
    partition = [[] for _ in range(nparts)]
    for u, i in zip(graph, parts):
        partition[i].append(u)

    # Only return non-empty parts
    return [part for part in partition if part]


if __name__ == "__main__":
    from matplotlib import pyplot
    from gistools.layer import PolygonLayer
    test = PolygonLayer(
        "/home/benjamin/Documents/PRO/PROJET_GREECE_OPSPV/001_DONNEES/data_greece"
        "/Geo layers/Parc amazonien/enp_pn_s_973.shp")
    # test = PolygonLayer("/home/benjamin/Desktop/APUREZA/geocoding/04_Codes/01_CodeSaoSeb/admin_level_10.shp")
    test = test.to_crs(epsg=32723)
    m = test.partition(100000000,
                       contig=True,
                       ncuts=50,
                       show_progressbar=True,
                       objtype="cut")

    m.plot()

    pyplot.show()
示例#2
0
# -*- coding: utf-8 -*-
""" Split polygon into sub-polygons with equal area using graph partition (requires METIS packages)

More detailed description.
"""
import numpy as np
from matplotlib import pyplot as plt

from gistools.layer import PolygonLayer

test = PolygonLayer("enp_pn_s_973.shp")
test = test[[0]].to_crs(32622)
test = test.partition(50000000,
                      disaggregation_factor=20,
                      precision=100,
                      split_method="hexana",
                      contig=True,
                      ncuts=2)
test["attr"] = np.random.randint(1000, size=(len(test), ))

# Plot the resulting sub-polygons
test.plot(attribute="attr")
plt.show()

# Show corresponding areas
print(test.area)