<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<div>
<div dir="auto" style="direction:ltr; margin:0; padding:0; font-family:sans-serif; font-size:11pt; color:black">
Hei Nikos, <br>
</div>
<div dir="auto" style="direction:ltr; margin:0; padding:0; font-family:sans-serif; font-size:11pt; color:black">
What about using gdal_rasterize and then r.external output=MASK? <br>
<br>
</div>
<div dir="auto" style="direction:ltr; margin:0; padding:0; font-family:sans-serif; font-size:11pt; color:black">
Cheers <br>
</div>
<div dir="auto" style="direction:ltr; margin:0; padding:0; font-family:sans-serif; font-size:11pt; color:black">
Stefan <br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> grass-user <grass-user-bounces@lists.osgeo.org> on behalf of Nikos Alexandris <nik@nikosalexandris.net><br>
<b>Sent:</b> Tuesday, May 8, 2018 4:01:14 PM<br>
<b>To:</b> GRASS-GIS user mailing list<br>
<b>Cc:</b> Giacomo.DELLI@ext.ec.europa.eu<br>
<b>Subject:</b> [GRASS-user] To import from or to link to data stored in a PostgreSQL data base?</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:11pt;">
<div class="PlainText">Dears,<br>
<br>
the following concerns an update of an existing workflow, part of which<br>
is GRASS GIS, that makes use of a large PostgreSQL data base which does<br>
not reside locally.<br>
<br>
<br>
The original data set consists of tens of thousands of (overlapping)<br>
polygons. The data are required solely to build raster MASKs.<br>
So, importing the whole of it, is an overkill. Instead, options, already<br>
working, are to split all records in single tables or views. Then access<br>
these via GRASS to perform some analytics.<br>
<br>
<br>
First instructions of the workflow are:<br>
<br>
- read a (external) vector map<br>
- set the computational region<br>
- build a raster mask.<br>
<br>
<br>
Building a MASK using a pseudo vector map that links to an<br>
external table, stored in a PostgreSQL data base, is times slower than<br>
importing the vetor of interest in GRASS GIS and then building a MASK<br>
using the "native" GRASS GIS vector map.<br>
<br>
<br>
Giacomo timed different options, using `v.external` as well as importing<br>
the data using `v.in.ogr`. Specifically,<br>
<br>
- building a MASK using one pseudo vector map (without and with a<br>
  spatial-index), takes about 9 minutes (real time).<br>
<br>
time r.mask vector=test_nogeoindex --o<br>
<br>
real 8m40.306s<br>
user 5m14.225s<br>
sys 0m56.378s<br>
<br>
and<br>
<br>
time r.mask vector=test_geoindex --o<br>
<br>
real 8m46.096s<br>
user 5m15.693s<br>
sys 0m56.346s<br>
<br>
- building a MASK using a native GRASS GIS vector map, imported via a<br>
  table or a view, takes about 0.4 seconds.<br>
<br>
real 0m0.373s<br>
user 0m0.191s<br>
sys 0m0.111s<br>
<br>
and<br>
<br>
real 0m0.350s<br>
user 0m0.179s<br>
sys 0m0.115s<br>
<br>
<br>
For the latter, building a view is way faster than a table (half a<br>
minute for more than 20000 views, while it would take approximately an<br>
hour to build single tables).<br>
<br>
The trade-off appears to be space vs time. If data are imported, more<br>
disk space is required. If data are not imported, and `v.external` is<br>
used, then `r.mask` takes too much time to build a raster MASK.<br>
<br>
- Is it acceptable for `r.mask` to take so long in building a MASK based<br>
  on an external vector map stored in a PostgreSQL data base?<br>
<br>
- Is network connection a limiting factor here, since the PG data base<br>
  is not local?<br>
<br>
- Would anyone have any recommendations/considerations on this approach?<br>
<br>
Thank you, Nikos<br>
</div>
</span></font>
</body>
</html>