Sunday, March 29, 2020

10 most frequently used "Command Line" commands

Here below are my 10 most frequently used "Command Line" commands.

There are hundreds of commands to use depending on your operating system (OS). Some commands that work on Linux OS may not work on windows OS.

On windows machine, I make use of the Cmder tool to have access to does commands that work on Linux but not windows.

1) cd (change down a directory)




2) cd .. (change up a directory)




3) ls (list all the content of your current working directory) - On windows it is: dir




4) pwd (print name of your current working directory)




5) mkdir (make directory)




6) touch (create a new file)




7) tree (display how a directory structure looks like)




8) cd / (to navigate into the root directory)




9) cd ..\ (go up one level) or cd ..\..\ (go up two levels)



10) To change to a different drive - Type the drive letter and colon. Example is: d: or e: or f:



Enjoy!

Friday, March 27, 2020

Pandas dataFrame - Compare two rows and keep one if condition is met

Here I have two columns 'A' and 'B', I want to keep the row where the cell value in column 'A' is less than the corresponding cell value in column 'B'.



There are many ways to do this, but one of the easiest is to use the query() method to delete rows from a dataframe based on a conditional expression.


You can reset the index values using: reset_index(drop=True)


That is it!

Monday, March 16, 2020

Understanding Spatial Database From Scratch In Open Source Software (QGIS)

Understanding Spatial Database From Scratch In Open Source Software (QGIS)

Location enabled applications are very common nowadays and many of them use spatial database functions from the back-end. This article describes the fundamentals of spatial databases in general as used within the world's leading open source geospatial software.

In our quest to understand what "spatial database" is, let’s first understand the meaning of the two words "spatial" and "database" that formed the phrase.


WHAT IS SPATIAL?
The word spatial describes how objects fit together in a certain location (space), either among the planets or down here on earth. Spatial is relating to, occupying, or having the character of space.


WHAT IS DATABASE?
A database is an organized collection of data that can easily be accessed, managed, and updated. Database is also viewed as a collection of related information that permits the entry, storage, input, output and organization of data. A database consists of an organized collection of data for one or more uses, typically in digital form.

A database management system (DBMS) serves as an interface between users and their database. A database management system (DBMS) consists of software that operates databases, providing storage, access, security, backup and other facilities (Wikipedia, 2020).
Data are organized into fields (columns/attributes) and records (rows/entries) in most traditional or regular databases. Another name for traditional or regular database is non-spatial database or normal database.


COMMONLY USED DATABASES
There are several examples of database servers available, but the top common once include: SQLite, Oracle, MySQL, PostgreSQL, IBM DB2, MS Access and MsSQL server.


WHAT MAKES A DATABASE "SPATIAL DATABASE"?
The ability of a database to store and access data that represent objects defined in a geometric space makes it a Spatial Database. Spatial databases use specialized software to extend a traditional database to store and query data defined in two-dimensional or three-dimensional space. The spatial extensions allow you to query geometries using Structured Query Language (SQL) in a similar way to traditional database queries. Spatial queries and attribute queries can also be combined to select results based on both location and attributes.

A Spatial database is also referred to as 'geodatabase' or 'geographical database' or 'geospatial database'.
Most of the commonly used (well-known) databases that have an extended support for spatial objects are listed below:-

S/N
Database
Spatial Extension
License
1.
Oracle
Oracle Spatial/Locator
Proprietary
2.
PostgreSQL
PostGIS
Open Source
3.
MsSQL Server
MsSQL Spatial
Proprietary
4.
IBM DB2
DB2 Spatial
Proprietary
5.
MySQL
MySQL Spatial
Open Source
6.
MS Access
Not supported
Proprietary
7.
SQLite
SpatiaLite
Open Source

Note: If your dataset is extremely large (big data), you may like to consider a database framework called: Hadoop - SpatialHadoop.

Above are all SQL /relational based databases that best work with data that have relationship.
Another category of databases worth mentioning is the NoSQL (Not only SQL) database. NoSQL databases are designed for volume and rapid indexing of unstructured or semi-structured data. They are good at dealing with lots and lots of reading/writing tasks coming in at once in real-time (a common feature found in web-based GIS), something that tends to slow down SQL/relational databases.

Web-based GIS is probably the area that is currently leading in the use of NoSQL databases within GIS industry, as types of real-time data are more typically found in these platforms when compared to the desktop platforms.
Some popular examples of NoSQL database are:-
a) Cassandra
b) Mongodb
c) CouchDB
d) Redis
e) Riak
f) RethinkDB
g) Couchbase (ex-Membase)
h) Hypertable
i) ElasticSearch
j) Accumulo
k) VoltDB
l) Kyoto Tycoon
m) Scalaris
n) OrientDB
o) Aerospike
p) Neo4j
q) HBase

Saturday, March 14, 2020

ArcMap - Create a curve as part of polygon with straight sides


It is very common to create polygons with all sides perfectly joined by straight lines. And chances are you are already familiar with digitizing polygons where all edges are connected by straight lines.

However, there are occasions where you did prefer a smooth curve to connect your polygon edges as seen below.



On this page, I will guide you on how to achieve such combination of both straight lines and smooth curves in one polygon. This is made possible in ArcMap by switching between "Straight Segment" and "End Point Arc Segment" as seen in the demo video below.




Enjoy!

Sunday, March 8, 2020

Python Pandas - Group by common values in a column and save to excel


I was working with a big dataframe containing states and their LGAs and wards as seen below;-



Now, my client want to have data for each state grouped into a separate excel workbook as seen below;-

Doing this manually will take sometime to complete and beside, we still need to group each state by LGA afterward in a separate excel file (similar to the state above - that is about 774 excel files for all local government areas (LGAs)).

So, I decided to write a python script to make my life easier.

# Group the dataframe by state column using groupby() method
group_df = df.groupby('STATE')

# Generate list of the states (groupby keys)
group_keys = list(group_df.groups.keys())

# Loop over the keys and save each group to excel file
for s in group_keys:
    # save_df = group_df.get_group('Abia')
    save_df = group_df.get_group(s)
    
    # make the file name, e.g: "Abia state.xlsx"
    s_name = s + ' state.xlsx'
    save_df.to_excel(s_name, index=None)


Another example is the split this dataframe table of distinguished senators in Nigeria, so that a table contains only senators from one state.


# Group the dataframe by state column using groupby() method
group_df = senator_df.groupby('State')

# Generate list of the states (groupby keys)
group_keys = list(group_df.groups.keys())

# Loop over the keys and save each group to excel file
for s in group_keys:
    # save_df = group_df.get_group('Abia')
    save_df = group_df.get_group(s)
    
    # make the file name, e.g: "Abia state.xlsx"
    s_name = s + ' state.xlsx'
    save_df.to_excel(s_name, index=None)



The comments included are quite explanatory :)

Enjoy!

Saturday, March 7, 2020

ArcMap - Streaming and Freehand Digitizing


ArcGIS has an excellent digitizing feature where you can digitize or create lines and polygons without clicking at every vertex.

This is one great feature that makes ArcGIS standout from other competing software. When you need to digitize a feature with 1000s of vertexes, use any of the methods below:-

1) Digitize by streaming (stream mode digitizing)
2) Digitize by freehand drawing

The video below, demonstrate how to use each method to digitize a lake as a polygon feature.




It save 90% of your time when compared to the regular digitizing method. It is simply faster/quicker to digitize an irregular shaped feature using these methods.

Enjoy!