Friday, June 30, 2023

Plotting Survey Data in AutoCAD Using Script

 Often you will find yourself trying to plot multiple survey points in AutoCAD. How about if I tell you that you don't have to manually plot each point after the other? You can type a script command with the data points you want to plot into a file and have it plotted on the fly.

Point

Easting

 Northing

P1

331117.87

939830.78

P2

331132.19

939673.41

P3

331144.47

939620.28

P4

331107.64

939601.88

P5

331117.87

939548.75

P6

331173.11

939507.87

P7

331258.45

939526.61

P8

331326.25

939512.55

P9

331438.83

939554.72

P10

331501.51

939534.28

P11

331546.29

939513.83

P12

331630.72

939516.38

P13

331715.15

939521.5

P14

331749.7

939536.83

P15

331766.33

939577.72

P16

331749.7

939665.9

P17

331666.54

939700.4

P18

331557.8

939688.9

P19

331443.94

939678.68

P20

331424.75

939745.13

P21

331391.49

939816.69

P22

331359.51

939883.14

P23

331227.51

939850.09

Plotting using Coordinates

Lets say you got these twenty-three survey points to plot. To use a script to plot the points, you will create a script file with .scr extension (AutoCAD Script (.scr)).

Inside the file, you will type the data like this:-

_POINT 331117.87,939830.78
_POINT 331132.19,939673.41
_POINT 331144.47,939620.28
_POINT 331107.64,939601.88
_POINT 331117.87,939548.75
_POINT 331173.11,939507.87
_POINT 331258.45,939526.61
_POINT 331326.25,939512.55
_POINT 331438.83,939554.72
_POINT 331501.51,939534.28
_POINT 331546.29,939513.83
_POINT 331630.72,939516.38
_POINT 331715.15,939521.50
_POINT 331749.70,939536.83
_POINT 331766.33,939577.72
_POINT 331749.70,939665.90
_POINT 331666.54,939700.40
_POINT 331557.80,939688.90
_POINT 331443.94,939678.68
_POINT 331424.75,939745.13
_POINT 331391.49,939816.69
_POINT 331359.51,939883.14
_POINT 331227.51,939850.09
Run or Load the script file using the SCRIPT command. This will plot all the points starting from the first to the last point.


Make sure you use the PTYPE command to set the point style and size. The end result should look like this image below:-

Friday, June 23, 2023

Mapping GTBank Card Printing Machine Locations

 In this post, I will map the locations of GTBank Card Printing Machine

As at the time of writing, GTBank listed 66 locations where you can self-print ATM card instantly. 

These addresses are note geocoded (that is they don't have latitude and longitude coordinates). For GIS mapping purpose, we need the latitude and longitude coordinates.

Lets see if the trending AI tool "ChatGPT" can help complete this geocoding process. Unfortunately, ChatGPT doesn't give me direct result instead it gave hint on where to get the results.



Make use of the hints provided by ChatGPT, I was able to generate the  latitude and longitude coordinates of GTBank card printing machine locations for mapping purpose as seen below.



Thanks for reading.

Sunday, June 18, 2023

Format codes for python DateTime object

 Python DateTime object have several format codes as listed on this w3schools page. In this post, we shall extract different components of the table from a datatime object that looks like this: YYYY-MM-DD HH:MM:SS

Where;-

  • YYYY = Year
  • MM = Month
  • DD = Day
  • HH = Hour
  • MM = Minute
  • SS = Second

Example is: '2023-02-01 10:04:19'. 

The table below shows the format codes and their description;-



from datetime import datetime


date_time_string = '2023-02-01 10:04:19'
dt = datetime.fromisoformat(date_time_string)


print(dt.strftime("Weekday, short version >> %a \n"))
print(dt.strftime("Weekday, full version >> %A \n"))
print(dt.strftime("Weekday as a number 0-6, 0 is Sunday >> %w \n"))
print(dt.strftime("Day of month 01-31 >> %d \n"))
print(dt.strftime("Month name, short version >> %b \n"))
print(dt.strftime("Month name, full version >> %B \n"))
print(dt.strftime("Month as a number 01-12 >> %m \n"))
print(dt.strftime("Year, short version, without century >> %y \n"))
print(dt.strftime("Year, full version >> %Y \n"))
print(dt.strftime("Hour 00-23 >> %H \n"))
print(dt.strftime("Hour 00-12 >> %I \n"))
print(dt.strftime("AM/PM >> %p \n"))
print(dt.strftime("Minute 00-59 >> %M \n"))
print(dt.strftime("Second 00-59 >> %S \n"))
print(dt.strftime("Microsecond 000000-999999 >> %f \n"))
print(dt.strftime("UTC offset >> %z \n"))
print(dt.strftime("Timezone >> %Z \n"))
print(dt.strftime("Day number of year 001-366 >> %j \n"))
print(dt.strftime("Week number of year, Sunday as the first day of week, 00-53 >> %U \n"))
print(dt.strftime("Week number of year, Monday as the first day of week, 00-53 >> %W \n"))
print(dt.strftime("Local version of date and time >> %c \n"))
print(dt.strftime("Century >> %C \n"))
print(dt.strftime("Local version of date >> %x \n"))
print(dt.strftime("Local version of time >> %X \n"))
print(dt.strftime("A percent character >> %% \n"))
print(dt.strftime("ISO 8601 year >> %G \n"))
print(dt.strftime("ISO 8601 weekday (1-7) >> %u \n"))
print(dt.strftime("ISO 8601 weeknumber (01-53) >> %V \n"))

That is it!

Sunday, June 4, 2023

Data Wrangling of GIS API Data Using Python

Data wrangling in the context of GIS (Geographic Information System) typically involves processing and manipulating spatial data to extract valuable insights or prepare it for further analysis.

In this post, we shall look at extracting API data to prepare it for further analysis in QGIS or any GIS software. Basically, we will use the two different API datasets listed below:-

1. Digital Atlas of the Roman Empire

2. REST countries

Lets get started... So we want to get the API data into a friendly format that a GIS software will read in for further analysis. In this case we want the format to be a spread sheet in .CSV extension.


 Digital Atlas of the Roman Empire

Just as the title suggest, the API provides information on cities of the Roman Empire.


import json
import requests
import pandas as pd

resp = requests.get('http://imperium.ahlfeldt.se/api/geojson.php').text
json_obj = json.loads(resp)
# --------------------------


json_obj_df = pd.DataFrame(json_obj)

data_list = []
for item in json_obj_df['features']:
    coordinates = json_obj_df['features'][0]['geometry']['coordinates']

    name = json_obj_df['features'][0]['properties']['name']
    ids = json_obj_df['features'][0]['properties']['id']
    ancient = json_obj_df['features'][0]['properties']['ancient']
    country = json_obj_df['features'][0]['properties']['country']
    types = json_obj_df['features'][0]['properties']['type']
    numType = json_obj_df['features'][0]['properties']['numType']
    precision = json_obj_df['features'][0]['properties']['precision']

    data = coordinates, name, ids, ancient, country, types, numType, precision
    data_list.append(data)
# --------------------------

data_list_df = pd.DataFrame(data_list)
data_list_df


REST countries

This is an API that provides information about countries via a RESTful API.


The code below is real world application where the data was wrangled and visualized using bokeh library.

# importing the modules
import json
import requests
from datetime import datetime

import pandas as pd

import pandas_bokeh # pip install pandas-bokeh
pandas_bokeh.output_notebook()

from bokeh.plotting import figure, output_file, show



# Bokeh is a Data Visualization library that provides interactive charts and plots.
# Use this command to install Bokeh: pip install bokeh

# Get API content using requests library...
response = requests.get('https://restcountries.com/v3.1/all')
data = json.loads(response.text)


# Write API data to text file...
fname = datetime.today().strftime('%Y%b%d%H%M%S')
with open(f'{fname}.txt', 'w', encoding="utf-8") as f:
    print(data, file=f)

# Write to CSV file..
df = pd.DataFrame(data)
df.to_csv(f'{fname}.csv', encoding="utf-8-sig", index=False)

# Read data from text file...
with open(f'{fname}.txt', 'r', encoding="utf-8") as f:
    txt_data = f.readlines()


# Prepare data for visualization using Bokeh....
common_name = [ x['name']['common'] for x in data ]
official_name = [ x['name']['official'] for x in data ]
population = [ x['population'] for x in data ]
region = [ x['region'] for x in data ]
continent = [ x['continents'][0] for x in data ]
area = [ x['area'] for x in data ]
latlng = [ x['latlng'] for x in data ]
lat_Y = [x[0] for x in latlng]
lng_X = [x[1] for x in latlng]


# Create scatter plot of countries latlong coordinates...
# create a new plot with a title and axis labels
p = figure(title="Coutries Location", x_axis_label="Longitude", y_axis_label="Latitude")

# add circle renderer with additional arguments
p.circle(
    lng_X,
    lat_Y,
    legend_label="Countries",
    fill_color="blue",
    fill_alpha=0.2,
    line_color="blue",
    size=8,
)


# show the results
show(p)

Happy coding...!