Database Reference
In-Depth Information
shp2pgsql -s 3734 -d -i -I -W LATIN1 -g
the_geom CUY_ADDRESS_POINTS chp04.knn_addresses
| psql -U me -d postgis_cookbook
As this dataset may take a while to load, you can alternatively load a subset using
the following command:
shp2pgsql -s 3734 -d -i -I -W LATIN1 -g
the_geom CUY_ADDRESS_POINTS_subset
chp04.knn_addresses | psql -U me -d
postgis_cookbook
Ifyouloadedthisinthepreviousrecipe,thereisnoneedtoreloadthedata.Thead-
dress points will serve as a proxy for our building structures. However, to align our
structuretothenearbystreets,wewillneeda streets layer.WewilluseCuyahoga
County's street centerline data for this:
shp2pgsql -s 3734 -d -i -I -W LATIN1 -g
the_geom CUY_STREETS chp04.knn_streets | psql
-U me -d postgis_cookbook
Before we commence, however, we have to consider another aspect of using in-
dexes, which we need not have considered in our previous KNN recipe. When our
KNN approach used only points, our indexing was exact—the bounding box of a
pointiseffectivelyapoint.Asboundingboxesarewhatindexesarebuiltaround,our
indexing estimates of distance perfectly reflected the actual distances between our
points.Inthecaseofnonpointgeometries,asisourexamplehere,theboundingbox
isanapproximationofthelinestowhichwewillbecomparingourpoints.Putanother
way,whatthismeansisthatournearestneighbormaynotbeour very nearestneigh-
bor,butislikelyourapproximatelynearestneighbor,oroneofournearestneighbors.
Inpractice,weapplyaheuristicapproach—wesimplygatherslightlymorethanthe
numberofnearestneighborsweareinterestedinandthensortthembasedonthe
actualdistanceinordertogatheronlythenumberweareinterestedin.Inthisway,
we only need to sort a small number of records.
Search WWH ::




Custom Search