Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Method is looking for an existing parcel boundary point with the same coordinates as point parameter
- /// </summary>
- /// <param name="existingBuildingBPsList">list of existing ParcelBoundaryPoint objects from DB</param>
- /// <param name="existingBuildingBPs">hashmap of existing ParcelBoundaryPoint objects from DB - hash points for quicker search</param>
- /// <param name="point">Point to find</param>
- /// <param name="pointId">point counter for new points</param>
- /// <param name="currentLine">ParcelBoundaryLine object which contains this point</param>
- /// <param name="cadastreZoneId">Cadastre Zone ID</param>
- /// <returns>BuildingBoundaryPointId or -1 in case of an error</returns>
- private long CheckIfBoundaryPointExists(List<PBoundaryPoint> existingParcelBPsList, Dictionary<int, List<PBoundaryPoint>> existingParcelBPs, IPoint point, long pointId, PBoundaryLine currentLine, long cadastreZoneId)
- {
- int pointHash = point.GetHashCode();
- // try to find point by hash
- List<PBoundaryPoint> pointsFoundList = existingParcelBPs.ContainsKey(pointHash) ? existingParcelBPs[pointHash] : null;
- PBoundaryPoint currentPoint = null;
- // if found more than one, do spatial filtering in found list
- if (pointsFoundList != null && pointsFoundList.Count > 1)
- {
- pointsFoundList = pointsFoundList.Where(b => b.geometry.EqualsTopologically(point)).ToList();
- }
- // will this ever return something???
- /*else if (pointsFoundList == null || pointsFoundList.Count == 0)
- {
- pointsFoundList = existingParcelBPsList.Where(b => b.geometry.EqualsTopologically(point)).ToList();
- }*/
- // if point not found by hash or founded point is not topologically identical to searched point, create a new one
- if (pointsFoundList == null || pointsFoundList.Count == 0 || !pointsFoundList[0].geometry.EqualsTopologically(point))
- {
- /*if (pointsFoundList != null && pointsFoundList.Count > 0 && !pointsFoundList[0].geometry.EqualsTopologically(point))
- {
- Debug.WriteLine(point.AsText());
- Debug.WriteLine(pointsFoundList[0].geometry.AsText());
- }*/
- // point doesn't exist, create a new one
- IGeometry newPoint = (IGeometry)point.Clone();
- currentPoint = new PBoundaryPoint()
- {
- parcelBoundaryPointId = pointId,
- geometry = newPoint,
- geometryArray = SqlGeometry.STGeomFromText(new System.Data.SqlTypes.SqlChars(newPoint.AsText()), srid).STAsBinary().Value,
- hash = newPoint.GetHashCode(),
- cadastreZoneId = cadastreZoneId,
- modified = true
- };
- existingParcelBPsList.Add(currentPoint);
- // new hash, create a new list with this point
- if (pointsFoundList == null || pointsFoundList.Count == 0)
- {
- List<PBoundaryPoint> list = new List<PBoundaryPoint>();
- list.Add(currentPoint);
- existingParcelBPs.Add(currentPoint.hash, list);
- }
- // existing hash, add point to list with this hash
- else
- {
- existingParcelBPs[currentPoint.hash].Add(currentPoint);
- }
- }
- // single point has been found and it's topologically identical to searched point
- else
- {
- currentPoint = pointsFoundList[0];
- pointId = currentPoint.parcelBoundaryPointId;
- }
- /*if (pointsFoundList == null || pointsFoundList.Count == 0)
- {
- // point doesn't exist, create a new one
- IGeometry newPoint = (IGeometry)point.Clone();
- currentPoint = new PBoundaryPoint()
- {
- parcelBoundaryPointId = pointId,
- geometry = newPoint,
- geometryArray = SqlGeometry.STGeomFromText(new System.Data.SqlTypes.SqlChars(newPoint.AsText()), srid).STAsBinary().Value,
- hash = newPoint.GetHashCode(),
- cadastreZoneId = cadastreZoneId,
- modified = true
- };
- existingParcelBPsList.Add(currentPoint);
- List<PBoundaryPoint> list = new List<PBoundaryPoint>();
- list.Add(currentPoint);
- existingParcelBPs.Add(currentPoint.hash, list);
- }
- else
- {
- currentPoint = pointsFoundList[0];
- pointId = currentPoint.parcelBoundaryPointId;
- }*/
- // update parcelBoundaryPoint references
- if (currentLine != null)
- {
- if (currentLine.firstBoundaryPointId == null && (currentLine.secondBoundaryPointId == null || currentLine.secondBoundaryPointId != pointId))
- {
- currentLine.firstBoundaryPointId = pointId;
- currentLine.modified = true;
- }
- else if (currentLine.secondBoundaryPointId == null && (currentLine.firstBoundaryPointId == null || currentLine.firstBoundaryPointId != pointId))
- {
- currentLine.secondBoundaryPointId = pointId;
- currentLine.modified = true;
- }
- else if (currentLine.firstBoundaryPointId != pointId && currentLine.secondBoundaryPointId != pointId)
- {
- log.Warn("BoundaryLine has both parcelBoundaryPointIds already assigned. ParcelBoundaryLineId=" + currentLine.parcelBoundaryLineId + ", " + currentLine.geometry.ToString());
- return -1;
- }
- }
- return pointId;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement