def search_index(gps_location, accuracy, index): longitude, latitude = gps_location if accuracy: accuracy = abs(accuracy) dlat = accuracy / METERS_PER_DEGREE latitude_rad = degrees_to_radians(latitude) dlon = accuracy / (METERS_PER_DEGREE * math.cos(latitude_rad)) query_bbox = (longitude - dlon, latitude - dlat, longitude + dlon, latitude + dlat) for registrar_dict in index.intersection(query_bbox, objects="raw"): polygon = registrar_dict["geometry"] square = shapely.geometry.Polygon([ (longitude - dlon, latitude - dlat), (longitude - dlon, latitude + dlat), (longitude + dlon, latitude + dlat), (longitude + dlon, latitude - dlat), ]) if polygon.intersects(square): yield registrar_dict else: query_bbox = (longitude, latitude, longitude, latitude) for registrar_dict in index.intersection(query_bbox, objects="raw"): polygon = registrar_dict["geometry"] point = shapely.geometry.Point(*gps_location) if polygon.contains(point): yield registrar_dict
def find_shape_in_index(shape: BaseGeometry, index): # (minx, miny, maxx, maxy) bounds = shape.bounds lon = [] lat = [] weights = [] for result in index.intersection(bounds, objects="raw"): point = result['point'] rect = result['bbox'] poly = Polygon([(r[0], r[1]) for r in rect]) inters = shape.intersection(poly) # Intersection with bounds might not intersect with detailed poly if inters: weights.append(inters.area) lon.append(point[0]) lat.append(point[1]) lon = np.array(lon) lat = np.array(lat) weights = np.array(weights) weights = weights / np.sum(weights) return GridLookupResults(lon, lat, weights)
def already_present(p): # FIXME: cette recherche vas être quadratique si les intersections # sont importantes, comme à Apatou en Guyane: center = p.centroid.coords[0] for i in index.intersection(center): if p.almost_equals(polygons[i], PARCEL_LIMIT_ALMOST_EQUALS_DECIMAL): return True return False
def find_location(coordinates): coordinates = map(float, coordinates) point = Point(coordinates) for candidate in rtree.intersection(coordinates): polygon = polygons[candidate] if point.within(polygon): return locations[candidate] raise LookupError()
def already_present(p): # FIXME: cette recherche vas être quadratique si les intersections sont importantes, # comme à Apatou en Guyane: center = shapely.geometry.box(*(p.bounds)).centroid.coords[0] for i in index.intersection(center): if p.almost_equals(polygones[i], LIMITE_ALMOST_EQUALS_DECIMAL): return True return False
def search_index(index, validTupl, validated_image_filename): nearHits = list(index.nearest(validTupl, objects=True)) nearHitsId = [str(item.id) + " -- " + item.object for item in nearHits] for h in nearHitsId: print("R-tree near for: " + validated_image_filename + ' matches ' + h) intrHits = list(index.intersection(validTupl, objects=True)) intrHitsId = [str(item.id) + " -- " + item.object for item in intrHits] for h in intrHitsId: print("R-tree intersect for: " + validated_image_filename + ' matches ' + h)
def getEntitiesNearPoint(index, slack, tweet_lat, tweet_lng): try: #note these are for rochester - go to http://www.csgnetwork.com/degreelenllavcalc.html to calculate for a different latitude dX = slack * 0.000012297 dY = slack * 0.000009001 lng_low = tweet_lng - dX lng_high = tweet_lng + dX lat_low = tweet_lat - dY lat_high = tweet_lat + dY intersect = index.intersection( (tweet_lng - dX, tweet_lat - dY, tweet_lng + dX, tweet_lat + dY), objects=True) return [n.object for n in intersect] except KeyError: return []
def getEntitiesNearPoint(index, slack, tweet_lat, tweet_lng): try: #note these are for rochester - go to http://www.csgnetwork.com/degreelenllavcalc.html to calculate for a different latitude dX = slack * 0.000012297 dY = slack * 0.000009001 lng_low = tweet_lng - dX lng_high = tweet_lng + dX lat_low = tweet_lat - dY lat_high = tweet_lat + dY intersect = index.intersection((tweet_lng - dX, tweet_lat - dY, tweet_lng + dX, tweet_lat + dY), objects = True) return [n.object for n in intersect] except KeyError: return []