Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
David Youssefi
OTB Guided Tour
Commits
12450d49
Commit
12450d49
authored
May 15, 2019
by
David Youssefi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BUG: Remove SQLite files
parent
f9af702f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
10 deletions
+21
-10
ogr_io.py
ogr_io.py
+1
-0
step4_filter_shapefile.ipynb
step4_filter_shapefile.ipynb
+20
-10
No files found.
ogr_io.py
View file @
12450d49
...
...
@@ -2,6 +2,7 @@
Read/Write OGR functions
"""
from
osgeo
import
ogr
import
sys
def
openToRead
(
shapefile
):
driver
=
ogr
.
GetDriverByName
(
"SQLite"
)
...
...
step4_filter_shapefile.ipynb
View file @
12450d49
...
...
@@ -31,6 +31,7 @@
"source": [
"import os\n",
"import subprocess\n",
"from osgeo import ogr, osr\n",
"\n",
"import ogr_io\n",
"\n",
...
...
@@ -41,12 +42,23 @@
"OUTPUT_DIR = \"output\"\n",
"\n",
"# Input / Output filenames\n",
"envelope_fname = os.path.join(DATA_DIR, \"morbihan.sqlite\")\n",
"ndwi_thres_fname = os.path.join(OUTPUT_DIR, \"ndwi_threshold30.tif\")\n",
"watermask_fname = os.path.join(OUTPUT_DIR, \"watermask.sqlite\")\n",
"envelope_fname = os.path.join(OUTPUT_DIR, \"morbihan.sqlite\")\n",
"results_fname = os.path.join(OUTPUT_DIR, \"results.sqlite\")\n",
"geojson_fname = os.path.join(OUTPUT_DIR, \"geojson.json\")\n",
"\n",
"# Get SQLite driver\n",
"outDriver = ogr.GetDriverByName(\"SQLite\")\n",
"\n",
"# Remove results if it already exists\n",
"if os.path.exists(results_fname):\n",
" outDriver.DeleteDataSource(results_fname)\n",
" \n",
"# Remove watermask if it already exists\n",
"if os.path.exists(watermask_fname):\n",
" outDriver.DeleteDataSource(watermask_fname)\n",
"\n",
"# Convert the TIF file in a shapefile with polygons\n",
"try:\n",
" subprocess.call([\"gdal_polygonize.py\", ndwi_thres_fname,\"-f\", \"SQLite\", watermask_fname])\n",
...
...
@@ -82,15 +94,6 @@
"metadata": {},
"outputs": [],
"source": [
"from osgeo import ogr, osr\n",
"\n",
"# Save extent to a new Shapefile\n",
"outDriver = ogr.GetDriverByName(\"SQLite\")\n",
"\n",
"# Remove output shapefile if it already exists\n",
"if os.path.exists(results_fname):\n",
" outDriver.DeleteDataSource(results_fname)\n",
"\n",
"# create the spatial reference, WGS84\n",
"srs = osr.SpatialReference()\n",
"srs.ImportFromEPSG(32630)\n",
...
...
@@ -163,6 +166,13 @@
"m, dc = display_api.rasters_on_map([raster], OUTPUT_DIR, [DATE], geojson_data=fc)\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment