Ejemplo n.º 1
0
def create_thwing():

    proto = places_data_manager.min_place_dict

    place = proto.copy()
    place['name'] = 'Thwing Student Center'
    place['type'] = 'CampusBuilding'
    place['geo_coordinates'] = Point((-81.608199, 41.507386))
    place['senti_score'] = 6
    place['rating_average'] = 4
    place['rating_count'] = 14
    return place
def get_points(camp_id): #update name to id after testing
    """will return a set of coordinates"""

    campsite = session.query(Campsite).filter_by(campsite_id=camp_id).first()
    lat = campsite.lat
    lon = campsite.lon
    if lon > 0:
        lon = lon * -1
    point = Point((lon, lat))
    session.close()

    return point
Ejemplo n.º 3
0
def create_stop_location_detail(title, latitude, longitude, index,
                                route_index):
    point = Point([longitude, latitude])
    properties = {
        "title": title,
        'icon': "campsite",
        'marker-color': '#6B1A74',
        'marker-symbol': index,
        'route_index': route_index
    }
    feature = Feature(geometry=point, properties=properties)
    return feature
Ejemplo n.º 4
0
def create_veale():

    proto = places_data_manager.min_place_dict

    place = proto.copy()
    place['name'] = 'Veale Athletic Center'
    place['type'] = 'CampusBuilding'
    place['geo_coordinates'] = Point((-81.606295, 41.500936))
    place['senti_score'] = 7
    place['rating_average'] = 4
    place['rating_count'] = 45
    return place
Ejemplo n.º 5
0
def create_bingham_lounge():

    proto = places_data_manager.min_place_dict

    place = proto.copy()
    place['name'] = 'Bingham Lounge'
    place['type'] = 'StudyLocation'
    place['geo_coordinates'] = Point((-81.606955, 41.502412))
    place['senti_score'] = 7
    place['rating_average'] = 3
    place['rating_count'] = 81
    return place
Ejemplo n.º 6
0
def create_ksl():

    proto = places_data_manager.min_place_dict

    place = proto.copy()
    place['name'] = 'Kelvin Smith Library'
    place['type'] = 'StudyLocation'
    place['geo_coordinates'] = Point((-81.609578, 41.507348))
    place['senti_score'] = -9
    place['rating_average'] = 4.1
    place['rating_count'] = 20
    return place
Ejemplo n.º 7
0
def create_glennan_lounge():

    proto = places_data_manager.min_place_dict

    place = proto.copy()
    place['name'] = 'Glennan Lounge'
    place['type'] = 'StudyLocation'
    place['geo_coordinates'] = Point((-81.606998, 41.501553))
    place['senti_score'] = 1
    place['rating_average'] = 3
    place['rating_count'] = 42
    return place
Ejemplo n.º 8
0
def create_strosacker():

    proto = places_data_manager.min_place_dict

    place = proto.copy()
    place['name'] = 'Strosacker Auditorium'
    place['type'] = 'CampusBuilding'
    place['geo_coordinates'] = Point((-81.607330, 41.503304))
    place['senti_score'] = 8
    place['rating_average'] = 4.1
    place['rating_count'] = 18
    return place
Ejemplo n.º 9
0
def get_all_visits_user_geojson(user_id):
    visits = user_traces_db.load_user_all_visits_per_place(user_id)
    features = []
    for v in visits:
        features.append(
            Feature(geometry=Point((v['lon'], v['lat'])),
                    properties={
                        "dur": v['dur'],
                        "nb_visits": v['nb_visits']
                    }))

    return FeatureCollection(features)
Ejemplo n.º 10
0
def create_nord():

    proto = places_data_manager.min_place_dict

    place = proto.copy()
    place['name'] = 'Nord Hall'
    place['type'] = 'CampusBuilding'
    place['geo_coordinates'] = Point((-81.607824, 41.502485))
    place['senti_score'] = 8.66
    place['rating_average'] = 0
    place['rating_count'] = 0
    return place
Ejemplo n.º 11
0
def create_yost():

    proto = places_data_manager.min_place_dict

    place = proto.copy()
    place['name'] = 'Yost Hall'
    place['type'] = 'CampusBuilding'
    place['geo_coordinates'] = Point((-81.608950, 41.503553))
    place['senti_score'] = -3.55
    place['rating_average'] = 3.9
    place['rating_count'] = 21
    return place
Ejemplo n.º 12
0
def create_white():

    proto = places_data_manager.min_place_dict

    place = proto.copy()
    place['name'] = 'White Building'
    place['type'] = 'CampusBuilding'
    place['geo_coordinates'] = Point((-81.607416, 41.501922))
    place['senti_score'] = 4.20
    place['rating_average'] = 2.6
    place['rating_count'] = 5
    return place
Ejemplo n.º 13
0
def write_geojson(file, output_file):
    features = []
    for i, row in file.iterrows():
        if i % 50_000 == 0:
            logger.info('Processed %s / %s adresses', i, len(file))
        point = Point((row['EPSG:4326_lon'], row['EPSG:4326_lat']))
        properties = {
            key: val
            for key, val in row.to_dict().items()
            if not pd.isnull(val) and 'EPSG:' not in key
        }
        features.append(Feature(geometry=point, properties=properties))
Ejemplo n.º 14
0
def create_geojson_feature(point, properties={}, feature_id=None):
    """
    point is a (lon, lat) tuple,
    properties is a dictionary (e.g. {'country': 'Spain})
    """

    gj_point = Point(point)
    gj_feature = Feature(geometry=gj_point,
                         properties=properties,
                         id=feature_id)

    return gj_feature
Ejemplo n.º 15
0
def event_to_geojson(x,y,userID,eventID,firstName,lastName,eventName,startTime,endTime,description,attendance,attending):
    return Feature(geometry=Point((x,y)),\
    properties={"userID":userID,\
    "eventID":eventID,\
    "firstName":firstName,\
    "lastName":lastName,\
    "eventName":eventName,\
    "startTime":startTime,\
    "endTime":endTime,\
    "description":description,\
    "attendance":attendance,\
    "attending":attending})
Ejemplo n.º 16
0
def addpts(pt1, pt2, wt):
    lat1 = pt1['geometry']['coordinates'][1]
    lat2 = pt2['geometry']['coordinates'][1]

    lon1 = pt1['geometry']['coordinates'][0]
    lon2 = pt2['geometry']['coordinates'][0]

    newlat = (lat1 * (1 - wt)) + lat2 * wt
    newlon = (lon1 * (1 - wt)) + lon2 * wt

    newpt = Feature(geometry=Point((newlon, newlat)))
    return newpt
Ejemplo n.º 17
0
def test_boolean_point_in_polygon():
    point = Feature(geometry=Point((-77, 44)))
    polygon = Feature(
        geometry=MultiPolygon(
            [
                ([(-81, 41), (-81, 47), (-72, 47), (-72, 41), (-81, 41)],),
                ([(3.78, 9.28), (-130.91, 1.52), (35.12, 72.234), (3.78, 9.28)],),
            ]
        )
    )
    bpp = boolean_point_in_polygon(point, polygon)
    assert bpp == True
Ejemplo n.º 18
0
def create_wade_commons():

    proto = places_data_manager.min_place_dict

    place = proto.copy()
    place['name'] = 'Wade Commons'
    place['type'] = 'StudyLocation'
    place['geo_coordinates'] = Point((-81.605211, 41.513051))
    place['senti_score'] = 12
    place['rating_average'] = 2
    place['rating_count'] = 17
    return place
Ejemplo n.º 19
0
def get_pm10_points_as_geojson(source):
    pm10_data = get_pm10_data(source)

    features = []
    for index, measurement in enumerate(pm10_data['measurements']):
        polygon = Point(
            (pm10_data['longitudes'][index], pm10_data['latitudes'][index]))
        features.append(
            Feature(geometry=polygon, properties={"value": measurement}))

    feature_collection = FeatureCollection(features)
    return feature_collection
Ejemplo n.º 20
0
    def create(self, validated_data):

        plan_file_json = validated_data['plan_file_json']
        plan_file = self.parse_and_validate_plan_file(
            plan_file_json=plan_file_json)
        all_geo_json_features = []
        for mission_item in plan_file.Mission.Items:
            if isinstance(mission_item, SimpleMissionItem):
                if mission_item.Params[5] and mission_item.Params[4]:
                    p = Point([mission_item.Params[5], mission_item.Params[4]])
                    all_geo_json_features.append(Feature(geometry=p))

            elif isinstance(mission_item, ComplexMissionItem):

                if mission_item.Polygon != 0:
                    all_polygon_points = []
                    for polygon_coordinates in mission_item.Polygon:
                        p = Point(
                            [polygon_coordinates[1], polygon_coordinates[0]])
                        all_polygon_points.append(p)

                    polygon = Polygon(all_polygon_points)

                    all_geo_json_features.append(Feature(geometry=polygon))

                if mission_item.Polyline != 0:
                    all_polyline_points = []
                    for polyline_coordinates in mission_item.Polyline:
                        p = Point(
                            [polyline_coordinates[1], polyline_coordinates[0]])

                        all_polyline_points.append(p)
                    polyline = LineString(all_polyline_points)
                    all_geo_json_features.append(Feature(geometry=polyline))

        feature_collection = FeatureCollection(all_geo_json_features)
        validated_data['geo_json'] = json.loads(
            geojson.dumps(feature_collection))

        return super(FlightPlanSerializer, self).create(validated_data)
Ejemplo n.º 21
0
    def _getStreets(regions: FeatureCollection) -> MultiLineString:
        """Collect a set of Ways (from OSM) and convert them to a MultiLineString"""

        overpassQueryUrl = OSMMiner._createCollectStreetsQuery(regions)

        OSMMiner._lock.acquire()
        #write_to_log("Rate limit %d, current queries: %d \n" % (OSMMiner._rateLimit, OSMMiner._currentQueries))
        write_to_log(f'OSMMiner._OSMServerURL: {OSMMiner._OSMServerURL}')
        #write_to_log(f'overpassQueryUrl: {overpassQueryUrl}')
        
        while OSMMiner._currentQueries >= OSMMiner._rateLimit:
            time.sleep(1)
        OSMMiner._waitForAvailableSlots()
        OSMMiner._currentQueries += 1
        ##DEBUG
        #print("added query: %d\n" % OSMMiner._currentQueries)
        OSMMiner._lock.release()
        jsonString = requests.get(overpassQueryUrl).content
        OSMMiner._currentQueries -= 1
        ##DEBUG
        #print("removed query: %d\n" % OSMMiner._currentQueries)
        try:
            #TODO: Treat cases in which the OSM server fails
            osmResult = OSMResult.fromJsonString(jsonString)
        except:
            write_to_log("Error while parsing overpass message. Message sample: %s" % jsonString[:100])
            raise AttributeError("Invalid jsonString")
        streetSegments = {}
        
        # Data needs to be sorted before being grouped, otherwise
        # the same group may appear multiple times
        data = sorted(osmResult.Ways.values(), key=lambda x: x.tags.get('name'))
        g = groupby(data, lambda x: x.tags.get('name'))
        for streetName, group in g:
            nodesList = [x.nodes for x in group]
            OSMMiner._mergeWays(nodesList)
            if streetName in streetSegments:
                streetSegments[streetName] = streetSegments[streetName] + nodesList
            else:
                streetSegments[streetName] = nodesList
        featuresList = []
        for streetName in streetSegments:
            featuresList.append(
                Feature(id=streetName, 
                    properties={'name':streetName}, 
                    geometry=MultiLineString([LineString([
                    Point([osmResult.Nodes[n].lon, 
                    osmResult.Nodes[n].lat]) for n in s]) 
                    for s in streetSegments[streetName]]))
            )
           
        return FeatureCollection(featuresList, crs=OSMMiner._crs)
Ejemplo n.º 22
0
def to_geojson_feature(dx: DictAny, properties: Optional[DictAny]=None) -> Feature:
    # More of this raw data from google should be pushed down
    # this ix is perhaps an issue given that the data source isn't
    # persisting UUIDs across updates.
    g = dx["geometry"]["location"]
    coords = g["lng"], g["lat"]
    pt = Point(coords)

    keys = ("formatted_address", "place_id", "plus_code")
    if properties is not None:
        for key in keys:
            properties[key] = dx.get(key)
    return Feature(geometry=pt, properties=properties)
Ejemplo n.º 23
0
    def transform(self, values):
        features = []
        for value in values:
            type = value['other_tags'].get('seamark:type')
            features.append(
                Feature(geometry=Point(loads(value['geom'])),
                        properties={
                            'osm_ref': value['osm_id'] + 'n',
                            'type':
                            'minor' if type == 'light_minor' else 'major'
                        }))

        return features
Ejemplo n.º 24
0
def vaccine_to_geojson(data):
    geo = []
    for k, v in data.items():
        geo.append(
            Feature(geometry=Point(
                [float(str(v['longitude'])),
                 float(str(v['latitude']))]),
                    properties={
                        'name': v['name'],
                        'address': v['address']
                    }))
    feature_collection = FeatureCollection(geo)
    return feature_collection
def tweetToFeature(tweet):
    """
    Convert a tweet to a GeoJSON Feature
    """
    point = Point(tweet['coordinates']['coordinates'])
    properties = {
        'text': tweet['text'],
        'sentiment': tweet['polarity'],
        'tokens': tweet['tokens']
    }
    feature = Feature(geometry=point, id=tweet['id'], properties=properties)

    return feature
Ejemplo n.º 26
0
    def transform(self, values):
        for value in values:
            polygon = loads(value['geom'])
            coordinates = polylabel(polygon['coordinates'][0])
            value['geom'] = Point(coordinates,
                                  crs={
                                      'type': 'name',
                                      'properties': {
                                          'name': 'EPSG:3857'
                                      }
                                  })

        return values
Ejemplo n.º 27
0
Archivo: gjson.py Proyecto: QilinGu/geo
    def writePointsFeatureCollection(self,latlons,colors,varname):
        featureCollection = {'features':[]}
        print latlons.shape,colors.shape
        for latlon,color in zip(latlons,colors):
            hexcolor = self.rgb2hex(color)
            st = {"fillcolor": hexcolor, "radius":40}
            #st = {"fillOpacity":0.3, "fillcolor": hexcolor, "color":hexcolor,"radius":40, "stroke":False}
            pr = {"style":st}
            ft = Feature(geometry=Point(latlon.tolist()), properties=pr)
            featureCollection['features'].append(ft)

        print>>self.outfile, "var %s = "%(varname)
        geojson.dump(featureCollection,self.outfile)
    async def test_search_partner_by_coordinate_be_none_when_no_partner_found(
            self, backend):
        partner = partner_adega_ze_ambev()
        coordinate = [0, 0]

        await backend.save(partner)

        point = Point(coordinate)

        found_partner = await backend.search_nearest_by_coordinate(
            coordinate=point)

        assert found_partner is None
Ejemplo n.º 29
0
def square(bbox: list):
    """
    Takes a bounding box and calculates the minimum square bounding box that would contain
    the input.

    :param bbox: Bounding box extent in west, south, east, north order
    :return: A square surrounding bbox

    Example:

    >>> from turfpy.measurement import square
    >>> bbox = [-20, -20, -15, 0]
    >>> square(bbox)
    """
    west = bbox[0]
    south = bbox[1]
    east = bbox[2]
    north = bbox[3]

    horizontal_distance = distance(Feature(geometry=Point(bbox[0:2])),
                                   Feature(geometry=Point((east, south))))
    vertical_distance = distance(Feature(geometry=Point(bbox[0:2])),
                                 Feature(geometry=Point((west, north))))
    if horizontal_distance >= vertical_distance:
        vertical_midpoint = (south + north) / 2
        return [
            west,
            vertical_midpoint - ((east - west) / 2),
            east,
            vertical_midpoint + ((east - west) / 2),
        ]
    else:
        horizontal_midpoint = (west + east) / 2
        return [
            horizontal_midpoint - ((north - south) / 2),
            south,
            horizontal_midpoint + ((north - south) / 2),
            north,
        ]
Ejemplo n.º 30
0
 def get(self, lng, lat):
     try:
         lnglat = map(float, (lng, lat))
     except Exception:
         raise tornado.web.HTTPError(400)
     sampler = TileSampler()
     pixel = CoordSystem.lnglat_to_pixel(lnglat)
     print 'Getting elevation at lng,lat:%s,%s %s,%s:' % (lng, lat, pixel[0], pixel[1])
     value = yield sampler.sample_pixel(pixel)
     lnglat = CoordSystem.pixel_to_lnglat(pixel)
     self.write_geojson(Feature(geometry=Point(lnglat), properties={
         "elevation":float(value)
     }))