Thin-plate-spline fit of the forester's 2022 map to the parcel, trails traced and checked against the 2023 0.25 ft ortho and 2 ft lidar; crossings snapped to DEM-derived channels. GeoJSON in WGS84 and EPSG:6433, overlay images, method notes, and a payload/push script for the viewer's plan layer.
56 lines
4 KiB
Python
56 lines
4 KiB
Python
import json, numpy as np
|
|
from scipy.interpolate import RBFInterpolator
|
|
from PIL import Image, ImageDraw
|
|
P='/home/alex/property-research/properties/willington-ct-049-002-00/'
|
|
FT=0.3048006096012192 # US survey foot
|
|
# control points: forester map pixel (2200x1700 north-up) -> EPSG:6433 metres (GIS boundary vertex)
|
|
cp=[((675,93),(347910.2,275144.1)),((890,113),(348028.5,275129.5)),((953,27),(348062.5,275195.8)),
|
|
((899,177),(348035.4,275078.9)),((1067,193),(348130.5,275068.8)),((1117,220),(348161.5,275046.9)),
|
|
((1100,400),(348148.3,274913.2)),((1500,437),(348374.1,274888.4)),((607,503),(347873.8,274832.1)),
|
|
((803,557),(347985.1,274795.7)),((760,777),(347961.5,274636.1)),((340,1173),(347723.2,274330.7)),
|
|
((1373,1360),(348304.7,274193.7)),((1410,987),(348334.8,274445.3)),((1473,987),(348358.2,274471.4)),
|
|
((1557,847),(348418.0,274577.0)),((1640,625),(348490.4,274717.8))]
|
|
src=np.array([c[0] for c in cp],float); dst=np.array([c[1] for c in cp],float)
|
|
# affine for diagnostics
|
|
A=np.c_[src,np.ones(len(src))]; coef,res,_,_=np.linalg.lstsq(A,dst,rcond=None)
|
|
aff=A@coef; r=np.hypot(*(aff-dst).T); print('affine residual m: mean %.1f max %.1f'%(r.mean(),r.max()))
|
|
print('scale m/px', np.hypot(coef[0,0],coef[1,0]), 'rot deg', np.degrees(np.arctan2(coef[1,0],coef[0,0])))
|
|
tps=RBFInterpolator(src,dst,kernel='thin_plate_spline',smoothing=5.0)
|
|
r2=np.hypot(*(tps(src)-dst).T); print('tps residual m: mean %.1f max %.1f'%(r2.mean(),r2.max()))
|
|
trails={
|
|
'A-west-spine':[(747,247),(767,280),(793,333),(813,373),(833,433),(847,480),(863,527),(873,567),(900,620),(940,667),(973,693),(1007,700),(1060,700),(1100,693),(1147,690),(1187,693)],
|
|
'A-east-to-landing':[(1187,693),(1213,683),(1260,667),(1313,660),(1367,667),(1407,680),(1447,673),(1480,670),(1500,658),(1530,615),(1563,580)],
|
|
'B-centre':[(1187,693),(1180,733),(1177,787),(1167,847),(1153,887),(1140,933),(1127,1000),(1120,1053),(1107,1095),(1095,1105),(1060,1150),(1040,1185)],
|
|
'C-south':[(633,1120),(680,1130),(720,1143),(760,1150),(800,1153),(853,1157),(907,1157),(953,1167),(1007,1177),(1040,1185),(1067,1185),(1100,1200),(1153,1203),(1200,1213),(1253,1220),(1280,1227)],
|
|
}
|
|
points={'SC-1':(1500,658),'SC-2':(1095,1105),'Landing':(1563,580)}
|
|
out={'trails':{k:tps(np.array(v,float)).round(1).tolist() for k,v in trails.items()},
|
|
'points':{k:tps(np.array([v],float))[0].round(1).tolist() for k,v in points.items()}}
|
|
json.dump(out,open('fit.json','w'),indent=1)
|
|
# overlay on hillshade (EPSG:6434 ft, 2 ft/px, origin 1140656,903040)
|
|
hs=Image.open(P+'terrain/hillshade-2023.jpg').convert('RGB')
|
|
def px(x,y): return ((x/FT-1140656)/2.0, (903040-y/FT)/2.0)
|
|
ring=json.load(open(P+'terrain/terrain-features.geojson'))
|
|
from pyproj import Transformer
|
|
tr=Transformer.from_crs('EPSG:4326','EPSG:6433',always_xy=True)
|
|
b=json.load(open(P+'boundary.geojson'))['features'][0]['geometry']['coordinates'][0]
|
|
bp=[px(*tr.transform(x,y)) for x,y in b]
|
|
Z=2; big=hs.resize((hs.width*Z,hs.height*Z),Image.LANCZOS); d=ImageDraw.Draw(big)
|
|
d.line([(x*Z,y*Z) for x,y in bp]+[(bp[0][0]*Z,bp[0][1]*Z)],fill=(255,255,0),width=2)
|
|
for k,v in out['trails'].items():
|
|
d.line([(px(x,y)[0]*Z,px(x,y)[1]*Z) for x,y in v],fill=(255,0,0),width=2)
|
|
for k,(x,y) in out['points'].items():
|
|
cx,cy=px(x,y); d.ellipse([cx*Z-6,cy*Z-6,cx*Z+6,cy*Z+6],outline=(0,255,0),width=2); d.text((cx*Z+8,cy*Z-6),k,fill=(0,255,0))
|
|
# 100 m grid in 6433
|
|
for gx in range(347700,348600,100):
|
|
x0,_=px(gx,274000); d.line([(x0*Z,0),(x0*Z,big.height)],fill=(0,200,255),width=1); d.text((x0*Z+2,2),str(gx),fill=(0,200,255))
|
|
for gy in range(274100,275300,100):
|
|
_,y0=px(347000,gy); d.line([(0,y0*Z),(big.width,y0*Z)],fill=(0,200,255),width=1); d.text((2,y0*Z+2),str(gy),fill=(0,200,255))
|
|
big.save('hs-overlay.png')
|
|
# crops: parcel bbox in px
|
|
xs=[p[0] for p in bp]; ys=[p[1] for p in bp]
|
|
x0,x1,y0,y1=int(min(xs))-20,int(max(xs))+20,int(min(ys))-20,int(max(ys))+20
|
|
print('parcel px box',x0,x1,y0,y1)
|
|
cw=(x1-x0)//2; ch=(y1-y0)//2
|
|
for name,(cx,cy) in {'nw':(x0,y0),'ne':(x0+cw,y0),'sw':(x0,y0+ch),'se':(x0+cw,y0+ch)}.items():
|
|
big.crop((cx*Z,cy*Z,(cx+cw+40)*Z,(cy+ch+40)*Z)).save(f'hs-{name}.png')
|