All Projects → flavors → django-graphql-geojson

flavors / django-graphql-geojson

Licence: MIT license
GeoJSON support for Graphene Django

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to django-graphql-geojson

Mapstore2
Modern webmapping with OpenLayers, Leaflet and React
Stars: ✭ 251 (+311.48%)
Mutual labels:  geojson, maps, gis
geojson-to-wfs-t-2
A lightweight javascript module to format WFS-T-2 statements from GeoJSON features
Stars: ✭ 21 (-65.57%)
Mutual labels:  geojson, gis
geofiddle
Geometric conversions between different formats and projections
Stars: ✭ 15 (-75.41%)
Mutual labels:  geojson, maps
MapDownloader
Map downloader based on GMap.NET
Stars: ✭ 226 (+270.49%)
Mutual labels:  maps, gis
geojson-to-sqlite
CLI tool for converting GeoJSON files to SQLite (with SpatiaLite)
Stars: ✭ 41 (-32.79%)
Mutual labels:  geojson, gis
mini-map-maker
A tool for automatically generating 3D printable STLs from freely available lidar scan data.
Stars: ✭ 51 (-16.39%)
Mutual labels:  maps, gis
ilong
轻量级跨平台瓦片地图库,大部分算法来自QMapControl,就想练手的。。。因为需要轻量级跨平台的,所以只能先用SQLite数据库。。。
Stars: ✭ 24 (-60.66%)
Mutual labels:  maps, gis
deck.gl-time-series-widget
A React Time Slider implementation for DECK.GL - (non)temporal data - by CPU filtering ⌛
Stars: ✭ 19 (-68.85%)
Mutual labels:  maps, gis
pyturf
A modular geospatial engine written in python
Stars: ✭ 15 (-75.41%)
Mutual labels:  geojson, gis
vaguely-rude-places
The map of Vaguely Rude Place Names
Stars: ✭ 19 (-68.85%)
Mutual labels:  geojson, maps
osm-geojson
🔰 Get GeoJSON of a OpenStreetMap's relation from the API.
Stars: ✭ 42 (-31.15%)
Mutual labels:  geojson, maps
de9im
DE-9IM spatial predicate library implemented in Javascript.
Stars: ✭ 22 (-63.93%)
Mutual labels:  geojson, gis
osm-static-maps
Openstreetmap static maps is a nodejs lib, CLI and server open source inspired on google static map service
Stars: ✭ 130 (+113.11%)
Mutual labels:  geojson, maps
30DayMapChallenge
The official website for #30DayMapChallenge, It is a daily mapping/cartography/data visualization challenge aimed at the spatial community. Code for map submissions.
Stars: ✭ 33 (-45.9%)
Mutual labels:  maps, gis
geoJSON-Nepal
GeoJSON for Nepal. 🇳🇵
Stars: ✭ 49 (-19.67%)
Mutual labels:  geojson, maps
Atlas
An extensible 3D GIS application for visualization, analysis and research.
Stars: ✭ 113 (+85.25%)
Mutual labels:  maps, gis
turf-go
A Go language port of Turf.js
Stars: ✭ 41 (-32.79%)
Mutual labels:  geojson, gis
graphene-sqlalchemy-filter
Filters for Graphene SQLAlchemy integration
Stars: ✭ 117 (+91.8%)
Mutual labels:  graphene, filters
rlayers
React Component Library for OpenLayers
Stars: ✭ 98 (+60.66%)
Mutual labels:  maps, gis
check-geojson
a checker for the geojson format. goes beyond a schema, checking semantics and producing character-level warnings.
Stars: ✭ 36 (-40.98%)
Mutual labels:  geojson, maps

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.

pip install django-graphql-geojson

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

from django.contrib.gis.db import models


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

schema.py

import graphene
import graphql_geojson


class PlaceType(graphql_geojson.GeoJSONType):

    class Meta:
        model = models.Place
        geojson_field = 'location'


class Query(graphene.ObjectType):
    places = graphene.List(PlaceType)


schema = graphene.Schema(query=Query)

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

import graphene
import graphql_geojson


class CreatePlace(graphene.Mutation):
    place = graphene.Field(types.PlaceType)

    class Arguments:
        name = graphene.String(required=True)
        location = graphql_geojson.Geometry(required=True)

    @classmethod
    def mutate(cls, root, info, **args):
        place = models.Place.objects.create(**args)
        return cls(place=place)

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):
"POINT(5 23)"
  • Hexadecimal (HEX):
"010100000000000000000014400000000000003740"
  • GeoJSON:
{
  "type": "Point",
  "coordinates": [5, 23]
}

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

from graphql_geojson.filters import GeometryFilterSet


class PlaceFilter(GeometryFilterSet):

    class Meta:
        model = models.Place
        fields = {
            'name': ['exact'],
            'location': ['exact', 'intersects', 'distance_lte'],
        }

schema.py

import graphene
import graphql_geojson
from graphene import relay
from graphene_django.filter import DjangoFilterConnectionField


class PlaceNode(graphql_geojson.GeoJSONType):

    class Meta:
        model = Place
        interfaces = [relay.Node]
        geojson_field = 'location'


class Query(graphene.ObjectType):
    places = DjangoFilterConnectionField(
        PlaceNode,
        filterset_class=PlaceFilter)

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].