裂缝探测python

    科技2024-01-02  102

    裂缝探测python

    In the first blog of this series, we developed an idea aiming to address the site selection problem from the perspective of the demand and supply. We completed the analysis of the demand side and simulated the distribution of the customers in the target city, Penang. Although the case study is conducted in the scenario of the grocery industry, the same solution can be applied to real estate, e-commerce, and education sectors as well. In this blog, we are going to tackle the supply side and look into the imbalance between the demand and supply across the city. Bear in mind that our client is a supermarket chain and its potential customers are the entire population of the city.

    在本系列的第一个博客中,我们提出了一个想法,旨在从需求和供应的角度解决选址问题。 我们完成了需求方面的分析,并模拟了目标城市槟城的客户分布。 尽管案例研究是在杂货业的情况下进行的,但相同的解决方案也可以应用于房地产,电子商务和教育领域。 在此博客中,我们将解决供应方面的问题,并研究整个城市的需求和供应之间的不平衡。 请记住,我们的客户是一家连锁超市,其潜在客户是该城市的全部人口。

    The supply analysis consists of the following sections.

    供应分析包括以下部分。

    Competitor discovery: to find the locations of the existing supermarkets and grocery stores.

    竞争对手发现:查找现有超市和杂货店的位置。

    Distance estimation: to estimate the distance between the competitors and the different regions of the city.

    距离估算:估算竞争对手与城市不同区域之间的距离。

    Customer density estimation: to estimate the average number of customers served by one supermarket or grocery store at different locations of the city.

    顾客密度估算:估算城市中不同地点的一家超级市场或杂货店所服务的平均顾客数量。

    竞争对手发现 (Competitor Discovery)

    The information about existing grocery providers can be obtained using the Google Places API. It provides a variety of information about different types of places of interest, including their outlet name, geographical location, opening hours, and even visitor ratings etc. Here we expect the information provided by the API is up to date. However, it is not guaranteed that the API can detect all the places which fulfil the search criteria, especially for the less developed regions. For the purpose of this study, this is the best accessible data source we can rely on.

    可以使用Google Places API获取有关现有杂货店提供商的信息。 它提供了有关不同类型的景点的各种信息,包括其景点名称,地理位置,开放时间,甚至访客评分等。在这里,我们希望API提供的信息是最新的。 但是,不能保证API可以检测到所有满足搜索条件的地点,特别是对于欠发达地区。 就本研究而言,这是我们可以依靠的最佳可访问数据源。

    The Places API works with an API key and is usually queried with 3 parameters: the type of amenity, a center location, and a radius. Recap in the first series, we split the entire city area into thousands of 1km x 1km grids. In order to collect all the existing grocery providers available via the API, we take the geo-coordinates of the grid centers, and search for the supermarkets and grocery stores within 2 km’s distance. To make the blog more concise and less heavy with code, I’m going to omit the preparatory steps of the input data and the config parameters, and only highlight how the Places API is queried. The following code extracts the supermarkets within 2 km’s distance from Orchard Road, Singapore.

    Places API与API密钥一起使用,通常使用3个参数查询:舒适性的类型,中心位置和半径。 回顾第一个系列,我们将整个城市区域划分为数千个1km x 1km的网格。 为了收集通过API提供的所有现有杂货店提供商,我们采用网格中心的地理坐标,并在2公里范围内搜索超级市场和杂货店。 为了使博客更简洁,更省力,我将省略输入数据和config参数的准备步骤,仅强调如何查询Places API。 以下代码提取了距新加坡乌节路2公里以内的超市。

    import googlemaps API_KEY = "YOUR_API_KEY" gmaps = googlemaps.Client(key=API_KEY) res = gmaps.places( "supermarket", location="1.304833,103.831833", # Orchard Road, Singapore radius=2000 ) if res["status"] == 'OK' and len(res["results"]) > 0: for result in res["results"]: print(result) else: print("No place is found")

    The query results are returned as a list of Python dictionaries. One of them looks as follows. In this study, we only use the geolocation information of the existing supermarkets.

    查询结果作为Python字典列表返回。 其中之一如下所示。 在本研究中,我们仅使用现有超市的地理位置信息。

    { "business_status":"OPERATIONAL", "formatted_address":"491 River Valley Rd, #01-14, Singapore 248371", "geometry":{ "location":{ "lat":1.2929051, "lng":103.8270208 }, "viewport":{ "northeast":{ "lat":1.294498079892722, "lng":103.8284264298927 }, "southwest":{ "lat":1.291798420107278, "lng":103.8257267701073 } } }, "icon":"https://maps.gstatic.com/mapfiles/place_api/icons/shopping-71.png", "id":"fda0ec60faa787f2bf992132e66c80f29daa5964", "name":"FairPrice Finest Valley Point", "opening_hours":{ "open_now":False }, "photos":[ { "height":2048, "html_attributions":[ "<a href=\"https://maps.google.com/maps/contrib/111973208857299784904\">Anusha Lalwani</a>" ], "photo_reference":"CmRaAAAAQ6An4L-A5PbgDFkpZVllEGuB4Ayw0hdrZ9coCBaF6esLM2B7RVnJCvf0DPeZrlcbZ3KVFUz9cciPtArUAZ6tof_lJHzJHqKzcEFyRGJurK_Drld0GUec9sCWm25bXURVEhD6GZqf6j_Kb5IOTtQ1ogslGhQas22jzBT2rJ0jkj9zUhDvCLYj_w", "width":1536 } ], "place_id":"ChIJTyWXW4EZ2jERNKBCOx_-4LA", "plus_code":{ "compound_code":"7RVG+5R Singapore", "global_code":"6PH57RVG+5R" }, "rating":4, "reference":"ChIJTyWXW4EZ2jERNKBCOx_-4LA", "types":[ "grocery_or_supermarket", "food", "point_of_interest", "store", "establishment" ], "user_ratings_total":112}

    The supermarkets and grocery stores are collected from all the grids and plotted on the QGIS map after removing the duplicates, as shown in Figure 2. It can be observed that the distribution of the existing grocery providers (the white dots) is approximately aligned with the customer distribution.

    从所有网格中收集超级市场和杂货店,并在删除重复项后将其绘制在QGIS地图上,如图2所示。可以看到,现有杂货店的分布(白点)与零售店的分布大致一致。客户分布。

    Figure 2 Partial view of the existing supermarkets and grocery stores across Penang city 图2槟城市现有超市和杂货店的局部视图

    距离估算(Distance Estimation)

    Allow me to ask you a question. How long would you like to spend on travelling for grocery shopping?

    请允许我问一个问题。 您想花多长时间去杂货店购物?

    People living in different cities could have different answers. My answer to this question is 15 min’s walking distance. Walking to the grocery store can be taken as a regular physical exercise during a lockdown. In this study, we are expecting a longer threshold of travelling time due to the relatively small population density of Penang. According to the advice given by a friend from Malaysia, we assume a threshold of 10 min’s driving distance. It is the most important parameter used in this analysis and can be adjusted easily if the solution is deployed as a dashboard application later on. Please note that in consulting projects, such parameters need to be obtained via rigorous market research.

    生活在不同城市的人们可能会有不同的答案。 我对这个问题的回答是15分钟的步行距离。 锁定期间,步行到杂货店可以作为常规体育锻炼。 在这项研究中,由于槟城人口密度相对较小,我们预计出行时间会更长。 根据马来西亚朋友的建议,我们假设开车的距离为10分钟。 它是此分析中最重要的参数,如果以后将该解决方案部署为仪表板应用程序,则可以轻松调整。 请注意,在咨询项目中,需要通过严格的市场研究来获得此类参数。

    This travelling distance question is important here because, given the threshold of the travelling time, we can estimate the number of customers each grocery store can reach out to, which is known as catchment analysis. To facilitate this analysis, we extract the estimated driving time between each pair of grid and existing grocery store via Google Distance Matrix API. The following code extracts the driving time from Orchard Road to Marina Bay Sands, Singapore.

    这个旅行距离问题在这里很重要,因为给定旅行时间的阈值,我们可以估计每个杂货店可以联系的顾客数量,这被称为流域分析。 为了方便进行此分析,我们通过Google Distance Matrix API提取了每对网格与现有杂货店之间的预计行驶时间。 以下代码提取了从乌节路到新加坡滨海湾金沙的行驶时间。

    import googlemaps API_KEY = "YOUR_API_KEY" gmaps = googlemaps.Client(key=API_KEY) ORCHARD_ROAD = (1.304833, 103.831833) MARINA_BAY_SANDS = (1.282302, 103.858528) res = gmaps.distance_matrix( ORCHARD_ROAD, MARINA_BAY_SANDS, mode='driving' ) print(res)

    The result indicates that the driving time from the origin to the destination address is 13 min.

    结果表明,从起点到终点的行驶时间为13分钟。

    { "destination_addresses":[ "10 Bayfront Ave, Singapore 018956" ], "origin_addresses":[ "2 Orchard Turn, Singapore 238801" ], "rows":[ { "elements":[ { "distance":{ "text":"5.2 km", "value":5194 }, "duration":{ "text":"13 mins", "value":761 }, "status":"OK" } ] } ], "status":"OK"}

    客户密度估算 (Customer Density Estimation)

    Let’s summarise the key information we have obtained at grid level.

    让我们总结一下我们在网格级别获得的关键信息。

    Population, or number of customers for each grid.

    每个网格的人口或客户数量。 Number of grocery stores and supermarkets which serve the customers living in each grid.

    服务于每个网格中的顾客的杂货店和超市的数量。

    Now we take a quick look at the distribution of the number of customers and the grocery stores across the grids. The grids with no population are ignored in the following histograms.

    现在,我们快速浏览一下网格上客户和杂货店数量的分布。 在以下直方图中,将忽略没有总体的网格。

    Figure 3 Distribution of the grid-wise number of customers 图3按网格划分的客户数量分布 Figure 4 Distribution of the grid-wise number of stores within 10 min’s driving distance 图4在10分钟的行驶距离内的网格存储数量分布

    Both the number of customers and grocery stores look reasonable. From here, we are going to calculate a customer density index for each grid to evaluate the imbalance of the demand and supply across the city. Conceptually, it is equivalent to the demand to supply ratio (DSR).

    客户和杂货店的数量看起来都很合理。 从这里,我们将为每个网格计算一个客户密度指数,以评估整个城市的供需不平衡。 从概念上讲,它等于供求比(DSR)。

    customer density = Number of customers / Number of grocery stores and supermarkets serving the customers in the grid

    客户密度=客户数量/为网格中的客户提供服务的杂货店和超市的数量

    We are going to recommend locations of the new supermarkets based on the customer density value. In general, high customer density indicates a good location for the new outlets. Therefore, our client can use it as a reference for site selection.

    我们将根据客户密度值推荐新超市的位置。 通常,较高的客户密度表明新网点的位置很好。 因此,我们的客户可以将其用作站点选择的参考。

    Figure 5 shows the distribution of customer density across Penang. The regions with high DSR are highlighted in dark blue.

    图5显示了槟城各地客户密度的分布。 DSR高的区域以深蓝色突出显示。

    Figure 5 Distribution of customer density across Penang city 图5槟城全市客户密度分布

    最后的话(Final Words)

    This concludes the series of the site selection case study. You might have noticed that the capacity of the supermarkets is not considered when estimating customer density. In other words, the capacity of all the existing stores is treated the same in this study, which is not accurate in reality. One possible solution to this issue is to match the existing stores with their corresponding shapes from the OpenStreetMap (OSM) data. Floor area can be calculated with the coordinates and used to estimate the capacity of the stores.

    总结了选址案例研究系列。 您可能已经注意到,在估计客户密度时并未考虑超市的容量。 换句话说,在本研究中,所有现有商店的容量都被视为相同,这在实际中并不准确。 解决此问题的一种可能方法是将现有商店与其来自OpenStreetMap(OSM)数据的相应形状进行匹配。 可以使用坐标计算建筑面积,并将其用于估计商店的容量。

    In addition, please plan your queries of Google API before execution. Do an estimation of the number of queries and the total cost.

    另外,请在执行前计划对Google API的查询。 估算查询数量和总成本。

    The scripts and notebooks used in this study are available on GitHub. Thanks for the read.

    本研究中使用的脚本和笔记本可在GitHub上获得。 感谢您的阅读。

    翻译自: https://towardsdatascience.com/crack-site-selection-puzzle-by-geospatial-analysis-part-2-2eefc5f5140

    裂缝探测python

    相关资源:裂缝检测数字图像处理在裂缝识别与检测中的应用_
    Processed: 0.010, SQL: 8