enable using the tileserver with minimal requirements

This commit is contained in:
Laura Klünder 2017-11-21 02:12:00 +01:00
parent 11678251bf
commit 2185c1ac6a
9 changed files with 21 additions and 17 deletions

View file

@ -22,7 +22,7 @@ from c3nav.editor.utils import is_created_pk
from c3nav.editor.wrappers import ModelInstanceWrapper, ModelWrapper
from c3nav.mapdata.models import LocationSlug, MapUpdate
from c3nav.mapdata.models.locations import LocationRedirect
from c3nav.mapdata.utils.cache import changed_geometries
from c3nav.mapdata.utils.cache.changes import changed_geometries
from c3nav.mapdata.utils.models import get_submodels

View file

@ -20,7 +20,7 @@ from c3nav.mapdata.models import Level
from c3nav.mapdata.models.access import AccessRestrictionMixin
from c3nav.mapdata.models.geometry.base import GeometryMixin
from c3nav.mapdata.models.locations import SpecificLocation
from c3nav.mapdata.utils.cache import changed_geometries
from c3nav.mapdata.utils.cache.changes import changed_geometries
from c3nav.mapdata.utils.geometry import (assert_multilinestring, assert_multipolygon, clean_cut_polygon,
cut_polygon_with_line)

View file

@ -8,7 +8,7 @@ from shapely.geometry import CAP_STYLE, JOIN_STYLE, mapping
from c3nav.mapdata.fields import GeometryField
from c3nav.mapdata.models.geometry.base import GeometryMixin
from c3nav.mapdata.models.locations import SpecificLocation
from c3nav.mapdata.utils.cache import changed_geometries
from c3nav.mapdata.utils.cache.changes import changed_geometries
from c3nav.mapdata.utils.json import format_geojson

View file

@ -92,7 +92,7 @@ class MapUpdate(models.Model):
if not new_updates:
return ()
from c3nav.mapdata.utils.cache import changed_geometries
from c3nav.mapdata.utils.cache.changes import changed_geometries
changed_geometries.reset()
logger.info('Recalculating altitude areas...')
@ -142,7 +142,7 @@ class MapUpdate(models.Model):
with suppress(FileExistsError):
os.mkdir(os.path.dirname(self._changed_geometries_filename()))
from c3nav.mapdata.utils.cache import changed_geometries
from c3nav.mapdata.utils.cache.changes import changed_geometries
pickle.dump(changed_geometries, open(self._changed_geometries_filename(), 'wb'))
transaction.on_commit(

View file

@ -1,5 +1,4 @@
from c3nav.mapdata.utils.cache.indexed import GeometryIndexed # noqa
from c3nav.mapdata.utils.cache.maphistory import MapHistory # noqa
from c3nav.mapdata.utils.cache.accessrestrictions import AccessRestrictionAffected # noqa
from c3nav.mapdata.utils.cache.changes import changed_geometries # noqa
from c3nav.mapdata.utils.cache.package import CachePackage # noqa

View file

@ -3,7 +3,6 @@ import struct
from functools import reduce
import numpy as np
from shapely.geometry.base import BaseGeometry
from c3nav.mapdata.utils.cache.indexed import LevelGeometryIndexed
@ -81,6 +80,7 @@ class AccessRestrictionAffectedCells:
return (self.values & (2**i)).any()
def add(self, restriction):
from shapely.geometry.base import BaseGeometry
if not isinstance(self.selector, BaseGeometry):
raise TypeError('Can only add restrictions with Geometry based selectors')
@ -93,6 +93,7 @@ class AccessRestrictionAffectedCells:
self._set(self.values | (2**i))
def discard(self, restriction):
from shapely.geometry.base import BaseGeometry
if not isinstance(self.selector, BaseGeometry):
raise TypeError('Can only discard restrictions with Geometry based selectors')

View file

@ -4,10 +4,6 @@ import struct
import threading
import numpy as np
from PIL import Image
from shapely import prepared
from shapely.geometry import box
from shapely.geometry.base import BaseGeometry
class GeometryIndexed:
@ -122,6 +118,9 @@ class GeometryIndexed:
maxx = min(maxx, self.x + width)
maxy = min(maxy, self.y + height)
from shapely import prepared
from shapely.geometry import box
cells = np.zeros_like(self.data, dtype=np.bool)
prep = prepared.prep(geometry)
res = self.resolution
@ -138,10 +137,6 @@ class GeometryIndexed:
return self.x, self.y, self.x+width, self.y+height
def __getitem__(self, key):
if isinstance(key, BaseGeometry):
bounds = self._get_geometry_bounds(key)
return self.data[self.get_geometry_cells(key, bounds)]
if isinstance(key, tuple):
xx, yy = key
@ -158,9 +153,15 @@ class GeometryIndexed:
return self.data[miny:maxy, minx:maxx].flatten()
from shapely.geometry.base import BaseGeometry
if isinstance(key, BaseGeometry):
bounds = self._get_geometry_bounds(key)
return self.data[self.get_geometry_cells(key, bounds)]
raise TypeError('GeometryIndexed index must be a shapely geometry or tuple, not %s' % type(key).__name__)
def __setitem__(self, key, value):
from shapely.geometry.base import BaseGeometry
if isinstance(key, BaseGeometry):
bounds = self._get_geometry_bounds(key)
self.fit_bounds(*bounds)
@ -184,6 +185,7 @@ class GeometryIndexed:
visible_data = ((self.data.astype(float)-minval)*255/(maxval-minval)).clip(0, 255).astype(np.uint8)
image_data[self.y:self.y+height, self.x:self.x+width] = visible_data
from PIL import Image
return Image.fromarray(np.flip(image_data, axis=0), 'L')

View file

@ -5,8 +5,6 @@ from collections import namedtuple
from io import BytesIO
from tarfile import TarFile, TarInfo
from django.conf import settings
from c3nav.mapdata.utils.cache import AccessRestrictionAffected, GeometryIndexed, MapHistory
CachePackageLevel = namedtuple('CachePackageLevel', ('history', 'restrictions'))
@ -76,6 +74,7 @@ class CachePackage:
@classmethod
def open(cls, filename=None):
if filename is None:
from django.conf import settings
filename = os.path.join(settings.CACHE_ROOT, 'package.tar')
return cls.read(open(filename, 'rb'))

View file

@ -0,0 +1,3 @@
requests>=2.17,<2.18
numpy>=1.13,<1.14