Iskanje najbližjega objekta z matriko izvor-destinacija (QGIS3)

V prejšnji vadnici, Osnove vizualizacije in usmerjanja omrežja (QGIS3), smo se naučili, kako zgraditi omrežje in izračunati najkrajšo pot med dvema točkama. To tehniko lahko uporabimo pri številnih različnih vrstah analiz, ki temeljijo na omrežju. Ena takih aplikacij je izračun matrike izvora in destinacije ali matrike OD. Če imamo množico izvornih točk in drugo množico ciljnih točk, lahko izračunamo najkrajšo pot med vsakim parom izvor-cilj in ugotovimo potovalno razdaljo/čas med njima. Takšna analiza je uporabna za iskanje najbližjega objekta do katere koli točke. Logistično podjetje lahko na primer uporabi to analizo za iskanje najbližjega skladišča svojim strankam, da bi optimiziralo dostavne poti. Tukaj uporabljamo algoritem Distance Matrix iz vtičnika QGIS Network Analysis Toolbox (QNEAT3) za iskanje najbližje zdravstvene ustanove vsakega naslova v mestu.

Opomba

V tej vadnici je prikazano, kako za izračun matrike izvora in destinacije uporabite lastne omrežne podatke. Če nimate lastnih omrežnih podatkov, lahko uporabite ORS Tools Plugin in algoritem ORS Tools ‣ Matrix ‣ Matrix from Layers za izvedbo podobne analize z uporabo podatkov OpenStreetMap. Če želite izvedeti, kako uporabljati vtičnik ORS Tools, glejte Analiza storitvenih območij z uporabo storitve Openrouteservice (QGIS3).

Pregled naloge

Vzamemo dva sloja za Washington DC - enega s točkami, ki predstavljajo naslove, in drugega s točkami, ki predstavljajo ustanove za duševno zdravje - in poiščemo ustanovo z najkrajšo potovalno razdaljo od vsakega naslova.

Druga znanja, ki se jih boste naučili

  • Izbor naključnega vzorca iz točkovnega sloja.

  • Uporabite virtualne sloje za izvajanje poizvedbe SQL na sloju QGIS.

Pridobivanje podatkov

Vlada okrožja Columbia prosto deli na stotine podatkovnih nizov na portalu Open Data Catalog.

Prenesite naslednje podatkovne sloje kot shapefile.

Zaradi priročnosti lahko kopijo zbirk podatkov neposredno prenesete s spodnjih povezav:

Roadway_Block-shp.zip

Address_Points.zip

Community Based Service Provider.zip

Vir podatkov: [DCOPENDATA]

Nastavitve

Obiščite Plugins ‣ Manage and Install plugins. Izberite Vse Poiščite vtičnik QNEAT3 in ga namestite. Kliknite Close.

../../_images/setup11.png

Postopek

  1. Locate the Community_Based_Service_Providers.zip file, expand it and add Community_Based_Service_Providers.shp to the canvas. We will select only those centres providing facilities to adults. Right-click on the Community_Based_Service_Providers.shp layer and select Filter.

../../_images/1103.png
  1. It will open a Query Builder dialog box. Enter the following query in the :guilabel:` Filter Expression` Click Run.

"PROVIDER_T"  IN ('Adult','Adult & Child')
../../_images/280.png
  1. Next, locate the Roadway_Block.zip file, expand it and add the Roadway_Block.shp. Similarly, locate the Address_Points.zip file, expand it and add the Address_Points.shp. You will see a lot of points around the city. Each point represents a valid address. We will select 1000 points randomly. This technique is called random sampling. Go to Processing ‣ Toolbox.

../../_images/338.png
  1. Poiščite in najdite algoritem Vector Selection ‣ Random extract.

../../_images/338.png
  1. Izberite Address_Points kot Input layer, Number of feature kot Method in vnesite 1000 v Number/percentage of features. V polju Extracted (random) izberite ... in kliknite Save to a file. Zdaj izberite imenik in vnesite ime kot address_point_subset.shp ter kliknite Run

../../_images/517.png

Opomba

Ker bo algoritem iz danega nabora podatkov pridobil 1000 naključnih točk, lahko za ponovitev vaje, tu uporabljenih točk, prenesete datoteko nabora, ki smo jo dobili med izvajanjem algoritma, tukaj address_point_subset.zip . Po prenosu naložite sloj address_point_subset.shp v QGIS.

  1. A new layer address_point_subset will be added to the Layers panel, you can turn off the visibility of Address_Points address points layer. Let’s rename this layer as origin_points. Right-click on the address_point_subset layer and select Rename layer.

../../_images/617.png
  1. Similarly, rename the Adult_Mental_Health_Providers layers representing the health facilities as destination_points. Naming the layers this way makes it easy to identify them in subsequent processing. Further we will open processing toolbox to create the distance matrix using origin and destination layers.

../../_images/716.png
  1. Poiščite algoritem QNEAT3 ‣ Distance matrices ‣ OD Matrix from Layers as Line (m:n). Če tega algoritma ne vidite v orodjarni, se prepričajte, da ste namestili vtičnik QNEAT3.

../../_images/816.png
  1. Ta algoritem pomaga poiskati razdalje skupaj z omrežjem med izbranima izvornim in ciljnim slojem. Izberite Roadway_Block kot Mrežni sloj. Izberite origin_points kot sloj From-Points in OBJECTID_1 kot polje Unique Point ID. Podobno nastavite destination_points kot To-Points Layer in OBJECTID kot Unique Point ID field. Nastavite Optimization Criterion kot Shortest Path (distance optimization).

../../_images/916.png
  1. As many streets in the network are one-way, we need to set the Advanced parameters to specify the direction. See Osnove vizualizacije in usmerjanja omrežja (QGIS3) for more details on how these attributes are structured. We also have an option to select geometry style of the generated matrix. We are having a road network with direction information so we can generate matrix by folling the route. Choose Matrix geometry follows routes.Choose SUMMARYDIR as the Direction field. Enter OB as the Value for the forward direction, IB as the Value for backward direction, and BD as the Value for the both direction. Set the Topology tolerance as 0.0000150. Keep other options to their default values and click Run.

../../_images/1023.png
  1. Na ploščo Layers bo dodan nov sloj tabele z imenom Output OD Matrix. Kliknite z desno tipko miške in izberite Open Attributes Table. Videli boste, da tabela vsebuje 13000 vrstic. Imeli smo 13 izvornih točk in 1000 ciljnih točk - zato izhodna tabela vsebuje 13x1000 = 13000 parov izvornih in ciljnih točk. Stolpec total_cost vsebuje razdaljo v metrih med vsako izvorno točko in vsako ciljno točko.

../../_images/1126.png
  1. For this tutorial, we are interested in only the destination point with the shortest distance. We can create a SQL query to pick the destination with the least total_cost among all destinations. Go to Processing ‣ Toolbox.Search for and locate the Vector general ‣ Execute SQL.

../../_images/1224.png
  1. In Additional input data sources select ... and check the Output OD Matrix and, click OK. Now click the Summation under SQL query. Enter the following query in SQL query dialog box. Enter geometry as the Geometry field and, select LineString as the Geometry type. Click Run.

select origin_id, destination_id, min(total_cost) as shortest_distance, geometry
from input1 group by origin_id
../../_images/1322.png
  1. A new virtual layer SQL Output will be added to the Layers panel. This Layer has the result of our analysis. Nearest service provider for each of the 1000 origin points.

../../_images/1420.png
comments powered by Disqus