Created
May 21, 2020 00:22
-
-
Save Jeremiah-England/58931dd06ce5c3ddd4ee6dadd42d7d11 to your computer and use it in GitHub Desktop.
Time points along geometry in QGIS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from shapely.geometry import mapping, LineString | |
from qgis import processing | |
import timeit | |
import fiona | |
SHAPEFILE_DIRECTORY = 'path/to/shapefiles' | |
# create some linestrings to test on | |
scheme = {'geometry': 'LineString', 'properties': []} | |
for size in [100, 1000, 10000, 100000]: | |
linestring = LineString([(5*i/size, 5*i/size) for i in range(size + 1)]) | |
with fiona.open(SHAPEFILE_DIRECTORY + f'/linestring_{size}.shp', 'w', 'ESRI Shapefile', scheme) as c: | |
c.write({'geometry': mapping(linestring), 'properties': {}}) | |
def get_params(line_size, points_size): | |
return { | |
'INPUT': SHAPEFILE_DIRECTORY + f"/linestring_{line_size}.shp", | |
'DISTANCE': 5 / points_size, | |
'START_OFFSET': 0, | |
'END_OFFSET': 0, | |
'OUTPUT': SHAPEFILE_DIRECTORY + f"/points_{line_size}_{points_size}.shp", | |
} | |
def time_pag(line_size, points_size, number=1): # pag = points along geometry | |
callible = lambda: processing.run('native:pointsalonglines', get_params(line_size, points_size)) | |
return timeit.timeit(callible, number=number) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment