private void AddWay(Way way) { _waysOsm.Add(way); if (_nodesRefs.Count > COUNT_ROW) { ImportPrimitiveWaysToDb(); } }
private GeoType WayIsPolygonOrLine(Way way) { if (way.IsPolygon()) { return(new GeoType(GeoTypeOGC.Polygon)); } else { return(new GeoType(GeoTypeOGC.LineString)); } }
/// <summary> /// Imports WaysRefs in Sql Server /// </summary> private void ImportRefsWays(Way waySimple) { int orderNode = 0; for (int i = 0; i < waySimple.Nodes.Count; i++) { orderNode++; DataRow rowWayRefs = _tableWaysRefs.NewRow(); rowWayRefs["idWay"] = waySimple.Id; rowWayRefs["idNode"] = waySimple.Nodes[i].Id; rowWayRefs["orders"] = orderNode; _tableWaysRefs.Rows.Add(rowWayRefs); } }
private void ImportGeoWayToDb(DataTable nodesRefsAndWays) { this.FillCoordinateNodesForWays(nodesRefsAndWays); for (int w = 0; w < _waysOsm.Count; w++) { DataRow rowWay = _tableWays.NewRow(); Way waySimple = _waysOsm[w]; rowWay["id"] = waySimple.Id; if (_waysOsm[w].GeoType != null) { rowWay["typeGeo"] = Convert.ToByte(waySimple.GeoType.GeoTypeOGC); } rowWay["times"] = waySimple.DateStamp; _tableWays.Rows.Add(rowWay); ImportRefsWays(waySimple); } }
/// <summary> /// Imports Ways in Sql Server /// </summary> private void ImportPrimitiveWaysToDb() { for (int w = 0; w < _waysOsm.Count; w++) { DataRow rowWay = _tableWays.NewRow(); Way waySimple = _waysOsm[w]; rowWay["id"] = waySimple.Id; if (_waysOsm[w].GeoType != null) { rowWay["typeGeo"] = Convert.ToByte(waySimple.GeoType.GeoTypeOGC); } rowWay["times"] = waySimple.DateStamp; _tableWays.Rows.Add(rowWay); ImportRefsWays(waySimple); } this.ImportGeoWayToDb(_tableWaysRefs); this.ImportDataTableInDb(ref _tableWays, TablesTemplates.GetTableWays); this.ImportDataTableInDb(ref _tableWaysRefs, TablesTemplates.GetTableWaysRefs); _waysOsm.Clear(); _nodesRefs.Clear(); }
/// <summary> /// Reads and parses a ways (OSMPBF.Way) /// </summary> /// <param name="ways">List of ways</param> private void ReadWays(PrimitiveBlock primitiveBlock, List <Helpers.ReadPdb.Way> ways) { int dateGranularity = primitiveBlock.date_granularity; long second = 0; string key, val; int idKey, idValue; TypeValueTag typeValueTag; // Is it possible to import on the basis of the presence of significant tags bool IsImportToDb; for (int wayIndex = 0; wayIndex < ways.Count; wayIndex++) { Helpers.ReadPdb.Way osmpbfWay = ways[wayIndex]; DateTime stamp = new DateTime(); if (osmpbfWay.info != null) { Info info = osmpbfWay.info; second = (info.timestamp * dateGranularity) / 1000; stamp = this.timeEpoche.AddSeconds(second); } long deltaref = 0; var way = new Way(osmpbfWay.id, stamp); for (int nodeRef = 0; nodeRef < osmpbfWay.refs.Count; nodeRef++) { deltaref += osmpbfWay.refs[nodeRef]; way.Nodes.Add(this.AddNodeSimpleToNodesRefs(deltaref)); } IsImportToDb = false; GeoType geoType = null; if (osmpbfWay.keys.Count != 0 || osmpbfWay.keys.Count != 0) { for (int keyId = 0; keyId < osmpbfWay.keys.Count; keyId++) { key = UTF8Encoding.UTF8.GetString( primitiveBlock.stringtable.s[Convert.ToInt32(osmpbfWay.keys[keyId])]); val = UTF8Encoding.UTF8.GetString( primitiveBlock.stringtable.s[Convert.ToInt32(osmpbfWay.vals[keyId])]); OsmRepository.TagsRepository.AddTag(key, val, out idKey, out idValue, out typeValueTag); if (typeValueTag != TypeValueTag.NoImport) { IsImportToDb = true; this.InsertTagsAndValue(way.Id, idKey, idValue, val, typeValueTag); if (_importConfigurator.GetTypeOGC(Type.GetType("OsmImportToSqlServer.OsmData.Way"), key, out geoType)) { way.GeoType = geoType; } } } } //// DEBUG //Console.WriteLine(DateTime.Now + " Way - " + way.Id + ", " + way.Nodes.Count + " nodes"); if (IsImportToDb) { if (way.GeoType != null) { this.AddWay(way); } else { way.GeoType = this.WayIsPolygonOrLine(way); this.AddWay(way); } } else { this.AddWay(way); } } }
private GeoType WayIsPolygonOrLine(Way way) { if (way.IsPolygon()) { return new GeoType(GeoTypeOGC.Polygon); } else { return new GeoType(GeoTypeOGC.LineString); } }
/// <summary> /// Reads and parses a ways (OSMPBF.Way) /// </summary> /// <param name="ways">List of ways</param> private void ReadWays(PrimitiveBlock primitiveBlock, List<Helpers.ReadPdb.Way> ways) { int dateGranularity = primitiveBlock.date_granularity; long second = 0; string key, val; int idKey, idValue; TypeValueTag typeValueTag; // Is it possible to import on the basis of the presence of significant tags bool IsImportToDb; for (int wayIndex = 0; wayIndex < ways.Count; wayIndex++) { Helpers.ReadPdb.Way osmpbfWay = ways[wayIndex]; DateTime stamp = new DateTime(); if (osmpbfWay.info != null) { Info info = osmpbfWay.info; second = (info.timestamp * dateGranularity) / 1000; stamp = this.timeEpoche.AddSeconds(second); } long deltaref = 0; var way = new Way(osmpbfWay.id, stamp); for (int nodeRef = 0; nodeRef < osmpbfWay.refs.Count; nodeRef++) { deltaref += osmpbfWay.refs[nodeRef]; way.Nodes.Add(this.AddNodeSimpleToNodesRefs(deltaref)); } IsImportToDb = false; GeoType geoType = null; if (osmpbfWay.keys.Count != 0 || osmpbfWay.keys.Count != 0) { for (int keyId = 0; keyId < osmpbfWay.keys.Count; keyId++) { key = UTF8Encoding.UTF8.GetString( primitiveBlock.stringtable.s[Convert.ToInt32(osmpbfWay.keys[keyId])]); val = UTF8Encoding.UTF8.GetString( primitiveBlock.stringtable.s[Convert.ToInt32(osmpbfWay.vals[keyId])]); OsmRepository.TagsRepository.AddTag(key, val, out idKey, out idValue, out typeValueTag); if (typeValueTag != TypeValueTag.NoImport) { IsImportToDb = true; this.InsertTagsAndValue(way.Id, idKey, idValue, val, typeValueTag); if (_importConfigurator.GetTypeOGC(Type.GetType("OsmImportToSqlServer.OsmData.Way"), key, out geoType)) way.GeoType = geoType; } } } //// DEBUG //Console.WriteLine(DateTime.Now + " Way - " + way.Id + ", " + way.Nodes.Count + " nodes"); if (IsImportToDb) { if (way.GeoType != null) { this.AddWay(way); } else { way.GeoType = this.WayIsPolygonOrLine(way); this.AddWay(way); } } else { this.AddWay(way); } } }
/// <summary> /// Imports WaysRefs in Sql Server /// </summary> private void ImportRefsWays(Way waySimple) { int orderNode = 0; for (int i = 0; i < waySimple.Nodes.Count; i++) { orderNode++; DataRow rowWayRefs = _tableWaysRefs.NewRow(); rowWayRefs["idWay"] = waySimple.Id; rowWayRefs["idNode"] = waySimple.Nodes[i].Id; rowWayRefs["orders"] = orderNode; _tableWaysRefs.Rows.Add(rowWayRefs); } }
private void AddWay(Way way) { _waysOsm.Add(way); if (_nodesRefs.Count > COUNT_ROW) { ImportPrimitiveWaysToDb(); } }