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

WIP: Update + optimize geocontext #116

Merged
merged 1 commit into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions deployment/production/build.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env bash

if [ -z "$REPO_NAME" ]; then
REPO_NAME=kartoza
REPO_NAME=andretheronsa
fi

if [ -z "$IMAGE_NAME" ]; then
IMAGE_NAME=geocontext
fi

if [ -z "$TAG_NAME" ]; then
TAG_NAME=latest
TAG_NAME=2.0
fi

if [ -z "$BUILD_ARGS" ]; then
Expand All @@ -19,7 +19,7 @@ fi
# Build Args Environment

if [ -z "$BIMS_TAG" ]; then
BIMS_TAG=develop
BIMS_TAG=2.0
fi

echo "BIMS_TAG=${BIMS_TAG}"
Expand Down
25 changes: 16 additions & 9 deletions django_project/geocontext/models/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def retrieve_external_csr(util_arg):
else:
return None


def get_session():
"""Get thread local request session"""
if not hasattr(thread_local, "session"):
Expand Down Expand Up @@ -101,7 +102,7 @@ def __init__(self, csr_key, x, y, srid=4326):

# Geometry defaults to generalized point - for basic cache hits.
self.x = x
self.y = y
self.y = y
self.query_srid = srid
self.generalize_point()
self.geometry = self.point
Expand Down Expand Up @@ -131,10 +132,11 @@ def generalize_point(self):
:return: point
:rtype: Point
"""

if self.query_srid != self.srid:
point = Point(
*convert_coordinate(self.x, self.y, self.query_srid, self.srid),
*convert_coordinate(
self.x, self.y, self.query_srid, self.srid),
srid=self.srid
)
else:
Expand Down Expand Up @@ -189,7 +191,8 @@ def retrieve_context_value(self):
self.value = e
return True

if self.query_type in [ServiceDefinitions.ARCREST, ServiceDefinitions.PLACENAME]:
if self.query_type in [
ServiceDefinitions.ARCREST, ServiceDefinitions.PLACENAME]:
build_url = self.build_query_url()
build_content = self.request_content(build_url)
if build_content is not None:
Expand All @@ -212,11 +215,13 @@ def retrieve_context_value(self):
return True

build_url = self.build_query_url()
build_content = self.request_content(build_url)
build_content = self.request_content(build_url)
if build_content is not None:
geometry = parse_gml_geometry(build_content, self.layer_typename)
geometry = parse_gml_geometry(
build_content, self.layer_typename)
if geometry is not None:
geometry.srid = self.srid if not geometry.srid else geometry.srid
if not geometry.srid:
geometry.srid = self.srid
self.geometry = geometry

self.cache_url = build_url
Expand All @@ -237,7 +242,9 @@ def request_content(self, url, retries=0):
if response.status_code == 200:
return response.content
except requests.exceptions.RequestException as e:
LOGGER.error(f"'{self.service_registry_key}' url failed: {url} with: {e}")
LOGGER.error(
f"'{self.service_registry_key}' url failed: {url} with: {e}"
)
return None

def parse_request_value(self, request_content):
Expand Down Expand Up @@ -317,7 +324,7 @@ def build_query_url(self):
else:
url = f'{self.url}/identify?{query_dict.urlencode()}'
url += f'&mapExtent={bbox_string}'

elif self.query_type == ServiceDefinitions.PLACENAME:
parameters = {
'lat': str(self.point.y),
Expand Down
6 changes: 1 addition & 5 deletions django_project/geocontext/tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
"""Test for utilities module."""

import os
import unittest

from django.test import SimpleTestCase
from geocontext.utilities import (
convert_coordinate, parse_gml_geometry, convert_2d_to_3d, get_bbox)
from django.contrib.gis.geos import (
Point, LineString, LinearRing, Polygon, MultiPoint,
MultiLineString, MultiPolygon)
convert_coordinate, parse_gml_geometry, get_bbox)

test_data_directory = os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'data')
Expand Down
3 changes: 1 addition & 2 deletions django_project/geocontext/utilities.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# coding=utf-8
"""Utilities module for geocontext app."""
import logging
import requests
from xml.dom import minidom
import xml.etree.ElementTree as ET

Expand Down Expand Up @@ -75,7 +74,7 @@ def parse_gml_geometry(gml_string, tag_name='qgs:geometry'):
logger.error(f'Could not parse GML string: {e}')
return None
try:
if tag_name == 'qgs:geometry':
if tag_name == 'qgs:geometry':
geometry_dom = xmldoc.getElementsByTagName(tag_name)[0]
geometry_gml_dom = geometry_dom.childNodes[1]
return GEOSGeometry.from_gml(geometry_gml_dom.toxml())
Expand Down