Skip to content

Instantly share code, notes, and snippets.

@giswqs
Created October 20, 2020 23:46
Show Gist options
  • Save giswqs/3e2be526bc5df83d71269ac0fcb01d4f to your computer and use it in GitHub Desktop.
Save giswqs/3e2be526bc5df83d71269ac0fcb01d4f to your computer and use it in GitHub Desktop.
csv to ee
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import os\nimport ee\nimport geemap",
"execution_count": 1,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "Map = geemap.Map()\nMap",
"execution_count": 2,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "Map(center=[40, -100], controls=(WidgetControl(options=['position'], widget=HBox(children=(ToggleButton(value=…",
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "8476bc48fe864a6d995497262924cfa2"
}
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "points = []\n\nwith open('pts.csv') as f:\n lines = f.readlines()\n for line in lines[1:]:\n lon = float(line.split(',')[2])\n lat = float(line.split(',')[3])\n points.append([lon, lat])",
"execution_count": 3,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "points",
"execution_count": 4,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 4,
"data": {
"text/plain": "[[-92.72554643, 38.53975537],\n [-92.7276574, 38.53914705],\n [-92.72588034, 38.53929967],\n [-92.72602624, 38.54094663],\n [-92.72643792, 38.53948058],\n [-92.71708615, 38.54290355],\n [-92.71704117, 38.54273717],\n [-92.71801116, 38.54321991],\n [-92.71712318, 38.54300404]]"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "ee_list = ee.List(points)",
"execution_count": 5,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "ee_points = ee_list.map(lambda xy: ee.Feature(ee.Geometry.Point(xy)))",
"execution_count": 6,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "fc = ee.FeatureCollection(ee_points)",
"execution_count": 7,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "Map.addLayer(fc, {}, 'points')",
"execution_count": 8,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "Map.centerObject(fc, 15)",
"execution_count": 9,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"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"
},
"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"
]
},
"gist": {
"id": "",
"data": {
"description": "csv to ee",
"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