flavors / django-graphql-geojson

GeoJSON support for Graphene Django

Home Page:https://pypi.python.org/pypi/django-graphql-geojson

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Django GraphQL GeoJSON

Pypi Wheel Build Status Codecov Code Climate

GeoJSON support for Django GraphQL

Dependencies

  • Python ≥ 3.4
  • Django ≥ 1.11

Installation

Install last stable version from Pypi.

GeoJSONType

GeoJSONType is a subclass of DjangoObjectType which provides GraphQL fields in GeoJSON format.

Just define a Meta.geojson_field to be represented as a Geometry type.

models.py

schema.py

Query

query {
  places {
    id
    type
    geometry {
      type
      coordinates
    }
    bbox
    properties {
      name
    }
  }
}

Geometry Type

Geometry is a special GraphQL type that represents a GEOS geometry object.

schema.py

Mutation

mutation CreatePlace($name: String!, $location: Geometry!) {
  createPlace(name: $name, location: $location) {
    place {
      id
    }
  }
}

Geometry type may be initialized in a few ways:

  • Well-known text (WKT):
  • Hexadecimal (HEX):
  • GeoJSON:

GeometryFilterSet

Django GraphQL GeoJSON provides a custom FilterSet for spatial lookups.

The Meta.fields option is combined with model to automatically generate filters.

filters.py

schema.py

Query

query Places($geometry: Geometry!){
  places(location_Intersects: $geometry) {
    edges {
      node {
        id
      }
    }
  }
}

Distance lookups take a Distance parameter comprising:

  • The desired unit attribute name
  • Distance value
  • A geometry to base calculations from
query Places(
    $unit: DistanceUnitEnum!,
    $value: Float!,
    $geometry: Geometry!)
  {
  places(location_DistanceLte: {
      unit: $unit,
      value: $value,
      geometry: $geometry
    }) {
    edges {
      node {
        id
      }
    }
  }
}

If you have a problem don't hesitate to ask for assistance.

About

GeoJSON support for Graphene Django

https://pypi.python.org/pypi/django-graphql-geojson

License:MIT License


Languages

Language:Python 97.9%Language:Makefile 2.1%