public static Collection <Feature> GetFeaturesIntersecting(this QueryTools queryTools, BaseShape targetShape, IEnumerable <string> returningColumnNames, bool useSqlType) { Collection <Feature> returnFeatures = null; if (useSqlType) { returnFeatures = new Collection <Feature>(); RectangleShape boundingBox = targetShape.GetBoundingBox(); Collection <Feature> allPossibleFeatures = queryTools.GetFeaturesInsideBoundingBox(boundingBox, returningColumnNames); foreach (Feature feature in allPossibleFeatures) { BaseShape sourceShape = feature.GetShape(); sourceShape = SqlTypesGeometryHelper.MakeValid(sourceShape); targetShape = SqlTypesGeometryHelper.MakeValid(targetShape); bool intersects = SqlTypesGeometryHelper.Intersects(sourceShape, targetShape); if (intersects) { returnFeatures.Add(feature); } } } else { returnFeatures = queryTools.GetFeaturesIntersecting(targetShape, returningColumnNames); } return(returnFeatures); }
public static ulong GetLocation(RectangleShape extent, BaseShape shape, int level) { RectangleShape extentBoundingBox = SquaredExtent(extent); RectangleShape shapeBoundingBox = shape.GetBoundingBox(); ulong location = 1; if (shapeBoundingBox.IsWithin(extentBoundingBox)) { int currentlevel = 1; while (currentlevel < level) { RectangleShape upperLeft = GetUpperLeftQuater(extentBoundingBox); RectangleShape uppperRight = GetUpperRightQuater(extentBoundingBox); RectangleShape lowerLeft = GetLowerLeftQuater(extentBoundingBox); RectangleShape lowerRight = GetLowerRightQuater(extentBoundingBox); if (shapeBoundingBox.IsWithin(upperLeft)) { location = (location << 1) | 1; currentlevel++; extentBoundingBox = upperLeft; } else if (shapeBoundingBox.IsWithin(uppperRight)) { location = (location << 2) | 1; currentlevel++; extentBoundingBox = uppperRight; } else if (shapeBoundingBox.IsWithin(lowerLeft)) { location = (location << 3) | 1; currentlevel++; extentBoundingBox = lowerLeft; } else if (shapeBoundingBox.IsWithin(lowerRight)) { location = (location << 4) | 1; currentlevel++; extentBoundingBox = lowerRight; } else { break; } } } return(location); }
public static int GetAppropriateLevel(RectangleShape extent, BaseShape shape) { RectangleShape currentBoundingBox = SquaredExtent(extent); RectangleShape shapeBoundingBox = shape.GetBoundingBox(); int level = 0; if (shapeBoundingBox.IsWithin(currentBoundingBox)) { while (true) { level++; RectangleShape upperLeft = GetUpperLeftQuater(currentBoundingBox); RectangleShape uppperRight = GetUpperRightQuater(currentBoundingBox); RectangleShape lowerLeft = GetLowerLeftQuater(currentBoundingBox); RectangleShape lowerRight = GetLowerRightQuater(currentBoundingBox); if (shapeBoundingBox.IsWithin(upperLeft)) { currentBoundingBox = upperLeft; } else if (shapeBoundingBox.IsWithin(uppperRight)) { currentBoundingBox = uppperRight; } else if (shapeBoundingBox.IsWithin(lowerLeft)) { currentBoundingBox = lowerLeft; } else if (shapeBoundingBox.IsWithin(lowerRight)) { currentBoundingBox = lowerRight; } else { break; } } } return level; }
public static int GetAppropriateLevel(RectangleShape extent, BaseShape shape) { RectangleShape currentBoundingBox = SquaredExtent(extent); RectangleShape shapeBoundingBox = shape.GetBoundingBox(); int level = 0; if (shapeBoundingBox.IsWithin(currentBoundingBox)) { while (true) { level++; RectangleShape upperLeft = GetUpperLeftQuater(currentBoundingBox); RectangleShape uppperRight = GetUpperRightQuater(currentBoundingBox); RectangleShape lowerLeft = GetLowerLeftQuater(currentBoundingBox); RectangleShape lowerRight = GetLowerRightQuater(currentBoundingBox); if (shapeBoundingBox.IsWithin(upperLeft)) { currentBoundingBox = upperLeft; } else if (shapeBoundingBox.IsWithin(uppperRight)) { currentBoundingBox = uppperRight; } else if (shapeBoundingBox.IsWithin(lowerLeft)) { currentBoundingBox = lowerLeft; } else if (shapeBoundingBox.IsWithin(lowerRight)) { currentBoundingBox = lowerRight; } else { break; } } } return(level); }
public static ulong GetLocation(RectangleShape extent, BaseShape shape, int level) { RectangleShape extentBoundingBox = SquaredExtent(extent); RectangleShape shapeBoundingBox = shape.GetBoundingBox(); ulong location = 1; if (shapeBoundingBox.IsWithin(extentBoundingBox)) { int currentlevel = 1; while (currentlevel < level) { RectangleShape upperLeft = GetUpperLeftQuater(extentBoundingBox); RectangleShape uppperRight = GetUpperRightQuater(extentBoundingBox); RectangleShape lowerLeft = GetLowerLeftQuater(extentBoundingBox); RectangleShape lowerRight = GetLowerRightQuater(extentBoundingBox); if (shapeBoundingBox.IsWithin(upperLeft)) { location = (location << 1) | 1; currentlevel++; extentBoundingBox = upperLeft; } else if (shapeBoundingBox.IsWithin(uppperRight)) { location = (location << 2) | 1; currentlevel++; extentBoundingBox = uppperRight; } else if (shapeBoundingBox.IsWithin(lowerLeft)) { location = (location << 3) | 1; currentlevel++; extentBoundingBox = lowerLeft; } else if (shapeBoundingBox.IsWithin(lowerRight)) { location = (location << 4) | 1; currentlevel++; extentBoundingBox = lowerRight; } else { break; } } } return location; }
public static Collection<QuadCell> GetIntersectingCells(RectangleShape extent, BaseShape shape, int startLevel, int endLevel) { RectangleShape extentBoundingBox = SquaredExtent(extent); RectangleShape shapeBoundingBox = shape.GetBoundingBox(); Collection<QuadCell> result = new Collection<QuadCell>(); if (shapeBoundingBox.Intersects(extentBoundingBox)) { ulong location = GetLocation(extentBoundingBox, shape, int.MaxValue); ulong reversedResult = Reverse(location); ulong temporaryValue = reversedResult; temporaryValue >>= 1; int locationLength = GetLevelsCount(temporaryValue); if (startLevel <= locationLength) { int index = startLevel; while (index <= endLevel) { ulong temporaryLocation = temporaryValue; if (index <= locationLength) { MovePositionByIndex(ref temporaryLocation, index); if (locationLength > 1) { result.Add(GetCellByLocation(extentBoundingBox, temporaryLocation)); } else { result.Add(GetCellByLocation(extentBoundingBox, 0)); } } index++; } } if (endLevel > locationLength) { Queue<ulong> locationsToProcess = new Queue<ulong>(); locationsToProcess.Enqueue(location); while (locationsToProcess.Count > 0) { ulong currentLocation = locationsToProcess.Dequeue(); for (int k = 1; k <= 4; k++) { ulong newLocation = (currentLocation << k) | 1; result.Add(GetCellByLocation(extentBoundingBox, newLocation)); int newLocationsCount = GetLevelsCount(newLocation); if (newLocationsCount < endLevel) { locationsToProcess.Enqueue(newLocation); } } } } } //if (result.Count == 0) //{ // result.Add(GetCellByLocation(extentBoundingBox, "01")); // result.Add(GetCellByLocation(extentBoundingBox, "02")); // result.Add(GetCellByLocation(extentBoundingBox, "03")); // result.Add(GetCellByLocation(extentBoundingBox, "04")); //} return result; }
public static Collection <QuadCell> GetIntersectingCells(RectangleShape extent, BaseShape shape, int startLevel, int endLevel) { RectangleShape extentBoundingBox = SquaredExtent(extent); RectangleShape shapeBoundingBox = shape.GetBoundingBox(); Collection <QuadCell> result = new Collection <QuadCell>(); if (shapeBoundingBox.Intersects(extentBoundingBox)) { ulong location = GetLocation(extentBoundingBox, shape, int.MaxValue); ulong reversedResult = Reverse(location); ulong temporaryValue = reversedResult; temporaryValue >>= 1; int locationLength = GetLevelsCount(temporaryValue); if (startLevel <= locationLength) { int index = startLevel; while (index <= endLevel) { ulong temporaryLocation = temporaryValue; if (index <= locationLength) { MovePositionByIndex(ref temporaryLocation, index); if (locationLength > 1) { result.Add(GetCellByLocation(extentBoundingBox, temporaryLocation)); } else { result.Add(GetCellByLocation(extentBoundingBox, 0)); } } index++; } } if (endLevel > locationLength) { Queue <ulong> locationsToProcess = new Queue <ulong>(); locationsToProcess.Enqueue(location); while (locationsToProcess.Count > 0) { ulong currentLocation = locationsToProcess.Dequeue(); for (int k = 1; k <= 4; k++) { ulong newLocation = (currentLocation << k) | 1; result.Add(GetCellByLocation(extentBoundingBox, newLocation)); int newLocationsCount = GetLevelsCount(newLocation); if (newLocationsCount < endLevel) { locationsToProcess.Enqueue(newLocation); } } } } } //if (result.Count == 0) //{ // result.Add(GetCellByLocation(extentBoundingBox, "01")); // result.Add(GetCellByLocation(extentBoundingBox, "02")); // result.Add(GetCellByLocation(extentBoundingBox, "03")); // result.Add(GetCellByLocation(extentBoundingBox, "04")); //} return(result); }