Skip to content

A script to convert geometry (shapefile, geojson) to a TopoJSON format. This format is useful for visualizing in PowerBI.

License

Notifications You must be signed in to change notification settings

NYCMayorOps/GeometryToTopoJSON

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#######################################

Geometry To Topo JSON Converter

By Steve Scott

#######################################

Converting a geospatial file to a topojson

Why convert to a TopoJSON?

Most geojson files are coordinate based. A topoJSON uses a series of arcs to store its geometry. Why use TopoJSON? Because PowerBI's Shape Map visulaization component only works with TopoJSON files.

requirements

always create a virtual environment to install requirements into

To install requirements in a conda environment:

conda env create -f environment.yml
conda activate topojson-env

To use the Script:

python \Path\To\repo\convert_to_topo.py \path\of\file\to\convert\<filename>.<file extension>

This will generate a file named _topojson.json in the same directory next to the file .

arguments:

'--input_geo_file'

  • type: string ,
  • Input file path to geography. It can be a geojson, a zipped shapefile, or any other geopandas compatable file

'-p', '--precision'

  • type : float
  • default=0.0001
  • Simplification precision of the TopoJSON output in decimal degrees. The default is 0.0001 degrees which is around 8 to 11 meters. Enter 0 to disable simplification.

'-s', '--string_cols'

  • type: list of strings
  • List of columns to convert to string. This may help if you have something like "Police Precinct" which is "1" or "32" which should be a string but is read as a float. This will attempt to coerce it to a str.
  • Note, string columns will raise warnings that it is not supported. It may work on GeoJSON, it won't work on Shapefiles.
  • If the coercion fails the program will still output a topojson, it will ignore this parameter import and cast it automatically to whatever geopandas sees fit.

About

A script to convert geometry (shapefile, geojson) to a TopoJSON format. This format is useful for visualizing in PowerBI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages