class GpGridCell(): Origin = GpGridPoint() def InitFromGridPoint(self,gpGridPoint): self.Origin.InitFromIntLatLon(gpGridPoint.LattitudeInt,gpGridPoint.LongitudeInt,gpGridPoint.Resolution) def InitFromCoordinates(self, lattitude, longitude, resolution): self.Origin.InitFromCoordinates( lattitude, longitude, resolution) def InitFromShortCellString(self, cellShortString, resolution): self.Origin = GpGridPoint() self.Origin.InitFromShortString(cellShortString, resolution) def ToLongString(self): """ Return a long string representation of this GridCell. The cell is identified by the long string representation of its origin.""" return self.Origin.ToLongString() def ToShortString(self): """ Return a short string representation of this GridCell. The cell is identified by the short string representation of its origin along with its resolution.""" return self.Origin.ToShortString() def ListCornerPointsShort(self): """Return a list of the four corner points for this cell in the short string format. The points are identified by their short string representation""" cellList= [] cellList.append(self.Origin.ToShortString()) nwPoint = self.Origin.GetAdjacentPoint('N') cellList.append(nwPoint.ToShortString()) nePoint = nwPoint.GetAdjacentPoint('E') cellList.append(nePoint.ToShortString()) sePoint = nePoint.GetAdjacentPoint('S') cellList.append(sePoint.ToShortString()) return cellList 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