Skip to main content

Faster, cheaper way of pulling Places API data for large geographies

Project description

saturated-places

PyPI version

A python package for effeciently downloading Point of Interest (POI) data from Google Places API for large geographies. Currently, this is done by creating a fishnet grid within a custom polygon and running Delauny Triangulation for each grid cell till the API result is saturated i.e the API returns < 60 results.

We are open to contributors who wish to further optimize this logic.

Installation

You can either go the latest release, download the tarball to your local directory and run:

pip install saturated-places-X.Y.Z.tar.gz

Or you can go simply download it from PyPi by running:

pip install saturatedplaces

Usage


import saturatedplaces as sp
from shapely.geometry import Polygon
import json

# Put Google API key here with Places API service enabled.
api_key = "#######"


# Custom GeoJson created using geojson.io
with open('lahore_sample.geojson','r') as file:
    poly = json.load(file)


# Convert GeoJson coordinates feature into shapely.geometry.Polygon object.
# This is important since later functions only accepts this data type.
poly = poly['features'][0]['geometry']['coordinates'][0]
poly = Polygon(poly)


# resolution determines the space between each Point of the mesh. The same variable 
# is also used in the 'radius' parameter for the Places API call, as used the saturate
# function. You could set this variable independently for both get_grid_from_poly and
# and saturate function.
resolution = 500

# Creates a mesh of equally spaced points within a polygon 'poly', resolution controls
# distance between each point of the mesh.
mesh = sp.get_grid_from_poly(poly=poly,resolution=resolution)

# Generates a fishnet grid using the mesh of point generated using mesh get_grid_from_poly function
vor_gpd = sp.generate_fishnet(mesh,poly)


# Runs saturation algorithm to return a dataframe with places data for area within a polygon.
places_df = sp.saturate(grid_df=vor_gpd,boundary_poly=poly,
                        fp_working_file='working.shp',
                        fp_outpt='final.pkl',
                        api_request_limit=2000,
                        api_key=api_key,
                        resolution = resolution)

# Saves places data as flat csv file.
places_df.to_csv('places_data.csv',index=False)


Contribution

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. I will also be creating issues to chalk out what features, or improvements need to be worked on next. Feel free to pick up any one of these issues after aligning.

For any queries feel free to reach out to hishamsajid113@gmail.com or drop a DM @hishamsajid

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

saturatedplaces-0.1.2.tar.gz (9.0 kB view details)

Uploaded Source

File details

Details for the file saturatedplaces-0.1.2.tar.gz.

File metadata

  • Download URL: saturatedplaces-0.1.2.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.11

File hashes

Hashes for saturatedplaces-0.1.2.tar.gz
Algorithm Hash digest
SHA256 bde28e6351308bc1dcef5410f60be4899d52cad62963af8a4a7796dd6e1ddee3
MD5 0797f259500d13ba98e8fa18f353445c
BLAKE2b-256 12b2fa066a6710fa54640b2df7dd8e925eeb82b20aa1e0a5dc0e72aa209b3596

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page