Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

A simple Python GeoJSON file reader and writer.

Project Description

PyGeoj is a simple Python GeoJSON file reader and writer intended for end-users. It exposees dictionary structures as high level objects with convenience methods, so the user does not have to get caught up in the details of the format specification.


So far only tested on Python version 2.x.


Pure Python, no dependencies.

Installing it

PyGeoj is installed with pip from the commandline:

pip install pygeoj

It also works to just place the “pygeoj” package folder in an importable location like “C:/PythonXX/Lib/site-packages”.

Example Usage

Begin by importing the pygeoj module:

import pygeoj


Reading geojson formatted GIS files is a simple one-liner (requires the geojson file to be a “FeatureCollection”):

testfile = pygeoj.load(filepath="testfile.geojson")

Basic information about the geojson file can then be extracted, such as:

len(testfile) # the number of features
testfile.bbox # the bounding box region of the entire file # the coordinate reference system
testfile.common_attributes # retrieves which field attributes are common to all features

Individual features can be accessed by their index in the features list:

# or

Or by iterating through all of them:

for feature in testfile:
    # do something

A feature can be inspected in various ways:


The standard Python list operations can be used to edit and swap around the features in a geojson instance, and then saving to a new geojson file:

testfile[3] = testfile[8]
# or testfile.replace_feature(3, testfile[8])
del testfile[8]
# or testfile.remove_feature(8)"test_edit.geojson")

An existing feature can also be tweaked by using simple attribute-setting:

# set your own properties = {"newfield1":"newvalue1", "newfield2":"newvalue2"}

# borrow the geometry of the 16th feature
feature.geometry = testfile[16].geometry


Creating a new geojson file from scratch is also easy:

newfile =

# The data coordinate system defaults to long/lat WGS84 or can be manually defined:
newfile.define_crs(type="link", link="", link_type="esriwkt")

The new file can then be populated with new features:

                    geometry={type="Polygon", coordinates=[[(21,3),(33,11),(44,22)]]} )
                    geometry={type="Polygon", coordinates=[[(11,23),(14,5),(66,31)]]} )

Finally, some useful additional information can be added to top off the geojson file before saving it to file:


More Information:


This code is free to share, use, reuse, and modify according to the MIT license, see license.txt


Karim Bahgat (2015)

Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date (13.5 kB) Copy SHA256 Checksum SHA256 Source Jun 18, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting