Skip to content

Commit

Permalink
Adds userinfo on exports to be available
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijrajsharma committed Aug 29, 2024
1 parent a38a24e commit 6cee018
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 27 deletions.
3 changes: 2 additions & 1 deletion api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Used by the View classes api/views.py to serialize API responses as JSON or HTML.
See DEFAULT_RENDERER_CLASSES setting in core.settings.contrib for the enabled renderers.
"""

# -*- coding: utf-8 -*-
import logging

Expand Down Expand Up @@ -113,7 +114,7 @@ class Meta:
"mbtiles_maxzoom",
"pinned",
"unfiltered",
"preserve_geom",
"userinfo",
)
extra_kwargs = {
"the_geom": {"write_only": True},
Expand Down
2 changes: 1 addition & 1 deletion jobs/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Migration(migrations.Migration):
("expire_old_runs", models.BooleanField(default=True)),
("pinned", models.BooleanField(default=False)),
("unfiltered", models.BooleanField(default=False)),
("preserve_geom", models.BooleanField(default=False)),
("userinfo", models.BooleanField(default=False)),
(
"user",
models.ForeignKey(
Expand Down
2 changes: 1 addition & 1 deletion jobs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class Job(models.Model):
expire_old_runs = models.BooleanField(default=True)
pinned = models.BooleanField(default=False)
unfiltered = models.BooleanField(default=False)
preserve_geom = models.BooleanField(default=False)
userinfo = models.BooleanField(default=False)

class Meta: # pragma: no cover
managed = True
Expand Down
15 changes: 11 additions & 4 deletions tasks/task_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,17 +675,16 @@ def add_metadata(z, theme):
mapping_filter = mapping
if job.unfiltered:
mapping_filter = None
userinfo = job.userinfo

if "geojson" in export_formats:
preserved_geom = geom
if job.preserve_geom:
preserved_geom = load_geometry(job.the_geom.json)
geojson = Galaxy(
settings.RAW_DATA_API_URL,
preserved_geom,
geom,
mapping=mapping_filter,
file_name=valid_name,
access_token=settings.RAW_DATA_ACCESS_TOKEN,
userinfo=userinfo,
)
start_task("geojson")

Expand All @@ -696,6 +695,7 @@ def add_metadata(z, theme):
mapping=mapping_filter,
file_name=valid_name,
access_token=settings.RAW_DATA_ACCESS_TOKEN,
userinfo=userinfo,
)
start_task("fgb")

Expand All @@ -716,6 +716,7 @@ def add_metadata(z, theme):
mapping=mapping_filter,
file_name=valid_name,
access_token=settings.RAW_DATA_ACCESS_TOKEN,
userinfo=userinfo,
)
start_task("sql")

Expand All @@ -726,6 +727,7 @@ def add_metadata(z, theme):
mapping=mapping_filter,
file_name=valid_name,
access_token=settings.RAW_DATA_ACCESS_TOKEN,
userinfo=userinfo,
)
# geopackage = tabular.Geopackage(join(stage_dir,valid_name),mapping)
# tabular_outputs.append(geopackage)
Expand All @@ -738,6 +740,7 @@ def add_metadata(z, theme):
mapping=mapping_filter,
file_name=valid_name,
access_token=settings.RAW_DATA_ACCESS_TOKEN,
userinfo=userinfo,
)
start_task("shp")

Expand All @@ -748,6 +751,7 @@ def add_metadata(z, theme):
mapping=mapping_filter,
file_name=valid_name,
access_token=settings.RAW_DATA_ACCESS_TOKEN,
userinfo=userinfo,
)
# kml = tabular.Kml(join(stage_dir,valid_name),mapping)
# tabular_outputs.append(kml)
Expand Down Expand Up @@ -912,6 +916,7 @@ def add_metadata(z, theme):
mapping=mapping_filter,
file_name=valid_name,
access_token=settings.RAW_DATA_ACCESS_TOKEN,
userinfo=userinfo,
)
start_task("mbtiles")
LOG.debug(
Expand Down Expand Up @@ -944,6 +949,7 @@ def add_metadata(z, theme):
mapping=mapping_filter,
file_name=valid_name,
access_token=settings.RAW_DATA_ACCESS_TOKEN,
userinfo=userinfo,
)
start_task("pmtiles")
LOG.debug(
Expand Down Expand Up @@ -976,6 +982,7 @@ def add_metadata(z, theme):
mapping=mapping_filter,
file_name=valid_name,
access_token=settings.RAW_DATA_ACCESS_TOKEN,
userinfo=userinfo,
)
start_task("mvt")
LOG.debug("Raw Data API fetch started for mvt run: {0}".format(run_uid))
Expand Down
2 changes: 1 addition & 1 deletion ui/app/actions/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const cloneExport = e => (dispatch, getState) => {
name: e.name,
published: e.published,
unfiltered: e.unfiltered,
preserve_geom: e.preserve_geom,
userinfo: e.userinfo,
the_geom: rsp.data.the_geom,
aoi: {
description: "Cloned Area",
Expand Down
14 changes: 7 additions & 7 deletions ui/app/components/Summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const messages = defineMessages({
// id: "export.bundle_for_posm.description",
// defaultMessage: "Bundle for POSM"
// },
preserveGeometry: {
id: "export.preserve_geom.description",
defaultMessage: "Preserve Geometry - Avoid simplify ( Only supports for geojson )"
userinfo: {
id: "export.userinfo.description",
defaultMessage: "Include user info on exports"
},
publishedDescription: {
id: "export.published.description",
Expand Down Expand Up @@ -84,12 +84,12 @@ export default injectIntl(
component={renderCheckbox}
type="checkbox"
/> */}
{/* <Field
name="preserve_geom"
description={formatMessage(messages.preserveGeometry)}
<Field
name="userinfo"
description={formatMessage(messages.userinfo)}
component={renderCheckbox}
type="checkbox"
/> */}
/>
<Button
bsStyle="danger"
disabled={submitting}
Expand Down
24 changes: 12 additions & 12 deletions utils/aoi_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
# be buffered efficiently, they must be simplified first.
# so first simplify them to 0.01 degrees.


def force2d(geom):
# force geom to be 2d: https://groups.google.com/forum/#!topic/django-users/7c1NZ76UwRU
wkt = wkt_w(dim=2).write(geom).decode()
return GEOSGeometry(wkt)

def simplify_geom(geom,force_buffer=False, preserve_geom=False):
if preserve_geom is False:
if geom.num_coords > 10000:
geom = geom.simplify(0.01)
if geom.num_coords > 500:
geom = geom.buffer(0.02)
param = 0.01
while geom.num_coords > 500:
geom = geom.simplify(param, preserve_topology=True)
param = param * 2

def simplify_geom(geom, force_buffer=False):
if geom.num_coords > 10000:
geom = geom.simplify(0.01)
if geom.num_coords > 500:
geom = geom.buffer(0.02)
param = 0.01
while geom.num_coords > 500:
geom = geom.simplify(param, preserve_topology=True)
param = param * 2
if force_buffer:
geom = geom.buffer(0.02)
geom = geom.buffer(0.02)
return geom

0 comments on commit 6cee018

Please sign in to comment.