Пример #1
0
        private static void MatchBuilding(MatchAddressItem item)
        {
            _progress.IncrementItemsDone();

            var address = (item.HouseNumber + '?').TrimStart('0');

            var matchedPoints = GetRdfPointsForAddress(item.StreetZipId, address);
            var numMatches    = matchedPoints.Count;

            if (numMatches == 0)
            {
                Log.WriteLine($"No match for {item.BuildingId}, {item.StreetZipId}, {address}");
                return;
            }
            if (numMatches > 1)
            {
                Log.WriteLine($"More than one match for {item.BuildingId}, {item.StreetZipId}, {address}");
                return;
            }

            var match       = matchedPoints[0];
            var coordinates = match.Coordinates;

            coordinates.Lat = Utils.RdfCoordinateInsertDecimal(coordinates.Lat);
            coordinates.Lng = Utils.RdfCoordinateInsertDecimal(coordinates.Lng);

            InsertMatchedBuildingItem(new MatchedAddressItem
            {
                StreetZipId = item.StreetZipId,
                Address     = address,
                RoadLinkId  = match.RoadLinkId,
                BuildingId  = item.BuildingId,
                Coordinates = coordinates
            });

            _progress.IncrementItemsSuccessful();
        }
Пример #2
0
        static void Main(string[] args)
        {
            GlobalLibraryState.Init("MatchAddress", "Marcel", "YyQzKeSSX0TlgsI4", "RUS");

            string commandText = "SELECT b.ID as B_ID, b.HNO, b.HNO_EXTENSION, b.STREET_ZIP_ID as SZ_ID " +
                                 "FROM building b " +
                                 "WHERE b.ID NOT IN (SELECT BUILDING_ID FROM match_building) " +
                                 "AND b.STREET_ZIP_ID IN (SELECT SZ_ID FROM match_sz);";

            var taskList = new List <Task>();

            var reader = DatabaseHelper.ExecuteReader(GlobalLibraryState.ConnectionString, commandText);

            while (reader.Read())
            {
                var item = new MatchAddressItem
                {
                    BuildingId           = reader.GetInt64("B_ID"),
                    StreetZipId          = reader.GetInt64("SZ_ID"),
                    HouseNumber          = reader.GetString("HNO"),
                    HouseNumberExtension = reader.GetString("HNO_EXTENSION")
                };

                taskList.Add(Task.Run(() =>
                                      MatchBuilding(item)
                                      ));
            }

            var whenAll = Task.WhenAll(taskList);

            while (!whenAll.IsCompleted)
            {
                _progress.PrintProgress();
                Thread.Sleep(1000);
                Log.Flush();
            }
        }