D=-dsco NAME="街路名群 Street name groups" \ -dsco DESCRIPTION="See $(subst $(HOME)/,https://www.,$(PWD))" ## Author: Dan Jacobson https://www.jidanni.org/ ## Copyright: https://www.gnu.org/licenses/gpl.html ## Created: 2025-04-27T12:55:10+0000 ## Last-Updated: 2025-05-10T22:48:48+0000 ## Update #: 178 d=~/Downloads/d/data #A={{geocodeArea:Beitun District, Taichung}} A=area(id:3602959946)#what is official way to get these? Wikidata? # https://community.openstreetmap.org/t/how-to-get-all-street-names-of-city/88436/5 # https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#CSV_output_mode W=https://overpass-api.de/api/interpreter vv=[out:csv(::lon,::lat)]\ [timeout:20];$A->.searchArea; way[\ "highway"]["name"~"^$*"](area.searchArea);out geom; want = \ 安順 崇德 昌平 軍福 敦富 文昌 景賢 南興 祥順 遼陽 松竹 后庄 \ 豐樂 太和 敦和 太順 山西 經貿 河北 軍榮 洲際 和祥 三光 松柏 \ 豐美 中清 太安 順平 榮德 德和 敦化 太祥 豐德 同榮 ww = $(addsuffix .wkt,$(want)) $d/%.csv: perl -MURI::Escape -wle 'use utf8; print "$W?data=", uri_escape_utf8(q($(vv)))'|\ xargs wget -O $@ # Concave hull approach: # %.kml:$d/%.csv # ogr2ogr -q $@ $< -dialect SQLite -of LIBKML \ # -oo X_POSSIBLE_NAMES=@lon -oo Y_POSSIBLE_NAMES=@lat -sql \ # 'SELECT ST_ConcaveHull(ST_Collect(GEOMETRY)), "$*" AS name FROM "$*"' #street_name_groups.kmz:$(ww); ogrmerge -f LIBKML -overwrite_ds -o $@ $^ $D # Single point approach: %.wkt:$d/%.csv ogr2ogr -of CSV -q /vsistdout/ $< -dialect SQLite \ -lco GEOMETRY=AS_WKT -lco STRING_QUOTING=IF_NEEDED \ -oo X_POSSIBLE_NAMES=@lon -oo Y_POSSIBLE_NAMES=@lat -sql \ 'SELECT ST_Centroid(Extent(GEOMETRY)) AS WKT,'\ 'CONCAT("$*(",COUNT(*),")") AS name FROM "$*"' > $@ #so it won't make a directory. mm.csv:$(ww); sort -o $@ -ur $^ #to leave just one header line at top street_name_groups.kml:mm.csv; ogr2ogr -of LIBKML $@ $< -sql 'SELECT name FROM $(basename $<)' ## Here's how we get the list of what are the heavy use prefixes for this area: HEAVY=3 #minimum number of streets for a group to be interesting to us B=beitun b=$d/$B.csv numbers = 一|二|三|四|五|六|七|八|九|十 directions = 東|西|南|北|中 rank:$b #interesting name stems, by frequency LC_ALL=zh_TW.UTF-8 perl -Mutf8 -C -nwle \ 'next unless /..(:?$(numbers)|$(directions))(:?街|路)$$/; /../; $$h{$$&}++;'\ 'END{for(sort{$$h{$$b}<=>$$h{$$a}}keys %h){print "$$_,$$h{$$_}"}}' $< > $@ test -s $@ r:rank; perl -F, -anwle 'exit unless $$F[1] >= $(HEAVY); print $$F[0]' $<|xargs -n 12 # And then I pasted the list into this Makefile. R=太 順 祥 和 v:rank; for i in $R; do printf $$i:; perl -nwe 's/,.*//; print;' $<; done # Not considering 文昌四巷, 碧柳一巷, etc. non-useful exceptions. # Note e.g., 崇德 roads might extend between Districts, so perhaps use a bounding box instead. .PRECIOUS: $d/%.csv .SECONDARY: