<jupyter_start><jupyter_text>Selecting DatasetsSelect the workspace, this is the folder that will be used for the outputs. NOTE Select an empty folder as all the files will be deleted from the workspace You will also have to select the three datasets used in the analysis. These are:    1) Administrative boundaries.2) Agro Maps<jupyter_code>messagebox.showinfo('AGRODEM Creating base grid', 'Output folder')
workspace = filedialog.askdirectory()

messagebox.showinfo('AGRODEM Creating base grid', 'Select the administrative boundaries')
filename_admin = (filedialog.askopenfilename(filetypes = (("shapefile","*.shp"),("all files","*.*"))))
admin=gpd.read_file(filename_admin)

messagebox.showinfo('AGRODEM Creating base grid', 'Select the agro map')
filename_agro = (filedialog.askopenfilename(filetypes = (("shapefile","*.shp"),("all files","*.*"))))
agro=gpd.read_file(filename_agro)<jupyter_output><empty_output><jupyter_text>Select the target coordinate systemFind the appropriate target crs from:  https://epsg.io/<jupyter_code>crs = 'EPSG:3037'<jupyter_output><empty_output><jupyter_text>Ensuring vectors are in the same coordinate system<jupyter_code># reprojecing to target coordinate system written above
def target_crs(vectors,crs,workspace):   
    vectors = vectors.to_crs(crs) 
    vectors.to_file(workspace, driver='ESRI Shapefile')  
    return vectors

agro_pr = agro.to_crs(crs)
admin_pr = admin.to_crs(crs)<jupyter_output><empty_output><jupyter_text>Fix geometries<jupyter_code>def fixgeometries(polygon):
    #creates a valid representation of a given invalid geometry without losing any of the input vertices. 
    fix = polygon.buffer(0.001)
    return fix<jupyter_output><empty_output><jupyter_text>Preparing agro maps<jupyter_code>#fix geometries
fixed_agro = fixgeometries(agro_pr)

#clip agro map to place of interest
clipped_agro = gpd.clip(fixed_agro,admin_pr)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1032325338894682, 'fraction_numerical': 0.005213764337851929, 'mean_word_length': 7.165957446808511, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '93899', 'license': 'MIT', 'n_tokens_mistral': 647, 'n_tokens_neox': 615, 'n_words': 157, 'path': 'agrodem_preprocessing/Downscaling/Downscaling_prepping/.ipynb_checkpoints/Agrodem_plugin_creating_basegrid_master-checkpoint.ipynb', 'repo_name': 'babakkhavari/agrodem', 'size': '1918'}