コード例 #1
0
        type=float,
        metavar="x",
        default=10,
        dest="tail_length",
        help="Maximum length/width for " "tails Default %(default)f",
    )

    args = parser.parse_args()

    logging.basicConfig()
    log.setLevel(logging.INFO)

    # Get generator of clustered nodes
    # We keep these in OSRM units for now.
    clustered_nodes = itertools.groupby(
        topotools.read_clusters(args.input, args.bbox, scale=False), operator.attrgetter("clust")
    )

    # keep a list of nodes we orphan
    orphans = []
    good_nodes = []

    for clustidx, nodes in clustered_nodes:
        node_list = list(nodes)
        points = np.array([(x.lon, x.lat) for x in node_list], dtype=float)

        if len(node_list) < 20:
            log.info("Cluster has less than 20 nodes, orphaning")
            orphans.extend(node_list)
            continue
コード例 #2
0
    log.setLevel(logging.INFO)

    with open(args.hulls, 'r') as inputfd:
        features = geojson.load(inputfd)

    cluster_features = {}
    for feature in features['features']:
        cluster_id = feature['properties']['clust']
        cluster_features[cluster_id] = asShape(feature['geometry'])

    log.info("Loaded %i hulls", len(cluster_features))

    # Get generator of clustered nodes
    # We keep these in OSRM units for now.
    clustered_node_iters = itertools.groupby(
        topotools.read_clusters(args.input, args.bbox, scale=False),
        operator.attrgetter('clust')
    )

    # Get the ID, the hull (if it exists), and the nodes for each cluster
    clustered_nodes = (
        (clust, cluster_features.get(clust), list(nodes))
        for clust, nodes in clustered_node_iters
    )

    def find_edge_nodes(fargs):
        """ Find nodes are near the edge of the hull"""
        cluster, cluster_hull, nodes = fargs
        # There is no hull for this community, it's been deleted.
        if cluster_hull is None:
            log.error("Missing hull, keeping all nodes in cluster %i",
コード例 #3
0
    parser.add_argument('--AND', dest="and_shapes", nargs='+', type=str,
                        default=[], metavar='file.shp',
                        help='List of .shp files to '
                        'AND the output shapes with')

    parser.add_argument('--seed', default=1, type=int, help='random seed')

    args = parser.parse_args()

    logging.basicConfig()
    log.setLevel(logging.INFO)

    random.seed(args.seed)

    clustered_nodes = itertools.groupby(
        topotools.read_clusters(args.input, args.bbox),
        operator.attrgetter('clust')
    )

    pruned_nodes = []

    for clustidx, nodes in clustered_nodes:
        log.info("Pruning interior of cluster %i", clustidx)
        draw = None
        if args.drawprune and clustidx in args.drawprune:
            draw = 'prune_%i.png' % clustidx
        pruned = topotools.voronoi_prune_region(nodes, 25, draw=draw)
        pruned_nodes.extend(pruned)

    pruned_nodes.sort(key=operator.attrgetter('clust'))