Skip to main content

Top-level package for TopoJoin.

Project description

https://img.shields.io/pypi/v/topojoin.svg https://img.shields.io/travis/SimmonsRitchie/topojoin.svg Documentation Status

A lightweight utility to join CSV data to a topojson file. Produces a new topojson file with CSV properties added to the properties of each feature.

Install

pip install topojoin

Basic usage

Command line

In the command line, enter the topojoin command followed by the path to your topojson file and your CSV file.

By default TopoJoin will assume both files have a common field called ‘id’ that can be joined.

topojoin example.json example.csv

>> Joining example.csv to example.json...
>> CSV key 'id' will be joined with topojson key 'id'
>> Joined data saved to: joined.json

To define the join keys, use the ‘-tk’ option for the key in your topojson file and the ‘-ck’ option for the key in your CSV file:

topojoin -tk GEOID -ck fips example.json example.csv

>> Joining example.csv to example.json...
>> CSV key 'fips' will be joined with topojson key 'GEOID'
>> Joined data saved to: joined.json

Programmatic

If you prefer, you can also import and call TopoJoin from a python script:

from topojoin.topojoin import TopoJoin

tj = TopoJoin("./example.json", "./example.csv", topo_key="GEOID", csv_key="fips")
topojson_data = tj.join()

Or, to write to a file:

from topojoin.topojoin import TopoJoin

tj = TopoJoin("./example.json", "./example.csv", topo_key="GEOID", csv_key="fips")
tj.join("joined.json")

Advanced usage

Command line

TopoJoin’s actions can be modified in a number of ways by passing optional arguments. Here are its available options:

-tk, --topokey TEXT

Key in CSV file that will be used to join with CSV file [default: id]

-ck, --csvkey TEXT

Key in CSV file that will be used to join with topojson file [default: id]

-cp, --csv_props TEXT

Comma separated list of fields in CSV file to merge to each topojson feature (eg: name,population,net_income). Defaults to including all fields in CSV file.

-o, --output_path TEXT

Output path of joined topojson file. Defaults to current working directory.

-q, --quiet

Disables stdout during program run

--version

Show the version and exit.

--help

Show this message and exit.

For example:

topojoin -tk GEOID -ck fips -o "mydir/my-custom-filename.json" example.json example.csv

TO DO

  • Prefix CSV keys if key name is already present in topojson props.

  • Raise exception or prompt if CSV file has duplicate values in column specified by csv_key.

Alternatives

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

topojoin-0.3.1.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

topojoin-0.3.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file topojoin-0.3.1.tar.gz.

File metadata

  • Download URL: topojoin-0.3.1.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.5 Linux/5.3.0-1032-azure

File hashes

Hashes for topojoin-0.3.1.tar.gz
Algorithm Hash digest
SHA256 7b95d85d5a533dc9bd04a954eba37f8b3bb1e472d6877c4d908b1cbf65cd782c
MD5 9835903bce7fd6a7336b7c4ee500e1cd
BLAKE2b-256 5df594bbf835706eb6de4f360a2b09c329bef80cf07833f51f9c25ee84db249e

See more details on using hashes here.

File details

Details for the file topojoin-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: topojoin-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.5 Linux/5.3.0-1032-azure

File hashes

Hashes for topojoin-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ac42ed441bf6f7682690f035e6d37c9ee25d257b5e9191c940c30b688bbb4c3f
MD5 f12d302ea33faadebfd17d6d48f5c2a8
BLAKE2b-256 388cdfd4b432285f606e5c1da9c4f318c0f3ef23b2277b492d174e6234a5224d

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