Skip to content

Commit 75709b9

Browse files
committed
-
1 parent 2bf8142 commit 75709b9

9 files changed

+310
-84
lines changed

__pycache__/desCartes.cpython-310.pyc

-19.9 KB
Binary file not shown.
56 Bytes
Binary file not shown.

desCartes.py

+2-46
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ def get_nearest_parallel_linestring(gdf, geoindex, test_point, max_distance, tan
9494
break
9595
except ValueError: # Tried to find tangent using point beyond end of linestring
9696
continue
97+
if candidate_tangent_point.is_empty:
98+
continue
9799
dx = candidate_tangent_point.x - candidate_closest_point.x
98100
dy = candidate_tangent_point.y - candidate_closest_point.y
99101
candidate_angle = math.atan2(dy, dx)
@@ -351,52 +353,6 @@ def desCartes(map_directory,
351353
footpaths_single_EPSG4326_gdf.to_file(map_directory + 'desCartes.gpkg', layer="single_dashes", driver="GPKG")
352354

353355
binary_image = np.where(footpaths == 255, 255, binary_image) # Remove dashes
354-
355-
# std_deviation_multiplier = 3
356-
# area_range = (dash_detector['area']['mean'] - std_deviation_multiplier * dash_detector['area']['std_dev'], dash_detector['area']['mean'] + std_deviation_multiplier * dash_detector['area']['std_dev'])
357-
# convexity_range = (dash_detector['convexity']['mean'] - std_deviation_multiplier * dash_detector['convexity']['std_dev'], 1)
358-
# aspect_ratio_range = (dash_detector['aspect_ratio']['mean'] - std_deviation_multiplier * dash_detector['aspect_ratio']['std_dev'], dash_detector['aspect_ratio']['mean'] + std_deviation_multiplier * dash_detector['aspect_ratio']['std_dev'])
359-
# contours, _ = cv2.findContours(binary_image_otsu, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
360-
# footpaths = np.zeros_like(binary_image)
361-
# for contour in contours:
362-
# # Calculate areas of contour and its convex hull
363-
# contour_area = cv2.contourArea(contour)
364-
# if not area_range[0] <= contour_area <= area_range[1]:
365-
# continue
366-
# hull = cv2.convexHull(contour)
367-
# hull_area = cv2.contourArea(hull)
368-
# convexity = contour_area / hull_area
369-
# if not convexity_range[0] <= convexity <= convexity_range[1]:
370-
# continue
371-
# # Calculate aspect ratio
372-
# rect = cv2.minAreaRect(contour)
373-
# rect_width, rect_height = rect[1]
374-
# if rect_width == 0 or rect_height == 0:
375-
# continue # Reject contour
376-
# else:
377-
# aspect_ratio = min(rect_width, rect_height) / max(rect_width, rect_height)
378-
# if not aspect_ratio_range[0] <= aspect_ratio <= aspect_ratio_range[1]:
379-
# continue
380-
# cv2.drawContours(footpaths, [contour], -1, 255, -1)
381-
#
382-
# binary_image = np.where(footpaths == 255, 255, binary_image) # Remove dashes
383-
# # Dilate to merge double-dash lines
384-
# kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (6, 6))
385-
# footpaths_merged = cv2.dilate(footpaths, kernel, iterations=2)
386-
# footpaths_double = cv2.erode(footpaths_merged, kernel, iterations=3)
387-
# footpaths_double = cv2.dilate(footpaths_double, kernel, iterations=4)
388-
# footpaths_single = cv2.subtract(footpaths_merged, footpaths_double)
389-
# footpaths_double = skeletonize(footpaths_double / 255.).astype(np.uint8) * 255
390-
# footpaths_single = skeletonize(footpaths_single / 255.).astype(np.uint8) * 255
391-
# footpaths_double = vector_skeleton(footpaths_double)
392-
# footpaths_single = vector_skeleton(footpaths_single)
393-
# footpaths_double = gpd.GeoDataFrame({'geometry': footpaths_double})
394-
# footpaths_single = gpd.GeoDataFrame({'geometry': footpaths_single})
395-
#
396-
# footpaths_double_EPSG4326_gdf = XY_to_EPSG4326(footpaths_double, raster.transform)
397-
# footpaths_double_EPSG4326_gdf.to_file(map_directory + 'desCartes.gpkg', layer="double_dashes", driver="GPKG")
398-
# footpaths_single_EPSG4326_gdf = XY_to_EPSG4326(footpaths_single, raster.transform)
399-
# footpaths_single_EPSG4326_gdf.to_file(map_directory + 'desCartes.gpkg', layer="single_dashes", driver="GPKG")
400356

401357
# Thin all black lines to 1px
402358
binary_image = np.invert(binary_image)
Binary file not shown.

obsolete_code/tester.py

+34-12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
# from find_areas import find_areas
2727
from desCartes import desCartes
2828
from coloured_roads import coloured_roads
29+
from realign_1950s_to_1890s import realign_1950s_to_1890s
2930
import json
3031

3132
#####################
@@ -35,32 +36,41 @@
3536
# A simple way to get the extent coordinates is to open a Google map in a browser,
3637
# then right-click on the south-west corner of the area of interest. Then click on
3738
# the displayed coordinates and then paste them below. Repeat for the north-east corner.
38-
EXTENT_SOUTHWEST_LAT, EXTENT_SOUTHWEST_LNG = 52.567900, -1.990716
39-
EXTENT_NORTHEAST_LAT, EXTENT_NORTHEAST_LNG = 52.588912, -1.957963
4039

41-
EXTENT_SOUTHWEST_LNG, EXTENT_SOUTHWEST_LAT, EXTENT_NORTHEAST_LNG, EXTENT_NORTHEAST_LAT = -1.935997009277344,52.56137658013496,-1.898918151855469,52.58339467314521
40+
EXTENT_SOUTHWEST_LAT, EXTENT_SOUTHWEST_LNG = 51.50349919463678, -2.3478318403222653
41+
EXTENT_NORTHEAST_LAT, EXTENT_NORTHEAST_LNG = 51.511351738991365, -2.332338484447449
42+
LOCATION_NAME = 'tormarton'
43+
44+
# EXTENT_SOUTHWEST_LAT, EXTENT_SOUTHWEST_LNG = 52.567939367463715, -1.992658440245488
45+
# EXTENT_NORTHEAST_LAT, EXTENT_NORTHEAST_LNG = 52.591446281961645, -1.9622368833162331
46+
# LOCATION_NAME = 'walsall'
47+
48+
# EXTENT_SOUTHWEST_LNG, EXTENT_SOUTHWEST_LAT, EXTENT_NORTHEAST_LNG, EXTENT_NORTHEAST_LAT = -1.935997009277344,52.56137658013496,-1.898918151855469,52.58339467314521
49+
# LOCATION_NAME = 'great_barr'
4250

4351
## The location name will be used to name the directory where files are stored.
4452
## If a geotiff already exist in this directory, it will be re-used, and the coordinates given above ignored.
45-
LOCATION_NAME = 'test3'
53+
# LOCATION_NAME = 'test5'
4654
# LOCATION_NAME = 'test2'
47-
# LOCATION_NAME = 'tormarton'
48-
# LOCATION_NAME = 'walsall'
4955
# LOCATION_NAME = 'sutton_coldfield'
5056

5157
## Uncomment one of these methods, or create your own in the IMAGE PROCESSING CALLS section.
5258
## Any name you type here will be used in creating a filename, so avoid funky characters.
5359
# METHOD = 'road_contours'
5460
# METHOD = 'progressive'
5561
# METHOD = 'development'
56-
METHOD = 'colour'
62+
# METHOD = 'colour'
63+
METHOD = '1950s_to_1890s'
5764

58-
# RASTER_TILE_KEY = 'ySlCyGP2kmmfm9Dgtiqj' # TO USE THE URL GIVEN BELOW, GET YOUR OWN KEY FROM https://cloud.maptiler.com/account/keys/
59-
# RASTER_TILE_URL = 'https://api.maptiler.com/tiles/uk-osgb10k1888/{z}/{x}/{y}.jpg?key=' + RASTER_TILE_KEY
60-
RASTER_TILE_URL = 'https://api.maptiler.com/tiles/uk-osgb63k1955/{z}/{x}/{y}.jpg?key=ySlCyGP2kmmfm9Dgtiqj'
61-
# RASTER_TILE_ZOOM = 17
6265
# RASTER_TILE_URL = 'https://overlays.humap.site/layersoflondon/os_drawings/{z}/{x}/{y}.png'
63-
RASTER_TILE_ZOOM = 15
66+
# RASTER_TILE_ZOOM = 15
67+
68+
RASTER_TILE_KEY = 'ySlCyGP2kmmfm9Dgtiqj' # TO USE THE URL GIVEN BELOW, GET YOUR OWN KEY FROM https://cloud.maptiler.com/account/keys/
69+
RASTER_TILE_URL = 'https://api.maptiler.com/tiles/uk-osgb10k1888/{z}/{x}/{y}.jpg?key=' + RASTER_TILE_KEY
70+
RASTER_TILE_ZOOM = 17
71+
72+
# RASTER_TILE_URL = 'https://api.maptiler.com/tiles/uk-osgb63k1955/{z}/{x}/{y}.jpg?key=ySlCyGP2kmmfm9Dgtiqj'
73+
# RASTER_TILE_ZOOM = 15
6474

6575
## The ROADFILE must contain LineStrings only, reprojected if necessary to EPSG:4326 (WGS84)
6676
## It should be placed in the DATADIR defined below.
@@ -371,6 +381,18 @@
371381
# result_binary, _ = erase_areas(result_binary, raster_image_gray, 2000, closed = True, SHOW_IMAGES = SHOW_IMAGES, OUTPUTDIR = OUTPUTDIR) # Erase white shapes
372382
# result_binary, _ = erase_areas(result_binary, raster_image_gray, 3, contours = False, SHOW_IMAGES = SHOW_IMAGES, OUTPUTDIR = OUTPUTDIR) # Erase white noise
373383

384+
case '1950s_to_1890s':
385+
realign_1950s_to_1890s(
386+
map_directory = f"./output/{LOCATION_NAME}/",
387+
extent = {
388+
"sw_lng": EXTENT_SOUTHWEST_LNG,
389+
"sw_lat": EXTENT_SOUTHWEST_LAT,
390+
"ne_lng": EXTENT_NORTHEAST_LNG,
391+
"ne_lat": EXTENT_NORTHEAST_LAT
392+
}
393+
)
394+
395+
374396
case _: # Default
375397
contours, skeleton, result_images, message = desCartes(OUTPUTDIR, template_dir = './../data/templates', show_images = True, shape_filter = False, MAX_ROAD_WIDTH = 40)
376398

0 commit comments

Comments
 (0)