Wednesday, June 17, 2015

Using GDAL to cut a large GeoTIFF raster image to smaller files

Sometimes it may be necessary to cut up a large raster image into smaller tiles so that the dataset can be more manageable. GDAL's command line executable gdal_translate has a projwin option where a bounding window in geographical coordinates can be specified to extract a smaller subset from the input raster image into one or more smaller raster files.


The following steps show how this can be done.

  1. Create a DOS batch file with commands of the following syntax.

    gdal_translate -projwin xlow yhigh xhigh ylow input.tif output.tif

    Note:
    replace xlow with the clipping box's low X geographical coordinate
    replace yhigh with the clipping box's high Y geographical coordinate
    replace xhigh with the clipping box's high X geographical coordinate
    replace ylow with the clipping box's low Y geographical coordinate


  2. Run the clipping batch file.



    The larger image is separated into smaller tiles.

Wednesday, June 10, 2015

WebApp for monitoring traffic incidents in Singapore

This web app allows users to monitor traffic incidents in Singapore including accidents, vehicle breakdowns, obstacles, road blocks, traffic diversions etc. in Singapore (updated every 2 minutes) on a Google Maps backdrop by subscribing to the traffic incidents geoRSS feed. The incidents are shown as clickable and color coded icons with tool tips. 


Clicking on the icon will bring up more details about the incident. 

Together with Google's StreetView, users can truly immerse themselves into the incident environment.


The traffic incidents are also shown as a list on the right pane. The list can be sorted by incident category, and date-time - either in ascending or descending order. Clicking the Maps hyperlink will automatically locate, zoom, and center the incident in the Map view.
The WebApp can be launched from this link http://dominoc925-pages.appspot.com/webapp/trafmon_sg/default.html

Tuesday, June 2, 2015

Using Git with Visual Studio: cloning a repository

I like using the source code repository tool Git with Microsoft Visual Studio 2013. It makes life easier for a developer in managing software code. To start using Git, perhaps one of the first thing to do is to set up Git with Visual Studio and clone an existing repository. The following steps illustrate the basic steps.

  1. Start Visual Studio.


  2. Select View | Team Explorer.

    The Team Explorer pane appears on the right.

  3. Click Settings. Then click Git Settings.

    The Git Global Settings appear.

  4. Type in your User Name and Email Address that you want to associate with Git. If you like, define the Default Repository Location. Click Update.

    The settings are saved.

  5.  Click the Connect to Team Projects button.


  6. Click Clone.


  7. Type in the URL to the Git repository.


  8. Define the directory to clone to, e.g. D:\GitRepos\gps-localtime-windows\.
  9. Click Clone.

    Processing messages appear.


    Finally, the repository is cloned.

Saturday, May 16, 2015

Trainsity Sapporo Android App

Find your way around Sapporo city's subway using the high resolution vector maps of the train network. The following metro rail lines are available:

  • Namboku, 
  • Tozai, and 
  • Toho lines. 

The maps have small file size footprints but with many levels of zoom and can work offline without connecting to the Internet. Users can click the train station box labels to open Google Maps or Google StreetView, where they can use all the functions of the Google apps to visualize the surrounding area and/or perform routing for directions. There is also an offline function to calculate the best way to travel from a station to another station with a direction breakdown and timings (which may vary from the actual travelling time).

On a mobile handset, the app will display a list of train maps, which when tapped will open up a detail view of the subway transit map, as shown below.

Tapping the station boxes will bring up an option menu where users can choose to display the station in Google Maps or Street View.

There is also an option to find the best direction to or from the tapped stations.

The app is also optimized for tablet sized devices. Both the list and the vector maps are displayed at the same time, as shown below.

The user can toggle the map to full screen mode by tapping the action bar icon at the top right corner.

 The app can be downloaded from the Google Play Store. Just click the button below.
Get it on Google Play

Monday, April 13, 2015

Resampling a single GeoTiff image in QGIS

QGIS comes bundled with GDAL tools which you can use to resample one or more raster images, though the QGIS menu labels may be a little unclear.

To resample an geo image in QGIS, do the following:

  1. Start QGIS. Optional. Load in a geo image file to resample.



  2. Select Raster | Projections | Warp (Reproject).

    The Warp (Reproject) dialog box appears.

  3. In the Input file field, click Select. Browse and select the source file, e.g. UTM2GTIF.tif.
  4. In the Output file field, click Select. Type in the destination file e.g. ResampleUTM2GTIF.tif.
  5. Toggle on Resize.
  6. In the Width field, type in the destination width in pixels e.g. 100.
  7. In the Height field, type in the destination height in pixels e.g. 133.


  8. Click OK.

    The source file is resampled.

Tuesday, April 7, 2015

Using RawTherapee RGB curves to make color corrections to aerial photographs

Besides graphics editing software like Photoshop and Gimp, the free and open source raw image format processing software RawTherapee (see http://rawtherapee.com/) can be used to correct color cast problems in aerial photographs due to atmospheric haze or sensor problems. An example of an image with a color cast problem is shown below. The sample can be downloaded from http://commons.wikimedia.org/wiki/File:Lakeside_Amusement_Park,_1966.jpg.
Aerial photograph courtesy of http://www.airlinesafety.com/editorials/AboutTheEditor.htm
RawTherapee has the RGB curves function that can be used to easily correct the color cast problem.

The trick to solving the color cast problem is to adjust the RGB curves to ensure the color gray values have the same RGB values.  If a gray color feature in the image e.g. an asphalt road has unequal RGB values, then the image has a color cast problem. Some times, it may be necessary to adjust the curves in the middle, dark, and/or light tones. The following example illustrates how to correct the color cast problem using RawTherapee.


  1. Start RawTherapee. Load the image.


  2. Click the Color tab on the right pane. Then click RGB Curves as shown below.


  3. Move the screen pointer around the image. Observe the RGB % values in the Navigator pane on the left when the pointer is on a mid tone gray colored feature e.g. paved road.



    Note: in this example, the RGB values are 67.5%, 63.5%, and 82.4%. The numbers indicate that there is a blue cast in the mid tone values, i.e. the blues are too high and will have to be lowered. The red and green values are alright (maybe the reds need to be lowered just a tad).
  4. In the RGB Curves, choose the Blue Channel Control Cage as shown below.


  5. Drag down the blue curve in the middle tone area. Move the cursor to the mid tone gray color feature and observe the adjusted RGB values in the Navigator pane underneath the screen pointer. Readjust the blue curve if necessary until the RGB values are about equal.


  6. I decided to adjust the mid tone red curve a little. So in the RGB Curves pane, click the Red Channel Control cage. Drag down the red curve in the mid tone area slightly and observe the adjusted RGB values in the Navigator pane. Readjust until the RGB values are about equal.


  7. No adjustment is necessary for the light tones since the color cast seems to be minimal. However the dark tones seem to need a little more red values as shown in the screenshot below.


  8. In the RGB Curves pane, drag the red curve in the dark tones slightly up. When the RGB values are about equal, the correction is complete.

    Note: after every change, always move the cursor to the dark area and check the adjusted RGB values in the Navigator pane.
  9. Now to apply the color correction, send the job to the queue and generate the image in your desired format e.g. JPEG.

    The color corrected image is created.


Monday, March 30, 2015

How to change the Android ActionBar background from the default dark color

By default, the background color of the ActionBar in any Android App is black as shown in the example below.

I wanted to style the background to a different non-black color. After some investigation, I had to do the following:
  • Choose a color
  • Define a custom theme
  • Assign the custom theme to the application
Choose a color
  1. Decide on a color to use for the background e.g. red or #303f9f in hex.
  2. Decide on a color for the text e.g. white of #ffffff in hex.
  3. Add these colors to the Android app's XML file e.g. [app]/res/values/color.xml.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="actionbar_background">#303f9f</color>
<color name="actionbar_text">#ffffff</color>
</resources>


Define a Custom theme

  1. Open up the Android app's styles XML file e.g. [app]/res/valuess/styles.xml, in a text editor.
  2. Append in a new style e.g. CustomActionBarTheme that inherits a parent theme e.g. Theme.AppCompat.Light.DarkActionBar.
  3. Append in new styles for the action bar, title text, and tabs text, e.g. MyActionBar, MyActionBarTitleText and MyActionBarTabText.
  4. The following code shows the complete styles.xml file.

<resources>
 
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
 
<style name="CustomActionBarTheme"
parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">@style/MyActionBarTabText</item>
<item name="android:actionMenuTextColor">@color/actionbar_text</item>
 
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
<item name="actionBarTabTextStyle">@style/MyActionBarTabText</item>
<item name="actionMenuTextColor">@color/actionbar_text</item>
</style>
 
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse" >
<item name="android:background">@color/actionbar_background</item>
<item name="android:titleTextStyle">@style/MyActionBarTitleText</item>
 
<!-- Support library compatibility -->
<item name="background">@color/actionbar_background</item>
<item name="titleTextStyle">@style/MyActionBarTitleText</item>
</style>
 
<!-- ActionBar title text -->
<style name="MyActionBarTitleText"
parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/actionbar_text</item>
</style>
 
<!-- ActionBar tabs text -->
<style name="MyActionBarTabText"
parent="@style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">@color/actionbar_text</item>
</style>
 
</resources>


Assign the new custom theme to the Android Application

  1. Open up the AndroidManifest.xml file in a text editor.
  2. In the application tag, change the theme to the new theme e.g. @style/CustomActionBarTheme.
  3. The following code snippet shows the relevant portion of the edited AndroidManifest.xml file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="auto"
package="com.dom925.demo" >
 
<application
android:name=".App"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/CustomActionBarTheme">
 
<!-- etc -->
 
</manifest>

Now the application's ActionBar should be using the custom theme with a non-black background.
Related Posts with Thumbnails