Skip to content

Instantly share code, notes, and snippets.

@giswqs
Created October 17, 2020 14:59
Show Gist options
  • Save giswqs/3fb49e5b90783373547a7755398139f7 to your computer and use it in GitHub Desktop.
Save giswqs/3fb49e5b90783373547a7755398139f7 to your computer and use it in GitHub Desktop.
loop
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import os\nimport glob",
"execution_count": 3,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "in_dir = '/media/hdd/Team-Drives/Data/Boundaries/China/'\nout_dir = '/media/hdd/Team-Drives/Data/Boundaries/China/step1'",
"execution_count": 11,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "files = glob.glob('/media/hdd/Team-Drives/Data/Boundaries/China/*.shp')",
"execution_count": 4,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "files",
"execution_count": 5,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 5,
"data": {
"text/plain": "['/media/hdd/Team-Drives/Data/Boundaries/China/chn_admin_level1.shp',\n '/media/hdd/Team-Drives/Data/Boundaries/China/chn_admin_level2.shp',\n '/media/hdd/Team-Drives/Data/Boundaries/China/chn_admin_line.shp',\n '/media/hdd/Team-Drives/Data/Boundaries/China/chn_admin_level0.shp']"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "threshould = 100\n\nfor file in files:\n print(file)\n basename = str(os.path.basename(file))\n out_name = basename.replace(\"chn_admin\", 'water_body').replace('shp', 'tif')\n out_path = os.path.join(out_dir, out_name)\n print(basename)\n print(out_name)\n print(out_path)\n arcpy.PolygonToRaster(file, out_path)\n out_name_2 = basename.replace(\"chn_admin\", 'seletion_')\n arcpy.PolygonToRaster(file, out_path)",
"execution_count": 14,
"outputs": [
{
"output_type": "stream",
"text": "/media/hdd/Team-Drives/Data/Boundaries/China/chn_admin_level1.shp\nchn_admin_level1.shp\nwater_body_level1.tif\n/media/hdd/Team-Drives/Data/Boundaries/China/step1/water_body_level1.tif\n/media/hdd/Team-Drives/Data/Boundaries/China/chn_admin_level2.shp\nchn_admin_level2.shp\nwater_body_level2.tif\n/media/hdd/Team-Drives/Data/Boundaries/China/step1/water_body_level2.tif\n/media/hdd/Team-Drives/Data/Boundaries/China/chn_admin_line.shp\nchn_admin_line.shp\nwater_body_line.tif\n/media/hdd/Team-Drives/Data/Boundaries/China/step1/water_body_line.tif\n/media/hdd/Team-Drives/Data/Boundaries/China/chn_admin_level0.shp\nchn_admin_level0.shp\nwater_body_level0.tif\n/media/hdd/Team-Drives/Data/Boundaries/China/step1/water_body_level0.tif\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"varInspector": {
"window_display": false,
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"library": "var_list.py",
"delete_cmd_prefix": "del ",
"delete_cmd_postfix": "",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"library": "var_list.r",
"delete_cmd_prefix": "rm(",
"delete_cmd_postfix": ") ",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
]
},
"hide_input": false,
"toc": {
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": true,
"base_numbering": 1,
"title_cell": "Table of Contents",
"title_sidebar": "Table of Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": true
},
"language_info": {
"name": "python",
"version": "3.8.2",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"gist": {
"id": "",
"data": {
"description": "loop",
"public": true
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment