Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.09 KB | None | 0 0
  1.         /// <summary>
  2.         /// Method is looking for an existing parcel boundary point with the same coordinates as point parameter
  3.         /// </summary>
  4.         /// <param name="existingBuildingBPsList">list of existing ParcelBoundaryPoint objects from DB</param>
  5.         /// <param name="existingBuildingBPs">hashmap of existing ParcelBoundaryPoint objects from DB - hash points for quicker search</param>
  6.         /// <param name="point">Point to find</param>
  7.         /// <param name="pointId">point counter for new points</param>
  8.         /// <param name="currentLine">ParcelBoundaryLine object which contains this point</param>
  9.         /// <param name="cadastreZoneId">Cadastre Zone ID</param>
  10.         /// <returns>BuildingBoundaryPointId or -1 in case of an error</returns>
  11.         private long CheckIfBoundaryPointExists(List<PBoundaryPoint> existingParcelBPsList, Dictionary<int, List<PBoundaryPoint>> existingParcelBPs, IPoint point, long pointId, PBoundaryLine currentLine, long cadastreZoneId)
  12.         {
  13.             int pointHash = point.GetHashCode();
  14.             // try to find point by hash
  15.             List<PBoundaryPoint> pointsFoundList = existingParcelBPs.ContainsKey(pointHash) ? existingParcelBPs[pointHash] : null;
  16.             PBoundaryPoint currentPoint = null;
  17.             // if found more than one, do spatial filtering in found list
  18.             if (pointsFoundList != null && pointsFoundList.Count > 1)
  19.             {
  20.                 pointsFoundList = pointsFoundList.Where(b => b.geometry.EqualsTopologically(point)).ToList();
  21.             }
  22.             // will this ever return something???
  23.             /*else if (pointsFoundList == null || pointsFoundList.Count == 0)
  24.             {
  25.                 pointsFoundList = existingParcelBPsList.Where(b => b.geometry.EqualsTopologically(point)).ToList();
  26.             }*/
  27.  
  28.             // if point not found by hash or founded point is not topologically identical to searched point, create a new one
  29.             if (pointsFoundList == null || pointsFoundList.Count == 0 || !pointsFoundList[0].geometry.EqualsTopologically(point))
  30.             {
  31.                 /*if (pointsFoundList != null && pointsFoundList.Count > 0  && !pointsFoundList[0].geometry.EqualsTopologically(point))
  32.                 {
  33.                     Debug.WriteLine(point.AsText());
  34.                     Debug.WriteLine(pointsFoundList[0].geometry.AsText());
  35.                 }*/
  36.                 // point doesn't exist, create a new one
  37.                 IGeometry newPoint = (IGeometry)point.Clone();
  38.                 currentPoint = new PBoundaryPoint()
  39.                 {
  40.                     parcelBoundaryPointId = pointId,
  41.                     geometry = newPoint,
  42.                     geometryArray = SqlGeometry.STGeomFromText(new System.Data.SqlTypes.SqlChars(newPoint.AsText()), srid).STAsBinary().Value,
  43.                     hash = newPoint.GetHashCode(),
  44.                     cadastreZoneId = cadastreZoneId,
  45.                     modified = true
  46.                 };
  47.                 existingParcelBPsList.Add(currentPoint);
  48.  
  49.                 // new hash, create a new list with this point
  50.                 if (pointsFoundList == null || pointsFoundList.Count == 0)
  51.                 {
  52.                     List<PBoundaryPoint> list = new List<PBoundaryPoint>();
  53.                     list.Add(currentPoint);
  54.                     existingParcelBPs.Add(currentPoint.hash, list);
  55.                 }
  56.                 // existing hash, add point to list with this hash
  57.                 else
  58.                 {
  59.                     existingParcelBPs[currentPoint.hash].Add(currentPoint);
  60.                 }
  61.             }
  62.             // single point has been found and it's topologically identical to searched point
  63.             else
  64.             {
  65.                 currentPoint = pointsFoundList[0];
  66.                 pointId = currentPoint.parcelBoundaryPointId;
  67.             }
  68.  
  69.             /*if (pointsFoundList == null || pointsFoundList.Count == 0)
  70.             {
  71.                 // point doesn't exist, create a new one
  72.                 IGeometry newPoint = (IGeometry)point.Clone();
  73.                 currentPoint = new PBoundaryPoint()
  74.                 {
  75.                     parcelBoundaryPointId = pointId,
  76.                     geometry = newPoint,
  77.                     geometryArray = SqlGeometry.STGeomFromText(new System.Data.SqlTypes.SqlChars(newPoint.AsText()), srid).STAsBinary().Value,
  78.                     hash = newPoint.GetHashCode(),
  79.                     cadastreZoneId = cadastreZoneId,
  80.                     modified = true
  81.                 };
  82.                 existingParcelBPsList.Add(currentPoint);
  83.                 List<PBoundaryPoint> list = new List<PBoundaryPoint>();
  84.                 list.Add(currentPoint);
  85.                 existingParcelBPs.Add(currentPoint.hash, list);
  86.             }
  87.             else
  88.             {
  89.                 currentPoint = pointsFoundList[0];
  90.                 pointId = currentPoint.parcelBoundaryPointId;
  91.             }*/
  92.  
  93.             // update parcelBoundaryPoint references
  94.             if (currentLine != null)
  95.             {
  96.                 if (currentLine.firstBoundaryPointId == null && (currentLine.secondBoundaryPointId == null || currentLine.secondBoundaryPointId != pointId))
  97.                 {
  98.                     currentLine.firstBoundaryPointId = pointId;
  99.                     currentLine.modified = true;
  100.                 }
  101.                 else if (currentLine.secondBoundaryPointId == null && (currentLine.firstBoundaryPointId == null || currentLine.firstBoundaryPointId != pointId))
  102.                 {
  103.                     currentLine.secondBoundaryPointId = pointId;
  104.                     currentLine.modified = true;
  105.                 }
  106.                 else if (currentLine.firstBoundaryPointId != pointId && currentLine.secondBoundaryPointId != pointId)
  107.                 {
  108.                     log.Warn("BoundaryLine has both parcelBoundaryPointIds already assigned. ParcelBoundaryLineId=" + currentLine.parcelBoundaryLineId + ", " + currentLine.geometry.ToString());
  109.                     return -1;
  110.                 }
  111.             }
  112.             return pointId;
  113.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement