public static void testPostgreSQL() { OSMPostgresqlSource sourcePostgre = new OSMPostgresqlSource(connPostGreSql); var bbbbpostgre = sourcePostgre.Bounds; OsmNode nooode = new OsmNode(); nooode.id = "81069"; var taagspg = nooode.GetTagsPostgreSQL(connPostGreSql); Aram.OSMParser.Relation rel = new Aram.OSMParser.Relation("2340"); var members = rel.GetMembersPostgreSQL(connPostGreSql); Console.WriteLine("Completed without errors."); Console.ReadLine(); }
static void MainTemp(string[] args) { NpgsqlConnection schemaConnection = new NpgsqlConnection(connPostGreSql); schemaConnection.Open(); var databaseName = "GIS"; DataTable dataTables = schemaConnection.GetSchema("Tables", new string[] { databaseName, "public", null, null }); foreach (DataRow rowTable in dataTables.Rows) { string tableName = rowTable["table_name"].ToString(); if (tableName != "geometry_collection") { continue; } DataTable dataColumns = schemaConnection.GetSchema("Columns", new string[] { databaseName, "public", tableName }); StringBuilder sb = new StringBuilder(); sb.AppendLine("public class " + tableName); sb.AppendLine("{"); sb.AppendLine("\tpublic " + tableName + "(){}"); foreach (DataRow rowColumn in dataColumns.Rows) { string columnName = rowColumn["column_name"].ToString(); string type = rowColumn["data_type"].ToString(); sb.AppendLine("\tpublic " + type + " " + columnName + " {get;set;}"); } sb.AppendLine("}"); sb.Replace("int8", "long"); sb.Replace("int4", "int"); sb.Replace("text", "string"); sb.Replace("oid", "long"); sb.Replace("numeric", "float"); sb.Replace("timestamp", "DateTime"); var def = sb.ToString(); } schemaConnection.Close(); return; var geometryRetrieval = geometryCollection.GetSingleObjectWithId("8", true, connPostGreSql); // testing GeometryCollection Aram.OSMParser.geometryCollection col = new Aram.OSMParser.geometryCollection(); // col.gisId = col.gisType = "dummy"; col.format = "txt"; col.largeObject = null; col.lastUpdate = DateTime.Now; col.latitude = 563213212; col.longitude = 171231231; col.name = "Test2"; col.pivot = new Aram.OSMParser.Vector3GaPS() { x = 1f, y = 2f, z = 3f }; col.version = new Aram.OSMParser.GaPSlabsVersion() { versionTitle = "development", major = 0, minor = 1 }; col.AddGeometryCollectionToDatabase(connPostGreSql, false); var bytes = File.ReadAllBytes(@"C:\Users\admgaming\Documents\Visual Studio 2012\Projects\GaPSLabs\AramOSMParser\OsmParserTestApplication\bin\Debug\Npgsql.xml"); col.largeObject = bytes; col.UpdateThisGeometryOnDatabase(connPostGreSql, true); var resultBytes = geometryCollection.GetLargeObject(col.largeObjectReference, connPostGreSql); File.WriteAllBytes("c:\\dummy", resultBytes); return; // ERROR: 42704: invalid large-object descriptor: 0 ?? // largeobject only works within a transaction. Use bytea as an alternative to large objects. // http://www.postgresql.org/message-id/002701c49d7e$0f059240$d604460a@zaphod NpgsqlConnection testConnection = new NpgsqlConnection(connPostGreSql); testConnection.Open(); NpgsqlTypes.LargeObjectManager lm = new NpgsqlTypes.LargeObjectManager(testConnection); var generatedLO = lm.Create(NpgsqlTypes.LargeObjectManager.READWRITE); // It must be within a transaction var TransWrite = testConnection.BeginTransaction(); LargeObject lo = lm.Open(generatedLO, LargeObjectManager.READWRITE); lo.Write(new byte[] { 0, 10, 50, 24 }); lo.Close(); TransWrite.Commit(); var TransRead = testConnection.BeginTransaction(); var loOid = lo.GetOID(); var readlo = lm.Open(loOid, LargeObjectManager.READWRITE); var resultLo = readlo.Read(readlo.Size()); lm.Delete(generatedLO); TransRead.Commit(); testConnection.Close(); return; OSMPostgresqlSource sourceVisTest = new OSMPostgresqlSource(connPostGreSql); var bounds = sourceVisTest.Bounds; return; GaPSlabsSimulationLibrary.SUMOSimulationFCD df = new GaPSlabsSimulationLibrary.SUMOSimulationFCD(); //df.LoadFromXML(@"C:\Users\admgaming\Desktop\Dropbox\GaPSLabs\SUMO Packet Tester\Pedestrians.xml"); //df.LoadFromXML(@"C:\Users\admgaming\Desktop\Dropbox\GaPSLabs\SUMO Packet Tester\bufferoutput - 500.xml"); ServiceGapslabsClient client2 = ServicePropertiesClass.GetGapslabsService(ServicePropertiesClass.ServiceUri); int id = client2.LoadSUMOFCDSimulationList(@"C:\Users\admgaming\Desktop\Dropbox\GaPSLabs\SUMO Packet Tester\bufferoutput - 500.xml", "__POSTFIX"); //client.LoadSUMOFCDSimulation(@"C:\Users\admgaming\Desktop\Dropbox\GaPSLabs\SUMO Packet Tester\bufferoutput - 500.xml"); while (!client2.IsSimulationLoadedList(id)) { } var vvvv = client2.GetTimestepAtList(6, id); var vvvv2 = client2.GetTimestepAtList(7, id); return; int size = 16777216; int[] aa = new int[size]; int[] bbb = new int[size]; int[] cccc = new int[size]; for (int i = 0; i < size; i++) { aa[i] = i; bbb[i] = i; } var apointer = aa.ToIntPtr <int[]>(); var bpointer = bbb.ToIntPtr <int[]>(); var cpointer = cccc.ToIntPtr <int[]>(); long MinGPU = 1000000; long MinCPU = 1000000; long MinCPUParallel = 100000; Stopwatch watch = new Stopwatch(); bool SkipCpu = false; GPU_WarmUp(); int TestCounter = 0; int blockSize = 16; while (TestCounter++ < 7) { watch.Restart(); GPU_Add(apointer, bpointer, cpointer, size, blockSize); watch.Stop(); Console.WriteLine("Total GPU" + "(" + blockSize + ")" + ": " + watch.ElapsedMilliseconds); if (watch.ElapsedMilliseconds < MinGPU) { MinGPU = watch.ElapsedMilliseconds; } blockSize *= 2; } Console.WriteLine("Minimum GPU was " + MinGPU); if (!SkipCpu) { TestCounter = 0; while (TestCounter++ < 10) { watch.Restart(); CPU_AddParallel(apointer, bpointer, cpointer, size); watch.Stop(); Console.WriteLine("Total CPU Parallel: " + watch.ElapsedMilliseconds); if (watch.ElapsedMilliseconds < MinCPUParallel) { MinCPUParallel = watch.ElapsedMilliseconds; } } Console.WriteLine("Minimum CPU was " + MinCPU); TestCounter = 0; while (TestCounter++ < 10) { watch.Restart(); CPU_Add(apointer, bpointer, cpointer, size); watch.Stop(); Console.WriteLine("Total CPU: " + watch.ElapsedMilliseconds); if (watch.ElapsedMilliseconds < MinCPU) { MinCPU = watch.ElapsedMilliseconds; } } Console.WriteLine("Minimum CPU was " + MinCPU); } //apointer.Free(); //bpointer.Free(); //cpointer.Free(); Console.ReadLine(); return; //GaPSlabsSimulationLibrary.SUMOSimulationFCD simulation = new GaPSlabsSimulationLibrary.SUMOSimulationFCD(); //simulation.LoadFromXML(@"C:\Users\admgaming\Desktop\Dropbox\GaPSLabs\SUMOData\fcdoutput.xml"); //simulation.LoadFromCSV(@"C:\Users\admgaming\Desktop\Notable Software\iMobility\stkhlm-taxi.csv"); ServiceGapslabsClient client = ServicePropertiesClass.GetGapslabsService(ServicePropertiesClass.ServiceUri); //client.LoadSUMOFCDSimulation(@"C:\Users\admgaming\Desktop\Dropbox\GaPSLabs\SUMO Packet Tester\bufferoutput - 500.xml"); //while (!client.IsSimulationLoaded()) // Console.WriteLine("Loading..."); //Console.WriteLine("Load finished"); //Console.ReadLine(); //return; OSMPostgresqlSource sour = new OSMPostgresqlSource(connPostGreSql); // var TrafficNodes = sour.GetNodeIdsInBoundWithInfo(sour.Bounds, "traffic_signals"); var result = client.GetWayTags("134972364", connPostGreSql); BoundsWCF b = new BoundsWCF(); b.minlat = 59.32973; b.maxlat = 59.34481; b.minlon = 18.07556; b.maxlon = 18.1062; client.GetWayExtIdsInBound(connPostGreSql, b); client.InitializeRouter(connPostGreSql); OsmNodeWCF n1 = new OsmNodeWCF(); n1.id = "none"; n1.order = -1; n1.lat = 59.330957; n1.lon = 18.059285; //n1.lat = 59.374563; //n1.lon = 18.0135727; OsmNodeWCF n2 = new OsmNodeWCF(); n2.id = "none"; n2.order = -1; n2.lat = 59.33784; n2.lon = 18.088558; //n2.lat = 59.37225; //n2.lon = 18.00733; var RouterResult = client.RouteUsingDykstra(VehicleEnum.Car, n1, n2); OsmGeo.ShapeInterperter = new SimpleShapeInterpreter(); PostgreSQLSimpleSchemaSource source = new PostgreSQLSimpleSchemaSource(connPostGreSql); // keeps a memory-efficient version of the osm-tags. OsmTagsIndex tags_index = new OsmTagsIndex(); // creates a routing interpreter. (used to translate osm-tags into a routable network) OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter(); // create routing inter OsmSourceRouterDataSource routing_data = new OsmSourceRouterDataSource( interpreter, tags_index, source); // create the router object. //IRouter<RouterPoint> router = new Router<PreProcessedEdge>(routing_data, interpreter, // new DykstraRoutingPreProcessed(routing_data.TagsIndex)); IRouter <RouterPoint> router = new Router <PreProcessedEdge>(routing_data, interpreter , new DykstraRoutingPreProcessed(routing_data.TagsIndex)); // resolve both points; find the closest routable road. //RouterPoint point1 = router.Resolve(VehicleEnum.Car, new GeoCoordinate(60.1674654,18.454302)); // RouterPoint point2 = router.Resolve(VehicleEnum.Car, new GeoCoordinate(60.1673373,18.4541732)); // Working //RouterPoint point1 = router.Resolve(VehicleEnum.Car, new GeoCoordinate(59.3863281, 18.0176665)); //RouterPoint point2 = router.Resolve(VehicleEnum.Car, new GeoCoordinate(59.3675634, 18.0140447)); // Working RouterPoint point1 = router.Resolve(VehicleEnum.Car, new GeoCoordinate(59.374563, 18.0135727)); RouterPoint point2 = router.Resolve(VehicleEnum.Car, new GeoCoordinate(59.37225, 18.00733)); //ArrayList al=new ArrayList(); //foreach (var en in Enum.GetValues(typeof(VehicleEnum))) //{ // al.Add(Enum.GetName(typeof(VehicleEnum), (VehicleEnum)en) + "=" + router.SupportsVehicle((VehicleEnum)en)); //} // calculate route. OsmSharpRoute route = router.Calculate(VehicleEnum.Car, point1, point2); route.SaveAsGpx(new FileInfo("route.gpx")); Console.ReadLine(); }
static void MainParallel(string[] args, MapProperties properties , string exportPath) { int max = 25; int current = 0; GaPSlabsVersion version = new GaPSlabsVersion("GaPSLabs 3D City Generator 1.0", 1, 0); if (!System.IO.Directory.Exists(exportPath)) System.IO.Directory.CreateDirectory(exportPath); Random rand = new Random((int)DateTime.Now.Ticks); MapProperties mapboundaries = new MapProperties(); if (properties != null) mapboundaries = properties; else { //mapboundaries.minLat = 59.3457; //mapboundaries.maxLat = 59.3527; //mapboundaries.minLon = 18.0609; //mapboundaries.maxLon = 18.0765; //mapboundaries.Name = "KTH Area"; mapboundaries.minLat = 59.2294; mapboundaries.maxLat = 59.4800; mapboundaries.minLon = 17.7649; mapboundaries.maxLon = 18.2977; mapboundaries.Name = "KTH Area"; mapboundaries.BuildingLineThickness = 0.6f; mapboundaries.RoadLineThickness = 0.2f; mapboundaries.Scale = new Vector2(16, 16); mapboundaries.BuildingColor = new Color(0, 255, 0); mapboundaries.LineColorStart = new Color(255, 255, 0); mapboundaries.LineColorEnd = new Color(255, 255, 0); mapboundaries.BuildingMaterial = null; mapboundaries.RoadMaterial = new Material("Route"); mapboundaries.CycleWayMaterial = new Material("RouteCycleway"); mapboundaries.FootWayMaterial = new Material("RouteFootway"); mapboundaries.RailWayMaterial = null; mapboundaries.StepsMaterial = new Material("RouteSteps"); mapboundaries.RoadWidth = 1;// 0.05f; mapboundaries.CyclewayWidth = 0.05f; mapboundaries.FootwayWidth = 0.05f; mapboundaries.BuildingHeight = 7.5f; mapboundaries.CombinationOptimizationSize = new Vector2(100, 100); } bool GenerateBuildingShapes = true; bool GenerateRoads = true; bool GenerateBuildings = true; bool CorrectAspectRatio = false; OSMPostgresqlSource source = new OSMPostgresqlSource(connPostGreSql); var bounds = source.Bounds; float[] minmaxX; float[] minmaxY; minmaxX = new float[] { 0, 5000 }; minmaxY = new float[] { 0, 5000 }; Bounds SelectedArea = new Bounds(); float LineWidth = 0.4f; float BuildingWidth = 0.6f; float height; height = 7.5f; SelectedArea.minlat = mapboundaries.minLat; SelectedArea.maxlat = mapboundaries.maxLat; SelectedArea.minlon = mapboundaries.minLon; SelectedArea.maxlon = mapboundaries.maxLon; minmaxX = mapboundaries.minMaxX; minmaxY = mapboundaries.minMaxY; if (CorrectAspectRatio) { var aspectRatio = System.Math.Abs(SelectedArea.maxlat - SelectedArea.minlat) / System.Math.Abs(SelectedArea.maxlon - SelectedArea.minlon); minmaxY[1] = (float)(minmaxX[1] * aspectRatio); } LineWidth = mapboundaries.RoadLineThickness; BuildingWidth = mapboundaries.BuildingLineThickness; height = mapboundaries.BuildingHeight; if (height < 4) height = 4; string[] ways = null; if (!GenerateRoads) { string[][] buildingtag = new string[1][]; buildingtag[0] = new string[] { "building", "" }; // NOTE: building tag in OSM is in lower case. ways = source.GetWayIdsWithTags(SelectedArea, buildingtag); } else if (!GenerateBuildings) { string[][] roadtag = new string[1][]; roadtag[0] = new string[] { "highway", "" }; // NOTE: highway tag in OSM is in lower case. ways = source.GetWayIdsWithTags(SelectedArea, roadtag); } else ways = source.GetWayIdsInBound(SelectedArea); float[] MinPointOnArea = CoordinateConvertor.SimpleInterpolation((float)SelectedArea.minlat, (float)SelectedArea.minlon, bounds, minmaxX, minmaxY); int direction = -1; Vector3 MinPointOnMap = new Vector3(direction * MinPointOnArea[0], 0, MinPointOnArea[1]); mapboundaries.MinPointOnMap = MinPointOnMap; int totalWays = ways.Length; int progress = 0; //List<OsmNode> WayNodes; //List<Tag> WayTags; //Vector3[] tempPoints; //PolygonCuttingEar.CPolygonShape shp; Console.WriteLine("Started at " + DateTime.Now + " for " + ways.Length + " objects."); var duration = Stopwatch.StartNew(); Parallel.ForEach<string>(ways, (FirstWay, state) => //foreach (var FirstWay in ways) { var w = new Way(FirstWay); List<OsmNode> WayNodes; List<Tag> WayTags; using (Npgsql.NpgsqlConnection con = new Npgsql.NpgsqlConnection(connPostGreSql)) { con.Open(); WayNodes = w.GetNodesPostgreSQL(FirstWay, con); WayTags = w.GetTagsPostgreSQL(FirstWay, con); con.Close(); } if (WayTags.Where(i => i.KeyValueSQL[0].ToLower() == "landuse" || i.KeyValueSQL[0].ToLower() == "building" || i.KeyValueSQL[0].ToLower() == "highway").Count() != 0) { var tempPoints = new Vector3[WayNodes.Count]; int counter = 0; foreach (var node in WayNodes) { var result = CoordinateConvertor.SimpleInterpolation((float)node.PositionSQL.Lat, (float)node.PositionSQL.Lon, bounds, minmaxX, minmaxY); // Testing the correct direction tempPoints[counter] = new Vector3(direction * (float)result[0], 0, (float)result[1]) - MinPointOnMap; counter++; } WayNodes = null; var building = WayTags.Where(i => i.KeyValueSQL[0].ToLower() == "building"); var highwayType = WayTags.Where(i => i.KeyValueSQL[0].ToLower() == "highway"); WayTags = null; if (building.Count() != 0) { if (GenerateBuildings) { //Debug.Log("Current building: "+FirstWay); if (GenerateBuildingShapes) { // Check if it has overlapping start and ending points. // NOTE: Replaced with the code to remove all the duplicates, not only the endpoints. // Checking for duplicates: tempPoints = tempPoints.ToArray().RemoveDuplicates(); var Skip = false; if (tempPoints.Length <= 2) { // Buildings that are too small to show such as 76844368 // http://www.openstreetmap.org/browse/way/76844368 // "A weird building were found and ignored. FirstWay \nRelated url: http://www.openstreetmap.org/browse/way/{0}" Skip = true; // continue; } if (!Skip) { var p2d = tempPoints.ToCPoint2D(); // TODO bug in the cpolygon, probably duplicates var shp = new PolygonCuttingEar.CPolygonShape(p2d); shp.CutEar(); p2d = null; GC.Collect(); // TODO: var randHeight = CoordinateConvertor.linear((float)rand.NextDouble(), 0, 1, -3f, height); var randMaterial = (randHeight > height / 2f) ? "BuildingTall" : randHeight < height / 2f ? "Building2" : "Building"; var resultedGameObject = shp.GenerateShapeUVedWithWalls_Balanced( CoordinateConvertor.OSMType.Polygon, FirstWay, "Building", "Building", randMaterial, height + randHeight, height + 7, true); //Console.WriteLine("Generating building..id=" + FirstWay); // To file: // ObjFormat.MeshToFile(resultedGameObject,System.IO.Path.Combine( exportPath , resultedGameObject.Name.Replace("|", "-") + ".obj")); // To PostGreSql LargeObjects: var objData = ObjFormat.GameObjectToString(resultedGameObject); var binaryData = System.Text.Encoding.ASCII.GetBytes(objData); AddToDatabase(binaryData, FirstWay, resultedGameObject.Name, resultedGameObject, version, connPostGreSql); // gc.id , gc is now set } } else Console.WriteLine("TODO"); // draw.Draw(tempPoints, buildingColor, buildingColor, BuildingWidth, BuildingWidth, LineDraw.OSMType.Line, FirstWay, "Building", "Building"); } } else { if (highwayType.Count() != 0) { if (GenerateRoads) { var hwtype = highwayType.First(); //Console.WriteLine("Generating roads..id=" + FirstWay); switch (hwtype.KeyValueSQL[1]) { case "cycleway": { var resultedGameObject = CoordinateConvertor.MeshGenerationFilledCorners(tempPoints.ToSegmentedPoints(2f), mapboundaries.CyclewayWidth, CoordinateConvertor.OSMType.Line, FirstWay, hwtype.KeyValueSQL[1], "Line", mapboundaries.CycleWayMaterial.Name, -0.01f); // ObjFormat.MeshToFile(resultedGameObject,System.IO.Path.Combine( exportPath , resultedGameObject.Name.Replace("|", "-") + ".obj")); // To PostGreSql LargeObjects: var objData = ObjFormat.GameObjectToString(resultedGameObject); var binaryData = System.Text.Encoding.ASCII.GetBytes(objData); AddToDatabase(binaryData, FirstWay, resultedGameObject.Name, resultedGameObject, version, connPostGreSql); // gc.id , gc is now set break; } case "footway": case "path": case "pedestrian": { var resultedGameObject = CoordinateConvertor.MeshGenerationFilledCorners(tempPoints.ToSegmentedPoints(4f), mapboundaries.FootwayWidth, CoordinateConvertor.OSMType.Line, FirstWay, hwtype.KeyValueSQL[1], "Line", mapboundaries.FootWayMaterial.Name, -0.01f); // ObjFormat.MeshToFile(resultedGameObject,System.IO.Path.Combine( exportPath , resultedGameObject.Name.Replace("|", "-") + ".obj")); // To PostGreSql LargeObjects: var objData = ObjFormat.GameObjectToString(resultedGameObject); var binaryData = System.Text.Encoding.ASCII.GetBytes(objData); AddToDatabase(binaryData, FirstWay, resultedGameObject.Name, resultedGameObject, version, connPostGreSql); // gc.id , gc is now set break; } case "steps": { var resultedGameObject = CoordinateConvertor.MeshGenerationFilledCorners(tempPoints.ToSegmentedPoints(4f), mapboundaries.CyclewayWidth, CoordinateConvertor.OSMType.Line, FirstWay, hwtype.KeyValueSQL[1], "Line", mapboundaries.StepsMaterial.Name, -0.01f); // ObjFormat.MeshToFile(resultedGameObject,System.IO.Path.Combine( exportPath , resultedGameObject.Name.Replace("|", "-") + ".obj")); // To PostGreSql LargeObjects: var objData = ObjFormat.GameObjectToString(resultedGameObject); var binaryData = System.Text.Encoding.ASCII.GetBytes(objData); AddToDatabase(binaryData, FirstWay, resultedGameObject.Name, resultedGameObject, version, connPostGreSql); // gc.id , gc is now set break; } case "motorway": { break; } default: { var resultedGameObject = CoordinateConvertor.MeshGenerationFilledCorners(tempPoints.ToSegmentedPoints(0.5f), mapboundaries.RoadWidth, CoordinateConvertor.OSMType.Line, FirstWay, hwtype.KeyValueSQL[1], "Line", mapboundaries.RoadMaterial.Name, 0f); // ObjFormat.MeshToFile(resultedGameObject,System.IO.Path.Combine( exportPath , resultedGameObject.Name.Replace("|", "-") + ".obj")); // To PostGreSql LargeObjects: var objData = ObjFormat.GameObjectToString(resultedGameObject); var binaryData = System.Text.Encoding.ASCII.GetBytes(objData); AddToDatabase(binaryData, FirstWay, resultedGameObject.Name, resultedGameObject, version, connPostGreSql); // gc.id , gc is now set break; } } //current++; //if (current > max) // state.Break(); } } } } }); duration.Stop(); Console.WriteLine("Finished in " + duration.Elapsed.Minutes + " minutes, " + duration.Elapsed.Seconds + " seconds, " + duration.Elapsed.Milliseconds + " milliseconds."); Console.ReadLine(); }