Python: Install OWSLib package on windows 7 64 bit

21 04 2014

20140421

OWSLib is a Python package for client programming with Open Geospatial Consortium (OGC) web service (hence OWS) interface standards, and their related content models. There are no binary package for windows but you can use this way to install.

 

step 1:

you need to install easy_install.exe it come with setuptools package. download setuptools link

after install setuptools you will have c:\Python27\Scripts\easy_inistall.exe

 

step 2:

open command prompt (terminal window) [how to open command prompt ]

type this in command prompt window

C:\Users\EnyMap>cd\
C:\>cd Python27\Scripts
C:\Python27\Scripts>easy_install.exe OWSLib

 

when this message show that mean package installed

Finished processing dependencies for OWSLib

C:\Python27\Scripts>

now you can test OWSLib by follow tutorial [Tutorial OWSLib]

enjoy! or leave comment 🙂

Advertisements




Pyahon: List data from two lists

11 12 2013

20131211

When we want to display data from 2 lists we can do this.

a = [1,2,3,4,5]

b = [6,7,8,9,0]

if we use zip funcetion

zip(a,b)

the output is [(1,6),(2,7),(3,8),(4,9),(5,0)]

we can display in loop for

for i in zip(a,b):

     pirnt i

the output will show

(1,6)

(2,7)

(3,8)

(4,9)

(5,0)

 





Python: OpenCV: Plot points on image

4 09 2013

Python: OpenCV: Plot points on image

20130904

use cv2 to plot points on image
point symbol like control point symbol

การพล๊อตข้อมูลจุดลงไปบนภาพ โดยกำหนดลักษณะของจุดเป็นแบบรูปจุดควบคุม

code:

import cv2
 if __name__ == '__main__':
 image067="""
    1,2725.816,1578.254
    2,2339.446,1381.908
    3,2263.594,1318.698
    4,2261.619,1222.698
    6,1941.855,1376.561
    7,1941.188,1288.783
    ...
    68,2357.619,1264.970
    """
 imageFile = r'ladybug067.jpg'
 imagePointList = data2List(image067)
 OriImage = cv2.imread(imageFile)

## plot point on image
 for i in imagePointList:
   pid,cx,cy = i
   cv2.circle(OriImage,(int(cx),int(cy)),10,(255,255,255),-11)
   cv2.circle(OriImage,(int(cx),int(cy)),11,(0,0,255),1) # draw circle
   cv2.ellipse(OriImage, (int(cx),int(cy)), (10,10), 0, 0, 90,(0,0,255),-1 )
   cv2.ellipse(OriImage, (int(cx),int(cy)), (10,10), 0, 180, 270,(0,0,255),-1 )
   cv2.circle(OriImage,(int(cx),int(cy)),1,(0,255,0),1) # draw center
   cv2.putText(OriImage,pid,(int(cx)+10,int(cy)-10),cv2.FONT_HERSHEY_COMPLEX_SMALL,1,(255,180,180))
 print 'plot points completed'
 outputfile = 'PlotPoint'+imageFile
 cv2.imwrite(outputfile,OriImage)

รูปร่างของจุดที่ได้

the symbol will like this cp





Python: read text file into list

24 12 2012

20121224

text file contain data of 15 ground point. file name is grounddata.txt

 15
 1 18160.153 -57509.869 1284.700 0.2 0.2 0.1
 2 24207.094 -54489.362 1341.192 0.2 0.2 0.1
 3 27248.245 -51442.223 824.272 0.2 0.2 0.1
 4 21195.711 -51470.131 946.992 0.2 0.2 0.1
 5 24000.0 -54000.0 1000.0 1000.0 1000.0 1000.0
 6 24000.0 -54000.0 1000.0 1000.0 1000.0 1000.0
 7 24000.0 -54000.0 1000.0 1000.0 1000.0 1000.0
 8 24000.0 -54000.0 1000.0 1000.0 1000.0 1000.0
 9 24000.0 -54000.0 1000.0 1000.0 1000.0 1000.0
 10 24000.0 -54000.0 1000.0 1000.0 1000.0 1000.0
 11 24000.0 -54000.0 1000.0 1000.0 1000.0 1000.0
 12 24000.0 -54000.0 1000.0 1000.0 1000.0 1000.0
 13 24000.0 -54000.0 1000.0 1000.0 1000.0 1000.0
 14 24000.0 -54000.0 1000.0 1000.0 1000.0 1000.0
 15 24000.0 -54000.0 1000.0 1000.0 1000.0 1000.0

the first line is number of points.
second line to end is point number, X, Y, Z, SDX,SDY,SDZ

I need to read text file and convert data from text to number and add them to list in Python.
I use this code

def num(s):
  try:
     return int(s)
  except ValueError:
     return float(s)
if __name__ == '__main__':
   filemane = 'grounddataTom.txt'
   with open(filemane,'r') as f:
     i = 0
     groundPointList = []
     for line in f:
       if i == 0:
         groundPoint = int(line)
       else:
         lineTxt = line.split()
         lineNum = []
           for j in lineTxt:
             lineNum.append(num(j))
           groundPointList.append(lineNum)
       i +=1
  print groundPoint
  print groundPointList

it work very well





Python: get last folder from path

7 12 2012

20121207

ต้องการใช้ชื่อโฟล์ดเดอร์สุดท้าย ไปใช้งานสามารถทำได้ดังนี้

code:

import os
mypath = ‘G:\Python\Sample\lastFolder’
print os.path.basename(os.path.normpath(mypath)

the result is “lastFolder”