Thursday, April 19, 2018

Pemetaan Tumpahan Minyak di Pantai Balikpapan Menggunakan Citra Radar Sentinel 1A dan Google Earth Engine

Kasus tumpahan minyak di Pantai Balikpapan awal April 2018 menjadi isu hangat bulan ini. Berbagai media memberitakan dampak negatif dari bencana lingkungan ini. Sebagai geoscientist, isu ini menarik buat saya pribadi karena sebaran tumpahan minyak di laut saat ini sudah bisa dideteksi dengan baik dan dipetakan sebarannya menggunakan data radar SAR.

Dengan bermodal layanan cloud image processing dari Google Earth Engine (GEE) saya mencoba bereksperimen memetakan sebaran area tumpahan minyak di Pantai Balikpapan. GEE menyediakan akses ke repositori data Sentinel 1 SAR yang saat ini operasional, dan kebetulan selang beberapa hari dari kejadian tumpahan minyak, satelit Sentinel 1A lewat di atas Balikpapan.

Saya menggunakan kode awal dari Simon Ilyuschenko dari GEE Team yang digunakan untuk pemetaan area banjir dari citra Sentinel, yang saya modifikasi untuk lebih peka terhadap tumpahan minyak. Dengan menggunakan teknik pemrosesan image tresholding dan image difference dari citra yang merekam pada kondisi sebelum ( minggu ke 3 maret 2018) dan sesudah kejadian tumpahan minyak (minggu pertama April 2018), area sebaran tumpahan minyak dapat diidentifikasi. Tumpahan minyak dapat diidentifikasi dengan mudah dari citra SAR karena  minyak dan air mempunyai konstanta dielektrik yang berbeda, dan spektrum gelombang mikro pada panjang gelombang C Band sangat sensitif dengan perbedaan konstanta dielektrik, terutama pada polarisasi VV (Vertical send Vertical return)

Meskipun demikian, kode ini belum sempurna karena masih terdapat area - area yang misklasifikasi, sehingga revisi dan pemrosesan citra lebih lanjut perlu dilakukan. Sebenarnya identifikasi area tumpahan minyak ini lebih gampang dilakukan kalau kita menggunakan software desktop yang bisa mengolah data radar seperti ESA SNAP, ENVI Sarscape atau ERDAS dan PCI Geomatica, tetapi GEE menawarkan sesuatu yang berbeda, yaitu kepraktisan, karena kita tidak perlu mendownload data yang ukurannya cukup besar, dan menyiapkan hardware komputer yang mumpuni. Semua bisa dikerjakan di Cloud hanya dengan mengetikkan beberapa baris kode javascript API. Berikut ini screenshot hasilnya.


Rekan - rekan yang tertarik mencoba bisa menggunakan kode yang saya gunakan di bawah ini. Sukur -sukur bisa memperbaiki dan mengembangkan lebih lanjut. Jangan lupa colek saya ya kalau ada revisi.

var geometry = geometry;

// Load Sentinel-1 images to map Oil Spill in Balikpapan Indonesia April 2018.
// This script was originally written by Simon Ilyushchenko (GEE team)
// and adapted by Simon Gascoin (CNRS/CESBIO) and Michel Le Page (IRD/CESBIO)
// and also adapted by Bramantiyo Marjuki (Indonesia Ministry of Public Works/Regional Development Departement of Diponegoro University)
// Default location
var pt = geometry; //Coulommiers

// Load Sentinel-1 C-band SAR Ground Range collection (log scaling, VV co-polar)
var collection =  ee.ImageCollection('COPERNICUS/S1_GRD').filterBounds(pt)
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
.select('VV');

// Filter by date 
var before = collection.filterDate('2018-03-10', '2018-03-29').mosaic();
var after = collection.filterDate('2018-03-31', '2018-04-06').mosaic();
var diff = after.subtract(before);
// Threshold smoothed radar intensities to identify "spill" areas.
var SMOOTHING_RADIUS = 200;
var DIFF_UPPER_THRESHOLD = -0.9;

var diff_smoothed = after.focal_median(SMOOTHING_RADIUS, 'circle', 'meters').subtract(before.focal_median(SMOOTHING_RADIUS, 'circle', 'meters'));

var diff_thresholded = diff_smoothed.lt(DIFF_UPPER_THRESHOLD);

// Display map
Map.centerObject(pt, 13);
Map.addLayer(before, {min:-30,max:0}, 'Before oil spill');
Map.addLayer(after, {min:-30,max:0}, 'After oil spill');
Map.addLayer(before.addBands(after).addBands(diff), {min:-10,max:10},'composite', 0);
Map.addLayer(after.subtract(before), {min:-10,max:10}, 'After - before', 0);
Map.addLayer(diff_smoothed, {min:-10,max:10}, 'diff smoothed', 0);
Map.addLayer(diff_thresholded.updateMask(diff_thresholded),
  {palette:"0000FF"},'oil spill areas - blue',1);

Saturday, February 17, 2018

Using Mapproxy to cache and host both online and offline basemaps (Basemap series Part 5)

Here we go again

In this post now I will continue about how to simultaneous host and cache basemaps, either from online or offline sources.

First, If you want to just use online basemaps to be available or hosted on your favorite protocols (like serving google Street Map to WMS or ArcGIS REST service) you could use Portable Basemap Server. I have previously covered it, check this LINK.

If you want to only cache the tiles to be used for offline needs, you can use MOBAC or SasPlanet.

Now if you want to have capabilities like both serving basemaps directly to your user using client server services protocols (either online or local online or even pure offline situation) while maintain online access, plus adding caching capabilities (useful if you want your application to be as fast as possible), you can use MAPPROXY.

It can do what PBS can do plus it has caching ability, so you wont have to worry if your internet networks get troubled, because the generated caches will serve as backup renderer. Basically it is combine PBS, and offline cacher like MOBAC or Sasplanet.

Now about the procedures:

1. Install mapproxy using python PIP from their official page.
2. You are python blind, dont worry this SITE provide you offline installer (install it as windows services for your convenient). Because the program will have their own webserver, beware of Port Conflict, make sure you choose unused HTTP PORT on your server/computer. 
3. Now deep down to settings, make YAML configuration file. The structure of the code will looks like this
services:
  demo:
  tms:
  wms:
    md: 
      title: Google MapProxy WMS Server
  wmts:
    kvp: false
    restful: true

sources:
  google_image:
    type: tile
    url: http://mt1.google.com/vt/lyrs=s&x=%(x)s&y=%(y)s&z=%(z)s&s=Galileo
    grid: grid_webmerc

grids:
  grid_webmerc:
    base: GLOBAL_WEBMERCATOR
  grid_merc:
    base: GLOBAL_MERCATOR

caches:
  cache_google_image:
    grids: [grid_merc]
    sources: [google_image]
    cache:
      type: mbtiles

layers:
  - name: layer_google_image
    title: Google Satellite Map
    sources: [cache_google_image]

globals:
  image:
    resampling_method: bilinear
    jpeg_quality: 90

4. The above YAML config file is dedicated to serve google image to your clients. Refer to this LINK for documentation. The most important things is, you must know the exact tile query URL of your target basemap providers.

5. Now save the YAML to directory C:\ProgramData\Mapproxy

6. Next, open the mapproxy_app.py or mapproxy_srv.py in C:\ProgramFiles(x86)\Mapproxy, and change the app_config line to your created YAML file.



7. Load up the mapproxy by launch it from CMD from the program files directory, like this (dont forget to run as administrator to avoid denied access error).


8. or from Windows Services (when it installed as services). Load the windows services from Control Panel or windows search tool at the taskbar and type "services",


9. Open browser and check if the webserver has been running, the typical URL is localhost:port/mapproxy/demo. In this page, you will see all the capabilities and protocols and endpoints of the map services. From this point, you can starts to seed the services to your GIS desktop, WebGIS, mobileGIS whatever.


10. A sneak peek.




Basemap is not so myths after all,

Stay Tuned


Friday, January 26, 2018

Modifying Vector Tile Style (Basemap series Part 4)

Please read my previous blog post about how to author vector tile.

Okay now I will continue about how to modify vector tile styling to suit custom needs.

we start from the vector tiles layer hosted on ArcGIS online.



what you must do first is copy the style using clik on layer name, and choose copy, because I use indonesian languange, it is called SALIN.


then followed by Save layer from the copied layer.


In order to edit the style of the copied layer, you can use two built in application from ArcGIS online, which is

1. Simple Editor . This is code based, so you can freely modify as long as you understand the syntax. The syntax is similar with CSS for your information.


2. Vector Basemap Style Editor. This tool is more GUI based and perform better in many cases.


Give the two apps permission to works on your arcGIS online account

Using these two applications, you can modifying the style of the tiled layer like changing colors, thicken the outline, make the layer transparent, changing font or any other modification permitted by Vector based tiled layer specifications. Dont forget to save your works.

Besides these two built in apps, you can edit the style using any other JSON supported text editor and validator (i.e notepad++, adobe brackets , psPad, or just plain NOTEPAD *lol)

Here are two screenshots of original and modified vector layer style coming from same vector tile package source.




Cheers!