<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by KIPYEGON AMOS on Medium]]></title>
        <description><![CDATA[Stories by KIPYEGON AMOS on Medium]]></description>
        <link>https://medium.com/@kiptoamos?source=rss-68165224313f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*rLzKWQojdfJY52W1</url>
            <title>Stories by KIPYEGON AMOS on Medium</title>
            <link>https://medium.com/@kiptoamos?source=rss-68165224313f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 21:30:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kiptoamos/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[GIS programming (introduction to Raster data type)]]></title>
            <link>https://medium.com/@kiptoamos/gis-programming-introduction-to-raster-data-type-cac502329214?source=rss-68165224313f------2</link>
            <guid isPermaLink="false">https://medium.com/p/cac502329214</guid>
            <dc:creator><![CDATA[KIPYEGON AMOS]]></dc:creator>
            <pubDate>Sun, 30 Jul 2023 12:50:38 GMT</pubDate>
            <atom:updated>2023-07-30T12:50:38.077Z</atom:updated>
            <content:encoded><![CDATA[<p>i n case you need to freshen up with vector data you can follow in this link, <a href="https://medium.com/@kiptoamos/gis-programming-for-beginners-5a7de0b4da9">Introduction to GIS programming (vector)</a></p><p>Raster data type is collection of rows and columns of pixels where each pixel represent a value between 0 and 255.</p><blockquote>In GIS, Remote Sensing Image (Raster) is made up pixel with Values that represent Digital Numbers (DN) which represent the intensity or strength of electromagnetic energy measured for ground.<br>- as a satellite vehicle orbits it carry a sensor that emits electromagnetic energy, features on the surface of the earth has different reflectance.<br>- python reads Raster image in form of 2D Numpy arrays, where each pixel represent different index.<br>- Numpy library is installed automatically when pandas is installed.</blockquote><p>Numpy simply means numeric python num -numeric py — python<br>- — it is use in processing array of values/numbers all of the same data type and are indexed by tubles of positive integers.<br>- it can be installed independently by<br>pip install Numpy<br>Numpy array class is called ndarray or alias</p><h3>Array</h3><p>. it is an ordered sequence of values arranged in an n-dimention<br> np.nan represent NoData<br> . Transposing array means changing rows to column<br>array.</p><h3><strong>create a 2-d ARRAY</strong></h3><pre>import numpy as np<br>array_values = np.array([<br>    [1,2,3,4],<br>    [5,6,7,8]<br>])<br># checking type of array<br>print(&quot;Array is of type: &quot; ,type(array_values))<br><br>#checking the dimention of array<br>print(&quot;Array dimention is :&quot;,array_values.ndim)<br><br># checking array total size<br>print(&quot;Array has a total siza of&quot;, array_values.size)<br># checking shape of an array<br>print(&quot;the shape of array is: &quot;, array_values.shape)</pre><h3>ways of creating array.</h3><p>arrays can be created from <br>1. list of values np.array([1,2,3])<br>2. create from tuples np.array((1,2,3,4))<br>3. from random values np.random.random((2,3))<br>np.nan is use in accessing null values</p><h3><strong>simple raster</strong></h3><p><strong>import required libraries</strong></p><pre>import numpy as np<br>from matplotlib import pyplot as plt<br>import rasterio<br>from rasterio.plot import show</pre><pre>data= np.random.random((10,10)) # 2 represent dimention (height) , 3 represent number of bands and 6 represent widht (2,3) represent shape<br><br># converting array to list<br>li=data.tolist()<br># plotting<br>show(data)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*daN59KraiHLNz_uZCAkqEQ.png" /><figcaption>Raster image from array of values</figcaption></figure><h3>Dealing with Spatial Raster</h3><p>. 2-d array in raster represent single band<br>. 3-d — multy band<br><strong>characteristics of raster</strong><br>- Area is subdivided into grids with equal cells<br>- each piel has only one value of DN<br>- X and Y of pixel is spatial resolution, so area is simply culculated as area of 1 pixel multibly by total number of pixels. (x*y) * Number of cells</p><p>. each pixel value in raster represent reflectance value of feature on the surface of the earth</p><h3><strong>Creating Raster from scratch</strong></h3><p>Geospatial raster is made up of array of values linked to geographic information with the following characteristics -:</p><p>1. Transformation matrix linking pixel index with coordintes (x minimum and y maximum, origin (0,0))</p><h3><strong>example</strong></h3><p><em>if raster values is ploted in a cartesian plane without transformation the north-west cordinate values is (0,0) since rasterio will plot based on index values,in order to plot this in its position on earth surface we need a transformation matrix that will transform this “cordinadte”(0,0) to exact cordinates on the surface,<br>- resolution (pixel size) it is delta x and delta uy, for a Landsat image it is 30m</em></p><p>2. coordinate reference system SRC<br>3. meta data which is pass as a dictionary</p><h3><strong>Note that : there is difference between Transformation and Projection.</strong></h3><p><em>projection is transformation of spherical earth into a planar surface<br>- when Transformation is done it causes different distortion on <br>1. shape<br>2. area<br>3. direction<br>4. shape <br>types of map projectio includes -:<br>- conformal- local shapes are preserved<br>- equal area — areas are preserved<br>- Azimuthal — direction from a single location to all location are preseved<br>- equidistrance — distance to all other location are preserved<br>- — projection surface include<br>1. Cylinder<br>2. cone<br>3. plane</em></p><p><em>Transformation take a matrix for changing values<br>- transform (1,5) with factor (2,-3) = new coordinates will be (3,2)</em></p><h3><strong>steps</strong></h3><p>creating random array of values values using Numpy and reshaping it into a two dimensional</p><p>we use round() function to round off to a 4 decimal place by passing 4 to the function</p><p>Another function to arrange values in in numpy is np.arrange(fro,to dtypes=uint8)</p><ul><li>Create 10000 random numbers between 0 and 255<br><em>1. np.random.uniform(0,255,100) <br>2. reshape the numpy array to relfect 2d of raster</em></li></ul><pre>arr_val =np.random.uniform(0,255,10000)<br>data=arr_val.reshape(100,100).round(4)<br>#de # de.dtype=np.uint8 to convert to intergers<br># plotting<br>show(data)</pre><figure><img alt="raster image of random array of values" src="https://cdn-images-1.medium.com/max/488/1*OWbJNPlEiCbYHRJne0zT6w.png" /><figcaption>raster of random points with values (0–255)</figcaption></figure><ol><li>count — — → Number of layers(bands)</li><li>height — → Number of Rows</li><li>width — — → Number of columns</li></ol><h3><strong>transforming to position on earth</strong></h3><p>in this example we will use abitrary tranformation.</p><p>. let set origin “(0.0)” to be<br>1. xmin,ymax =(10000,5000)<br>2. Resolution to be delta x, delta y(2,-2)<br>- this will mean that x values will be increasing by 2 from the x transformation matrix and y will be reducing by 2 from transformation matrix<br>- Affine(delta_x, 0.0, xmin,<br> 0.0, delta_y, ymax).</p><h3><strong>example</strong></h3><p>- [0,0]=10000,5000<br>- [0,1] =(10000, 4998); [0,2]= (10000,4996) <br>- [1,0] = (10002,5000); [2,0] = (10004,5000)<br>- [xn,yn] =((10000+(2*n)),( 5000-(2*n)))</p><p>. lets define our transformation in practice<br>- lets define corner coordinates and resolution</p><pre>spatial_attributes=rasterio.transform.from_origin(<br>west= 10000,# xmin<br>north= 5000, # ymax<br>xsize= 2, # delta_x<br>ysize= 2) # delta_y<br><br>spatial_attributes<br># plotting<br>show(data, transform= spatial_attributes)<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*AIc2wzDupC2iCmTV5TDPpA.png" /><figcaption>image of transform data</figcaption></figure><p>above raster is the same with previous only that it has undergo transformation</p><h3><strong>Writing Raster</strong></h3><p>spatial raster has metadata</p><h3><strong><em>lets define our metadata for above data</em></strong></h3><pre>meta={<br>    &#39;driver&#39;:&#39;GTiff&#39;,<br>    &#39;count&#39;:1,<br>    &#39;height&#39;:data.shape[0],<br>    &#39;width&#39;: data.shape[1],<br>    &#39;dtype&#39;:data.dtype,<br>    &#39;transform&#39;: spatial_attributes<br>}</pre><ul><li>we are passing value and key arguments (kwargs) using ** name</li></ul><pre>new_dt=rasterio.open(&quot;datatif&quot;,&#39;w&#39;, **meta)<br>new_dt.write(data,1)<br>new_dt.close()</pre><p>alternatively; we may pass all data as:</p><pre><br>new_data= rasterio.open(&quot;raster.tif&quot;, &#39;w&#39;,<br>                       driver=&#39;GTiff&#39;,<br>    count=1,<br>    height=data.shape[0],<br>    width= data.shape[1],<br>    dtype=data.dtype,<br>    transform= spatial_attributes)<br>new_data.write(data,1)<br>new_data.close()</pre><p>we can now open the saved raster</p><pre>de_r=rasterio.open(&quot;raster.tif&quot;)<br>rd=de_r.read()<br>rd</pre><pre><br>fig,ax =plt.subplots()<br>rasterio.plot.show(de_r,transform= spatial_attributes,ax=ax,title=&quot;random&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*ZdOsyFS97kJ21iu8qBFX5A.png" /><figcaption>raster image after writing</figcaption></figure><p>we can check meta data</p><pre>de_r.meta</pre><figure><img alt="metadata" src="https://cdn-images-1.medium.com/max/533/1*NcyPuFSKihrAu9p0ccESJw.png" /><figcaption>metadata</figcaption></figure><p>s<em>tay tuned for more and more # Geospatial to Transform view of The world. from Agriculture,Climate, Business, Infrastructure, communication, Politics and many more application</em></p><p>you cane get Jupiter notebook code here <a href="https://github.com/KIPYEGON2000/GIS_programming_Raster/blob/main/into_raster.ipynb">GIS Programming with raster</a></p><p>find and follow me at <em>Twitter </em><a href="https://twitter.com/kiptoamos">@kiptoamos</a></p><p>follow and connect with me at<em> LinkedIn</em> <a href="http://www.linkedin.com/in/kipyegon-amos-287a2a1a3">Kipyego Amos</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cac502329214" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GIS programming for Beginners]]></title>
            <link>https://medium.com/@kiptoamos/gis-programming-for-beginners-5a7de0b4da9?source=rss-68165224313f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a7de0b4da9</guid>
            <dc:creator><![CDATA[KIPYEGON AMOS]]></dc:creator>
            <pubDate>Sat, 22 Jul 2023 11:32:44 GMT</pubDate>
            <atom:updated>2023-07-22T20:33:33.559Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction to GIS programming (vector)</h3><p><strong><em>GIS </em></strong>is a technological field that is use to store, creates, manages, analyzes, and display spatial data along with none spatial data called <strong><em>attributes</em></strong></p><h3>Types of spatial data</h3><ol><li>vector data types (points,lines and polygons)</li><li>raster( Stored in Grid/pixel)</li></ol><h3><strong>GIS programming</strong></h3><p>it is writing code or programs that automate (storage,creation,analysis , management and display) of spatial data.</p><h3><strong>Area of specialization in GIS programming</strong></h3><ol><li>web mapping (web developer)</li><li>Desktop GIS</li><li>GIS database</li></ol><blockquote><strong>why do i need GIS programming</strong><br>in most cases existing software and programs was written to ‘fit’ individual needs at that particular time hence some functionalities might not address current problem on hand.</blockquote><blockquote>make work easy by automating boring process (combining different process that you could have been waiting and clicking in existing software)<br>2. flexibility — you can be able to manipulate process to fit your desire<br>3. safes on time</blockquote><p><strong>Best libraries to start with and not limited to</strong><br>1. Pandas<br>2. matplotlib<br>3. geopandas<br>4. shapely<br>5. rasterio<br>6. numpy</p><p><strong>Pandas</strong></p><blockquote>it is a open source easy to use rich python library desighned for data anallysis<br> Reading data from Different file types to pandas</blockquote><ol><li>CSV — → read_csv()<br>2. JASON — -&gt;read_json()<br>3. HTML — -&gt; READ_HTML()<br>4. XML — → read_xml()<br>5. SQL — → read_sql()<br>6. excel — → read_excel()</li></ol><p><strong>Creating a DataFrame and Series</strong></p><p>DataFrame is a 2-d (table -like) and is 1–D data structure</p><p>import required libraries</p><pre>import matplotlib.pyplot as plt<br>import pandas as pd<br>import geopandas as gpd<br>import shapely.geometry<br>import numpy as np<br>from shapely.geometry import Point,Polygon</pre><p>Lets create an empty dataframe</p><pre>data=pd.DataFrame()<br>print(data)</pre><p>ways of creating dataframe</p><p>Method 1. dictionary of list</p><pre>coordinates={<br>    &quot;x&quot;:[2,3,4,5,6,],<br>    &quot;y&quot;:[7,8,9,0,11]<br>}<br>#DataFrame creation<br>df=pd.DataFrame(coordinates)<br>df</pre><p>Method 2. pandas series</p><pre>#creating a dataframe from a dictionary of series<br>x=pd.Series([1,2,3,4,5,6,7,8,9])<br>y=pd.Series([1,2,3,4,5,6,7,8,9])<br>#DtataFrame<br>df1=pd.DataFrame({&quot;x&quot;:x,&#39;y&#39;:y})<br>df1</pre><p>Method 3. list</p><pre>#creating from list<br>data=[<br>    [1,2],<br>    [2,2],<br>    [3,4],<br>    [2,7]<br>]<br>df2=pd.DataFrame(data,columns=[&quot;x&quot;,&quot;y&quot;])<br>df2</pre><p>Method 4. Dictionaries</p><pre>#fromlist of dictionaries<br>data=[<br>    {&quot;name&quot;:&quot;Amos&quot;,&quot;age&quot;:23},<br>    {&quot;name&quot;:&quot;John&quot;,&quot;age&quot;:20}<br>]<br>df3=pd.DataFrame(data,index=[&#39;a&#39;,&#39;b&#39;])<br>df3</pre><p>exploring numpy functionalities.</p><p>creating a function that create random points from a polygon it takes 2 arguments<br>1. polygon<br>2. number of random points<br>polygon has xmin,ymin, xmax,ymax</p><pre>def randm(poly, number):<br>    xmin,ymin, xmax,ymax = poly.bounds<br>  <br>    x=np.random.uniform(xmin,xmax,number)<br>  <br>    y=np.random.uniform(ymin,ymax,number)<br>    return x,y</pre><pre>polygon = Polygon([[0,0],[0,20],[30,20],[30,-0.5],[0,0]]) #create a polygon using shapely geometry<br>x,y=randm(polygon,100)<br>x = x.round(3)<br>y= y.round(3)</pre><p>convert random points to list of points each representing location in Cartesian plane. first create an empty dataframe and pass there results</p><pre>df = pd.DataFrame()<br>df[&#39;geometry&#39;] = list(zip(x,y))<br>df</pre><p><strong>pandas dataframe from random points</strong></p><p>convert the list of coordinates to Shapely points using the following line of code. then convert pandas dataframe to Geopandas dataframe</p><pre>df[&#39;geometry&#39;] = df[&#39;geometry&#39;].apply(Point)<br><br>dta=gpd.GeoDataFrame(df)<br>dta</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*M3oHj9I8sxk09Zt47P5iSA.png" /><figcaption>GeoDataFrame from Pandas DF</figcaption></figure><p>plotting</p><pre>dta.plot()<br><br># plotting specific column and adding legend<br>#dta.plot(column=&#39;column_name&#39;,legend=True)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*b0cufo61CNJprkAU_-UQNg.png" /><figcaption>plotting (X,Y) of points</figcaption></figure><p>Find code from GitHub <a href="https://github.com/KIPYEGON2000/GIS_programming/blob/main/introduction.ipynb">KIPYEGON</a></p><p>find and follow me at Twitter <a href="https://twitter.com/kiptoamos">@kiptoamos</a></p><p>follow me at LinkedIn <a href="http://www.linkedin.com/in/kipyegon-amos-287a2a1a3">Kipyego Amos</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a7de0b4da9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>