-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
django>=4 | ||
django-computedfields | ||
fiona | ||
psycopg2-binary | ||
transifex-client | ||
djangorestframework | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import io | ||
from typing import OrderedDict | ||
|
||
import fiona | ||
from django.http import StreamingHttpResponse | ||
from rest_framework import renderers | ||
|
||
|
||
class FGBRenderer(renderers.BaseRenderer): | ||
format = "fgb" | ||
media_type = "application/octet-stream" | ||
# FIXME: This should be sent by the model. | ||
schema = {"geometry": "Point", "properties": {"name": "str", "_serialized": "str"}} | ||
|
||
def render( | ||
self, data: OrderedDict, accepted_media_type=None, renderer_context=None | ||
) -> StreamingHttpResponse: | ||
"""Renders pre-serialized Python objects as a flatgeobuf binary stream""" | ||
features = (fiona.Feature.from_dict(obj) for obj in data["features"]) | ||
buffer_wrapper = io.BytesIO() | ||
|
||
with fiona.open( | ||
buffer_wrapper, mode="w", driver="FlatGeobuf", schema=self.schema | ||
) as fh: | ||
for feature in features: | ||
fh.write(feature) | ||
|
||
buffer_wrapper.seek(0) | ||
return StreamingHttpResponse(buffer_wrapper) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters