question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for GIS field types

See original GitHub issue

Right now, using a DjangoObjectType on a model that contains GIS fields (like django.contrib.gis.db.models.fields.PointField) will trigger an exception: Exception: Don't know how to convert the Django field myapp.MyModel.point (<class 'django.contrib.gis.db.models.fields.PointField'>).

It would be great to add support for this. Otherwise, is there any docs on how to create a custom Field with custom serialization/deserialization like in django-rest-framework?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
mongkokcommented, Feb 4, 2018

Hi @sanfilippopablo,

the PR convert Geometry fields to well-known text (WKT):

{
    "id": "1",
    "location": "SRID=4326;POINT (0 1)"
}

if you want to convert to GeoJSON:

import json

from django.contrib.gis.db import models

import graphene
from graphene_django.converter import convert_django_field


class GeoJSON(graphene.Scalar):

    @classmethod
    def serialize(cls, value):
        return json.loads(value.geojson)


@convert_django_field.register(models.GeometryField)
def convert_field_to_geojson(field, registry=None):
    return graphene.Field(
        GeoJSON,
        description=field.help_text,
        required=not field.null)

Response:

{
    "id": "1",
    "location": {
        "type": "Point",
        "coordinates": [0.0, 1.0]
    }
}

Recently I have developed a library for Geographic types, inputs, filters… https://github.com/flavors/django-graphql-geojson

0reactions
EverWinter23commented, Mar 12, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

ArcGIS field data types
When you create feature classes and tables, you select a data type for each field. The available types include a variety of number...
Read more >
ArcGIS Desktop Help 9.2 - Geodatabase field data types
The available types include a variety of number types, text, date, binary large objects (BLOBs), or globally unique identifiers (GUIDs).
Read more >
Exploring Data Formats and Fields - QGIS Documentation
QGIS supports (multi)point, (multi)line, (multi)polygon, CircularString, CompoundCurve, CurvePolygon, MultiCurve, MultiSurface feature types, all with Z and/or ...
Read more >
ArcGIS Data Types - DBMS Data Types - GISRSStudy
ArcGIS Geodatabase Data Deacription ; Short integer, -32,768 to 32,767, 2 ; Long integer, -2,147,483,648 to 2,147,483,647, 4 ; Float (single-precision floating- ...
Read more >
GIS Data Types - YouTube
Description of raster and vector GIS data types.This video was produced by West Virginia View (http://www.wvview.org/) with support from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found