Exemplo n.º 1
0
def line2graph(geo, isPlot=False):
    """create a graph from a collection of lines"""
    gO = g_o.h3tree()
    G = nx.MultiDiGraph()
    # G = nx.Graph()
    G.graph['crs'] = {'init': 'epsg:4326'}
    G.graph['name'] = "local network"
    for i, g in geo.iterrows():
        seg = list(g['geometry'].coords)
        start, end = seg[0], seg[-1]
        dist = g_e.haversine(start[0], start[1], end[0], end[1])
        j1, j2 = gO.encode(start[0], start[1], precision=13), gO.encode(end[0], end[1], precision=13)
        G.add_edge(j1, j2, key=0, speed=g['maxspeed'], highway=g['fclass'], name=g['name'], length=dist)
        G.add_node(j1, pos=start, x=start[0], y=start[1], key=0)
        G.add_node(j2, pos=end, x=end[0], y=end[1], key=0)
    if isPlot:
        ox.plot_graph(G)
    print("built the graph size %d" % (G.size()))
    return G
Exemplo n.º 2
0
def intersectGeom(poly1, poly2, id1, id2, precDigit=10):
    """return the intersection ids between two lists of polygons"""
    gO = otree.h3tree()
    idx = index.Index()
    for i, p in enumerate(poly2):
        idx.insert(i, p.bounds)
    sectL = {}
    numL = []
    for i, p in zip(id1, poly1):
        merged_cells = cascaded_union(
            [poly2[i] for i in idx.intersection(p.bounds)])
        pint = p.intersection(merged_cells)
        if isinstance(pint, sh.geometry.Point):
            l = [gO.encode(pint.x, pint.y, precision=precDigit)]
        else:
            l = [gO.encode(x.x, x.y, precision=precDigit) for x in pint]
        sectL[i] = l
        numL.append(len(l))
    print("%.2f points per polygon" % (np.mean(numL)))
    return sectL
Exemplo n.º 3
0
def segment2graph(geo, isPlot=False):
    """create a graph from a collection of lines"""
    print("building the graph")
    gO = g_o.h3tree()
    G = nx.MultiDiGraph()
    # G = nx.Graph()
    G.graph['crs'] = {'init': 'epsg:4326'}
    G.graph['name'] = "local network"
    for i, g in geo.iterrows():
        seg = list(g['geometry'].coords)
        for start, end, j in zip(seg[:-1], seg[1:], range(len(seg))):
            # line = sh.geometry.LineString([start,end])
            dist = g_e.haversine(start[0], start[1], end[0], end[1])
            # j1, j2 = g['osm_id']+"_"+str(j), g['osm_id']+"_"+str(j+1)
            j1, j2 = gO.encode(start[0], start[1], precision=13), gO.encode(end[0], end[1], precision=13)
            G.add_edge(j1, j2, key=0, src=j1, trg=j2, speed=g['maxspeed'], highway=g['fclass'], name=g['name'],
                       length=dist)  # ,geometry=line,osm_id=g['osm_id'])
            G.add_node(j1, pos=start, x=start[0], y=start[1], key=0)  # ,osmid=j1)
            G.add_node(j2, pos=end, x=end[0], y=end[1], key=0)  # ,osmid=j2)
    if isPlot:
        ox.plot_graph(G)
    return G
Exemplo n.º 4
0
import os, sys, gzip, random, csv, json, datetime, re
import numpy as np
import pandas as pd
import geopandas as gpd
import shapely as sh
import matplotlib.pyplot as plt
sys.path.append(os.environ['LAV_DIR'] + '/src/')
baseDir = os.environ['LAV_DIR']
import geomadi.geo_octree as g_o
import lernia.train_viz as t_v
import networkx as nx
import geomadi.geo_enrich as g_e

gO = g_o.h3tree(BoundBox=[5.866, 47.2704, 15.0377, 55.0574])
precDigit = 8

if False:
    print('----------------------group-all-single-days----------------')
    projDir = baseDir + "raw/traj/"
    fL = os.listdir(projDir)
    for precDigit in [8, 9, 10]:
        trajL = []
        for f in fL:
            print(f)
            traj = pd.read_csv(projDir + f,
                               compression="gzip",
                               converters={
                                   "tx": eval,
                                   "bound": eval,
                                   "state": eval
                               })
Exemplo n.º 5
0
"""
markov_chain:
creation of Markov chains and Bayesian inference
"""
import numpy as np
import pandas as pd
import scipy as sp
from scipy import spatial
import matplotlib.pyplot as plt
import geomadi.graph_viz as g_v
import geomadi.geo_octree as g_o
import networkx as nx

gO = g_o.h3tree()


class MarkovChain():
    """Monte Carlo for path optimization"""
    def __init__(self, spotL, pairL=None, confM=None):
        """initialize quantities and Markov chains"""
        self.spotL = spotL
        if confM == None:
            self.confM = {
                "exp": 1,
                "threshold": "row",
                "leg": 7,
                "doc": "threshold:[percentile,mean,len,row]"
            }
        else:
            self.confM = confM
        self.loadRouted(pairL)
Exemplo n.º 6
0
import pandas as pd
import geopandas as gpd
import shapely as sh
from shapely.geometry.polygon import Polygon
import matplotlib.pyplot as plt
sys.path.append(os.environ['LAV_DIR'] + '/src/')
sys.path.append('/usr/local/lib/python3.6/dist-packages/')
baseDir = os.environ['LAV_DIR']
import lernia.train_viz as t_v
import albio.series_stat as s_s
import albio.series_interp as s_i
import geomadi.geo_octree as otree
import geomadi.geo_enrich as g_e
import geomadi.geo_ops as g_p

gO = otree.h3tree()
precDigit = 8
custD = "dep"

poi = pd.read_csv(baseDir + "raw/" + custD + "/poi_" + str(precDigit) +
                  ".csv.gz",
                  compression="gzip")

if False:
    print('----------------------------region------------------------')
    poi = pd.read_csv(baseDir + "raw/" + custD + "/poi_" + str(precDigit) +
                      ".csv.gz",
                      compression="gzip")
    poi.loc[:, "region"] = g_e.addRegion(poi,
                                         baseDir + "gis/geo/bundesland.shp")
    poi.to_csv(baseDir + "raw/" + custD + "/poi_" + str(precDigit) + ".csv.gz",