[OSGeo-Discuss] Conversion and filtering using ogr2ogr...

Kjell Are Refsvik kjell.a.refsvik at hiof.no
Mon Sep 15 02:45:26 PDT 2008


Hi,

First of all. I need to say thank you to Tyler Mitchell and to the  
rest of you that took the time this summer to aid me as I took my  
first steps into the geospatial universe. I would not have been able  
to do today with your help, and I am very grateful for the fact that  
you take time to help a newbie.

I am slowly learning and currently, I am at a point where I am able to  
convert my shapefiles between different SRS and also different formats.

Still - the goal of my small project is to make a unix shell script  
that use gnuplot to draw a map using data from a CSV file and place  
references on the map from geotagged images jpeg images:

http://www.ia-stud.hiof.no/~kjellare/misc/20080915_maps.png
(http://www.ia-stud.hiof.no/~kjellare/misc/20080915_plotmap.sh)

...to ultimately arrive at my own online photo album solution with  
embedded maps:
http://www.ia-stud.hiof.no/~kjellare/misc/20080902_programming_goal.jpg

With significant text-filtering efforts, I have been able to get a  
small rudimentary map of Norway going, but with a much more detailed  
map of Lebaonon on my hands, I would like to see if ogr2ogr could be  
used to output what I need directly.

Using ogr2ogr, I have been able to convert a map of the different  
regions of Lebanon from UTM to WGS84 using the following command:

ogr2ogr ~/Desktop/Lebanon_cadast.kml cadast_limits.shp -f "KML" -t_srs  
epsg:4326
(http://www.ia-stud.hiof.no/~kjellare/misc/20080915_lebanon_cadast_kml.png 
)

I could proceed to format the .kml file using sed and awk (basic text- 
processing programs in UNIX) to get output in the format I need, where  
the different poly-lines are simply divided by a blank line and a  
comment:

.
.
.
10.460277557373047     60.025833129882812
10.472221374511719     60.025833129882812
10.487220764160156     60.020828247070312

#Buskerud
8.190235137939453     61.079093933105469
8.203887939453125     61.093887329101562
8.212221145629883     61.100273132324219
.
.
.

...but I would like to use ogr2ogr to output a csv file directly with  
only the lon/lat values for the polygons. The following command:

ogr2ogr ~/Desktop/Lebanon_cadast.txt cadast_limits.shp -f "CSV" -t_srs  
epsg:4326

...provides me with a file with a bit too much information (and  
seemingly also lacking lon/lat references):

AREA 
,PERIMETER 
,CADAST_LIM 
,CADAST_L_1 
,ACS_CODE 
,CAD_CODE 
,ACS_NAME 
,CAD_NAME 
,ADMIN_CAZA 
,CAD_CAZA 
,ACS_CD_SP,UN_ID,KADA_NA,MOH_NA1,POP_AREA,POP_SUR1,LOG_SUT,LOG_SUR
11578600.00000000000,  14680.00000000000,2,1,   
35511.00000000000,35049,Dayret Nahr El-Kabir,Dayret Nahr El-Kébir,      
12.00000000000,     12.00000000000,   
35511.00000000000,2,Akkar,North,         0.8,       168.47,          
0.17,        34.00
19425900.00000000000,  39285.89843750000,3,30,   
35437.00000000000,35046,Machta Hammoud,Machta Hammoud,      
12.00000000000,     12.00000000000,   
35437.00000000000,3,Akkar,North,         4.6,        99.68,          
0.91,        19.00
88091000.00000000000,  78644.79687500000,4,33,   
35516.00000000000,35168ND,Mazareaa Jabal Akroum,Akroum,      
12.00000000000,     12.00000000000,   
35516.00000000000,4,Akkar,North,         0.6,        63.43,          
0.16,        16.00
4221400.00000000000,  12320.20019531250,5,35,   
35273.00000000000,35013,AAridet Cheikh Zennad,Arida,      
12.00000000000,     12.00000000000,   
35273.00000000000,5,Akkar,North,         2.1,        99.27,          
0.36,        17.00
3346430.00000000000,  12348.29980468750,6,40,   
35271.00000000000,35014,Sammaqiyé,Al-Semmakié,     12.00000000000,      
12.00000000000,  35271.00000000000,6,Akkar,North,         2.9,        
104.59,         0.48,        17.00
2740910.00000000000,   9681.73046875000,7,51,   
35263.00000000000,35106,Janine,Janine,     12.00000000000,      
12.00000000000,  35263.00000000000,7,Akkar,North,         0.4,          
0.00,         0.06,         0.00
.
.
.

I would very much appreciate it if any of you could point me in the  
direction of how to use ogr2ogr to filter/convert the information I  
need to get to my goal.

Sincerely,

Kjell Are Refsvik
Student - Information Technology
Ostfold University College
Dept. of Information Technology
http://refsvik.no


More information about the Discuss mailing list