Methods for Calculating GeoJSON object centroids.
- Allows users to calculate geoJSON centroids and output them to JSON file
This project is organized in the following manner:
Root directory: Contains all code needed to run the GeoJSON Centroid Calculator.
- centroidcalculator.py: File containing functions for calculation of centroids.
- run.py: Easy access edit point for quick use
- zip3.json: Example json file of 3 digit zip codes in the US
- zip3Centroid.json: Example output json file
This project uses an extra package to work properly:
- [json] - A lightweight data interchange inspired by java script
Make sure you have Python 3.6.x installed on your system. You can download it here.
- Clone this repo in your preferred directory:
$ git clone https://github.com/connor-makowski/geojson-centroid-calculator.git
- Go to the root directory of the project using the
cd
command.$ cd geojson-centroid-calculator
- Put your GeoJSON data in the root project folder.
- Your data should follow the GeoJSON pattern
- An example can be found at
zip2.json
- An example can be found at
-
Open up the run.py file with your favorite text editor.
-
Edit
infile=
(line 3) to exactly match your input data. For example:infile='zip3.json'
-
Edit
outfile=
(line 3) to exactly match your output data. For example:outfile='zip3Centroid.json'
-
Edit
propertiesId=
(line 3) to exactly match an identifier in your GeoJSON properties object. For example:propertiesId='ZIP3'
Use Python to execute the run.py
file. This will import the centroidcalculator.py file and your data to process the results.
$ python run.py
Your output will be located in the same folder under the outfile
you specified.
Copyright (c) 2018 Connor Makowski