piątek, 11 lutego 2011
poniedziałek, 7 lutego 2011
[linux] How many files of a certain type...
If you want to count how many files of a certain type or similar name you have (in linux), eg. all files starting with a word: "Report" - try:
find . -name 'Report*' | wc -l
- find
- . (dot) means here (in this catalogue)
- -name files or catalogues of a name...
- 'Report*' name starts with 'Report', asterisk means the rest of the name
- | and the result put to the another command...
- wc ... which is count
- -l means number of lines.
OGR in Python - an example
Required Python and GDAL.
1. Open Python
2. Import OGR module
3. Set data type
4. Open data source
5. Get layers (here we have only one)
And now we can e.g.:
6. Get layer extension
7. Get an object on the layer
8. Get attribute
9. Get object geometry
10. Get coordinates (point in this case).
from osgeo import ogr #2
driver = ogr.GetDriverByName('ESRI Shapefile') #3
dataSource = driver.Open('plik.shp',0) #4
layer = dataSource.GetLayer() #5
layer.GetExtent() #6
feature = layer.GetFeature(0) #7 (pobieramy obiekt pierwszy)
feature.GetField('ID') #8
geometry = feature.GetGeometryRef() #9
geometry.GetX() #10
geometry.GetY() #10
[PL: Przykład wykorzystania OGR (GDAL) w Python]
1. Open Python
2. Import OGR module
3. Set data type
4. Open data source
5. Get layers (here we have only one)
And now we can e.g.:
6. Get layer extension
7. Get an object on the layer
8. Get attribute
9. Get object geometry
10. Get coordinates (point in this case).
from osgeo import ogr #2
driver = ogr.GetDriverByName('ESRI Shapefile') #3
dataSource = driver.Open('plik.shp',0) #4
layer = dataSource.GetLayer() #5
layer.GetExtent() #6
feature = layer.GetFeature(0) #7 (pobieramy obiekt pierwszy)
feature.GetField('ID') #8
geometry = feature.GetGeometryRef() #9
geometry.GetX() #10
geometry.GetY() #10
______________________________________________________________
Src: Geoprocessing with Python using Open Source GIS
Src: Geoprocessing with Python using Open Source GIS
[py, gdal] GDAL for Python 2.7 installation package
If you have Python 2.7 and want to install GDAL library and you can't find it there:
http://download.osgeo.org/gdal/win32/1.7/
ftp://ftp.remotesensing.org/gdal/win32/1.7/
Try there:
http://www.lfd.uci.edu/~gohlke/pythonlibs/
http://download.osgeo.org/gdal/win32/1.7/
ftp://ftp.remotesensing.org/gdal/win32/1.7/
Try there:
http://www.lfd.uci.edu/~gohlke/pythonlibs/
niedziela, 6 lutego 2011
cx_Oracle - how to get SDO_GEOMETRY data
#Let's connect to the database
#we need some spatial data
#ok, what do we have?
# you MUST know (or read here) the you can use attributes from SDO_GEOMETRY object in ORCL, like:
#'SDO_GTYPE','SDO_SRID','SDO_POINT','SDO_ELEM_INFO','SDO_ORDINATES'
import cx_Oracle
orcl = cx_Oracle.connect ('scott/tiger@orcl')
c = orcl.cursor()
#we need some spatial data
sql = "SELECT geom FROM geometry_tab WHERE (...)"
res = c.execute(sql)
obj = res.fetchone()[0]
#ok, what do we have?
obj
<cx_Oracle.OBJECT object at 0x0158A4C0>
#if you type dir(obj) you will not get the attributes names - try..# you MUST know (or read here) the you can use attributes from SDO_GEOMETRY object in ORCL, like:
#'SDO_GTYPE','SDO_SRID','SDO_POINT','SDO_ELEM_INFO','SDO_ORDINATES'
obj.SDO_GTYPE
2003.0
obj.SDO_ELEM_INFO
[1.0, 1003.0, 1.0]
obj.SDO_ORDINATES
[20.623358189, 52.88806347, 20.623203441, 52.887897231000004, 20.623488043000002, 52.887861954, (...) , 52.888026894, 20.623358189, 52.88806347]
Subskrybuj:
Posty (Atom)