[OSGeo Africa] Batch conversion from shp to kml

Zibusiso Ncube ncubezedm at gmail.com
Mon Aug 15 06:11:51 PDT 2016


Hi Mnqweno

 i realised i had some errors in the little idea i sent earlier...maybe try
and modify this one i wrote quickly ..it might have some errors so just
play around with it till it works and if i have time i will write someting
for you tomorrow.

'''
Created on 15 Aug 2016

@author: NcubeZ
'''
"""
 download and install your system specific GDAL binaries from
https://trac.osgeo.org/gdal/wiki/DownloadingGdalBinaries
 or ask through another email and gurus like Tim can help you

 """
from convertor import ogr2ogr
import os

from osgeo import ogr


def filePathNamesList(directoryPath, extension):
    """ List of all files of a specific extension within a specific
directory

        path - directory in which the files are contained e.g
C:\\dir\\subDir\\subSubDir\\subSubSubDir
        extension - file extension e.g. .txt

    """
    fileList=[]
    for f in os.listdir(directoryPath):
        if f.endswith(extension):
            fileList.append(directoryPath +"\\" +f)

    return fileList

def convertshptokml(outputPath,inputPath):
    """ OGR2OGR """
    ogr2ogr.main(['-f', 'KML', outputPath,inputPath])

    #################
    #in your main
    #################


def main():

    #pathList=None

   '''
    you could add some method to iterate through sub directories and get
all path names
    and returns a fullist of all shpfiles within your work directory
instead of my smallanyana
    methodinyana i used as an example
   but for now it is just the input of directory where your shapefile are
immediately contained, it will not search further in sub directories
'''

    pathList=filePathNamesList(r"C:\Users\Zibusiso\Desktop\TestShapefiles",
extension)
    extension=".shp"

    #print(pathList)

    for shpPath in pathList:
        #remove .shp and add .kml to path name
        kmlPath=path[:-4]+".kml"
        convertshptokml(kmlPath, shpPath)
        outputPath=None


if __name__ == "__main__":
    main()


Regards

Zibusiso M Ncube


On Mon, Aug 15, 2016 at 1:04 PM, Mnqweno Mnyengeza <mnqwenom at statssa.gov.za>
wrote:

> Dear All
>
> I need to convert approximately thirteen million  points from shp2kml
> using QGIS. I have already split the points into their respective
> provinces, districts and the lowest level of demarcation which is an
> enumeration area (EA) here at Statistics South Africa. The output file of
> the split is the sub-folder named the EA reference number and containing
> the points and polygon of that particular EA. I now need to batch process
> this conversion using QGIS batch file processor if any is available or any
> other free open source tool that can easily serve the purpose.
>
> Please assist
>
>
> Kind regards
>
> Mnqweno Mnyengeza (Mr)
>
> Professional GIS Practitioner
> Geography
> 082 9048267 (Mobile)
> Statistics South Africa
> "..*.people are very quick to notice the change in your attitude towards
> them but always ignore their unacceptable behavior that led to your change*
> ....."
>
>
>
>
> _______________________________________________
> Africa mailing list
> Africa at lists.osgeo.org
> You can UNSUBSCRIBE at http://lists.osgeo.org/mailman/listinfo/africa
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/africa/attachments/20160815/b521fb76/attachment.html>


More information about the Africa mailing list