protected override Task DoTaskWork(string osmFile, AttributeRegistry attributeRegistry) { var watch = Stopwatch.StartNew(); ExecuteSqlCmd("TRUNCATE TABLE WayCreation"); ExecuteSqlCmd("TRUNCATE TABLE WayTag"); var dWays = new DataTable(); dWays.TableName = "WayCreation"; dWays.MinimumCapacity = MaxRowCountInMemory; dWays.Columns.Add("wayId", typeof(long)); dWays.Columns.Add("nodeId", typeof(long)); dWays.Columns.Add("sort"); var dWayTags = new DataTable(); dWayTags.TableName = "WayTag"; dWayTags.MinimumCapacity = MaxRowCountInMemory; dWayTags.Columns.Add("WayId", typeof(long)); dWayTags.Columns.Add("Typ", typeof(int)); dWayTags.Columns.Add("Info", typeof(string)); var insertingTask = Task.Factory.StartNew(() => StartInserting()); var reader = osmFile.EndsWith(".pbf") ? (IOsmReader) new PbfOsmReader() : (IOsmReader) new XmlOsmReader(); foreach (var way in reader.ReadWays(osmFile, attributeRegistry)) { if (!_timeOffset.HasValue) { watch.Stop(); _timeOffset = watch.Elapsed.TotalSeconds; } _countOfInsertedWays++; var sort = 0; foreach (var node in way.NodeRefs) { dWays = AddToCollection(dWays, way.WayId, node, sort++); } foreach (var tag in way.Tags) { dWayTags = AddToCollection(dWayTags, way.WayId, tag.Typ, tag.Value); } } DataTableCollection.Add(dWays); DataTableCollection.Add(dWayTags); DataTableCollection.CompleteAdding(); Trace.WriteLine(string.Format("Inserted {0} ways", _countOfInsertedWays)); return(insertingTask.Result); }
protected override Task DoTaskWork(string osmFile, AttributeRegistry attributeRegistry) { var reader = osmFile.EndsWith(".pbf") ? (IOsmReader) new PbfOsmReader() : (IOsmReader) new XmlOsmReader(); ExecuteSqlCmd("TRUNCATE TABLE [dbo].[tRelationCreation]"); ExecuteSqlCmd("TRUNCATE TABLE [dbo].[tRelationTag]"); var dRelationCreation = new DataTable { MinimumCapacity = MaxRowCountInMemory }; dRelationCreation.TableName = "tRelationCreation"; dRelationCreation.Columns.Add("RelationId", typeof(long)); dRelationCreation.Columns.Add("Ref", typeof(long)); dRelationCreation.Columns.Add("Type"); dRelationCreation.Columns.Add("Role"); dRelationCreation.Columns.Add("Sort"); var dRelationTags = new DataTable { MinimumCapacity = MaxRowCountInMemory }; dRelationTags.TableName = "tRelationTag"; dRelationTags.Columns.Add("RelationId", typeof(long)); dRelationTags.Columns.Add("Typ"); dRelationTags.Columns.Add("Info"); var insertingTask = Task.Factory.StartNew(() => StartInserting()); foreach (var relation in reader.ReadRelations(osmFile, attributeRegistry)) { _countOfInsertedRelations++; var sort = 0; foreach (var member in relation.Members) { dRelationCreation = AddToCollection(dRelationCreation, relation.RelationId, member.Ref, member.Type, member.Role, sort++); } foreach (var tag in relation.Tags) { dRelationTags = AddToCollection(dRelationTags, relation.RelationId, tag.Typ, tag.Value); } } DataTableCollection.Add(dRelationCreation); DataTableCollection.Add(dRelationTags); DataTableCollection.CompleteAdding(); Trace.WriteLine(string.Format("Inserted {0} relations", _countOfInsertedRelations)); return(insertingTask.Result); }
protected override Task DoTaskWork(string osmFile, AttributeRegistry attributeRegistry) { ExecuteSqlCmd("TRUNCATE TABLE [Node]"); ExecuteSqlCmd("TRUNCATE TABLE [NodeTag]"); var loadingNodeTable = new DataTable(); loadingNodeTable.TableName = "Node"; loadingNodeTable.MinimumCapacity = MaxRowCountInMemory; loadingNodeTable.Columns.Add("NodeId", typeof(long)); loadingNodeTable.Columns.Add("location", typeof(SqlGeography)); loadingNodeTable.Columns.Add("Latitude", typeof(double)); loadingNodeTable.Columns.Add("Longitude", typeof(double)); var dNodeTags = new DataTable(); dNodeTags.TableName = "NodeTag"; dNodeTags.MinimumCapacity = MaxRowCountInMemory; dNodeTags.Columns.Add("NodeId", typeof(long)); dNodeTags.Columns.Add("Typ"); dNodeTags.Columns.Add("Info"); IOsmReader reader = osmFile.EndsWith(".pbf") ? (IOsmReader) new PbfOsmReader() : (IOsmReader) new XmlOsmReader(); var insertingTask = Task.Factory.StartNew(() => StartInserting()); foreach (var node in reader.ReadNodes(osmFile, attributeRegistry)) { _countOfInsertedNodes++; loadingNodeTable = AddToCollection(loadingNodeTable, node.NodeId, node.ToSqlGeographyPoint(), node.Latitude, node.Longitude); foreach (var tag in node.Tags) { dNodeTags = AddToCollection(dNodeTags, node.NodeId, tag.Typ, tag.Value); } } DataTableCollection.Add(loadingNodeTable); DataTableCollection.Add(dNodeTags); DataTableCollection.CompleteAdding(); Trace.WriteLine(string.Format("Inserted {0} nodes", _countOfInsertedNodes)); return(insertingTask.Result); }