openstreetmap - How to convert a set of osm files to shape files using ogr2ogr in python -


i believe question asked can't find answer placing before you. having problem while running script convert osm files shp files. script reading osm files creating 1 shp file of first osm file @ end instead of converting osm files. providing code used below. please kindly me in resolving me this.


from xml.dom import minidom import os, sys import xml.etree.elementtree et  ### ruta gdal-data c:\program files (x86)\postgresql\9.4\gdal-data  path = r"c:\users\administrator\desktop\checking\t2"  systemoutput = 'shp'   print ("\n#### execute python ny_osm2shapes") print ("#### monitoring cities") print ("#### conversor osm shapes") print ("#### osm path: " + path)  print "#### " """ modify win: c:/program files/gdal/gdal-data/osmconfig.ini linux: /usr/share/gdal/1.11/osmconfig.ini report_all_ways=yes #activate lines without tag attributes=landuse, plots #inside [lines] attributes=landuse, plots #inside [multipolygons] """  ### check if path argv try:     if len(sys.argv) >= 2:        print("#### path argv: ", sys.argv[1])        path = sys.argv[1]     else:        print "#### path set to", path        sys.exit() except:       pass   #### ogr config print "\n#### process: osm shapes" ogroutputtype = ''      #-f "esri shapefile"' ogrprojection = ''      # -t_srs epsg:4326' #+ epsg ogrprojectiona = ''     #-a_srs epsg:3827' ogrprojectionin = ''    #-s_srs epsg:3827' #-t_srs epsg:4326  ogrconfigtype = ' --config osm_use_custom_indexing no'  ogr2ogr = 'ogr2ogr %s %s %s %s %s %s -overwrite %s %s %s  %s layer %s'  ### process l in os.walk(path):     archivos = l[2]     ruta = l[0]  in archivos:     if a.endswith(".osm"):         osmfile = os.path.join(ruta, a)         folder = os.path.join(ruta, systemoutput)         shapefile = a[:-4]         ogrfileoutput = " -nln " + shapefile         print "archivo shape: ", shapefile,         layertype = shapefile[-1]           if layertype=="0":             print "\t tipo 0: circles"             ogrselectlayer = "lines"             ogrlcotype = ' -lco shpt=arc'             ogrselect = ' -select id_string'          elif layertype == "1":             print "\t tipo 1: blocks"             ogrselectlayer = "lines"             ogrlcotype = ' -lco shpt=arc'             ogrselect = ' -select land_use'          elif layertype == "2":             print "\t tipo 2: plots"             ogrselectlayer = "lines"             ogrlcotype = ' -lco shpt=arc'             ogrselect = ' -select plot'          elif layertype == "3":             print "\t tipo 3: medians"             ogrselectlayer = "lines"             ogrlcotype = ' -lco shpt=arc'             ogrselect = ' -select id_string'           else:             print "else error*"           systemoutput = ogr2ogr % (ogroutputtype, folder, osmfile, ogrprojectiona, ogrprojectionin, ogrprojection, ogrfileoutput, ogrlcotype, ogrconfigtype, ogrselect, ogrselectlayer)          #print ("fichero: ", osmfile, shapefile, layertype, ogrselectlayer)          os.system(systemoutput) print "end process" 

the way used os.walk returns in archivos osm files in last ruta of tree structure traversed. possibly (at least part of) problem, or may in future.

you have use os.walk differently:

import os, re  ext_regx = '\.osm$' archivos = []  ruta, dirs, archs in os.walk( path ) :     arch in archs :         if re.search( ext_regx, arch ) :             archivos.append( os.path.join( ruta, arch ) )  osmfile in archivos :     print( osmfile )     ... 

now if code inside for loop not mean to, issue. suggest you:

  1. add print( systemoutput ) check each command executed intend be.
  2. check files , dirs refered in command correct.

ps: each item in archivos contain dir part, have split folder part, instead of joining.

ps2: might need use double backslashes dirs. also, bear in mind os.sep.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -