public IEnumerable <StreamEvent> ReadEvents(SqlConnection connection) { if (connection == null) { throw new ArgumentNullException(nameof(connection)); } return(new SqlCommand( @"SELECT wk.[wegknoopID], wk.[wegknoopversie], wk.[type], wk.[geometrie].AsBinaryZM(), wk.[beginorganisatie], lo.[label], wk.[begintijd] FROM [dbo].[wegknoop] wk LEFT OUTER JOIN [dbo].[listOrganisatie] lo ON wk.[beginorganisatie] = lo.[code]", connection ).YieldEachDataRecord(reader => { var id = reader.GetInt32(0); _logger.LogDebug("Reading road node with id {0}", id); var geometry = _wkbReader.ReadAs <NetTopologySuite.Geometries.Point>(reader.GetAllBytes(3)); return new StreamEvent(RoadNetworks.Stream, new ImportedRoadNode { Id = id, Version = reader.GetInt32(1), Type = RoadNodeType.ByIdentifier[reader.GetInt32(2)], Geometry = new RoadNodeGeometry { SpatialReferenceSystemIdentifier = SpatialReferenceSystemIdentifier.BelgeLambert1972.ToInt32(), Point = new BackOffice.Messages.Point { X = geometry.X, Y = geometry.Y } }, Origin = new ImportedOriginProperties { OrganizationId = reader.GetNullableString(4), Organization = reader.GetNullableString(5), Since = reader.GetDateTime(6) }, When = InstantPattern.ExtendedIso.Format(_clock.GetCurrentInstant()) }); })); }
private ImportedRoadSegment[] ReadInitialBatch() { var events = new List <ImportedRoadSegment>(1000); new SqlCommand( @"SELECT TOP 1000 ws.[wegsegmentID], --0 ws.[wegsegmentversie], --1 ws.[beginWegknoopID], --2 ws.[eindWegknoopID], --3 ws.[geometrie].AsBinaryZM(), --4 ws.[geometrieversie], --5 ws.[beheerder], --6 beheerders.[label], --7 ws.[methode], --8 ws.[morfologie], --9 ws.[status], --10 ws.[categorie], --11 ws.[toegangsbeperking], --12 ws.[linksStraatnaamID], --13 ISNULL(ls.[LOS], ''), --14 --streetname is empty string when not found lg.[NISCode], --15 lg.[naam], --16 ws.[rechtsStraatnaamID], --17 ISNULL(rs.[LOS], ''), --18 -streetname is empty string when not found rg.[NISCode], --19 rg.[naam], --20 ws.[opnamedatum], --21 ws.[beginorganisatie], --22 lo.[label], --23 ws.[begintijd] --24 FROM [dbo].[wegsegment] ws LEFT OUTER JOIN [dbo].[gemeenteNIS] lg ON ws.[linksGemeente] = lg.[gemeenteId] LEFT OUTER JOIN [dbo].[crabsnm] ls ON ws.[linksStraatnaamID] = ls.[EXN] LEFT OUTER JOIN [dbo].[gemeenteNIS] rg ON ws.[rechtsGemeente] = rg.[gemeenteId] LEFT OUTER JOIN [dbo].[crabsnm] rs ON ws.[rechtsStraatnaamID] = rs.[EXN] LEFT OUTER JOIN [dbo].[listOrganisatie] lo ON ws.[beginorganisatie] = lo.[code] LEFT OUTER JOIN [dbo].[listOrganisatie] beheerders ON ws.[beheerder] = beheerders.[code] WHERE ws.[eindWegknoopID] IS NOT NULL AND ws.[beginWegknoopID] IS NOT NULL ORDER BY ws.[wegsegmentID]", _connection ) .ForEachDataRecord(reader => { var id = reader.GetInt32(0); _logger.LogDebug("Reading road segment with id {0}", id); var wellKnownBinary = reader.GetAllBytes(4); var geometry = _reader .TryReadAs(wellKnownBinary, out NetTopologySuite.Geometries.LineString oneLine) ? new NetTopologySuite.Geometries.MultiLineString(new[] { oneLine }) : _reader.ReadAs <NetTopologySuite.Geometries.MultiLineString>(wellKnownBinary); var multiLineString = Array.ConvertAll( geometry.Geometries.Cast <NetTopologySuite.Geometries.LineString>().ToArray(), input => new BackOffice.Messages.LineString { Points = Array.ConvertAll( input.Coordinates, coordinate => new BackOffice.Messages.Point { X = coordinate.X, Y = coordinate.Y }), Measures = geometry.GetOrdinates(NetTopologySuite.Geometries.Ordinate.M) }); events.Add(new ImportedRoadSegment { Id = id, Version = reader.GetInt32(1), StartNodeId = reader.GetInt32(2), EndNodeId = reader.GetInt32(3), Geometry = new RoadSegmentGeometry { SpatialReferenceSystemIdentifier = SpatialReferenceSystemIdentifier.BelgeLambert1972.ToInt32(), MultiLineString = multiLineString }, GeometryVersion = reader.GetInt32(5), MaintenanceAuthority = new MaintenanceAuthority { Code = reader.GetString(6), Name = reader.GetString(7) }, GeometryDrawMethod = RoadSegmentGeometryDrawMethod.ByIdentifier[reader.GetInt32(8)], Morphology = RoadSegmentMorphology.ByIdentifier[reader.GetInt32(9)], Status = RoadSegmentStatus.ByIdentifier[reader.GetInt32(10)], Category = RoadSegmentCategory.ByIdentifier[reader.GetString(11)], AccessRestriction = RoadSegmentAccessRestriction.ByIdentifier[reader.GetInt32(12)], LeftSide = new ImportedRoadSegmentSideAttributes { StreetNameId = reader.GetNullableInt32(13), StreetName = reader.GetNullableString(14), MunicipalityNISCode = reader.GetNullableString(15), Municipality = reader.GetNullableString(16) }, RightSide = new ImportedRoadSegmentSideAttributes { StreetNameId = reader.GetNullableInt32(17), StreetName = reader.GetNullableString(18), MunicipalityNISCode = reader.GetNullableString(19), Municipality = reader.GetNullableString(20) }, RecordingDate = reader.GetDateTime(21), Origin = new ImportedOriginProperties { OrganizationId = reader.GetNullableString(22), Organization = reader.GetNullableString(23), Since = reader.GetDateTime(24) }, PartOfEuropeanRoads = Array.Empty <ImportedRoadSegmentEuropeanRoadAttributes>(), PartOfNationalRoads = Array.Empty <ImportedRoadSegmentNationalRoadAttributes>(), PartOfNumberedRoads = Array.Empty <ImportedRoadSegmentNumberedRoadAttributes>(), Lanes = Array.Empty <ImportedRoadSegmentLaneAttributes>(), Widths = Array.Empty <ImportedRoadSegmentWidthAttributes>(), Surfaces = Array.Empty <ImportedRoadSegmentSurfaceAttributes>(), When = InstantPattern.ExtendedIso.Format(_clock.GetCurrentInstant()) }); }); return(events.ToArray()); }