def get_average_prices(ad_type, asset_type):
    qfilter = {'ad_type': ad_type, 'asset_type': asset_type}
    prices = session.execute(
        'SELECT postcode, avg_price FROM inmosig_average_prices WHERE ad_type = :ad_type AND '
        'asset_type = :asset_type', qfilter)

    gdf = GeoDataFrame(columns=['geometry', 'price', 'postcode'])
    for price in prices.fetchall():
        postcode = postcode_dao.search_by_postcode(price[0])
        if postcode is not None:
            gdf = gdf.append(
                {
                    'geometry': to_shape(postcode.geom),
                    'price': float(price[1]),
                    'postcode': price[0]
                },
                ignore_index=True)

    return gdf
Esempio n. 2
0
postcode_dao = PostcodeDAO(session)
way_dao = WayDAO(session)

# Representación de las calles con GeoSeries
# Extraemos todas las calles
ways = []
for way in way_dao.getAll():
    ways.append(to_shape(way.geom))
wgs = GeoSeries(ways)
base = wgs.plot(color="blue")

qfilter = {'ad_type': 'RENT', 'asset_type': 'GARAGE'}
prices = session.execute(
    'SELECT postcode, avg_price FROM inmosig_average_prices WHERE ad_type = :ad_type AND '
    'asset_type = :asset_type', qfilter)

gdf = GeoDataFrame(columns=['geometry', 'price', 'postcode'])
for price in prices.fetchall():
    postcode = postcode_dao.search_by_postcode(price[0])
    if postcode is not None:
        gdf = gdf.append(
            {
                'geometry': to_shape(postcode.geom),
                'price': float(price[1]),
                'postcode': price[0]
            },
            ignore_index=True)

gdf.head()
gdf.plot(ax=base, column='price', cmap='OrRd', scheme="quantiles", legend=True)
plt.show()