def readLineAndAddToNetwork(row, fmt): """TODO""" edge_id = str(row[fmt.pos_edge_id]) if fmt.pos_edge_id < 0: edge_id = NetworkReader.counter NetworkReader.counter = NetworkReader.counter + 1 geom = str(row[fmt.pos_wkt]) TAB_OBS = wktLineStringToObs(geom, fmt.srid.upper()) # Au moins 2 points if len(TAB_OBS) < 2: return track = Track(TAB_OBS) Cinematics.computeAbsCurv(track) edge = Edge(edge_id, track) # Orientation orientation = int(row[fmt.pos_sens]) if orientation not in [ Edge.DOUBLE_SENS, Edge.SENS_DIRECT, Edge.SENS_INVERSE ]: orientation = Edge.DOUBLE_SENS edge.orientation = orientation # Poids if fmt.pos_poids == -1: poids = track.length() else: poids = float(row[fmt.pos_poids]) edge.weight = poids # Source node source = str(row[fmt.pos_source]) noeudIni = Node(source, track.getFirstObs().position) # Target node target = str(row[fmt.pos_target]) noeudFin = Node(target, track.getLastObs().position) # Return return (edge, noeudIni, noeudFin)
def getNetwork(bbox, proj=None, margin=0.0, tolerance=0.1, spatialIndex=True, nomproxy=None): """getNetwork :param bbox: The bounding box of the selected area (The bounding box must be expressed in WGS84). :param proj: projection of results, optional. For example: 'EPSG:2154' or 'EPSG:4326' """ # Adding margin xmin, xmax, ymin, ymax = bbox dx = (xmax - xmin) / 2 dy = (ymax - ymin) / 2 bbox = ( xmin - margin * dx, xmax + margin * dx, ymin - margin * dy, ymax + margin * dy, ) network = Network() if spatialIndex: network.spatial_index = SpatialIndex(bbox, resolution=(dx / 1e3, dy / 1e3), margin=0.4) network.spatial_index.collection = network cptNode = 0 if proj == None: proj = "EPSG:4326" fmt = NetworkFormat() fmt.createFromDict({ "name": "WFS", "pos_edge_id": 0, "pos_source": 5, "pos_target": 6, "pos_wkt": 1, "pos_poids": 3, "pos_sens": 4, "srid": "GEO", }) # PROXY proxyDict = {} if nomproxy != None: with open(IgnReader.PROXY_FILE_FORMAT) as ffmt: line = ffmt.readline().strip() while line: if line[0] == "#": line = ffmt.readline().strip() continue tab = line.split(",") if tab[0].strip() == nomproxy: FIELDS = tab proxyDict[FIELDS[1].lower()] = FIELDS[2] line = ffmt.readline().strip() ffmt.close() nbRoute = IgnReader.__getNbRouteEmprise(bbox, proxyDict) nbiter = int(nbRoute / IgnReader.NB_PER_PAGE) + 1 offset = 0 for j in range(nbiter): print("PAGE " + str(j + 1) + "/" + str(nbiter)) URL_FEAT = IgnReader.URL_SERVER URL_FEAT += "BBOX=" + str(bbox[2]) + "," + str(bbox[0]) URL_FEAT += "," + str(bbox[3]) + "," + str(bbox[1]) URL_FEAT += "&count=" + str(IgnReader.NB_PER_PAGE) URL_FEAT += "&startIndex=" + str(offset) URL_FEAT += "&RESULTTYPE=results" URL_FEAT += "&srsname=" + proj # print (URL_FEAT) response = requests.get(URL_FEAT, proxies=proxyDict) data = json.loads(response.text) features = data["features"] for feature in progressbar.progressbar(features): row = [] idd = feature["id"] # nature = feature['properties']['nature'] fictif = feature["properties"]["fictif"] if fictif == "True": continue row.append(idd) # TODO # pos = feature['properties']['position_par_rapport_au_sol'] TAB_OBS = [] coords = feature["geometry"]["coordinates"] if feature["geometry"]["type"] == "LineString": # print (str(len(coords))) # geom = coords # print (coords) typeCoord = "GEOCOORDS" if proj == "EPSG:2154": typeCoord = "ENUCoords" TAB_OBS = tabCoordsLineStringToObs(coords, typeCoord) if len(TAB_OBS) < 2: continue track = Track(TAB_OBS) row.append(track.toWKT()) row.append("ENU") row.append(track.length()) # Orientation sens = feature["properties"]["sens_de_circulation"] orientation = Edge.DOUBLE_SENS if sens == None or sens == "": orientation = Edge.DOUBLE_SENS elif sens == "Double sens" or sens == "Sans objet": orientation = Edge.DOUBLE_SENS elif sens == "Direct" or sens == "Sens direct": orientation = Edge.SENS_DIRECT elif sens == "Indirect" or sens == "Sens inverse": orientation = Edge.SENS_INVERSE else: print(sens) row.append(orientation) # Source node idNoeudIni = str(cptNode) p1 = track.getFirstObs().position candidates = selectNodes(network, Node("0", p1), tolerance) if len(candidates) > 0: c = candidates[0] idNoeudIni = c.id else: cptNode += 1 # Target node idNoeudFin = str(cptNode) p2 = track.getLastObs().position candidates = selectNodes(network, Node("0", p2), tolerance) if len(candidates) > 0: c = candidates[0] idNoeudFin = c.id else: cptNode += 1 row.append(idNoeudIni) row.append(idNoeudFin) (edge, noeudIni, noeudFin) = reader(row, fmt) network.addEdge(edge, noeudIni, noeudFin) # offset = offset + IgnReader.NB_PER_PAGE return network