def _GetGridCellsWithinRadius(self): """ Create a dictionary of {GpGridCell:(nCornerPointsInBound,inBoundPointsWeight)} for top GpGridCell resolution. The weight is a measure of the closeness of contained points to the center point""" stepSize = MAXIMUM_RESOLUTION - self.MaxSearchResolution + 1 self.maxResolutionSearchDic = {} # Iterate through GridPoints the bounding box for latInt in range(self.SWCornerGridPoint.LattitudeInt,self.NWCornerGridPoint.LattitudeInt + stepSize,\ stepSize): for lonInt in range (self.SWCornerGridPoint.LongitudeInt,self.SECornerGridPoint.LongitudeInt + stepSize, stepSize): # Construct a GpGridCell at each GridPoint originPoint = GpGridPoint() originPoint.InitFromIntLatLon(latInt,lonInt,self.MaxSearchResolution) gridCell = GpGridCell() gridCell.InitFromGridPoint(originPoint) cellCornerPoints = gridCell.ListCornerPointsShort() nCornerPointsInBound = 0 inBoundPointsWeight = 0.0 for cell in cellCornerPoints: if cell in self.gpGridPointsInBoundsDic: nCornerPointsInBound += 1 inBoundPointsWeight += self.gpGridPointsInBoundsDic[cell] if nCornerPointsInBound > 0: self.maxResolutionSearchDic[gridCell.ToShortString()] = \ CellSearchData(nCornerPointsInBound,inBoundPointsWeight)
def ListChildCellsShort(self): """ Return a list of the 4 child cells in GpGridPointShortString format""" # Get the origin point of child cell that is co-located with the Origin Point parentResolution = self.Origin.Resolution if parentResolution == MAXIMUM_RESOLUTION: logging.debug("GpGridCell is at maximum resolution %d, so there are no child cells" %\ parentResolution) return [] childOriginGridPoint = GpGridPoint() childOriginGridPoint.InitFromIntLatLon(self.Origin.LattitudeInt,self.Origin.LongitudeInt,\ self.Origin.Resolution +1) # Create a GpGridCell at the child origin swChildGridCell = GpGridCell() swChildGridCell.InitFromGridPoint(childOriginGridPoint) # The 4 corner points of the SW child GridCell are the origins of the 4 child cells return swChildGridCell.ListCornerPointsShort()
def _GetGridPointsWithinRadius(self): """ Create a dictionary of GpGridPoints within distanceMeters from a center point. Scan through the GridPoints in the bounding box region. Add all in-bound points to the dictionary. Associate a weight with each GridPoint that is inversely proportional to its distance from the center point. """ radiusMeters = self.SearchBoundaryMeters self.gpGridPointsInBoundsDic = {} stepSize = MAXIMUM_RESOLUTION - self.MaxSearchResolution + 1 for latInt in range(self.SWCornerGridPoint.LattitudeInt,self.NWCornerGridPoint.LattitudeInt + stepSize, \ stepSize): for lonInt in range (self.SWCornerGridPoint.LongitudeInt,self.SECornerGridPoint.LongitudeInt + stepSize, \ stepSize): gridPoint = GpGridPoint() gridPoint.InitFromIntLatLon(latInt,lonInt,self.MaxSearchResolution) gpPoint = GpPoint(gridPoint.LattitudeFloat,gridPoint.LongitudeFloat) distanceMeters = GpMath.distance(self.CenterGpPoint,gpPoint) if distanceMeters <= radiusMeters: weight = self._WeightGridPointByDistance(distanceMeters) self.gpGridPointsInBoundsDic[gridPoint.ToShortString()] = weight