Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from qgis.gui import *
- from qgis.core import *
- import processing
- #------------------------------------------------------
- # User Variables:
- #path to data location
- soil_path = "D:\soil\soildata"
- shp_path = "D:\soil\field_boundaries"
- print ("Soil data: " + soil_path)
- print ("Field Boundaries: " + shp_path)
- #-------------------------------------------------------
- def get_data(path, ending):
- data_list = []
- for root, dirs, files in os.walk(path):
- for data in sorted(files):
- if data.endswith(ending):
- data_list.append(os.path.join(root, data))
- return data_list
- print (str(len(data_list)) + " shapefiles found")
- def clip(vor_poly):
- clipped_data = []
- shp_data = get_data(shp_path, ".shp")
- print (str(len(shp_data)) + " field boundaries found")
- for f in shp_data:
- print (f)
- print (vor_poly)
- if f.geometry().intersects(vor_poly.geometry()):
- OUTPUT = os.path.splitext(polygons)[0] + os.path.basename(f) + ".shp"
- processing.runalg('qgis:clip', vor_poly, f, OUTPUT)
- print ("clipped " + OUTPUT)
- clipped_data.append(OUTPUT)
- return clipped_data
- def qgisprocess(soilpts):
- #voronoi polygons with 0 size buffer
- print("Voronoi Polygons")
- for f in soilpts:
- split_path = os.path.splitext(f)[0]
- inlayer = f
- outlayer = split_path + "_vor_poly.shp"
- processing.run("qgis:voronoipolygons", { 'INPUT':inlayer, 'BUFFER': 0, 'OUTPUT': outlayer})
- clippedpolys = clip(outlayer)
- def main():
- #list of data
- soil_data = get_data(soil_path, ".shp")
- print("running QGIS processes")
- qgisprocess(soil_data)
- if __name__ == '__console__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement