From 39f114a629067f6bad497e26a337fa3d9b331d34 Mon Sep 17 00:00:00 2001 From: Rob Savoye Date: Thu, 12 Oct 2023 20:16:59 -0600 Subject: [PATCH] fix: Add simple test case for creating imagery basemaps --- tests/test_basemap.py | 71 +++++++++++++++++++++++++++++ tests/testdata/Rollinsville.geojson | 8 ++++ 2 files changed, 79 insertions(+) create mode 100755 tests/test_basemap.py create mode 100644 tests/testdata/Rollinsville.geojson diff --git a/tests/test_basemap.py b/tests/test_basemap.py new file mode 100755 index 00000000..b6531eb5 --- /dev/null +++ b/tests/test_basemap.py @@ -0,0 +1,71 @@ +#!/usr/bin/python3 + +# Copyright (c) 2022, 2023 Humanitarian OpenStreetMap Team +# +# This file is part of osm_fieldwork. +# +# Underpass is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Underpass is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with osm_fieldwork. If not, see . +# + +import argparse +import logging +import os +import shutil + +from osm_fieldwork.xlsforms import xlsforms_path +from osm_fieldwork.basemapper import BaseMapper +import geojson +from shapely.geometry import shape +from geojson import Feature, FeatureCollection +from osm_fieldwork.sqlite import DataFile, MapTile + +log = logging.getLogger(__name__) + +infile = f"testdata/Rollinsville.geojson" +outfile = "rollinsville.mbtiles" +base = "./tiles" +#boundary = open(infile, "r") +#poly = geojson.load(boundary) +#if "features" in poly: +# geometry = shape(poly["features"][0]["geometry"]) +#elif "geometry" in poly: +# geometry = shape(poly["geometry"]) +#else: +# geometry = shape(poly) + +def test_create(): + """See if the file got loaded.""" + hits = 0 + basemap = BaseMapper(infile, base, 'topo', False) + tiles = list() + for level in [8, 9, 10, 11, 12]: + basemap.getTiles(level) + tiles += basemap.tiles + + if len(tiles) == 5: + hits += 1 + + if tiles[0].x == 52 and tiles[1].y == 193 and tiles[2].x == 211: + hits += 1 + + outf = DataFile(outfile, basemap.getFormat()) + outf.writeTiles(tiles, base) + + os.remove(outfile) + shutil.rmtree(base) + + assert hits == 2 + +if __name__ == "__main__": + test_create() diff --git a/tests/testdata/Rollinsville.geojson b/tests/testdata/Rollinsville.geojson new file mode 100644 index 00000000..511a026a --- /dev/null +++ b/tests/testdata/Rollinsville.geojson @@ -0,0 +1,8 @@ +{ +"type": "FeatureCollection", +"generator": "JOSM", +"name": "foo", +"features": [ +{ "type": "Feature", "properties": { "name": "Town of Rollinsville" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -105.502578282, 39.916775321499998 ], [ -105.502810751, 39.9168295869 ], [ -105.503045643, 39.916877261700002 ], [ -105.503282647, 39.916918282799998 ], [ -105.50339839, 39.916940560800001 ], [ -105.503662373, 39.9169718542 ], [ -105.503840169, 39.916989444499997 ], [ -105.503927286, 39.916998063599998 ], [ -105.504143095, 39.917015209900001 ], [ -105.504199007, 39.917017385699999 ], [ -105.504294001, 39.917021771100003 ], [ -105.504407786, 39.917028599200002 ], [ -105.504791869, 39.917045453100002 ], [ -105.504867699, 39.917048779700004 ], [ -105.504946738, 39.917052248399997 ], [ -105.505023521, 39.917055617099997 ], [ -105.505108939, 39.9170593646 ], [ -105.505186814, 39.917062780899997 ], [ -105.505276006, 39.917066694699997 ], [ -105.505352789, 39.917070063200001 ], [ -105.505440922, 39.917073930100003 ], [ -105.506814218, 39.917137005699999 ], [ -105.5069622, 39.917147998399997 ], [ -105.507051242, 39.917151005699999 ], [ -105.507140285, 39.917154012899999 ], [ -105.507229328, 39.91715702 ], [ -105.50731837, 39.917160027100003 ], [ -105.507407413, 39.9171630341 ], [ -105.507496457, 39.917166041 ], [ -105.507585499, 39.917169047900003 ], [ -105.507674542, 39.917172054700004 ], [ -105.507763586, 39.917175061400002 ], [ -105.507852629, 39.9171780681 ], [ -105.507941671, 39.917181074699997 ], [ -105.508030714, 39.917184081199999 ], [ -105.508119758, 39.917187087599999 ], [ -105.5082088, 39.917190094 ], [ -105.508297843, 39.917193100299997 ], [ -105.508386887, 39.917196106600002 ], [ -105.508475929, 39.917199112799999 ], [ -105.508564972, 39.917202118900001 ], [ -105.508654016, 39.917205124900001 ], [ -105.508705143, 39.9172068512 ], [ -105.508740761, 39.9172080536 ], [ -105.508739595, 39.917225821899997 ], [ -105.508734277, 39.917306845399999 ], [ -105.508729917, 39.917373281800003 ], [ -105.508726333, 39.917427884399999 ], [ -105.508690704, 39.917426440600003 ], [ -105.508641528, 39.9174244485 ], [ -105.508640287, 39.917424398100003 ], [ -105.508552413, 39.917422694300001 ], [ -105.508463297, 39.917420966199998 ], [ -105.508374181, 39.917419238100003 ], [ -105.508347397, 39.917418718599997 ], [ -105.50828499, 39.917418824800002 ], [ -105.508195767, 39.917418976199997 ], [ -105.508106544, 39.917419128399999 ], [ -105.508054413, 39.917419216799999 ], [ -105.508017276, 39.9174200633 ], [ -105.507927946, 39.917422098599999 ], [ -105.507838615, 39.917424134800001 ], [ -105.507761559, 39.917425890899999 ], [ -105.50774927, 39.917426430299997 ], [ -105.507659831, 39.917430358700003 ], [ -105.507570393, 39.917434287 ], [ -105.507480955, 39.917438214299999 ], [ -105.507469049, 39.917438737399998 ], [ -105.50739155, 39.917441564199997 ], [ -105.507302149, 39.917444824900002 ], [ -105.507226494, 39.917447583799998 ], [ -105.507210237, 39.917447813599999 ], [ -105.507120913, 39.917449077400001 ], [ -105.507086866, 39.9174495587 ], [ -105.50707356, 39.917449746800003 ], [ -105.50698371, 39.917451017700003 ], [ -105.506937724, 39.917450642200002 ], [ -105.506920497, 39.917406892 ], [ -105.506910134, 39.917406931400002 ], [ -105.505736379, 39.91732432 ], [ -105.505642558, 39.917316851 ], [ -105.505546896, 39.917309455 ], [ -105.505464625, 39.917304404399999 ], [ -105.505378893, 39.917298180400003 ], [ -105.505298014, 39.917291957 ], [ -105.505201313, 39.917285209200003 ], [ -105.505150147, 39.91728091 ], [ -105.50514166, 39.917392351300002 ], [ -105.505112945, 39.917727878900003 ], [ -105.505110962, 39.917751054699998 ], [ -105.505193138, 39.917756915200002 ], [ -105.505288841, 39.917763989100003 ], [ -105.505374132, 39.917770376199996 ], [ -105.505382684, 39.9177709963 ], [ -105.505396627, 39.917772005300002 ], [ -105.505500495, 39.917778762499999 ], [ -105.505556412, 39.917782024700003 ], [ -105.505599839, 39.917784382299999 ], [ -105.505629989, 39.917786301100001 ], [ -105.505729106, 39.917793635599999 ], [ -105.505735406, 39.9177941019 ], [ -105.505953715, 39.917809683 ], [ -105.506333374, 39.917841735099998 ], [ -105.50686735, 39.917871981899999 ], [ -105.507228575, 39.917891174399998 ], [ -105.507134376, 39.91830147 ], [ -105.50704829, 39.9189949533 ], [ -105.506696107, 39.918966799899998 ], [ -105.506167833, 39.918924568800001 ], [ -105.505989454, 39.918906968599998 ], [ -105.505893405, 39.918896408800002 ], [ -105.505551181, 39.918867626400001 ], [ -105.505474902, 39.918861211100001 ], [ -105.505422304, 39.9188545226 ], [ -105.504863036, 39.918807427 ], [ -105.504852155, 39.9188065106 ], [ -105.504848207, 39.9188342996 ], [ -105.504856039, 39.919090003900003 ], [ -105.504857958, 39.919152680499998 ], [ -105.504886812, 39.919606944500003 ], [ -105.504888355, 39.919631742299998 ], [ -105.50489318, 39.919707796200001 ], [ -105.504906917, 39.919840740700003 ], [ -105.504932018, 39.920083641399998 ], [ -105.505312983, 39.9201330056 ], [ -105.50531384, 39.920176605499996 ], [ -105.505319204, 39.920449354699997 ], [ -105.504848376, 39.920487944400001 ], [ -105.504724557, 39.920499478799996 ], [ -105.504653347, 39.920506112299996 ], [ -105.503926478, 39.920573819300003 ], [ -105.503834046, 39.9204689436 ], [ -105.503756203, 39.920349085 ], [ -105.503668622, 39.920221714199997 ], [ -105.503590791, 39.920071911299999 ], [ -105.50352268, 39.9199408156 ], [ -105.503391318, 39.919614946599999 ], [ -105.503313471, 39.919285331799998 ], [ -105.503291932, 39.919206277299999 ], [ -105.503154299, 39.9187010793 ], [ -105.503140828, 39.9186289911 ], [ -105.502985824, 39.9186196896 ], [ -105.50291871, 39.918616674100001 ], [ -105.502910574, 39.918616386099998 ], [ -105.502848181, 39.918614177499997 ], [ -105.502787854, 39.918611178900001 ], [ -105.502719598, 39.918607899400001 ], [ -105.502723153, 39.918539838500003 ], [ -105.502186573, 39.918545310600003 ], [ -105.502172655, 39.918476660099998 ], [ -105.50215268, 39.918404193599997 ], [ -105.502132729, 39.918340557199997 ], [ -105.502114202, 39.918274725800003 ], [ -105.502094252, 39.918216575199999 ], [ -105.502078576, 39.918159520700002 ], [ -105.502073195, 39.918143907 ], [ -105.50206005, 39.918105759 ], [ -105.502047224, 39.918051996300001 ], [ -105.502030123, 39.918000428600003 ], [ -105.502014449, 39.917941180100001 ], [ -105.501989921, 39.9179074941 ], [ -105.501904036, 39.917559964500001 ], [ -105.501786293, 39.917596599699998 ], [ -105.501582235, 39.917442760500002 ], [ -105.501507207, 39.917511797800003 ], [ -105.501318907, 39.917657777700001 ], [ -105.501261008, 39.917702664399997 ], [ -105.500754278, 39.917346937200001 ], [ -105.500662636, 39.917283636900002 ], [ -105.500598275, 39.917238284699998 ], [ -105.500510848, 39.917179075900002 ], [ -105.500453969, 39.917135440199999 ], [ -105.500204327, 39.916966087699997 ], [ -105.500140074, 39.916922532900003 ], [ -105.500088463, 39.916885223199998 ], [ -105.500029475, 39.9168446694 ], [ -105.499958904, 39.916795193600002 ], [ -105.499896756, 39.916752449299999 ], [ -105.499833557, 39.916708651100002 ], [ -105.499771411, 39.916664853 ], [ -105.499700838, 39.916617242299999 ], [ -105.499640799, 39.916575876700001 ], [ -105.499580761, 39.916535484800001 ], [ -105.499519668, 39.916492497100002 ], [ -105.499454362, 39.916447888100002 ], [ -105.499395377, 39.916406522499997 ], [ -105.499373721, 39.916392249600001 ], [ -105.499228913, 39.9164439591 ], [ -105.499981609, 39.915802545200002 ], [ -105.500033528, 39.915754323100003 ], [ -105.500208031, 39.915885971100003 ], [ -105.50039402, 39.915714441399999 ], [ -105.501369472, 39.916290164499998 ], [ -105.501532239, 39.916376596699997 ], [ -105.501699604, 39.916457654399998 ], [ -105.501871271, 39.916533190800003 ], [ -105.502046931, 39.916603071600001 ], [ -105.50222627, 39.916667172499999 ], [ -105.502408969, 39.916725377399999 ], [ -105.502578282, 39.916775321499998 ] ] ] } } +] +}