Sunday, December 31, 2017

UnicodeDecodeError while reading CSV into Pandas

Hello,

A common error that frustrates a developer while reading CSV file with Pandas is this:-
UnicodeDecodeError Traceback (most recent call last)...UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 9: invalid start byte
The Cause

The usual cause is because the CSV has some hidden special characters and pandas is unable to detect the right encoding system to read the file correctly.


The Solution

I was able to over come this error most of the time by open the CSV file in a text editor such as Sublime Text and re-save it with and encode system.

In Sublime Text, go to: File >> Save with Encoding >> UTF-8 (chose the right encoding for the file in question.)

Doing this means you have defined the encoding system for the file. In other word, you re-defined the file's encoding system which will allow pandas read it correctly.



That is it.
Good Luck

Thursday, December 28, 2017

The way forward for Land Surveying Profession in Nigeria

The way forward for Land Surveying Profession in Nigeria

There is no doubt, Land Surveying profession has experienced huge changes due to advancement in technology. This has lead experts in the field to modify its curriculum and nomenclature to Geomatics Engineering, Surveying and Geoinformatics, Geomatics etc.

Here is an extract from NASGL WhatsApp Group - National Association of Surveying and Geo-Informatics Lecturers (December, 2017)

Happy reading!

-------------------------------

Friday, December 22, 2017

Enable Legend window on QGIS Map Canvas

Hello there,
After styling your map analysis, you will want to add a legend or key to better communicate what is on the map to the map user/reader.

In QGIS, this is usually done through the "Print Composer". While this is excellent, the "Print Composer" dialog isn't an interactive mapping evironment. It is meant for final preparation of a map for printing or sharing in form of image/SVG/PDF.

In this post, we want an interactive legend layer separate from the "Layers Panel" on the map canvas so we can control map interactively to reveal some patterns with interfering with the main project "Layers Panel".

I will show you how to eanble the Legend dialog box using the python console with few lines of PyQGIS code.

Let get started...

Legend on QGIS Map Canvas
Start the "python console" enter the following codes...

from qgis.gui import *
root = QgsProject.instance().layerTreeRoot()
model = QgsLayerTreeModel(root)
view = QgsLayerTreeView()
view.setModel(model)
view.show()



This will start a GUI map Legend containing all the layer in the "Layers Panel". This especially good for interacting with the map canvas without obstructions from other setting on the "Layers Panel" (most especially if the map has large number of layers).

You can save the code as a .py file and run it anytime you want to start the Legend GUI window.

That is it!
Thanks for reading...



Wednesday, December 20, 2017

Creating 3D buildings model in QGIS

Creating 3D buildings model in QGIS

Hello there,
An easy way to wow your GIS client is to display his building mapping project modeled in 3D :).

Ok, on a more serious note, there are many reasons why you will model a map in 3D. In this article, an going to guide you on how to do it in QGIS software.

Let's get started..



Step 1:
Install the Qgis2threejs plugin through menu plugin manager (Plugins >> Manage and install plugins...). This plugin exports terrain data, map canvas image and vector data to your web browser. It allows you to view 3D objects in the web browser (You need a web browser which supports WebGL (Web Graphics Library)).


Step 2:
After isnalling the plugin, you can access it on the menu Web >> Qgis2threejs >> Qgis2threejs

Make sure you have you build layer loaded with attribute column for the builds height.






Step 3:
From the Qgis2threejs dialog window, select the layer you want to display, the building height attribute column, select a location to save the generated .html file and click on "Run" button.



That is it! The generated 3D model should now open on you default browser (as seen in the first image above) and you can always come back to manipulate other setting to get what you want.

Note: Your project coordinate reference system (CRS) should be in meters or the same unit of your building heights to avoid get a funny result.

thanks for reading.

Thursday, December 14, 2017

Switching to Monokai Color Scheme on SublimeText and RStudio


My Favorite IDE Color Scheme is: Monokai. The best color scheme, syntax highlighting and user interface theme for Sublime Text and Visual Studio Code, from the author of the original Monokai color scheme.

In this post, I will show you how to switch to this theme in both SublimeText and RStudio.


SublimeText: Go to Preferences >> Color Scheme and select Monokai





RStudio: Go to Tools >> Global Options >> Appearance >> Editor Theme and select Monokai


That is it!
Enjoy this beautiful  IDE Color Scheme.

Monday, December 11, 2017

Executing Python Script in RStudio - R + Python in one IDE

Hello there,

Without any doubt what-so-ever, the two most powerful data science programming tools are Python and R. How about if you could run these two in on Integrated Development Environment (IDE)?

That is what this post is all about. I will show you how you could run Python scripts right inside of a popular R environment.

R + Python in one IDE

A quick solution to this lies in RStudio. With the latest version of RStudio, you can use RStudio as a Python REPL. But first you need to download and install Python on your machine just the way you would do R.

RStudio is a free and open-source integrated development environment for R, a programming language for statistical computing and graphics. RStudio was founded by JJ Allaire, creator of the programming language ColdFusion (Source: WikiPedia).



To run R script in RStudio:
Because RStudio was originally made for R, it is fairly striaght forward to run R scripts. Just got to the "Comprehensive R Archive Network" (CRAN) web page to download R. Then also download and install RStudio.


To run Python script in RStudio:
To run Python in the same RStudio environment, go to the official Python web page and download it. During the installation, make sure that it is added to your system "Environment Variable" so that RStudio terminal could recognize it without you calling the full PATH all the time.

With the above in place, you can now write your python script in the RStudio "Script Pane" and save it with .py extension. Then run it and see the output on the "Console Pane".


As seen above, I import 'pandas' module and created a dataframe in the "Script Pane" and the result is displayed on the "Console Pane".

You can also use the interactive terminal to run python scripts by going to: Tools >> Terminal >> New Terminal. From the new terminal window that open, you can call the python interpreter and enter any python command just as you would do on cmd or python IDLE.



That is it!

Note: Apart fro R and Python, RStudio supports other programming languages such as JavaScript, SQL, etc.

Saturday, December 2, 2017

Downloading High Resolution Satellite Image Using Terra Incognita Software


Terra Incognita is a GPS mapping and management software that is available for download here. It is a program for downloading web source maps or local files maps for various programs or GPS devices.

In this post, I will show you how to use it to download High Resolution Satellite Images.