Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How Deserialize data from geojson format #253

Open
irfanpule opened this issue Dec 28, 2020 · 2 comments
Open

How Deserialize data from geojson format #253

irfanpule opened this issue Dec 28, 2020 · 2 comments

Comments

@irfanpule
Copy link

example I have serializer

class PointSerializer(GeoFeatureModelSerializer):
    class Meta:
        model = PointModel
        fields = '__all__'
        geo_field = 'geom'

and I get serialize data or response

{
    "type": "FeatureCollection",
    "features": [
        {
            "id": 395,
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    106.92374152131379,
                    -6.938941860571504
                ]
            },
            "properties": {
                "date": "2020-02-10",
                "time": "17:15:04",
                "video_sec": 7,
                "speed": 3.406,
                "road_number": 1
            }
        },
        {
            "id": 432,
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    106.92334589548409,
                    -6.940676830708981
                ]
            },
            "properties": {
                "date": "2020-02-10",
                "time": "17:15:41",
                "video_sec": 44,
                "speed": 6.093,
                "photo_file": "",
                "road_number": 1
            }
        }
    ]
}

How I deserializer this response ?

@devkapilbansal
Copy link
Member

@irfanpule may be you want to convert string you get back to dictionary
If that's the case, you can use json.loads(response.data) to deserialize it

@lukemckinstry
Copy link

it will deserialize a feature, not a FeatureCollection

{
            "id": 395,
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    106.92374152131379,
                    -6.938941860571504
                ]
            },
            "properties": {
                "date": "2020-02-10",
                "time": "17:15:04",
                "video_sec": 7,
                "speed": 3.406,
                "road_number": 1
            }
        }

so you can pass the features array from your request body to your PointSerializer model like so:

PointSerializer(data=request.data["features"], many=True)`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants