1

Is it possible to generate service areas from 65000 facilities? Batch processing or database analysis?

A friend tried with 6000 (1/10) facilities, OpenStreetMap data (country Latvia) to calculate service areas for 20 minute driving time but no success (memory error). That in ArcGIS.

In QGIS tied plugin Routes and Zones with no success (memory). The same for built in Service area tools. Maybe is limit for facilities count or ratio facilities/memory?

2
  • 2
    Have you tried Service area from point??
    – BERA
    May 7, 2022 at 13:52
  • Yes. But is one service area from one point. Don't know how to arange batch processing for 65000 points. May 7, 2022 at 20:19

1 Answer 1

2

You can execute Service Area from point in a loop for each point using pyqgis.

Try this on a small sample of your data first. You can select a sample of points and change pointlayer.getFeatures() to pointlayer.getSelectedFeatures() to execute it on selected points only.

#Change these two lines to match your layer names in Layers panel
roadlayer = QgsProject.instance().mapLayersByName('roads123')[0] #Create a layer
pointlayer = QgsProject.instance().mapLayersByName('points123')[0] #Same

outputs = [] #A list to hold each points service area

for pointnum, point in enumerate(pointlayer.getFeatures(), 1): #For each point
    print("Calculating point {0} of {1}".format(pointnum, pointlayer.featureCount()))
    x, y = point.geometry().asPoint().x(), point.geometry().asPoint().y() #Extracy x and y coordinates
    crs = pointlayer.crs().authid() #And coordinate system

    #Adjust the parameters as you like:
    #See: https://docs.qgis.org/testing/en/docs/user_manual/processing_algs/qgis/networkanalysis.html#qgisserviceareafrompoint
    #I use Strategy 0 which is shortest 
    #TRAVEL_COST2 is the distance. I cant find that parameter name in the docs
    result = processing.run("native:serviceareafrompoint", 
        {'INPUT':roadlayer,'STRATEGY':0,'DIRECTION_FIELD':'','VALUE_FORWARD':'',
        'VALUE_BACKWARD':'','VALUE_BOTH':'','DEFAULT_DIRECTION':2,'SPEED_FIELD':'',
        'DEFAULT_SPEED':50,'TOLERANCE':0,
        'START_POINT':f'{x},{y} [{crs}]',
        'TRAVEL_COST2':5000,'INCLUDE_BOUNDS':False,'OUTPUT_LINES':'TEMPORARY_OUTPUT'})['OUTPUT_LINES']
    outputs.append(result) #Each output is a layer, store it in outputs list

#Merge all the outputs
processing.runAndLoadResults("native:mergevectorlayers", {'LAYERS':outputs,
    'CRS':None,'OUTPUT':'TEMPORARY_OUTPUT'})

print('Done')

enter image description here

2
  • Thank You! What version of QGIS You running this script? I'm stacked on error NameError for "processing". Try to add (read in user forum) "feedback = QgsProcessingFeedback()" . May 9, 2022 at 6:01
  • QGIS version 3.24.0-Tisler
    – BERA
    May 9, 2022 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.