Skip to main content

graphene-gis

CircleCI

INSTALLATION

django==2.2 is supported. Install the graphene-gis with pip:

$ pip install graphene-gis

Make sure that you have appropriate driver to interact with postgis-- psycopg2 or psycopg2-binary. The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources. More info here.

Add it to your INSTALLED_APPS in settings.py:

INSTALLED_APPS = [
    ...
    'graphene_gis',
]

USAGE

Hi, check this-> geoql project out, it demonstrates usage-- such as querying, mutations using WKT and geojson. I will be adding more stuff soon such as containerization, interactive UI etc, and more examples that showcases the library. This project provides an insight into real-world usage of the library, do check it out.

This extension can works out of the box with WKT, but if you want to use GeoJSON for input while mutations, install rest_framework_gis alongside it-- or check out geoql sample project.

QUERY

models.py

from django.contrib.gis.db import models


class Place(models.Model):
    name = models.CharField(max_length=255)
    location = models.PointField()

schema.py

from graphene_django import DjangoObjectType
from graphene_gis.converter import gis_converter  # noqa

class PlaceType(DjangoObjectType):
    class Meta:
        model = Place

class Query(graphene.ObjectType):
    place = graphene.Field(Place)

    def resolve_place(self, info):
        return Place(name="San Andreas", location="POINT(34.2 54.3)")

schema = graphene.Schema(query=Query)

Query

query {
    place {
        name
        location
    }
}

Query Output

"place": {
    "name": "San Andreas",
    "location": {
        "type": "Point",
        "coordinates": [34.2, 54.3]
    }
}

MUTATION

schema.py

class PointModelType(graphene.ObjectType):
    location = graphene.Field(graphene.String, to=scalars.PointScalar())

class CreatePointModelType(graphene.Mutation):
    point = graphene.Field(PointModelType)

    class Arguments:
        location = graphene.Argument(scalars.PointScalar)

    def mutate(root, info, location):
        point = PointModelType(location=location)
        return CreatePointModelType(point=point)

Mutation

mutation {
    createPoint (location: "POINT(3 5)") {
        point {
            location
        }
    }
}

Mutation Output

"createPoint": {
    "point": {
        "location": "{'type': 'Point', 'coordinates': [3.0, 5.0]}"
    }
}

EXTRA STUFF

A JSON Converter, so if you're familiar with graphene, you know that it sends JSONField as stringified JSON, but with a lot of data, you dont want to parse it in the frontend, I know it goes against having a static type, but if you're not modifying the data on the frontend, plus you're using typescript which enforces types anyway, it works like a charm.

And geojson contains JSONField like properties section, and parsing every node in the frontend is cumbersome if you have ~9000 entries, also time consuming.

Output without using json_converter

{
  "data": {
    "vectors": [
      {
        "type": "Feature",
        "properties": "{\"Name\": \"Blues\", \"area\": 0.0006971253332413299, \"bbox\": [74.59639001261124, 24.7077612714826, 74.61615129922414, 24.755648349214077], \"perimeter\": 0.15862406542812008}",
        "geometry": {
          "type": "Polygon",
          "coordinates": [...]
        }
      }
    ]
  }
}

Now if you're working with GeoJSON, you're not working with just one vector, you're probably working with thousands. Voila json_converter!!! Now you can plot it directly, if you store it in such a way! I won't go into how to structure the model, but this is fairly accurate description of GeoJSON, and anyone familiar with django will be able to reproduce it without issues.

{
  "data": {
    "allVectors": [
      {
        "type": "Feature",
        "properties": {
          "Name": "Blues",
          "area": 0.0006971253332413299,
          "bbox": [
            74.59639001261124,
            24.7077612714826,
            74.61615129922414,
            24.755648349214077
          ],
          "perimeter": 0.15862406542812008
        },
        "geometry": {
          "type": "Polygon",
          "coordinates": [...]
        }
      }
    ]
  }
}

AUTHOR

Rishabh Mehta eternal.blizzard23@gmail.com

If you have any issues or queries regarding acadbot, please don't hesitate to email the @author. I have a lot of free time.

I forget stuff, this section is for anyone who wants to build the package.

$ python setup.py sdist
$ twine upload dist/*

UPDATE

  • Targeting graphene-v3 update by March'22 -> MR

  • Install the pre-release using:

  • Django 4.2 LTS support by May'23

    pip install graphene-gis==0.0.8b0

LICENSE License: MIT

This code falls under the MIT license which permits the reuse of the proprietary software provided that all copies of the licensed software include a copy of the MIT License terms and the copyright notice. Go crazy!

Metadata

Release files for graphene-gis 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graphene-gis 0.0.8
File Size Uploaded Provenance Actions
graphene-gis-0.0.8.tar.gz 5.3 kB Without provenance Details for graphene-gis-0.0.8.tar.gz

Release files / graphene-gis-0.0.8.tar.gz

Download URL graphene-gis-0.0.8.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
75fcdafcf79205bd697ebc4b376c38964a3d8c174f72505bccddf55dafc0fb9c
BLAKE2b-256 checksum
How to use checksums
2f40bc23c24fd51f089fda1abb0371dcab390e86a6113a5c25d16dcfe85d0662
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.4

Security for graphene-gis 0.0.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page