Skip to content

Commit

Permalink
Merge branch 'main' into frontend-IGI
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorIsay authored Dec 22, 2024
2 parents 2f3bdce + 09a4590 commit 40c57b9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
51 changes: 51 additions & 0 deletions db/mapdata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import osmnx as ox
import neo4j

G = ox.graph_from_place("Аптекарский остров", network_type="walk", simplify=False)
# fig, ax = ox.plot_graph(G)

gdf_nodes, gdf_relationships = ox.graph_to_gdfs(G)
gdf_nodes.reset_index(inplace=True)
gdf_relationships.reset_index(inplace=True)

NEO4J_URI = "bolt://localhost:7687"
NEO4J_USER = "neo4j"
NEO4J_PASSWORD = "password"

driver = neo4j.GraphDatabase.driver(NEO4J_URI, auth=(NEO4J_USER, NEO4J_PASSWORD))

constraint_query = "CREATE CONSTRAINT IF NOT EXISTS FOR (i:Intersection) REQUIRE i.osmid IS UNIQUE"

rel_index_query = "CREATE INDEX IF NOT EXISTS FOR ()-[r:ROAD_SEGMENT]-() ON r.osmids"

point_index_query = "CREATE POINT INDEX IF NOT EXISTS FOR (i:Intersection) ON i.location"

node_query = '''
UNWIND $rows AS row
WITH row WHERE row.osmid IS NOT NULL
MERGE (i:Intersection {osmid: row.osmid})
SET i.location = point({latitude: row.y, longitude: row.x }),
i.highway = row.highway,
i.street_count = toInteger(row.street_count)
RETURN COUNT(*) as total
'''

rels_query = '''
UNWIND $rows AS road
MATCH (u:Intersection {osmid: road.u})
MATCH (v:Intersection {osmid: road.v})
MERGE (u)-[r:ROAD_SEGMENT {osmid: road.osmid}]->(v)
SET r.oneway = road.oneway,
r.lanes = road.lanes,
r.name = road.name,
r.highway = road.highway,
r.length = toFloat(road.length)
RETURN COUNT(*) AS total
'''

driver.execute_query(constraint_query)
driver.execute_query(rel_index_query)
driver.execute_query(point_index_query)

driver.execute_query(node_query, {'rows': gdf_nodes.loc[:, gdf_nodes.columns != 'geometry'].to_dict('records')})
driver.execute_query(rels_query, {'rows': gdf_relationships.loc[:, gdf_relationships.columns != 'geometry'].to_dict('records')})
1 change: 0 additions & 1 deletion server/src/modules/dot/dto/create-dot.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {Type} from "class-transformer";

export class CreateDotDto {
@IsObject()
// @ValidateNested()
@Type(() => Point)
location: Point;
}
2 changes: 1 addition & 1 deletion server/src/modules/routes/dto/create-route.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {IsObject, IsString, IsNumber, MaxLength, MinLength, ValidateNested} from "class-validator";
import {IsString, IsNumber, MaxLength, MinLength} from "class-validator";

export class CreateRouteDto {
@IsString()
Expand Down

0 comments on commit 40c57b9

Please sign in to comment.