forked from lmotta/scripts-for-gis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
water_src_from_river.sh
42 lines (42 loc) · 1.36 KB
/
water_src_from_river.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
#
# *** 1) Shapefile of example:
# http://hidroweb.ana.gov.br/baixar/mapa/Bacia8.zip
#
# *** 2) Dialect SQLITE
#
# SELECT b.id, Centroid( b.geometry ) as geometry
# FROM
# (
# SELECT COTRECHO as id, Buffer( StartPoint( geometry ), 0.001 ) as geometry
# FROM hidrocotrecho
# --
# UNION
# --
# SELECT COTRECHO as id, Buffer( EndPoint( geometry ), 0.001 ) as geometry
# FROM hidrocotrecho
# )b
# INNER JOIN hidrocotrecho l
# ON
# MbrIntersects( b.geometry, l.geometry ) AND
# Intersects( b.geometry, l.geometry)
# GROUP BY b.id, b.geometry
# HAVING Count(1) = 1;
#
#
# *** 3) Create file without space and only field COTRECHO
ogr2ogr -overwrite -select COTRECHO hidrocotrecho.shp "Hidrografia 1000000.shp"
#
#
printf "Creating water source from river..."
# *** 4) Creating water source
ogr2ogr \
-overwrite \
-dialect SQLITE -sql \
"SELECT b.id, Centroid( b.geometry ) as geometry FROM ( SELECT COTRECHO as id, Buffer( StartPoint( geometry ), 0.001 ) as geometry FROM hidrocotrecho UNION SELECT COTRECHO as id, Buffer( EndPoint( geometry ), 0.001 ) as geometry FROM hidrocotrecho )b INNER JOIN hidrocotrecho l ON MbrIntersects( b.geometry, l.geometry ) AND Intersects( b.geometry, l.geometry) GROUP BY b.id, b.geometry HAVING Count(1) = 1" \
water_src.shp hidrocotrecho.shp
#
# *** 5) Cleanup
rm hidrocotrecho.*
#
printf "\r%-100s\n" "Created water source from river!"